From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Alexandre Chartre <alexandre.chartre@oracle.com>,
qemu-devel@nongnu.org, pbonzini@redhat.com
Cc: qemu-stable@nongnu.org, zhao1.liu@intel.com,
konrad.wilk@oracle.com, boris.ostrovsky@oracle.com,
maciej.szmigiero@oracle.com
Subject: Re: [PATCH] i386/cpu: ARCH_CAPABILITIES should not be advertised on AMD
Date: Tue, 1 Jul 2025 17:47:06 +0800 [thread overview]
Message-ID: <c8a0bd48-3f48-4f3b-b3ee-93a14e84a70a@intel.com> (raw)
In-Reply-To: <abdf31e3-2ada-47d8-9c9d-d875491537b2@oracle.com>
On 7/1/2025 5:22 PM, Alexandre Chartre wrote:
>
> On 7/1/25 10:23, Xiaoyao Li wrote:
>> On 6/30/2025 9:30 PM, Alexandre Chartre 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.
>>>
>>> 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;
>>> + }
>>
>> This changes the result for the existing usage of "-cpu host" on
>> AMD. So it will need a compat_prop to keep the old behavior for old
>> machine.
>
> Right, I will look at that.
>
>>
>> But I would like discuss if we really want to do it in QEMU.
>> ARCH_CAPABILITIES is not the only one KVM emulates unconditionally.
>> We have TSC_DEADLINE_TIMER as well. So why to treat them
>> differently? just because some Windows cannot boot? To me, it looks
>> just the bug of Windows. So please fix Windows. And to run with the
>> buggy Windows, we have the workaround: "-cpu host,-arch-capabilities"
>
> Well, the Windows behavior is not that wrong as it conforms to the AMD
> Manual
> which specifies that ARCH_CAPABILITIES feature and MSR are not defined
> on AMD
> cpus; while QEMU/KVM are providing an hybrid kind of AMD cpu with Intel
> feature/MSR.
It is currently reserved bit in AMD's manual. But it doesn't mean it
will be reserved forever. Nothing prevents AMD to implement it in the
future.
Software shouldn't set any expectation on the reserved bit.
> Microsoft is fixing that behavior anyway and has provided a preview fix
> (OS Build
> 26100.4484), so that's good news. But the goal here is also to prevent
> such future
> misbehavior. So if other features (like TSC_DEADLINE_TIMER) are exposed
> while they
> shouldn't then they should probably be fixed as well.
> > "-cpu host,-arch-capabilities" is indeed a workaround, but it defeats
> the purpose
> of the "-cpu host" option which is to provide a guest with the same
> features as the
> host. And this workaround basically says: "provide a guest with the same
> cpu as
> the host but disable this feature that the host doesn't provide"; this
> doesn't make
> sense. Also this workaround doesn't integrate well in heterogeneous
> environments
> (with Intel, AMD, ARM or other cpus) where you just want to use "-cpu
> host" whatever
> the platform is, and not have a special case for AMD cpus.
As I said, it's just the workaround for users who want to run a specific
version of Windows with "-cpu host" on AMD. That's why it's called
workaround.
The root-cause is the wrong behavior of the specific version of Windows.
If you don't use the buggy Windows, you don't need the workaround.
> Thanks,
>
> alex.
>
next prev parent reply other threads:[~2025-07-01 9:47 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=c8a0bd48-3f48-4f3b-b3ee-93a14e84a70a@intel.com \
--to=xiaoyao.li@intel.com \
--cc=alexandre.chartre@oracle.com \
--cc=boris.ostrovsky@oracle.com \
--cc=konrad.wilk@oracle.com \
--cc=maciej.szmigiero@oracle.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=zhao1.liu@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).