From: Joerg Roedel <joerg.roedel@amd.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Joerg Roedel <joerg.roedel@amd.com>
Subject: [PATCH 1/9] KVM: Add infrastructure to emulate instruction intercepts
Date: Wed, 24 Nov 2010 19:18:27 +0100 [thread overview]
Message-ID: <1290622715-8382-2-git-send-email-joerg.roedel@amd.com> (raw)
In-Reply-To: <1290622715-8382-1-git-send-email-joerg.roedel@amd.com>
This patch adds the necessary infrastructure to KVM to
implement instruction intercepts when the vcpu in in
emulated guest mode.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/include/asm/kvm_emulate.h | 2 ++
arch/x86/include/asm/kvm_host.h | 3 +++
arch/x86/kvm/svm.c | 8 ++++++++
arch/x86/kvm/vmx.c | 8 ++++++++
arch/x86/kvm/x86.c | 5 +++++
5 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h
index b48c133..3498431 100644
--- a/arch/x86/include/asm/kvm_emulate.h
+++ b/arch/x86/include/asm/kvm_emulate.h
@@ -54,6 +54,8 @@ struct x86_emulate_ctxt;
#define X86EMUL_RETRY_INSTR 3 /* retry the instruction for some reason */
#define X86EMUL_CMPXCHG_FAILED 4 /* cmpxchg did not see expected value */
#define X86EMUL_IO_NEEDED 5 /* IO is needed to complete emulation */
+#define X86EMUL_INTERCEPTED 6 /* VCPU is in guest mode and the
+ instruction is intercepted */
struct x86_emulate_ops {
/*
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 54e42c8..bcc781b 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -596,6 +596,9 @@ struct kvm_x86_ops {
void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2);
const struct trace_print_flags *exit_reasons_str;
+
+ int (*insn_intercepted)(struct kvm_vcpu *vcpu,
+ struct x86_emulate_ctxt *ctxt);
};
struct kvm_arch_async_pf {
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 2fd2f4d..d1721c2 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -3619,6 +3619,12 @@ static void svm_fpu_deactivate(struct kvm_vcpu *vcpu)
update_cr0_intercept(svm);
}
+static int svm_insn_intercepted(struct kvm_vcpu *vcpu,
+ struct x86_emulate_ctxt *ctxt)
+{
+ return X86EMUL_CONTINUE;
+}
+
static struct kvm_x86_ops svm_x86_ops = {
.cpu_has_kvm_support = has_svm,
.disabled_by_bios = is_disabled,
@@ -3703,6 +3709,8 @@ static struct kvm_x86_ops svm_x86_ops = {
.adjust_tsc_offset = svm_adjust_tsc_offset,
.set_tdp_cr3 = set_tdp_cr3,
+
+ .insn_intercepted = svm_insn_intercepted,
};
static int __init svm_init(void)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index caa967e..81de3a9 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -4278,6 +4278,12 @@ static void vmx_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
{
}
+static int vmx_insn_intercepted(struct kvm_vcpu *vcpu,
+ struct x86_emulate_ctxt *ctxt)
+{
+ return X86EMUL_CONTINUE;
+}
+
static struct kvm_x86_ops vmx_x86_ops = {
.cpu_has_kvm_support = cpu_has_kvm_support,
.disabled_by_bios = vmx_disabled_by_bios,
@@ -4362,6 +4368,8 @@ static struct kvm_x86_ops vmx_x86_ops = {
.adjust_tsc_offset = vmx_adjust_tsc_offset,
.set_tdp_cr3 = vmx_set_cr3,
+
+ .insn_intercepted = vmx_insn_intercepted,
};
static int __init vmx_init(void)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 410d2d1..759cc19 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4383,6 +4383,11 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
if (r == X86EMUL_PROPAGATE_FAULT)
goto done;
+ r = kvm_x86_ops->insn_intercepted(vcpu,
+ &vcpu->arch.emulate_ctxt);
+ if (r == X86EMUL_INTERCEPTED)
+ return EMULATE_DONE;
+
trace_kvm_emulate_insn_start(vcpu);
/* Only allow emulation of specific instructions on #UD
--
1.7.1
next prev parent reply other threads:[~2010-11-24 18:18 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-24 18:18 [PATCH 0/9] KVM: Make the instruction emulator aware of Nested Virtualization Joerg Roedel
2010-11-24 18:18 ` Joerg Roedel [this message]
2010-11-24 18:18 ` [PATCH 2/9] KVM: SVM: Add checks for CRx read and write intercepts Joerg Roedel
2010-11-24 18:18 ` [PATCH 3/9] KVM: SVM: Add checks for DRx " Joerg Roedel
2010-11-24 18:18 ` [PATCH 4/9] KVM: SVM: Add intercept checks for descriptor table accesses Joerg Roedel
2010-11-24 18:18 ` [PATCH 5/9] KVM: SVM: Add checks for all group 7 instructions Joerg Roedel
2010-11-24 18:18 ` [PATCH 6/9] KVM: SVM: Add intercept checks for remaining twobyte instructions Joerg Roedel
2010-11-24 18:18 ` [PATCH 7/9] KVM: SVM: Add intercept checks for one-byte instructions Joerg Roedel
2010-11-24 18:18 ` [PATCH 8/9] KVM: SVM: Add checks for IO instructions Joerg Roedel
2010-11-24 18:18 ` [PATCH 9/9] KVM: SVM: Remove nested sel_cr0_write handling code Joerg Roedel
2010-11-24 19:13 ` [PATCH 0/9] KVM: Make the instruction emulator aware of Nested Virtualization Avi Kivity
2010-11-25 11:46 ` Roedel, Joerg
2010-11-25 13:13 ` Roedel, Joerg
2010-11-25 15:17 ` Avi Kivity
2010-11-25 16:23 ` Roedel, Joerg
2010-11-29 17:23 ` Valdis.Kletnieks
2010-11-29 18:32 ` Joerg Roedel
2010-11-29 20:01 ` Valdis.Kletnieks
2010-11-30 8:47 ` Roedel, Joerg
2010-11-25 15:15 ` Avi Kivity
2010-11-25 18:21 ` Roedel, Joerg
2010-11-26 8:28 ` Avi Kivity
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=1290622715-8382-2-git-send-email-joerg.roedel@amd.com \
--to=joerg.roedel@amd.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@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