mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jim Mattson <jmattson@google.com>
To: seanjc@google.com, pbonzini@redhat.com, tglx@kernel.org,
	mingo@redhat.com,  bp@alien8.de, dave.hansen@linux.intel.com,
	x86@kernel.org, hpa@zytor.com,  shuah@kernel.org,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-kselftest@vger.kernel.org, ctpence@google.com,
	David.Kaplan@amd.com,  binbin.wu@linux.intel.com
Cc: Jim Mattson <jmattson@google.com>, Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH v4 2/5] KVM: x86: Prioritize CPUID faulting over CPUID VM-exits in nested VMX
Date: Wed, 27 May 2026 10:43:44 -0700	[thread overview]
Message-ID: <20260527174347.2356165-3-jmattson@google.com> (raw)
In-Reply-To: <20260527174347.2356165-1-jmattson@google.com>

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>
---
 arch/x86/kvm/vmx/nested.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index a78ce0080963..30dcabc899a2 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -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;
 	}
-- 
2.54.0.794.g4f17f83d09-goog


  parent reply	other threads:[~2026-05-27 17:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-27 17:43 [PATCH v4 0/5] KVM: x86: Virtualize AMD's "disable CPUID in usermode" Jim Mattson
2026-05-27 17:43 ` [PATCH v4 1/5] KVM: x86: Consolidate CPUID fault handling for emulator and interception logic Jim Mattson
2026-05-28  9:13   ` Peter Zijlstra
2026-05-28 14:20     ` Jim Mattson
2026-05-28 16:08       ` Sean Christopherson
2026-05-28 16:06     ` Sean Christopherson
2026-05-27 17:43 ` Jim Mattson [this message]
2026-05-27 17:43 ` [PATCH v4 3/5] KVM: x86: Remove supports_cpuid_fault() helper Jim Mattson
2026-05-27 17:43 ` [PATCH v4 4/5] KVM: x86: Virtualize AMD CPUID faulting Jim Mattson
2026-05-27 17:43 ` [PATCH v4 5/5] KVM: selftests: Update hwcr_msr_test for CPUID faulting bit Jim Mattson
2026-05-29 22:47 ` [PATCH v4 0/5] KVM: x86: Virtualize AMD's "disable CPUID in usermode" Sean Christopherson
2026-06-06 15:12   ` Jim Mattson
2026-06-06 16:00     ` Jim Mattson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260527174347.2356165-3-jmattson@google.com \
    --to=jmattson@google.com \
    --cc=David.Kaplan@amd.com \
    --cc=binbin.wu@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=ctpence@google.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=sashiko-bot@kernel.org \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®