Re: [PATCH v5] KVM: x86/xen: Update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present
From: Sean Christopherson
Date: Tue Jul 12 2022 - 10:28:22 EST
On Tue, Jul 12, 2022, Durrant, Paul wrote:
> > > @@ -1855,3 +1858,51 @@ void kvm_xen_destroy_vm(struct kvm *kvm)
> > > if (kvm->arch.xen_hvm_config.msr)
> > > static_branch_slow_dec_deferred(&kvm_xen_enabled);
> > > }
> > > +
> > > +void kvm_xen_after_set_cpuid(struct kvm_vcpu *vcpu)
> > > +{
> > > + u32 base = 0;
> > > + u32 limit;
> > > + u32 function;
> > > +
> > > + vcpu->arch.xen.cpuid_tsc_info = 0;
> > > +
> > > + for_each_possible_hypervisor_cpuid_base(function) {
> > > + struct kvm_cpuid_entry2 *entry = kvm_find_cpuid_entry(vcpu, function, 0);
> > > +
> > > + if (entry &&
> > > + entry->ebx == XEN_CPUID_SIGNATURE_EBX &&
> > > + entry->ecx == XEN_CPUID_SIGNATURE_ECX &&
> > > + entry->edx == XEN_CPUID_SIGNATURE_EDX) {
> > > + base = function;
> > > + limit = entry->eax;
> > > + break;
> > > + }
> > > + }
> > > + if (!base)
> > > + return;
> >
> > Rather than open code a variant of kvm_update_kvm_cpuid_base(), that helper can
> > be tweaked to take a signature. Along with a patch to provide a #define for Xen's
> > signature as a string, this entire function becomes a one-liner.
> >
>
> Sure, but as said above, we could make capturing the limit part of the
> general function too. It could even be extended to capture the Hyper-V
> base/limit too. As for defining the sig as a string... I guess it would be
> neater to use the values from the Xen header, but it'll probably make the
> code more ugly so a secondary definition is reasonable.
The base needs to be captured separately for KVM and Xen because KVM (and presumably
Xen itself since Xen also allows a variable base) supports advertising multiple
hypervisors to the guest. I don't know if there are any guests that will concurrently
utilize multiple hypervisor's paravirt features, so maybe we could squeak by, but
saving 4 bytes isn't worth the risk.
AFAIK, Hyper-V doesn't allow for a variable base, and so doesn't utilize the
for_each_possible... macro.