mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maxim Levitsky <mlevitsk@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] KVM: x86: Add dedicated helper to get CPUID entry with significant index
Date: Thu, 14 Jul 2022 13:58:17 +0300	[thread overview]
Message-ID: <087db845684c18af112e396172598172c7cc9980.camel@redhat.com> (raw)
In-Reply-To: <Ys2qwUmEJaJnsj6r@google.com>

On Tue, 2022-07-12 at 17:09 +0000, Sean Christopherson wrote:
> On Tue, Jul 12, 2022, Sean Christopherson wrote:
> > On Tue, Jul 12, 2022, Maxim Levitsky wrote:
> > > On Tue, 2022-07-12 at 00:06 +0000, Sean Christopherson wrote:
> > > > +               /*
> > > > +                * Function matches and index is significant; not specifying an
> > > > +                * exact index in this case is a KVM bug.
> > > > +                */
> > > Nitpick: Why KVM bug? Bad userspace can also provide a index-significant entry for cpuid
> > > leaf for which index is not significant in the x86 spec.
> > 
> > Ugh, you're right.
> > 
> > > We could arrange a table of all known leaves and for each leaf if it has an index
> > > in the x86 spec, and warn/reject the userspace CPUID info if it doesn't match.
> > 
> > We have such a table, cpuid_function_is_indexed().  The alternative would be to
> > do:
> > 
> >                 WARN_ON_ONCE(index == KVM_CPUID_INDEX_NOT_SIGNIFICANT &&
> >                              cpuid_function_is_indexed(function));
> > 
> > The problem with rejecting userspace CPUID on mismatch is that it could break
> > userspace :-/  Of course, this entire patch would also break userspace to some
> > extent, e.g. if userspace is relying on an exact match on index==0.  The only
> > difference being the guest lookups with an exact index would still work.
> > 
> > I think the restriction we could put in place would be that userspace can make
> > a leaf more relaxed, e.g. to play nice if userspace forgets to set the SIGNFICANT
> > flag, but rejects attempts to make guest CPUID more restrictive, i.e. disallow
> > setting the SIGNFICANT flag on leafs that KVM doesn't enumerate as significant.
> > 
> > > > +               WARN_ON_ONCE(index == KVM_CPUID_INDEX_NOT_SIGNIFICANT);
> 
> Actually, better idea.  Let userspace do whatever, and have direct KVM lookups
> for functions that architecturally don't have a significant index use the first
> entry even if userspace set the SIGNIFICANT flag.  That will mostly maintain
> backwards compatibility, the only thing that would break is if userspace set the
> SIGNIFICANT flag _and_ provided a non-zero index _and_ relied on KVM to not match
> the entry.

Makes sense as well.

Best regards,
	Maxim Levitsky

> 
> We could still enforce matching in the future, but it wouldn't be a prerequisite
> for this cleanup.
> 
>                 /*
>                  * Similarly, use the first matching entry if KVM is doing a
>                  * lookup (as opposed to emulating CPUID) for a function that's
>                  * architecturally defined as not having a significant index.
>                  */
>                 if (index == KVM_CPUID_INDEX_NOT_SIGNIFICANT) {
>                         /*
>                          * Direct lookups from KVM should not diverge from what
>                          * KVM defines internally (the architectural behavior).
>                          */
>                         WARN_ON_ONCE(cpuid_function_is_indexed(function));
>                         return e;
>                 }
> 



  reply	other threads:[~2022-07-14 10:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12  0:06 Sean Christopherson
2022-07-12  6:38 ` Xiaoyao Li
2022-07-12 15:33 ` Maxim Levitsky
2022-07-12 16:35   ` Sean Christopherson
2022-07-12 17:09     ` Sean Christopherson
2022-07-14 10:58       ` Maxim Levitsky [this message]
2022-07-14 15:38         ` Paolo Bonzini
2022-07-14 10:57     ` Maxim Levitsky

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=087db845684c18af112e396172598172c7cc9980.camel@redhat.com \
    --to=mlevitsk@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    /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

all inboxes | Powered by JetHome®