KVM/arm64 fixes for 5.8, take #2
Subsystems (6)
Marc Zyngier
maintainerHi Paolo,
Here's another pull request for a handful of KVM/arm64 fixes. Nothing absolutely critical (see the tag for the gory details), but I'd rather get these merged as soon as possible.
Please pull,
M.
The following changes since commit b3a9e3b9622ae10064826dccb4f7a52bd88c7407:
Linux 5.8-rc1 (2020-06-14 12:45:04 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git kvmarm-fixes-5.8-2
for you to fetch changes up to a3f574cd65487cd993f79ab235d70229d9302c1e:
KVM: arm64: vgic-v4: Plug race between non-residency and v4.1 doorbell (2020-06-23 11:24:39 +0100)
----------------------------------------------------------------
KVM/arm fixes for 5.8, take #2
- Make sure a vcpu becoming non-resident doesn't race against the doorbell delivery
- Only advertise pvtime if accounting is enabled
- Return the correct error code if reset fails with SVE
- Make sure that pseudo-NMI functions are annotated as __always_inline
----------------------------------------------------------------
Alexandru Elisei (1):
KVM: arm64: Annotate hyp NMI-related functions as __always_inline
Andrew Jones (1):
KVM: arm64: pvtime: Ensure task delay accounting is enabled
Marc Zyngier (1):
KVM: arm64: vgic-v4: Plug race between non-residency and v4.1 doorbell
Steven Price (1):
KVM: arm64: Fix kvm_reset_vcpu() return code being incorrect with SVE
arch/arm64/include/asm/arch_gicv3.h | 2 +- arch/arm64/include/asm/cpufeature.h | 2 +- arch/arm64/kvm/pvtime.c | 15 ++++++++++++--- arch/arm64/kvm/reset.c | 10 +++++++--- arch/arm64/kvm/vgic/vgic-v4.c | 8 ++++++++ drivers/irqchip/irq-gic-v3-its.c | 8 ++++++++ 6 files changed, 37 insertions(+), 8 deletions(-)
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerPATCH 1/4 KVM: arm64: Annotate hyp NMI-related functions as __always_inline
From: Alexandru Elisei <[email protected]>
The "inline" keyword is a hint for the compiler to inline a function. The functions system_uses_irq_prio_masking() and gic_write_pmr() are used by the code running at EL2 on a non-VHE system, so mark them as __always_inline to make sure they'll always be part of the .hyp.text section.
This fixes the following splat when trying to run a VM:
[ 47.625273] Kernel panic - not syncing: HYP panic: [ 47.625273] PS:a00003c9 PC:0000ca0b42049fc4 ESR:86000006 [ 47.625273] FAR:0000ca0b42049fc4 HPFAR:0000000010001000 PAR:0000000000000000 [ 47.625273] VCPU:0000000000000000 [ 47.647261] CPU: 1 PID: 217 Comm: kvm-vcpu-0 Not tainted 5.8.0-rc1-ARCH+ #61 [ 47.654508] Hardware name: Globalscale Marvell ESPRESSOBin Board (DT) [ 47.661139] Call trace: [ 47.663659] dump_backtrace+0x0/0x1cc [ 47.667413] show_stack+0x18/0x24 [ 47.670822] dump_stack+0xb8/0x108 [ 47.674312] panic+0x124/0x2f4 [ 47.677446] panic+0x0/0x2f4 [ 47.680407] SMP: stopping secondary CPUs [ 47.684439] Kernel Offset: disabled [ 47.688018] CPU features: 0x240402,20002008 [ 47.692318] Memory Limit: none [ 47.695465] ---[ end Kernel panic - not syncing: HYP panic: [ 47.695465] PS:a00003c9 PC:0000ca0b42049fc4 ESR:86000006 [ 47.695465] FAR:0000ca0b42049fc4 HPFAR:0000000010001000 PAR:0000000000000000 [ 47.695465] VCPU:0000000000000000 ]---
The instruction abort was caused by the code running at EL2 trying to fetch an instruction which wasn't mapped in the EL2 translation tables. Using objdump showed the two functions as separate symbols in the .text section.
--- arch/arm64/include/asm/arch_gicv3.h | 2 +- arch/arm64/include/asm/cpufeature.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/arch_gicv3.h +1 -1
@@ -109,7 +109,7 @@ static inline u32 gic_read_pmr(void)return read_sysreg_s (SYS_ICC_PMR_EL1 ); } -static inline void gic_write_pmr (u32 val) +static __always_inline void gic_write_pmr(u32 val) {write_sysreg_s (val,SYS_ICC_PMR_EL1 ); }
arch/arm64/include/asm/cpufeature.h +1 -1
@@ -675,7 +675,7 @@ static inline bool system_supports_generic_auth(void)cpus_have_const_cap (ARM64_HAS_GENERIC_AUTH ); } -static inline bool system_uses_irq_prio_masking (void ) +static __always_inline bool system_uses_irq_prio_masking(void) {return IS_ENABLED (CONFIG_ARM64_PSEUDO_NMI ) &&cpus_have_const_cap (ARM64_HAS_IRQ_PRIO_MASKING );
Signature · 6 lines
2.27.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerPATCH 2/4 KVM: arm64: Fix kvm_reset_vcpu() return code being incorrect with SVE
In reply to Marc ZyngierFrom: Steven Price <[email protected]>
If SVE is enabled then 'ret' can be assigned the return value of kvm_vcpu_enable_sve() which may be 0 causing future "goto out" sites to erroneously return 0 on failure rather than -EINVAL as expected.
Remove the initialisation of 'ret' and make setting the return value explicit to avoid this situation in the future.
--- arch/arm64/kvm/reset.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/arm64/kvm/reset.c +7 -3
@@ -245,7 +245,7 @@ static int kvm_vcpu_enable_ptrauth(struct kvm_vcpu *vcpu)*/ int kvm_reset_vcpu (struct kvm_vcpu *vcpu) { -int ret = -EINVAL ; +int ret;bool loaded;u32 pstate;
@@ -269,15 +269,19 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)if (test_bit (KVM_ARM_VCPU_PTRAUTH_ADDRESS , vcpu->arch.features) ||test_bit (KVM_ARM_VCPU_PTRAUTH_GENERIC , vcpu->arch.features)) { -if (kvm_vcpu_enable_ptrauth (vcpu)) +if (kvm_vcpu_enable_ptrauth (vcpu)) { + ret = -EINVAL ; goto out; + } }switch (vcpu->arch.target) {default :if (test_bit (KVM_ARM_VCPU_EL1_32BIT , vcpu->arch.features)) { -if (!cpus_have_const_cap (ARM64_HAS_32BIT_EL1 )) +if (!cpus_have_const_cap (ARM64_HAS_32BIT_EL1 )) { + ret = -EINVAL ; goto out; + } pstate =VCPU_RESET_PSTATE_SVC ; }else { pstate =VCPU_RESET_PSTATE_EL1 ;
Signature · 6 lines
2.27.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerPATCH 3/4 KVM: arm64: pvtime: Ensure task delay accounting is enabled
In reply to Marc ZyngierFrom: Andrew Jones <[email protected]>
Ensure we're actually accounting run_delay before we claim that we'll expose it to the guest. If we're not, then we just pretend like steal time isn't supported in order to avoid any confusion.
--- arch/arm64/kvm/pvtime.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
arch/arm64/kvm/pvtime.c +12 -3
@@ -3,6 +3,7 @@#include <linux/arm-smccc.h> #include <linux/kvm_host.h> +#include <linux/sched/stat.h> #include <asm/kvm_mmu.h> #include <asm/pvclock-abi.h>
@@ -73,6 +74,11 @@ gpa_t kvm_init_stolen_time(struct kvm_vcpu *vcpu)return base; } +static bool kvm_arm_pvtime_supported (void ) +{ +return !!sched_info_on (); +} +int kvm_arm_pvtime_set_attr (struct kvm_vcpu *vcpu,struct kvm_device_attr *attr) {
@@ -82,7 +88,8 @@ int kvm_arm_pvtime_set_attr(struct kvm_vcpu *vcpu,int ret =0 ;int idx; -if (attr->attr !=KVM_ARM_VCPU_PVTIME_IPA ) +if (!kvm_arm_pvtime_supported () || + attr->attr !=KVM_ARM_VCPU_PVTIME_IPA )return -ENXIO ;if (get_user (ipa, user))
@@ -110,7 +117,8 @@ int kvm_arm_pvtime_get_attr(struct kvm_vcpu *vcpu,u64 __user *user = (u64 __user *)attr->addr;u64 ipa; -if (attr->attr !=KVM_ARM_VCPU_PVTIME_IPA ) +if (!kvm_arm_pvtime_supported () || + attr->attr !=KVM_ARM_VCPU_PVTIME_IPA )return -ENXIO ; ipa = vcpu->arch.steal.base;
@@ -125,7 +133,8 @@ int kvm_arm_pvtime_has_attr(struct kvm_vcpu *vcpu, {switch (attr->attr) {case KVM_ARM_VCPU_PVTIME_IPA : -return 0 ; +if (kvm_arm_pvtime_supported ()) +return 0 ; }return -ENXIO ; }
Signature · 6 lines
2.27.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerPATCH 4/4 KVM: arm64: vgic-v4: Plug race between non-residency and v4.1 doorbell
In reply to Marc ZyngierWhen making a vPE non-resident because it has hit a blocking WFI, the doorbell can fire at any time after the write to the RD. Crucially, it can fire right between the write to GICR_VPENDBASER and the write to the pending_last field in the its_vpe structure.
This means that we would overwrite pending_last with stale data, and potentially not wakeup until some unrelated event (such as a timer interrupt) puts the vPE back on the CPU.
GICv4 isn't affected by this as we actively mask the doorbell on entering the guest, while GICv4.1 automatically manages doorbell delivery without any hypervisor-driven masking.
Use the vpe_lock to synchronize such update, which solves the problem altogether.
--- arch/arm64/kvm/vgic/vgic-v4.c | 8 ++++++++ drivers/irqchip/irq-gic-v3-its.c | 8 ++++++++ 2 files changed, 16 insertions(+)
arch/arm64/kvm/vgic/vgic-v4.c +8 -0
@@ -90,7 +90,15 @@ static irqreturn_t vgic_v4_doorbell_handler(int irq, void *info) !irqd_irq_disabled(&irq_to_desc(irq)->irq_data))disable_irq_nosync (irq); +/* +* The v4.1 doorbell can fire concurrently with the vPE being +* made non-resident. Ensure we only update pending_last +* *after* the non-residency sequence has completed. +*/ +raw_spin_lock (&vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vpe_lock); vcpu->arch.vgic_cpu.vgic_v3.its_vpe.pending_last = true; +raw_spin_unlock (&vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vpe_lock); +kvm_make_request (KVM_REQ_IRQ_PENDING , vcpu);kvm_vcpu_kick (vcpu);
drivers/irqchip/irq-gic-v3-its.c +8 -0
@@ -4054,16 +4054,24 @@ static void its_vpe_4_1_deschedule(struct its_vpe *vpe,u64 val;if (info->req_db) { +unsigned long flags; +/* * vPE is going to block: make the vPE non-resident with * PendingLast clear and DB set. The GIC guarantees that if * we read-back PendingLast clear, then a doorbell will be * delivered when an interrupt comes. +* +* Note the locking to deal with the concurrent update of +* pending_last from the doorbell interrupt handler that can +* run concurrently. */ +raw_spin_lock_irqsave (&vpe->vpe_lock, flags); val =its_clear_vpend_valid (vlpi_base, GICR_VPENDBASER_PendingLast,GICR_VPENDBASER_4_1_DB ); vpe->pending_last = !!(val & GICR_VPENDBASER_PendingLast); +raw_spin_unlock_irqrestore (&vpe->vpe_lock, flags); }else {/* * We're not blocking, so just make the vPE non-resident
Signature · 6 lines
2.27.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Paolo Bonzini
maintainerQuoted 43 lines · Marc Zyngier
Hi Paolo,
Here's another pull request for a handful of KVM/arm64 fixes. Nothing absolutely critical (see the tag for the gory details), but I'd rather get these merged as soon as possible.
Please pull,
M.The following changes since commit
b3a9e3b9622ae10064826dccb4f7a52bd88c7407:Linux 5.8-rc1 (2020-06-14 12:45:04 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.gitkvmarm-fixes-5.8-2for you to fetch changes up to
a3f574cd65487cd993f79ab235d70229d9302c1e:KVM: arm64: vgic-v4: Plug race between non-residency and v4.1 doorbell (2020-06-23 11:24:39 +0100)
----------------------------------------------------------------
KVM/arm fixes for 5.8, take #2- Make sure a vcpu becoming non-resident doesn't race against the doorbell delivery
- Only advertise pvtime if accounting is enabled
- Return the correct error code if reset fails with SVE
- Make sure that pseudo-NMI functions are annotated as__always_inline----------------------------------------------------------------
Alexandru Elisei (1):
KVM: arm64: Annotate hyp NMI-related functions as__always_inlineAndrew Jones (1):
KVM: arm64: pvtime: Ensure task delay accounting is enabledMarc Zyngier (1):
KVM: arm64: vgic-v4: Plug race between non-residency and v4.1 doorbellSteven Price (1):
KVM: arm64: Fixkvm_reset_vcpu()return code being incorrect with SVE
Quoted 8 lines
arch/arm64/include/asm/arch_gicv3.h | 2 +- arch/arm64/include/asm/cpufeature.h | 2 +- arch/arm64/kvm/pvtime.c | 15 ++++++++++++--- arch/arm64/kvm/reset.c | 10 +++++++--- arch/arm64/kvm/vgic/vgic-v4.c | 8 ++++++++ drivers/irqchip/irq-gic-v3-its.c | 8 ++++++++ 6 files changed, 37 insertions(+), 8 deletions(-)
Pulled, thanks.
Paolo