* [PATCH] KVM: x86: Virtualize AMD CPUID faulting
@ 2026-02-10 21:09 Jamie Liu
2026-02-10 23:23 ` Jim Mattson
2026-02-11 13:50 ` Sean Christopherson
0 siblings, 2 replies; 3+ messages in thread
From: Jamie Liu @ 2026-02-10 21:09 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Borislav Petkov
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
kvm, linux-kernel, Jamie Liu
CPUID faulting via MSR_MISC_FEATURES_ENABLES_CPUID_FAULT is only used on
Intel CPUs. The mechanism virtualized by this change is used on AMD
CPUs. See arch/x86/kernel/cpu/amd.c:bsp_init_amd(),
arch/x86/kernel/process.c:set_cpuid_faulting().
Signed-off-by: Jamie Liu <jamieliu@google.com>
---
arch/x86/include/asm/msr-index.h | 1 +
arch/x86/kvm/cpuid.c | 2 +-
arch/x86/kvm/cpuid.h | 28 +++++++++++++++++-----------
arch/x86/kvm/x86.c | 14 +++++++++-----
4 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 3d0a0950d20a..79600fb551cf 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -880,6 +880,7 @@
#define MSR_K7_HWCR_IRPERF_EN_BIT 30
#define MSR_K7_HWCR_IRPERF_EN BIT_ULL(MSR_K7_HWCR_IRPERF_EN_BIT)
#define MSR_K7_HWCR_CPUID_USER_DIS_BIT 35
+#define MSR_K7_HWCR_CPUID_USER_DIS BIT_ULL(MSR_K7_HWCR_CPUID_USER_DIS_BIT)
#define MSR_K7_FID_VID_CTL 0xc0010041
#define MSR_K7_FID_VID_STATUS 0xc0010042
#define MSR_K7_HWCR_CPB_DIS_BIT 25
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 88a5426674a1..1dba0982e543 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1221,7 +1221,7 @@ void kvm_set_cpu_caps(void)
F(PREFETCHI),
EMULATED_F(NO_SMM_CTL_MSR),
/* PrefetchCtlMsr */
- /* GpOnUserCpuid */
+ EMULATED_F(GP_ON_USER_CPUID),
/* EPSF */
SYNTHESIZED_F(SBPB),
SYNTHESIZED_F(IBPB_BRTYPE),
diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
index d3f5ae15a7ca..9ca8321762fb 100644
--- a/arch/x86/kvm/cpuid.h
+++ b/arch/x86/kvm/cpuid.h
@@ -173,17 +173,6 @@ static inline int guest_cpuid_stepping(struct kvm_vcpu *vcpu)
return x86_stepping(best->eax);
}
-static inline bool supports_cpuid_fault(struct kvm_vcpu *vcpu)
-{
- return vcpu->arch.msr_platform_info & MSR_PLATFORM_INFO_CPUID_FAULT;
-}
-
-static inline bool cpuid_fault_enabled(struct kvm_vcpu *vcpu)
-{
- return vcpu->arch.msr_misc_features_enables &
- MSR_MISC_FEATURES_ENABLES_CPUID_FAULT;
-}
-
static __always_inline void kvm_cpu_cap_clear(unsigned int x86_feature)
{
unsigned int x86_leaf = __feature_leaf(x86_feature);
@@ -267,6 +256,23 @@ static __always_inline bool guest_cpu_cap_has(struct kvm_vcpu *vcpu,
return vcpu->arch.cpu_caps[x86_leaf] & __feature_bit(x86_feature);
}
+static inline bool supports_cpuid_fault_intel(struct kvm_vcpu *vcpu)
+{
+ return vcpu->arch.msr_platform_info & MSR_PLATFORM_INFO_CPUID_FAULT;
+}
+
+static inline bool supports_cpuid_fault_amd(struct kvm_vcpu *vcpu)
+{
+ return guest_cpu_cap_has(vcpu, X86_FEATURE_GP_ON_USER_CPUID);
+}
+
+static inline bool cpuid_fault_enabled(struct kvm_vcpu *vcpu)
+{
+ return (vcpu->arch.msr_misc_features_enables &
+ MSR_MISC_FEATURES_ENABLES_CPUID_FAULT) ||
+ (vcpu->arch.msr_hwcr & MSR_K7_HWCR_CPUID_USER_DIS);
+}
+
static inline bool kvm_vcpu_is_legal_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
{
if (guest_cpu_cap_has(vcpu, X86_FEATURE_LAM))
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 72d37c8930ad..9140f66b21c6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3992,14 +3992,18 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
data &= ~(u64)0x8; /* ignore TLB cache disable */
/*
- * Allow McStatusWrEn and TscFreqSel. (Linux guests from v3.2
- * through at least v6.6 whine if TscFreqSel is clear,
- * depending on F/M/S.
+ * Allow McStatusWrEn, TscFreqSel, and CpuidUserDis. (Linux
+ * guests from v3.2 through at least v6.6 whine if TscFreqSel
+ * is clear, depending on F/M/S.)
*/
- if (data & ~(BIT_ULL(18) | BIT_ULL(24))) {
+ if (data & ~(BIT_ULL(18) | BIT_ULL(24) |
+ MSR_K7_HWCR_CPUID_USER_DIS)) {
kvm_pr_unimpl_wrmsr(vcpu, msr, data);
return 1;
}
+ if (data & MSR_K7_HWCR_CPUID_USER_DIS &&
+ !supports_cpuid_fault_amd(vcpu))
+ return 1;
vcpu->arch.msr_hwcr = data;
break;
case MSR_FAM10H_MMIO_CONF_BASE:
@@ -4248,7 +4252,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
case MSR_MISC_FEATURES_ENABLES:
if (data & ~MSR_MISC_FEATURES_ENABLES_CPUID_FAULT ||
(data & MSR_MISC_FEATURES_ENABLES_CPUID_FAULT &&
- !supports_cpuid_fault(vcpu)))
+ !supports_cpuid_fault_intel(vcpu)))
return 1;
vcpu->arch.msr_misc_features_enables = data;
break;
--
2.53.0.239.g8d8fc8a987-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: x86: Virtualize AMD CPUID faulting
2026-02-10 21:09 [PATCH] KVM: x86: Virtualize AMD CPUID faulting Jamie Liu
@ 2026-02-10 23:23 ` Jim Mattson
2026-02-11 13:50 ` Sean Christopherson
1 sibling, 0 replies; 3+ messages in thread
From: Jim Mattson @ 2026-02-10 23:23 UTC (permalink / raw)
To: Jamie Liu
Cc: Sean Christopherson, Paolo Bonzini, Borislav Petkov,
Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
kvm, linux-kernel
On Tue, Feb 10, 2026 at 1:09 PM Jamie Liu <jamieliu@google.com> wrote:
>
> CPUID faulting via MSR_MISC_FEATURES_ENABLES_CPUID_FAULT is only used on
> Intel CPUs. The mechanism virtualized by this change is used on AMD
> CPUs. See arch/x86/kernel/cpu/amd.c:bsp_init_amd(),
> arch/x86/kernel/process.c:set_cpuid_faulting().
>
> Signed-off-by: Jamie Liu <jamieliu@google.com>
You missed the cpuid faulting check in em_cpuid():
ctxt->ops->get_msr(ctxt, MSR_MISC_FEATURES_ENABLES, &msr);
if (msr & MSR_MISC_FEATURES_ENABLES_CPUID_FAULT &&
ctxt->ops->cpl(ctxt)) {
return emulate_gp(ctxt, 0);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: x86: Virtualize AMD CPUID faulting
2026-02-10 21:09 [PATCH] KVM: x86: Virtualize AMD CPUID faulting Jamie Liu
2026-02-10 23:23 ` Jim Mattson
@ 2026-02-11 13:50 ` Sean Christopherson
1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2026-02-11 13:50 UTC (permalink / raw)
To: Jamie Liu
Cc: Paolo Bonzini, Borislav Petkov, Thomas Gleixner, Ingo Molnar,
Dave Hansen, x86, H. Peter Anvin, kvm, linux-kernel
On Tue, Feb 10, 2026, Jamie Liu wrote:
> CPUID faulting via MSR_MISC_FEATURES_ENABLES_CPUID_FAULT is only used on
> Intel CPUs. The mechanism virtualized by this change is used on AMD
> CPUs. See arch/x86/kernel/cpu/amd.c:bsp_init_amd(),
> arch/x86/kernel/process.c:set_cpuid_faulting().
Please rewrite this to state what is being changed, e.g. how KVM is virtualizing
the feature, and most importantly why it is "safe" to do so. Specifically, this
needs to call out that CPUID_USER_DIS is documented in the APM as an architectural
MSR, which for me at least, is mandatory for virtualizing/emulating any of the
MSR_K7_HWCR.
The fact that Intel uses some other mechanism is irrelevant, and the kernel source
code is not authoritative for things like this.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-11 13:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-10 21:09 [PATCH] KVM: x86: Virtualize AMD CPUID faulting Jamie Liu
2026-02-10 23:23 ` Jim Mattson
2026-02-11 13:50 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox