]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86: Prioritize CPUID faulting over CPUID VM-exits in nested VMX
authorJim Mattson <jmattson@google.com>
Wed, 27 May 2026 17:43:44 +0000 (10:43 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 27 May 2026 18:21:41 +0000 (11:21 -0700)
Per the Intel SDM, "Certain exceptions have priority over VM exits.  These
include invalid-opcode exceptions, faults based on privilege level, and
general-protection exceptions that are based on checking I/O permission
bits in the task-state segment (TSS)."

Ensure that when L2 executes CPUID at CPL > 0 while L1 has enabled CPUID
faulting, KVM intercepts the exit in L0 and queues #GP rather than
forwarding the CPUID VM-exit to L1.

Empirical testing confirms that this #GP has higher precedence than a CPUID
VM-exit on Granite Rapids (F/M/S 6/0xad/1).

Fixes: db2336a80489 ("KVM: x86: virtualize cpuid faulting")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260513224608.1859737-1-jmattson%40google.com?part=3
Signed-off-by: Jim Mattson <jmattson@google.com>
Link: https://patch.msgid.link/20260527174347.2356165-3-jmattson@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/vmx/nested.c

index a78ce00809637cae0b9b1c4c97df42f984b075f7..30dcabc899a29c6ce76bcf12533bd1bce6b4cdc1 100644 (file)
@@ -6552,6 +6552,8 @@ static bool nested_vmx_l0_wants_exit(struct kvm_vcpu *vcpu,
                        nested_evmcs_l2_tlb_flush_enabled(vcpu) &&
                        kvm_hv_is_tlb_flush_hcall(vcpu);
 #endif
+       case EXIT_REASON_CPUID:
+               return !kvm_is_cpuid_allowed(vcpu);
        default:
                break;
        }