* [PATCH] target/i386: do not expose ARCH_CAPABILITIES on AMD CPU
@ 2025-07-17 10:34 Paolo Bonzini
2025-07-17 12:07 ` Xiaoyao Li
2025-07-18 9:47 ` Zhao Liu
0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2025-07-17 10:34 UTC (permalink / raw)
To: qemu-devel; +Cc: Alexandre Chartre, Daniel P. Berrangé
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. Therefore, hide the bit from "-cpu host":
migration of -cpu host guests is only possible between identical host
kernel and QEMU versions, therefore this is not a problematic breakage.
If a future AMD machine does include the MSR, that would re-expose the
Windows guest bug; but it would not be KVM/QEMU's problem at that
point, as we'd be following a genuine physical CPU impl.
Reported-by: Alexandre Chartre <alexandre.chartre@oracle.com>
Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/kvm/kvm.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index e8c8be09bae..369626f8c8d 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -503,8 +503,12 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
* Linux v4.17-v4.20 incorrectly return ARCH_CAPABILITIES on SVM hosts.
* We can detect the bug by checking if MSR_IA32_ARCH_CAPABILITIES is
* returned by KVM_GET_MSR_INDEX_LIST.
+ *
+ * But also, because Windows does not like ARCH_CAPABILITIES on AMD
+ * mcahines at all, do not show the fake ARCH_CAPABILITIES MSR that
+ * KVM sets up.
*/
- if (!has_msr_arch_capabs) {
+ if (!has_msr_arch_capabs || !(edx & CPUID_7_0_EDX_ARCH_CAPABILITIES)) {
ret &= ~CPUID_7_0_EDX_ARCH_CAPABILITIES;
}
} else if (function == 7 && index == 1 && reg == R_EAX) {
--
2.50.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] target/i386: do not expose ARCH_CAPABILITIES on AMD CPU
2025-07-17 10:34 [PATCH] target/i386: do not expose ARCH_CAPABILITIES on AMD CPU Paolo Bonzini
@ 2025-07-17 12:07 ` Xiaoyao Li
2025-07-18 9:47 ` Zhao Liu
1 sibling, 0 replies; 3+ messages in thread
From: Xiaoyao Li @ 2025-07-17 12:07 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: Alexandre Chartre, Daniel P. Berrangé
On 7/17/2025 6:34 PM, Paolo Bonzini wrote:
> 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. Therefore, hide the bit from "-cpu host":
> migration of -cpu host guests is only possible between identical host
> kernel and QEMU versions, therefore this is not a problematic breakage.
>
> If a future AMD machine does include the MSR, that would re-expose the
> Windows guest bug; but it would not be KVM/QEMU's problem at that
> point, as we'd be following a genuine physical CPU impl.
>
> Reported-by: Alexandre Chartre <alexandre.chartre@oracle.com>
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
This looks reasonable to me.
Though it will break the usecase of people boot VM with "-cpu
AMD-model,+arch_capabilities", like in [1], I think it's OK break it and
force people to not do such thing any more.
[1] https://gitlab.com/qemu-project/qemu/-/issues/3001
> ---
> target/i386/kvm/kvm.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
> index e8c8be09bae..369626f8c8d 100644
> --- a/target/i386/kvm/kvm.c
> +++ b/target/i386/kvm/kvm.c
> @@ -503,8 +503,12 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
> * Linux v4.17-v4.20 incorrectly return ARCH_CAPABILITIES on SVM hosts.
> * We can detect the bug by checking if MSR_IA32_ARCH_CAPABILITIES is
> * returned by KVM_GET_MSR_INDEX_LIST.
> + *
> + * But also, because Windows does not like ARCH_CAPABILITIES on AMD
> + * mcahines at all, do not show the fake ARCH_CAPABILITIES MSR that
> + * KVM sets up.
> */
> - if (!has_msr_arch_capabs) {
> + if (!has_msr_arch_capabs || !(edx & CPUID_7_0_EDX_ARCH_CAPABILITIES)) {
> ret &= ~CPUID_7_0_EDX_ARCH_CAPABILITIES;
> }
> } else if (function == 7 && index == 1 && reg == R_EAX) {
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] target/i386: do not expose ARCH_CAPABILITIES on AMD CPU
2025-07-17 10:34 [PATCH] target/i386: do not expose ARCH_CAPABILITIES on AMD CPU Paolo Bonzini
2025-07-17 12:07 ` Xiaoyao Li
@ 2025-07-18 9:47 ` Zhao Liu
1 sibling, 0 replies; 3+ messages in thread
From: Zhao Liu @ 2025-07-18 9:47 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel, Alexandre Chartre, Daniel P. Berrangé
On Thu, Jul 17, 2025 at 12:34:48PM +0200, Paolo Bonzini wrote:
> Date: Thu, 17 Jul 2025 12:34:48 +0200
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH] target/i386: do not expose ARCH_CAPABILITIES on AMD CPU
> X-Mailer: git-send-email 2.50.1
>
> 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. Therefore, hide the bit from "-cpu host":
> migration of -cpu host guests is only possible between identical host
> kernel and QEMU versions, therefore this is not a problematic breakage.
>
> If a future AMD machine does include the MSR, that would re-expose the
> Windows guest bug; but it would not be KVM/QEMU's problem at that
> point, as we'd be following a genuine physical CPU impl.
Make sense.
> Reported-by: Alexandre Chartre <alexandre.chartre@oracle.com>
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> target/i386/kvm/kvm.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
Good to see this fix. Late but,
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-18 9:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-17 10:34 [PATCH] target/i386: do not expose ARCH_CAPABILITIES on AMD CPU Paolo Bonzini
2025-07-17 12:07 ` Xiaoyao Li
2025-07-18 9:47 ` Zhao Liu
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).