Skip to content

Commit 94f29ab

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Force guest's HCR_EL2.E2H RES1 when NV1 is not implemented
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. Reviewed-by: Suzuki K Poulose <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent c21df6e commit 94f29ab

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ static inline bool vcpu_is_el2(const struct kvm_vcpu *vcpu)
209209

210210
static inline bool __vcpu_el2_e2h_is_set(const struct kvm_cpu_context *ctxt)
211211
{
212-
return ctxt_sys_reg(ctxt, HCR_EL2) & HCR_E2H;
212+
return (!cpus_have_final_cap(ARM64_HAS_HCR_NV1) ||
213+
(ctxt_sys_reg(ctxt, HCR_EL2) & HCR_E2H));
213214
}
214215

215216
static inline bool vcpu_el2_e2h_is_set(const struct kvm_vcpu *vcpu)

arch/arm64/kvm/sys_regs.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,16 @@ static bool access_spsr(struct kvm_vcpu *vcpu,
21752175
return true;
21762176
}
21772177

2178+
static u64 reset_hcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
2179+
{
2180+
u64 val = r->val;
2181+
2182+
if (!cpus_have_final_cap(ARM64_HAS_HCR_NV1))
2183+
val |= HCR_E2H;
2184+
2185+
return __vcpu_sys_reg(vcpu, r->reg) = val;
2186+
}
2187+
21782188
/*
21792189
* Architected system registers.
21802190
* Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2
@@ -2666,7 +2676,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
26662676
EL2_REG_VNCR(VMPIDR_EL2, reset_unknown, 0),
26672677
EL2_REG(SCTLR_EL2, access_rw, reset_val, SCTLR_EL2_RES1),
26682678
EL2_REG(ACTLR_EL2, access_rw, reset_val, 0),
2669-
EL2_REG_VNCR(HCR_EL2, reset_val, 0),
2679+
EL2_REG_VNCR(HCR_EL2, reset_hcr, 0),
26702680
EL2_REG(MDCR_EL2, access_rw, reset_val, 0),
26712681
EL2_REG(CPTR_EL2, access_rw, reset_val, CPTR_NVHE_EL2_RES1),
26722682
EL2_REG_VNCR(HSTR_EL2, reset_val, 0),

0 commit comments

Comments
 (0)