]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: nv: Track L2 to L1 exception emulation
authorMarc Zyngier <maz@kernel.org>
Mon, 11 May 2026 10:46:11 +0000 (11:46 +0100)
committerMarc Zyngier <maz@kernel.org>
Thu, 21 May 2026 06:42:19 +0000 (07:42 +0100)
While we currently track that we are emulating a nested ERET from
L1 to L2, we currently don't track the reverse direction (an exception
going from L2 to L1).

Add a new vcpu state flag for this purpose, which will see some
use shortly.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://patch.msgid.link/20260520085036.541666-2-maz@kernel.org
arch/arm64/include/asm/kvm_host.h
arch/arm64/kvm/emulate-nested.c

index 65eead8362e0b49d7ca4f36165802d2a964d1fd4..c79747d5f4dd1e77a2eb944e2b18bc2585c55739 100644 (file)
@@ -1112,7 +1112,8 @@ struct kvm_vcpu_arch {
 #define IN_NESTED_ERET         __vcpu_single_flag(sflags, BIT(7))
 /* SError pending for nested guest */
 #define NESTED_SERROR_PENDING  __vcpu_single_flag(sflags, BIT(8))
-
+/* KVM is currently emulating an L2 to L1 exception */
+#define IN_NESTED_EXCEPTION    __vcpu_single_flag(sflags, BIT(9))
 
 /* Pointer to the vcpu's SVE FFR for sve_{save,load}_state() */
 #define vcpu_sve_pffr(vcpu) (kern_hyp_va((vcpu)->arch.sve_state) +     \
index dba7ced74ca5e80607b964ed27f93b748943fac9..15c691a6266d54e2a634a3b60ce7b6e3f83ae77c 100644 (file)
@@ -2862,6 +2862,8 @@ static int kvm_inject_nested(struct kvm_vcpu *vcpu, u64 esr_el2,
 
        preempt_disable();
 
+       vcpu_set_flag(vcpu, IN_NESTED_EXCEPTION);
+
        /*
         * We may have an exception or PC update in the EL0/EL1 context.
         * Commit it before entering EL2.
@@ -2884,6 +2886,8 @@ static int kvm_inject_nested(struct kvm_vcpu *vcpu, u64 esr_el2,
        __kvm_adjust_pc(vcpu);
 
        kvm_arch_vcpu_load(vcpu, smp_processor_id());
+       vcpu_clear_flag(vcpu, IN_NESTED_EXCEPTION);
+
        preempt_enable();
 
        if (kvm_vcpu_has_pmu(vcpu))