From: lishusen <lishusen2@h-partners.com> Add kvm-arm.pv_qspinlock=1 to host cmdline parameters to enable the pv qspinlock feature when it cannot be enabled through libvirt or QEMU. lishusen (1): KVM: arm64: Add kvm-arm.pv_qspinlock for host .../admin-guide/kernel-parameters.txt | 8 +++++ arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/arm.c | 10 ++++++ arch/arm64/kvm/hypercalls.c | 34 +++++++++++++------ 4 files changed, 42 insertions(+), 11 deletions(-) -- 2.33.0
From: lishusen <lishusen2@h-partners.com> virt inclusion category: bugfix bugzilla: https://gitcode.com/openeuler/kernel/issues/10399 CVE: NA -------------------------------- In scenarios such as sandboxes where QEMU is not used, the pv qspinlock feature cannot be enabled through libvirt or QEMU configurations. Add kvm-arm.pv_qspinlock=1 to host cmdline parameters to enable this feature in such scenarios. Signed-off-by: lishusen <lishusen2@h-partners.com> --- .../admin-guide/kernel-parameters.txt | 8 +++++ arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/arm.c | 10 ++++++ arch/arm64/kvm/hypercalls.c | 34 +++++++++++++------ 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 9507ad3d3629..8136e56f6878 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2732,6 +2732,14 @@ [KVM,ARM] Allow use of HiSilicon DVMBM capability. Default: 0 + kvm-arm.pv_qspinlock= + [KVM,ARM] Force enable the PV queued spinlock + (KICK_CPU hypercall) for guests, even if userspace + did not enable it. Needed on setups where the VMM + cannot configure it, e.g. sandboxes that do not use + QEMU. + Default is 0 (disabled). + kvm_cma_resv_ratio=n [PPC] Reserves given percentage from system memory area for contiguous memory allocation for KVM hash pagetable diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 7e69a920eac2..4ad0ddd34575 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1319,6 +1319,7 @@ static inline bool kvm_arm_vcpu_is_preempted(struct kvm_vcpu_arch *vcpu_arch) #endif #ifdef CONFIG_PARAVIRT_SPINLOCKS +extern bool pv_qspinlock_force_enable; static inline void kvm_arm_pvspin_vcpu_init(struct kvm_vcpu_arch *vcpu_arch) { vcpu_arch->pv.pv_unhalted = false; diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 56a2daf882d7..2aff47e8661e 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -98,6 +98,16 @@ bool pv_preempted_enable = true; MODULE_PARM_DESC(pv_preempted_enable, "bool"); module_param_cb(pv_preempted_enable, &pv_preempted_enable_ops, &pv_preempted_enable, 0644); +#ifdef CONFIG_PARAVIRT_SPINLOCKS +bool __ro_after_init pv_qspinlock_force_enable; + +static int __init early_pv_qspinlock_cfg(char *buf) +{ + return strtobool(buf, &pv_qspinlock_force_enable); +} +early_param("kvm-arm.pv_qspinlock", early_pv_qspinlock_cfg); +#endif + static int vcpu_req_reload_wfi_traps(const char *val, const struct kernel_param *kp); static const struct kernel_param_ops force_wfi_trap_ops = { diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c index edd2adcc94d9..80f528f1e9da 100644 --- a/arch/arm64/kvm/hypercalls.c +++ b/arch/arm64/kvm/hypercalls.c @@ -107,6 +107,23 @@ static bool kvm_smccc_default_allowed(u32 func_id) } } +#ifdef CONFIG_PARAVIRT_SPINLOCKS +static bool kvm_pvspin_is_enabled(struct kvm_smccc_features *smccc_feat) +{ + if (pv_qspinlock_force_enable) + return true; + + /* + * NOPVSPINLOCK carries negative polarity: the bit is set by + * default (feature disabled) and userspace clears it to enable + * the PV queued spinlock. KICK_CPU is therefore allowed only + * while the bit is clear. + */ + return !test_bit(KVM_REG_ARM_VENDOR_HYP_BIT_NOPVSPINLOCK, + &smccc_feat->vendor_hyp_bmap); +} +#endif + static bool kvm_smccc_test_fw_bmap(struct kvm_vcpu *vcpu, u32 func_id) { struct kvm_smccc_features *smccc_feat = &vcpu->kvm->arch.smccc_feat; @@ -150,14 +167,7 @@ static bool kvm_smccc_test_fw_bmap(struct kvm_vcpu *vcpu, u32 func_id) #endif #ifdef CONFIG_PARAVIRT_SPINLOCKS case ARM_SMCCC_VENDOR_KICK_CPU: - /* - * NOPVSPINLOCK carries negative polarity: the bit is set by - * default (feature disabled) and userspace clears it to enable - * the PV queued spinlock. KICK_CPU is therefore allowed only - * while the bit is clear. - */ - return !test_bit(KVM_REG_ARM_VENDOR_HYP_BIT_NOPVSPINLOCK, - &smccc_feat->vendor_hyp_bmap); + return kvm_pvspin_is_enabled(smccc_feat); #endif default: return false; @@ -411,8 +421,7 @@ int kvm_smccc_call_handler(struct kvm_vcpu *vcpu) #endif /* CONFIG_PARAVIRT_SCHED */ #ifdef CONFIG_PARAVIRT_SPINLOCKS case ARM_SMCCC_VENDOR_KICK_CPU: - if (!test_bit(KVM_REG_ARM_VENDOR_HYP_BIT_NOPVSPINLOCK, - &smccc_feat->vendor_hyp_bmap)) + if (kvm_pvspin_is_enabled(smccc_feat)) val[0] = SMCCC_RET_SUCCESS; break; #endif /* CONFIG_PARAVIRT_SPINLOCKS */ @@ -444,7 +453,10 @@ int kvm_smccc_call_handler(struct kvm_vcpu *vcpu) #endif /* CONFIG_PARAVIRT_SCHED */ #ifdef CONFIG_PARAVIRT_SPINLOCKS case ARM_SMCCC_VENDOR_KICK_CPU: - val[0] = kvm_pvspin_kick_vcpu(vcpu); + if (kvm_pvspin_is_enabled(smccc_feat)) + val[0] = kvm_pvspin_kick_vcpu(vcpu); + else + val[0] = SMCCC_RET_NOT_SUPPORTED; break; #endif /* CONFIG_PARAVIRT_SPINLOCKS */ #ifdef CONFIG_ARM64_HISI_IPIV -- 2.33.0
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://atomgit.com/openeuler/kernel/merge_requests/31164 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/HVH... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://atomgit.com/openeuler/kernel/merge_requests/31164 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/HVH...
participants (2)
-
lishusen -
patchwork bot