[PATCH OLK-6.6 v3] arm64: Fix actlr_el1 can not set problem in guest

hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/release-management/issues/IBV2E4 -------------------------------- During the initialization of the vCPU, the vcpu->arch.hcr_el2 is set to HCR_GUEST_FLAGS, which include HCR_TACR, and before a vCPU is scheduled onto a physical CPU, the contents of vcpu->arch.hcr_el2 will be writen into the physical hcr_el2 register, so regardless of whether the host has configured HCR_EL2, accessing ACTLR_EL1 in the guest virtual machine will trap to EL2. However, the current implementation of KVM ignores writes to ACTLR_EL1, so it is currently not possible to set this register in guest, hardware xcall/xint can not take effect anyway. So modify the state of actlr_el1 based on the written value in access_actlr(), which can only affect the virtual register values seen by the virtual machine. Considering that a vCPU may be scheduled on a physical CPU, the value of the vCPU's ACTLR_EL1 register should be loaded into the physical ACTLR_EL1 register before the vCPU is scheduled onto the physical CPU. Conversely, when the vCPU is descheduled from the physical CPU, the original value of the physical ACTLR_EL1 register should be restored. Fixes: 7f2e02718bba ("arm64: entry: Support hardware xcall and xint") Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> --- arch/arm64/kernel/cpufeature.c | 4 ---- arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 6 ++++++ arch/arm64/kvm/sys_regs.c | 12 +++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index b26bdaae6e2f..37a7c9412889 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2522,10 +2522,6 @@ static void cpu_enable_arch_xcall_xint(const struct arm64_cpu_capabilities *__un el = read_sysreg(CurrentEL); if (el == CurrentEL_EL2) { - /* - * Enable EL2 trap when access ACTLR_EL1 in guest kernel. - */ - write_sysreg_s(read_sysreg_s(SYS_HCR_EL2) | HCR_TACR, SYS_HCR_EL2); actlr_el2 = read_sysreg(actlr_el2); actlr_el2 |= ACTLR_ELx_XINT; write_sysreg(actlr_el2, actlr_el2); diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h index d6cfb3dc7f7c..595ebff1de9f 100644 --- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h @@ -20,6 +20,9 @@ static inline void __sysreg_save_common_state(struct kvm_cpu_context *ctxt) { ctxt_sys_reg(ctxt, MDSCR_EL1) = read_sysreg(mdscr_el1); +#ifdef CONFIG_ACTLR_XCALL_XINT + ctxt_sys_reg(ctxt, ACTLR_EL1) = read_sysreg(actlr_el1); +#endif } static inline void __sysreg_save_user_state(struct kvm_cpu_context *ctxt) @@ -90,6 +93,9 @@ static inline void __sysreg_save_el2_return_state(struct kvm_cpu_context *ctxt) static inline void __sysreg_restore_common_state(struct kvm_cpu_context *ctxt) { write_sysreg(ctxt_sys_reg(ctxt, MDSCR_EL1), mdscr_el1); +#ifdef CONFIG_ACTLR_XCALL_XINT + write_sysreg(ctxt_sys_reg(ctxt, ACTLR_EL1), actlr_el1); +#endif } static inline void __sysreg_restore_user_state(struct kvm_cpu_context *ctxt) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 8cd4c95759a0..6d8b4bec4e93 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -279,10 +279,20 @@ static bool access_actlr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) { - u64 mask, shift; + u64 mask, shift, val; +#ifdef CONFIG_ACTLR_XCALL_XINT + if (p->is_write) { + val = vcpu_read_sys_reg(vcpu, r->reg); + val &= ~(ACTLR_ELx_XCALL | ACTLR_ELx_XINT); + val |= (p->regval & (ACTLR_ELx_XCALL | ACTLR_ELx_XINT)); + vcpu_write_sys_reg(vcpu, val, r->reg); + return true; + } +#else if (p->is_write) return ignore_write(vcpu, p); +#endif get_access_mask(r, &mask, &shift); p->regval = (vcpu_read_sys_reg(vcpu, r->reg) & mask) >> shift; -- 2.34.1

反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/17853 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/5ER... 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://gitee.com/openeuler/kernel/pulls/17853 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/5ER...
participants (2)
-
Jinjie Ruan
-
patchwork bot