public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Jue Wang <juew@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: x86: Add support for CMCI and UCNA.
Date: Tue, 12 Apr 2022 16:54:27 +0000	[thread overview]
Message-ID: <YlWuw7ANhiiLojQX@google.com> (raw)
In-Reply-To: <CAPcxDJ4iXwSRK9nRTemkMvhjE5WePeLuc0-60eRCOq5bRRHX0A@mail.gmail.com>

On Tue, Apr 12, 2022, Jue Wang wrote:
> > > +
> > > +                     if (!(mcg_cap & MCG_CMCI_P) &&
> > > +                         (data || !msr_info->host_initiated))
> >
> > This looks wrong, userspace should either be able to write the MSR or not, '0'
> > isn't special.  Unless there's a danger to KVM, which I don't think there is,
> > userspace should be allowed to ignore architectural restrictions, i.e. bypass
> > the MCG_CMCI_P check, so that KVM doesn't create an unnecessary dependency between
> > ioctls.  I.e. this should be:
> 
> I think the idea was writing unsupported values into an MSR should
> cause #GP.

Right, but when userspace is stuffing MSR values KVM only needs to prevent userspace
from writing values that are completely bogus, i.e. not supported by KVM at all.
Userspace is allowed to violated the guest vCPU model.

> The code is consistent (copied) from the code that handles MSR_IA32_MCG_CTL:
> 
> https://elixir.bootlin.com/linux/v5.17-rc8/source/arch/x86/kvm/x86.c#L3177

Ah.  Sadly, KVM has these sorts of bad examples lurking in dark corners :-/

> Can you elaborate what unnecessary dependency between ioctls this may cause?

Enforcing the vCPU model checks on userspace write means userspace must do
KVM_X86_SETUP_MCE before KVM_SET_MSRS, otherwise stuffing the MSRs will fail.
It's not a big deal since userspace is likely using this ordering given that no
one has complained about MSR_IA32_MCG_CTL, but it's easy to remedy and it makes
the code simpler.

  parent reply	other threads:[~2022-04-12 16:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-23 18:28 [PATCH] KVM: x86: Add support for CMCI and UCNA Jue Wang
2022-04-10 16:56 ` Jue Wang
2022-04-11 19:08 ` Sean Christopherson
2022-04-12 14:22   ` Jue Wang
2022-04-12 14:29     ` Jue Wang
2022-04-12 16:57       ` Sean Christopherson
2022-04-12 16:54     ` Sean Christopherson [this message]
2022-04-12 17:44   ` Paolo Bonzini
2022-04-12 18:19     ` Sean Christopherson
2022-04-12 19:52       ` Jue Wang

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=YlWuw7ANhiiLojQX@google.com \
    --to=seanjc@google.com \
    --cc=juew@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@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