From: Paolo Bonzini <pbonzini@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Babu Moger <babu.moger@amd.com>
Subject: Re: [PATCH 0/3] KVM: x86: SVM INVPCID fix, and cleanups
Date: Mon, 15 Feb 2021 17:45:24 +0100 [thread overview]
Message-ID: <65fa42a3-4f7b-4708-ffce-e77fe32aaed7@redhat.com> (raw)
In-Reply-To: <20210212003411.1102677-1-seanjc@google.com>
On 12/02/21 01:34, Sean Christopherson wrote:
> Fix an INVPCID bug on SVM where it fails to injected a #UD when INVPCID is
> supported but not exposed to the guest. Do a bit of cleanup in patch 02
> now that both VMX and SVM support PCID/INVPCID.
>
> Patch 03 address KVM behavior that has long confused the heck out of me.
> KVM currently allows enabling INVPCID if and only if PCID is also enabled
> for the guest, the justification being that the guest will see incorrect
> fault behavior (#UD instead of #GP) due to the way the VMCS control works.
>
> But that makes no sense, because nothing is forcing KVM to disable INVCPID
> in the VMCS when PCID is disabled. AFACIT, the myth was the result of a
> bug in the original _submission_, not even the original _commit_ was buggy.
>
> Digging back, the very original submission had this code, where
> vmx_pcid_supported() was further conditioned on EPT being enabled. This
> would lead to the buggy scenario of unexpected #UD, as a host with PCID
> and INVCPID would fail to enable INVPCID if EPT was disabled.
>
>>> + if (vmx_pcid_supported()) {
>>> + exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
>>> + if (exec_control & SECONDARY_EXEC_ENABLE_INVPCID) {
>>> + best = kvm_find_cpuid_entry(vcpu, 0x1, 0);
>>> + if (best && (best->ecx & bit(X86_FEATURE_PCID)))
>>> + vmx->invpcid_enabled = true;
>>> + else {
>>> + exec_control &= ~SECONDARY_EXEC_ENABLE_INVPCID;
>>> + vmcs_write32(SECONDARY_VM_EXEC_CONTROL,
>>> + exec_control);
>>> + best = kvm_find_cpuid_entry(vcpu, 0x7, 0);
>>> + best->ecx &= ~bit(X86_FEATURE_INVPCID);
>>> + }
>>> + }
>>> + }
>
> The incorrect behavior is especially problematic now that SVM also
> supports INVCPID, as KVM allows !PCID && INVPCID on SVM but not on VMX.
>
> Patches to fix kvm-unit-tests are also incoming...
>
> Sean Christopherson (3):
> KVM: SVM: Intercept INVPCID when it's disabled to inject #UD
> KVM: x86: Advertise INVPCID by default
> KVM: VMX: Allow INVPCID in guest without PCID
>
> arch/x86/kvm/cpuid.c | 2 +-
> arch/x86/kvm/svm/svm.c | 11 ++++-------
> arch/x86/kvm/vmx/vmx.c | 14 ++------------
> 3 files changed, 7 insertions(+), 20 deletions(-)
>
Queued, thanks.
Paolo
prev parent reply other threads:[~2021-02-15 17:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-12 0:34 [PATCH 0/3] KVM: x86: SVM INVPCID fix, and cleanups Sean Christopherson
2021-02-12 0:34 ` [PATCH 1/3] KVM: SVM: Intercept INVPCID when it's disabled to inject #UD Sean Christopherson
2021-02-12 1:01 ` Jim Mattson
2021-02-12 0:34 ` [PATCH 2/3] KVM: x86: Advertise INVPCID by default Sean Christopherson
2021-02-12 1:02 ` Jim Mattson
2021-02-12 0:34 ` [PATCH 3/3] KVM: VMX: Allow INVPCID in guest without PCID Sean Christopherson
2021-02-12 0:58 ` Jim Mattson
2021-02-15 16:45 ` Paolo Bonzini [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=65fa42a3-4f7b-4708-ffce-e77fe32aaed7@redhat.com \
--to=pbonzini@redhat.com \
--cc=babu.moger@amd.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.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;
as well as URLs for NNTP newsgroup(s).