On Thu, Sep 12, 2019 at 4:28 PM Jim Mattson <jmattson@xxxxxxxxxx> wrote: > > If these CPUID leaves are implemented, the EDX output is always the > x2APIC ID, regardless of the ECX input. Furthermore, the low byte of > the ECX output is always identical to the low byte of the ECX input. > > KVM's CPUID emulation doesn't report the correct ECX and EDX outputs > when the ECX input is greater than the first subleaf for which the > "level type" is zero. This is probably only significant in the case of > the x2APIC ID, which should be the result of CPUID(EAX=0BH):EDX or > CPUID(EAX=1FH):EDX, without even setting a particular ECX input value. > > Create a "wildcard" kvm_cpuid_entry2 for leaves 0BH and 1FH in > response to the KVM_GET_SUPPORTED_CPUID ioctl. This entry does not > have the KVM_CPUID_FLAG_SIGNIFCANT_INDEX flag, so it matches all > subleaves for which there isn't a prior explicit index match. > > Add a new KVM_CPUID flag that is only applicable to leaves 0BH and > 1FH: KVM_CPUID_FLAG_CL_IS_PASSTHROUGH. When KVM's CPUID emulation > encounters this flag, it will fix up ECX[7:0] in the CPUID output. Add > this flag to the aforementioned "wildcard" kvm_cpuid_entry2. > > Note that userspace is still responsible for setting EDX to the x2APIC > ID of the vCPU in each of these structures, *including* the wildcard. > > Qemu doesn't pass the flags from KVM_GET_SUPPORTED_CPUID to > KVM_SET_CPUID2, so it will have to be modified to take advantage of > these changes. Note that passing the new flag to older kernels will > have no effect. > > Unfortunately, the new flag bit was not previously reserved, so it is > possible that a userspace agent that already sets this bit will be > unhappy with the new behavior. Technically, I suppose, this should be > implemented as a new set of ioctls. Posting as an RFC to get comments > on the API breakage. > > Fixes: 0771671749b59a ("KVM: Enhance guest cpuid management") > Fixes: a87f2d3a6eadab ("KVM: x86: Add Intel CPUID.1F cpuid emulation support") > Signed-off-by: Jim Mattson <jmattson@xxxxxxxxxx> > Reviewed-by: Steve Rutherford <srutherford@xxxxxxxxxx> > Reviewed-by: Jacob Xu <jacobhxu@xxxxxxxxxx> > Reviewed-by: Peter Shier <pshier@xxxxxxxxxx> No comments on the API breakage? Shall I resubmit as an actual patch?