From: Bandan Das <bsd@redhat.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, jmattson@google.com, wei.huang2@amd.com,
babu.moger@amd.com
Subject: [PATCH 3/3] KVM: SVM: check if we need to track GP intercept for invpcid
Date: Thu, 11 Feb 2021 16:22:39 -0500 [thread overview]
Message-ID: <20210211212241.3958897-4-bsd@redhat.com> (raw)
In-Reply-To: <20210211212241.3958897-1-bsd@redhat.com>
This is only set when the feature is available on the host
but the guest has disabled it, this will allow us to inject
the correct exception to the guest
Signed-off-by: Bandan Das <bsd@redhat.com>
---
arch/x86/kvm/svm/svm.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 0e8ce7adb815..2ecbf9bc929f 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -1102,6 +1102,7 @@ static u64 svm_write_l1_tsc_offset(struct kvm_vcpu *vcpu, u64 offset)
static void svm_check_invpcid(struct vcpu_svm *svm)
{
+ struct kvm_vcpu *vcpu = &svm->vcpu;
/*
* Intercept INVPCID instruction only if shadow page table is
* enabled. Interception is not required with nested page table
@@ -1112,6 +1113,16 @@ static void svm_check_invpcid(struct vcpu_svm *svm)
svm_set_intercept(svm, INTERCEPT_INVPCID);
else
svm_clr_intercept(svm, INTERCEPT_INVPCID);
+ /*
+ * For CPL <> 0, #GP takes priority over intercepts.
+ * This means that if invpcid is present but guest has disabled
+ * it, it might end up getting a #GP instead of #UD
+ * Let kvm inject the correct exception instead.
+ */
+ if (!guest_cpuid_has(vcpu, X86_FEATURE_INVPCID))
+ set_exception_intercept(svm, GP_VECTOR);
+ else
+ clr_exception_intercept(svm, GP_VECTOR);
}
}
--
2.24.1
next prev parent reply other threads:[~2021-02-11 21:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-11 21:22 [PATCH 0/3] AMD invpcid exception fix Bandan Das
2021-02-11 21:22 ` [PATCH 1/3] KVM: Add a stub for invpcid in the emulator table Bandan Das
2021-02-11 21:22 ` [PATCH 2/3] KVM: SVM: Handle invpcid during gp interception Bandan Das
2021-02-11 21:22 ` Bandan Das [this message]
2021-02-12 10:51 ` [PATCH 0/3] AMD invpcid exception fix Paolo Bonzini
2021-02-12 14:49 ` Bandan Das
2021-02-12 17:43 ` Jim Mattson
2021-02-12 17:55 ` Bandan Das
2021-02-12 18:20 ` Jim Mattson
2021-02-12 18:35 ` Bandan Das
2021-02-12 19:40 ` Jim Mattson
2021-02-12 20:09 ` Bandan Das
2021-02-12 20:56 ` Jim Mattson
2021-02-12 21:42 ` Paolo Bonzini
2021-02-12 21:49 ` Bandan Das
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=20210211212241.3958897-4-bsd@redhat.com \
--to=bsd@redhat.com \
--cc=babu.moger@amd.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=wei.huang2@amd.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