KVM/arm64 fixes for 5.8, take #3
Subsystems (4)
Marc Zyngier
maintainercover KVM/arm64 fixes for 5.8, take #3
Hi Paolo,
Yet another small batch of fixes for 5.8. One is a long standing preemption issue that got uncovered by another fix that went in 5.8. The other one is a fix for an issue potentially affecting kexec.
Please pull,
M.
The following changes since commit a3f574cd65487cd993f79ab235d70229d9302c1e:
KVM: arm64: vgic-v4: Plug race between non-residency and v4.1 doorbell (2020-06-23 11:24:39 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvmarm-fixes-5.8-3
for you to fetch changes up to b9e10d4a6c9f5cbe6369ce2c17ebc67d2e5a4be5:
KVM: arm64: Stop clobbering x0 for HVC_SOFT_RESTART (2020-07-06 11:47:02 +0100)
----------------------------------------------------------------
KVM/arm fixes for 5.8, take #3
- Disable preemption on context-switching PMU EL0 state happening on system register trap
- Don't clobber X0 when tearing down KVM via a soft reset (kexec)
----------------------------------------------------------------
Andrew Scull (1):
KVM: arm64: Stop clobbering x0 for HVC_SOFT_RESTART
Marc Zyngier (1):
KVM: arm64: PMU: Fix per-CPU access in preemptible context
arch/arm64/kvm/hyp-init.S | 11 +++++++---- arch/arm64/kvm/pmu.c | 7 ++++++- 2 files changed, 13 insertions(+), 5 deletions(-)
Marc Zyngier
maintainerPATCH 1/2 KVM: arm64: PMU: Fix per-CPU access in preemptible context
Commit 07da1ffaa137 ("KVM: arm64: Remove host_cpu_context member from vcpu structure") has, by removing the host CPU context pointer, exposed that kvm_vcpu_pmu_restore_guest is called in preemptible contexts:
[ 266.932442] BUG: using smp_processor_id() in preemptible [00000000] code: qemu-system-aar/779 [ 266.939721] caller is debug_smp_processor_id+0x20/0x30 [ 266.944157] CPU: 2 PID: 779 Comm: qemu-system-aar Tainted: G E 5.8.0-rc3-00015-g8d4aa58b2fe3 #1374 [ 266.954268] Hardware name: amlogic w400/w400, BIOS 2020.04 05/22/2020 [ 266.960640] Call trace: [ 266.963064] dump_backtrace+0x0/0x1e0 [ 266.966679] show_stack+0x20/0x30 [ 266.969959] dump_stack+0xe4/0x154 [ 266.973338] check_preemption_disabled+0xf8/0x108 [ 266.977978] debug_smp_processor_id+0x20/0x30 [ 266.982307] kvm_vcpu_pmu_restore_guest+0x2c/0x68 [ 266.986949] access_pmcr+0xf8/0x128 [ 266.990399] perform_access+0x8c/0x250 [ 266.994108] kvm_handle_sys_reg+0x10c/0x2f8 [ 266.998247] handle_exit+0x78/0x200 [ 267.001697] kvm_arch_vcpu_ioctl_run+0x2ac/0xab8
Note that the bug was always there, it is only the switch to using percpu accessors that made it obvious.
The fix is to wrap these accesses in a preempt-disabled section, so that we sample a coherent context on trap from the guest.
--- arch/arm64/kvm/pmu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm64/kvm/pmu.c +6 -1
@@ -159,7 +159,10 @@ static void kvm_vcpu_pmu_disable_el0(unsigned long events) }/* -* On VHE ensure that only guest events have EL0 counting enabled +* On VHE ensure that only guest events have EL0 counting enabled. +* This is called from both vcpu_{load,put} and the sysreg handling. +* Since the latter is preemptible, special care must be taken to +* disable preemption. */ void kvm_vcpu_pmu_restore_guest (struct kvm_vcpu *vcpu) {
@@ -169,12 +172,14 @@ void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu)if (!has_vhe ())return ; +preempt_disable (); host =this_cpu_ptr (&kvm_host_data); events_guest = host->pmu_events.events_guest; events_host = host->pmu_events.events_host;kvm_vcpu_pmu_enable_el0 (events_guest);kvm_vcpu_pmu_disable_el0 (events_host); +preempt_enable (); }/*
Signature · 1 line
2.27.0
Marc Zyngier
maintainerPATCH 2/2 KVM: arm64: Stop clobbering x0 for HVC_SOFT_RESTART
In reply to Marc ZyngierFrom: Andrew Scull <[email protected]>
HVC_SOFT_RESTART is given values for x0-2 that it should installed before exiting to the new address so should not set x0 to stub HVC success or failure code.
--- arch/arm64/kvm/hyp-init.S | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
arch/arm64/kvm/hyp-init.S +7 -4
@@ -136,11 +136,15 @@ SYM_CODE_START(__kvm_handle_stub_hvc) 1: cmp x0, #HVC_RESET_VECTORS b.ne 1f -reset: + /* - * Reset kvm back to the hyp stub. Do not clobber x0-x4 in - * case we coming via HVC_SOFT_RESTART. + * Set the HVC_RESET_VECTORS return code before entering the common + * path so that we do not clobber x0-x2 in case we are coming via + * HVC_SOFT_RESTART. */ + mov x0, xzr +reset: + /* Reset kvm back to the hyp stub. */ mrs x5, sctlr_el2 mov_q x6, SCTLR_ELx_FLAGS bic x5, x5, x6 // Clear SCTL_M and etc
@@ -151,7 +155,6 @@ reset: /* Install stub vectors */ adr_l x5, __hyp_stub_vectors msr vbar_el2, x5 - mov x0, xzr eret 1: /* Bad stub call */
Signature · 1 line
2.27.0
Paolo Bonzini
maintainerQuoted 1 line · Marc Zyngier
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.gittags/kvmarm-fixes-5.8-3
Pulled, thanks.
Paolo