Message ID | 20231120123721.851738-14-maz@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | arm64: Add support for FEAT_E2H0, or lack thereof | expand |
On 20/11/2023 12:37, Marc Zyngier wrote: > If NV1 isn't supported on a system, make sure we always evaluate > the guest's HCR_EL2.E2H as RES1, irrespective of what the guest > may have written there. > > Signed-off-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com> > --- > arch/arm64/include/asm/kvm_emulate.h | 3 ++- > arch/arm64/kvm/sys_regs.c | 12 +++++++++++- > 2 files changed, 13 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > index 78a550537b67..7b10a44189d0 100644 > --- a/arch/arm64/include/asm/kvm_emulate.h > +++ b/arch/arm64/include/asm/kvm_emulate.h > @@ -213,7 +213,8 @@ static inline bool vcpu_is_el2(const struct kvm_vcpu *vcpu) > > static inline bool __vcpu_el2_e2h_is_set(const struct kvm_cpu_context *ctxt) > { > - return ctxt_sys_reg(ctxt, HCR_EL2) & HCR_E2H; > + return (cpus_have_final_cap(ARM64_HCR_NV1_RES0) || > + (ctxt_sys_reg(ctxt, HCR_EL2) & HCR_E2H)); > } > > static inline bool vcpu_el2_e2h_is_set(const struct kvm_vcpu *vcpu) > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index ff2e66f0bda1..9e1e3da2ed4a 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -2022,6 +2022,16 @@ static bool access_spsr(struct kvm_vcpu *vcpu, > return true; > } > > +static u64 reset_hcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) > +{ > + u64 val = r->val; > + > + if (cpus_have_final_cap(ARM64_HCR_NV1_RES0)) > + val |= HCR_E2H; > + > + return __vcpu_sys_reg(vcpu, r->reg) = val; > +} > + > /* > * Architected system registers. > * Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2 > @@ -2513,7 +2523,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { > EL2_REG(VMPIDR_EL2, access_rw, reset_unknown, 0), > EL2_REG(SCTLR_EL2, access_rw, reset_val, SCTLR_EL2_RES1), > EL2_REG(ACTLR_EL2, access_rw, reset_val, 0), > - EL2_REG(HCR_EL2, access_rw, reset_val, 0), > + EL2_REG(HCR_EL2, access_rw, reset_hcr, 0), > EL2_REG(MDCR_EL2, access_rw, reset_val, 0), > EL2_REG(CPTR_EL2, access_rw, reset_val, CPTR_NVHE_EL2_RES1), > EL2_REG(HSTR_EL2, access_rw, reset_val, 0),
diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index 78a550537b67..7b10a44189d0 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -213,7 +213,8 @@ static inline bool vcpu_is_el2(const struct kvm_vcpu *vcpu) static inline bool __vcpu_el2_e2h_is_set(const struct kvm_cpu_context *ctxt) { - return ctxt_sys_reg(ctxt, HCR_EL2) & HCR_E2H; + return (cpus_have_final_cap(ARM64_HCR_NV1_RES0) || + (ctxt_sys_reg(ctxt, HCR_EL2) & HCR_E2H)); } static inline bool vcpu_el2_e2h_is_set(const struct kvm_vcpu *vcpu) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index ff2e66f0bda1..9e1e3da2ed4a 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -2022,6 +2022,16 @@ static bool access_spsr(struct kvm_vcpu *vcpu, return true; } +static u64 reset_hcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) +{ + u64 val = r->val; + + if (cpus_have_final_cap(ARM64_HCR_NV1_RES0)) + val |= HCR_E2H; + + return __vcpu_sys_reg(vcpu, r->reg) = val; +} + /* * Architected system registers. * Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2 @@ -2513,7 +2523,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { EL2_REG(VMPIDR_EL2, access_rw, reset_unknown, 0), EL2_REG(SCTLR_EL2, access_rw, reset_val, SCTLR_EL2_RES1), EL2_REG(ACTLR_EL2, access_rw, reset_val, 0), - EL2_REG(HCR_EL2, access_rw, reset_val, 0), + EL2_REG(HCR_EL2, access_rw, reset_hcr, 0), EL2_REG(MDCR_EL2, access_rw, reset_val, 0), EL2_REG(CPTR_EL2, access_rw, reset_val, CPTR_NVHE_EL2_RES1), EL2_REG(HSTR_EL2, access_rw, reset_val, 0),
If NV1 isn't supported on a system, make sure we always evaluate the guest's HCR_EL2.E2H as RES1, irrespective of what the guest may have written there. Signed-off-by: Marc Zyngier <maz@kernel.org> --- arch/arm64/include/asm/kvm_emulate.h | 3 ++- arch/arm64/kvm/sys_regs.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-)