qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i386/cpu: ARCH_CAPABILITIES should not be advertised on AMD
@ 2025-06-30 13:30 Alexandre Chartre
  2025-07-01  8:23 ` Xiaoyao Li
  2025-07-01 10:26 ` Zhao Liu
  0 siblings, 2 replies; 28+ messages in thread
From: Alexandre Chartre @ 2025-06-30 13:30 UTC (permalink / raw)
  To: qemu-devel, pbonzini, xiaoyao.li
  Cc: qemu-stable, zhao1.liu, konrad.wilk, boris.ostrovsky,
	maciej.szmigiero, alexandre.chartre

KVM emulates the ARCH_CAPABILITIES on x86 for both Intel and AMD
cpus, although the IA32_ARCH_CAPABILITIES MSR is an Intel-specific
MSR and it makes no sense to emulate it on AMD.

As a consequence, VMs created on AMD with qemu -cpu host and using
KVM will advertise the ARCH_CAPABILITIES feature and provide the
IA32_ARCH_CAPABILITIES MSR. This can cause issues (like Windows BSOD)
as the guest OS might not expect this MSR to exist on such cpus (the
AMD documentation specifies that ARCH_CAPABILITIES feature and MSR
are not defined on the AMD architecture).

A fix was proposed in KVM code, however KVM maintainers don't want to
change this behavior that exists for 6+ years and suggest changes to be
done in qemu instead.

So this commit changes the behavior in qemu so that ARCH_CAPABILITIES
is not provided by default on AMD cpus when the hypervisor emulates it,
but it can still be provided by explicitly setting arch-capabilities=on.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
---
 target/i386/cpu.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 0d35e95430..7e136c48df 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -8324,6 +8324,20 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
         }
     }
 
+    /*
+     * For years, KVM has inadvertently emulated the ARCH_CAPABILITIES
+     * MSR on AMD although this is an Intel-specific MSR; and KVM will
+     * continue doing so to not change its ABI for existing setups.
+     *
+     * So ensure that the ARCH_CAPABILITIES MSR is disabled on AMD cpus
+     * to prevent providing a cpu with an MSR which is not supposed to
+     * be there, unless it was explicitly requested by the user.
+     */
+    if (IS_AMD_CPU(env) &&
+        !(env->user_features[FEAT_7_0_EDX] & CPUID_7_0_EDX_ARCH_CAPABILITIES)) {
+        env->features[FEAT_7_0_EDX] &= ~CPUID_7_0_EDX_ARCH_CAPABILITIES;
+    }
+
     if (x86_threads_per_pkg(&env->topo_info) > 1) {
         env->features[FEAT_1_EDX] |= CPUID_HT;
 
-- 
2.43.5



^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2025-07-07 20:25 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-30 13:30 [PATCH] i386/cpu: ARCH_CAPABILITIES should not be advertised on AMD Alexandre Chartre
2025-07-01  8:23 ` Xiaoyao Li
2025-07-01  9:22   ` Alexandre Chartre
2025-07-01  9:47     ` Xiaoyao Li
2025-07-01 19:47       ` Konrad Rzeszutek Wilk
2025-07-02  1:06         ` Xiaoyao Li
2025-07-01  9:25   ` Maciej S. Szmigiero
2025-07-07 19:36     ` Daniel P. Berrangé
2025-07-01 10:26 ` Zhao Liu
2025-07-01 11:12   ` Xiaoyao Li
2025-07-01 12:12     ` Alexandre Chartre
2025-07-01 15:13       ` Xiaoyao Li
2025-07-01 19:59         ` Konrad Rzeszutek Wilk
2025-07-07 19:31           ` Daniel P. Berrangé
2025-07-07 20:03             ` Sean Christopherson
2025-07-01 12:36     ` Zhao Liu
2025-07-01 13:05       ` Igor Mammedov
2025-07-01 20:01         ` Konrad Rzeszutek Wilk
2025-07-02  5:01           ` Zhao Liu
2025-07-02  5:19             ` Zhao Liu
2025-07-02  5:30             ` Xiaoyao Li
2025-07-02  8:34               ` Zhao Liu
2025-07-07 19:20                 ` Sean Christopherson
2025-07-02  9:27             ` Alexandre Chartre
2025-07-02 11:23           ` Igor Mammedov
2025-07-07 19:54             ` Sean Christopherson
2025-07-07 19:05           ` Sean Christopherson
2025-07-01 12:19   ` Alexandre Chartre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).