kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Sean Christopherson <seanjc@google.com>,
	"Durrant, Paul" <pdurrant@amazon.co.uk>
Cc: "x86@kernel.org" <x86@kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	David Woodhouse <dwmw2@infradead.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH v5] KVM: x86/xen: Update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present
Date: Fri, 15 Jul 2022 13:43:22 +0200	[thread overview]
Message-ID: <87ilnymwit.fsf@redhat.com> (raw)
In-Reply-To: <Ys2E2ckrk0JtDl52@google.com>

Sean Christopherson <seanjc@google.com> writes:

> 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.

FWIW, this matches my understanding too: Windows guests don't seem to
check anything besides 0x40000001 and give up if Hyper-V's id is not
there.

-- 
Vitaly


      reply	other threads:[~2022-07-15 11:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-29 13:05 [PATCH v5] KVM: x86/xen: Update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present Paul Durrant
2022-07-11 22:43 ` Sean Christopherson
2022-07-12  8:37   ` Durrant, Paul
2022-07-12 14:27     ` Sean Christopherson
2022-07-15 11:43       ` Vitaly Kuznetsov [this message]

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=87ilnymwit.fsf@redhat.com \
    --to=vkuznets@redhat.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dwmw2@infradead.org \
    --cc=hpa@zytor.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pdurrant@amazon.co.uk \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=wanpengli@tencent.com \
    --cc=x86@kernel.org \
    /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).