Skip to content

Commit 24f9515

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fixes from Paolo Bonzini: "ARM: - Clear the pending exception state from a vcpu coming out of reset, as it could otherwise affect the first instruction executed in the guest - Fix pointer arithmetic in address translation emulation, so that the Hardware Access bit is set on the correct PTE instead of some other location s390: - Fix deadlock in new memory management - Properly handle kernel faults on donated memory - Fix bounds checking for irq routing, with selftest - Fix invalid machine checks and log all of them" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: arm64: Fix the descriptor address in __kvm_at_swap_desc() KVM: s390: vsie: Avoid injecting machine check on signal KVM: s390: log machine checks more aggressively KVM: s390: selftests: Add IRQ routing address offset tests KVM: s390: Limit adapter indicator access to mapped page s390/mm: Add missing secure storage access fixups for donated memory KVM: arm64: Discard PC update state on vcpu reset KVM: s390: Fix a deadlock
2 parents 45f667e + 52dad81 commit 24f9515

14 files changed

Lines changed: 144 additions & 22 deletions

File tree

arch/arm64/kvm/at.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ int __kvm_at_swap_desc(struct kvm *kvm, gpa_t ipa, u64 old, u64 new)
17531753
if (!writable)
17541754
return -EPERM;
17551755

1756-
ptep = (u64 __user *)hva + offset;
1756+
ptep = (void __user *)hva + offset;
17571757
if (cpus_have_final_cap(ARM64_HAS_LSE_ATOMICS))
17581758
r = __lse_swap_desc(ptep, old, new);
17591759
else

arch/arm64/kvm/reset.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,20 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
247247
kvm_vcpu_set_be(vcpu);
248248

249249
*vcpu_pc(vcpu) = target_pc;
250+
251+
/*
252+
* We may come from a state where either a PC update was
253+
* pending (SMC call resulting in PC being increpented to
254+
* skip the SMC) or a pending exception. Make sure we get
255+
* rid of all that, as this cannot be valid out of reset.
256+
*
257+
* Note that clearing the exception mask also clears PC
258+
* updates, but that's an implementation detail, and we
259+
* really want to make it explicit.
260+
*/
261+
vcpu_clear_flag(vcpu, PENDING_EXCEPTION);
262+
vcpu_clear_flag(vcpu, EXCEPT_MASK);
263+
vcpu_clear_flag(vcpu, INCREMENT_PC);
250264
vcpu_set_reg(vcpu, 0, reset_state.r0);
251265
}
252266

arch/s390/include/asm/kvm_host.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,9 @@ void kvm_arch_crypto_clear_masks(struct kvm *kvm);
710710
void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
711711
unsigned long *aqm, unsigned long *adm);
712712

713+
#define SIE64_RETURN_NORMAL 0
714+
#define SIE64_RETURN_MCCK 1
715+
713716
int __sie64a(phys_addr_t sie_block_phys, struct kvm_s390_sie_block *sie_block, u64 *rsa,
714717
unsigned long gasce);
715718

arch/s390/include/asm/stacktrace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct stack_frame {
6262
struct {
6363
unsigned long sie_control_block;
6464
unsigned long sie_savearea;
65-
unsigned long sie_reason;
65+
unsigned long sie_return;
6666
unsigned long sie_flags;
6767
unsigned long sie_control_block_phys;
6868
unsigned long sie_guest_asce;

arch/s390/kernel/asm-offsets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int main(void)
6363
OFFSET(__SF_EMPTY, stack_frame, empty[0]);
6464
OFFSET(__SF_SIE_CONTROL, stack_frame, sie_control_block);
6565
OFFSET(__SF_SIE_SAVEAREA, stack_frame, sie_savearea);
66-
OFFSET(__SF_SIE_REASON, stack_frame, sie_reason);
66+
OFFSET(__SF_SIE_RETURN, stack_frame, sie_return);
6767
OFFSET(__SF_SIE_FLAGS, stack_frame, sie_flags);
6868
OFFSET(__SF_SIE_CONTROL_PHYS, stack_frame, sie_control_block_phys);
6969
OFFSET(__SF_SIE_GUEST_ASCE, stack_frame, sie_guest_asce);

arch/s390/kernel/entry.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ SYM_FUNC_START(__sie64a)
200200
stg %r3,__SF_SIE_CONTROL(%r15) # ...and virtual addresses
201201
stg %r4,__SF_SIE_SAVEAREA(%r15) # save guest register save area
202202
stg %r5,__SF_SIE_GUEST_ASCE(%r15) # save guest asce
203-
xc __SF_SIE_REASON(8,%r15),__SF_SIE_REASON(%r15) # reason code = 0
203+
xc __SF_SIE_RETURN(8,%r15),__SF_SIE_RETURN(%r15) # return code = 0
204204
mvc __SF_SIE_FLAGS(8,%r15),__TI_flags(%r14) # copy thread flags
205205
lmg %r0,%r13,0(%r4) # load guest gprs 0-13
206206
mvi __TI_sie(%r14),1
@@ -237,7 +237,7 @@ SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL)
237237
xgr %r4,%r4
238238
xgr %r5,%r5
239239
lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
240-
lg %r2,__SF_SIE_REASON(%r15) # return exit reason code
240+
lg %r2,__SF_SIE_RETURN(%r15) # return sie return code
241241
BR_EX %r14
242242
SYM_FUNC_END(__sie64a)
243243
EXPORT_SYMBOL(__sie64a)

arch/s390/kernel/nmi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
487487
mcck_dam_code = (mci.val & MCIC_SUBCLASS_MASK);
488488
if (test_cpu_flag(CIF_MCCK_GUEST) &&
489489
(mcck_dam_code & MCCK_CODE_NO_GUEST) != mcck_dam_code) {
490-
/* Set exit reason code for host's later handling */
491-
*((long *)(regs->gprs[15] + __SF_SIE_REASON)) = -EINTR;
490+
/* Set sie return code for host's later handling */
491+
((struct stack_frame *)regs->gprs[15])->sie_return = SIE64_RETURN_MCCK;
492492
}
493493
clear_cpu_flag(CIF_MCCK_GUEST);
494494

arch/s390/kvm/gaccess.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,8 @@ static int _do_shadow_pte(struct gmap *sg, gpa_t raddr, union pte *ptep_h, union
14341434
if (rc)
14351435
return rc;
14361436

1437-
pgste = pgste_get_lock(ptep_h);
1437+
if (!pgste_get_trylock(ptep_h, &pgste))
1438+
return -EAGAIN;
14381439
newpte = _pte(f->pfn, f->writable, !p, 0);
14391440
newpte.s.d |= ptep->s.d;
14401441
newpte.s.sd |= ptep->s.sd;
@@ -1444,7 +1445,8 @@ static int _do_shadow_pte(struct gmap *sg, gpa_t raddr, union pte *ptep_h, union
14441445
pgste_set_unlock(ptep_h, pgste);
14451446

14461447
newpte = _pte(f->pfn, 0, !p, 0);
1447-
pgste = pgste_get_lock(ptep);
1448+
if (!pgste_get_trylock(ptep, &pgste))
1449+
return -EAGAIN;
14481450
pgste = __dat_ptep_xchg(ptep, pgste, newpte, gpa_to_gfn(raddr), sg->asce, uses_skeys(sg));
14491451
pgste_set_unlock(ptep, pgste);
14501452

arch/s390/kvm/interrupt.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,6 +2724,9 @@ static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap)
27242724

27252725
bit = bit_nr + (addr % PAGE_SIZE) * 8;
27262726

2727+
/* kvm_set_routing_entry() should never allow this to happen */
2728+
WARN_ON_ONCE(bit > (PAGE_SIZE * BITS_PER_BYTE - 1));
2729+
27272730
return swap ? (bit ^ (BITS_PER_LONG - 1)) : bit;
27282731
}
27292732

@@ -2824,6 +2827,12 @@ void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu,
28242827
int rc;
28252828

28262829
mci.val = mcck_info->mcic;
2830+
2831+
/* log machine checks being reinjected on all debugs */
2832+
VCPU_EVENT(vcpu, 2, "guest machine check %lx", mci.val);
2833+
KVM_EVENT(2, "guest machine check %lx", mci.val);
2834+
pr_info("guest machine check pid %d: %lx", current->pid, mci.val);
2835+
28272836
if (mci.sr)
28282837
cr14 |= CR14_RECOVERY_SUBMASK;
28292838
if (mci.dg)
@@ -2852,6 +2861,7 @@ int kvm_set_routing_entry(struct kvm *kvm,
28522861
struct kvm_kernel_irq_routing_entry *e,
28532862
const struct kvm_irq_routing_entry *ue)
28542863
{
2864+
const struct kvm_irq_routing_s390_adapter *adapter;
28552865
u64 uaddr_s, uaddr_i;
28562866
int idx;
28572867

@@ -2862,6 +2872,14 @@ int kvm_set_routing_entry(struct kvm *kvm,
28622872
return -EINVAL;
28632873
e->set = set_adapter_int;
28642874

2875+
adapter = &ue->u.adapter;
2876+
if (adapter->summary_addr + (adapter->summary_offset / 8) >=
2877+
(adapter->summary_addr & PAGE_MASK) + PAGE_SIZE)
2878+
return -EINVAL;
2879+
if (adapter->ind_addr + (adapter->ind_offset / 8) >=
2880+
(adapter->ind_addr & PAGE_MASK) + PAGE_SIZE)
2881+
return -EINVAL;
2882+
28652883
idx = srcu_read_lock(&kvm->srcu);
28662884
uaddr_s = gpa_to_hva(kvm, ue->u.adapter.summary_addr);
28672885
uaddr_i = gpa_to_hva(kvm, ue->u.adapter.ind_addr);

arch/s390/kvm/kvm-s390.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4617,7 +4617,7 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)
46174617
return 0;
46184618
}
46194619

4620-
static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)
4620+
static int vcpu_post_run(struct kvm_vcpu *vcpu, int sie_return)
46214621
{
46224622
struct mcck_volatile_info *mcck_info;
46234623
struct sie_page *sie_page;
@@ -4633,14 +4633,14 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)
46334633
vcpu->run->s.regs.gprs[14] = vcpu->arch.sie_block->gg14;
46344634
vcpu->run->s.regs.gprs[15] = vcpu->arch.sie_block->gg15;
46354635

4636-
if (exit_reason == -EINTR) {
4637-
VCPU_EVENT(vcpu, 3, "%s", "machine check");
4636+
if (sie_return == SIE64_RETURN_MCCK) {
46384637
sie_page = container_of(vcpu->arch.sie_block,
46394638
struct sie_page, sie_block);
46404639
mcck_info = &sie_page->mcck_info;
46414640
kvm_s390_reinject_machine_check(vcpu, mcck_info);
46424641
return 0;
46434642
}
4643+
WARN_ON_ONCE(sie_return != SIE64_RETURN_NORMAL);
46444644

46454645
if (vcpu->arch.sie_block->icptcode > 0) {
46464646
rc = kvm_handle_sie_intercept(vcpu);
@@ -4679,7 +4679,7 @@ int noinstr kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,
46794679
#define PSW_INT_MASK (PSW_MASK_EXT | PSW_MASK_IO | PSW_MASK_MCHECK)
46804680
static int __vcpu_run(struct kvm_vcpu *vcpu)
46814681
{
4682-
int rc, exit_reason;
4682+
int rc, sie_return;
46834683
struct sie_page *sie_page = (struct sie_page *)vcpu->arch.sie_block;
46844684

46854685
/*
@@ -4719,9 +4719,9 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
47194719
guest_timing_enter_irqoff();
47204720
__disable_cpu_timer_accounting(vcpu);
47214721

4722-
exit_reason = kvm_s390_enter_exit_sie(vcpu->arch.sie_block,
4723-
vcpu->run->s.regs.gprs,
4724-
vcpu->arch.gmap->asce.val);
4722+
sie_return = kvm_s390_enter_exit_sie(vcpu->arch.sie_block,
4723+
vcpu->run->s.regs.gprs,
4724+
vcpu->arch.gmap->asce.val);
47254725

47264726
__enable_cpu_timer_accounting(vcpu);
47274727
guest_timing_exit_irqoff();
@@ -4744,7 +4744,7 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
47444744
}
47454745
kvm_vcpu_srcu_read_lock(vcpu);
47464746

4747-
rc = vcpu_post_run(vcpu, exit_reason);
4747+
rc = vcpu_post_run(vcpu, sie_return);
47484748
if (rc || guestdbg_exit_pending(vcpu)) {
47494749
kvm_vcpu_srcu_read_unlock(vcpu);
47504750
break;

0 commit comments

Comments
 (0)