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 2/3] KVM: SVM: Handle invpcid during gp interception
Date: Thu, 11 Feb 2021 16:22:38 -0500 [thread overview]
Message-ID: <20210211212241.3958897-3-bsd@redhat.com> (raw)
In-Reply-To: <20210211212241.3958897-1-bsd@redhat.com>
Use the gp interception path to inject a #UD
to the guest if the guest has invpcid disabled.
This is required because for CPL > 0, #GP takes
precedence over the INVPCID intercept.
Signed-off-by: Bandan Das <bsd@redhat.com>
---
arch/x86/kvm/svm/svm.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 754e07538b4a..0e8ce7adb815 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -2170,6 +2170,7 @@ enum {
SVM_INSTR_VMRUN,
SVM_INSTR_VMLOAD,
SVM_INSTR_VMSAVE,
+ SVM_INSTR_INVPCID,
};
/* Return NONE_SVM_INSTR if not SVM instrs, otherwise return decode result */
@@ -2177,6 +2178,8 @@ static int svm_instr_opcode(struct kvm_vcpu *vcpu)
{
struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt;
+ if (ctxt->b == 0x82)
+ return SVM_INSTR_INVPCID;
if (ctxt->b != 0x1 || ctxt->opcode_len != 2)
return NONE_SVM_INSTR;
@@ -2200,11 +2203,13 @@ static int emulate_svm_instr(struct kvm_vcpu *vcpu, int opcode)
[SVM_INSTR_VMRUN] = SVM_EXIT_VMRUN,
[SVM_INSTR_VMLOAD] = SVM_EXIT_VMLOAD,
[SVM_INSTR_VMSAVE] = SVM_EXIT_VMSAVE,
+ [SVM_INSTR_INVPCID] = SVM_EXIT_EXCP_BASE + UD_VECTOR,
};
int (*const svm_instr_handlers[])(struct kvm_vcpu *vcpu) = {
[SVM_INSTR_VMRUN] = vmrun_interception,
[SVM_INSTR_VMLOAD] = vmload_interception,
[SVM_INSTR_VMSAVE] = vmsave_interception,
+ [SVM_INSTR_INVPCID] = ud_interception,
};
struct vcpu_svm *svm = to_svm(vcpu);
@@ -2253,8 +2258,12 @@ static int gp_interception(struct kvm_vcpu *vcpu)
if (!is_guest_mode(vcpu))
return kvm_emulate_instruction(vcpu,
EMULTYPE_VMWARE_GP | EMULTYPE_NO_DECODE);
- } else
+ } else {
+ if ((opcode == SVM_INSTR_INVPCID) &&
+ guest_cpuid_has(vcpu, X86_FEATURE_INVPCID))
+ goto reinject;
return emulate_svm_instr(vcpu, opcode);
+ }
reinject:
kvm_queue_exception_e(vcpu, GP_VECTOR, error_code);
--
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 ` Bandan Das [this message]
2021-02-11 21:22 ` [PATCH 3/3] KVM: SVM: check if we need to track GP intercept for invpcid Bandan Das
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-3-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