Skip to content

Commit 38cba55

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Force HCR_E2H in guest context when ARM64_KVM_HVHE is set
Also make sure HCR_EL2.E2H is set when switching HCR_EL2 in guest context. Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230609162200.2024064-16-maz@kernel.org Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent aca1858 commit 38cba55

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static __always_inline bool vcpu_el1_is_32bit(struct kvm_vcpu *vcpu)
7474
static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
7575
{
7676
vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS;
77-
if (is_kernel_in_hyp_mode())
77+
if (has_vhe() || has_hvhe())
7878
vcpu->arch.hcr_el2 |= HCR_E2H;
7979
if (cpus_have_const_cap(ARM64_HAS_RAS_EXTN)) {
8080
/* route synchronous external abort exceptions to EL2 */

arch/arm64/kvm/hyp/nvhe/pkvm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu)
4444
BUILD_BUG_ON(!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_AdvSIMD),
4545
PVM_ID_AA64PFR0_ALLOW));
4646

47+
if (has_hvhe())
48+
hcr_set |= HCR_E2H;
49+
4750
/* Trap RAS unless all current versions are supported */
4851
if (FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_RAS), feature_ids) <
4952
ID_AA64PFR0_EL1_RAS_V1P1) {

0 commit comments

Comments
 (0)