[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Ys2E2ckrk0JtDl52@google.com>
Date: Tue, 12 Jul 2022 14:27:37 +0000
From: Sean Christopherson <seanjc@...gle.com>
To: "Durrant, Paul" <pdurrant@...zon.co.uk>
Cc: "x86@...nel.org" <x86@...nel.org>,
"kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
David Woodhouse <dwmw2@...radead.org>,
Paolo Bonzini <pbonzini@...hat.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"H. Peter Anvin" <hpa@...or.com>
Subject: Re: [PATCH v5] KVM: x86/xen: Update Xen CPUID Leaf 4 (tsc info)
sub-leaves, if present
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.
Powered by blists - more mailing lists