Skip to content

Commit 3af1105

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: nv: Apply guest's MDCR traps in nested context
KVM needs to ensure the guest hypervisor's traps take effect when the vCPU is in a nested context. While supporting infrastructure is in place for most of the EL2 trap registers, MDCR_EL2 is not. Fold the guest's trap configuration into the effective MDCR_EL2. Apply it directly to the in-memory representation as it gets recomputed on every vcpu_load() anyway. Signed-off-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 4a68408 commit 3af1105

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

arch/arm64/kvm/nested.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,13 +1797,32 @@ void kvm_nested_sync_hwstate(struct kvm_vcpu *vcpu)
17971797
kvm_inject_serror_esr(vcpu, vcpu_get_vsesr(vcpu));
17981798
}
17991799

1800+
/*
1801+
* KVM unconditionally sets most of these traps anyway but use an allowlist
1802+
* to document the guest hypervisor traps that may take precedence and guard
1803+
* against future changes to the non-nested trap configuration.
1804+
*/
1805+
#define NV_MDCR_GUEST_INCLUDE (MDCR_EL2_TDE | \
1806+
MDCR_EL2_TDA | \
1807+
MDCR_EL2_TDRA | \
1808+
MDCR_EL2_TTRF | \
1809+
MDCR_EL2_TPMS | \
1810+
MDCR_EL2_TPM | \
1811+
MDCR_EL2_TPMCR | \
1812+
MDCR_EL2_TDCC | \
1813+
MDCR_EL2_TDOSA)
1814+
18001815
void kvm_nested_setup_mdcr_el2(struct kvm_vcpu *vcpu)
18011816
{
1817+
u64 guest_mdcr = __vcpu_sys_reg(vcpu, MDCR_EL2);
1818+
18021819
/*
18031820
* In yet another example where FEAT_NV2 is fscking broken, accesses
18041821
* to MDSCR_EL1 are redirected to the VNCR despite having an effect
18051822
* at EL2. Use a big hammer to apply sanity.
18061823
*/
18071824
if (is_hyp_ctxt(vcpu))
18081825
vcpu->arch.mdcr_el2 |= MDCR_EL2_TDA;
1826+
else
1827+
vcpu->arch.mdcr_el2 |= (guest_mdcr & NV_MDCR_GUEST_INCLUDE);
18091828
}

0 commit comments

Comments
 (0)