On Tue, Jul 01, 2025 at 11:25:36AM +0200, Maciej S. Szmigiero wrote: > On 1.07.2025 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.char...@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. > > Do we really add machine compat props for CPUID flags? > > I thought CPUID flags aren't live migrated but the target QEMU uses whatever > it was launched with (and the target machine exposes)?
The vast majority of the time we require compat props for guest visible changes, to guarantee stable guest ABI across reboots with different QEMU versions. "-cpu host" is a bit of a special case though, because it is impossible for QEMU to provide any ABI guarantee for the CPUID exposed by '-cpu host' It can vary based on CPU silicon, firmware settings, microcode version, KVM version and QEMU version. Any user of '-cpu host' has to expect that variance, and so only if every single component in the stack is identical can they expect a matched CPUID for '-cpu host' between 2 cold boot attempts of the guest. So provided the proposed patch *exclusively* impacts '-cpu host', and NOT any of the named CPU models, we can likely avoid adding compat props. With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|