From: Joerg Roedel <joerg.roedel@amd.com>
To: Avi Kivity <avi@redhat.com>
Cc: Alexander Graf <agraf@suse.de>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Joerg Roedel <joerg.roedel@amd.com>
Subject: [PATCH 17/21] kvm/svm: move special nested exit handling to separate function
Date: Fri, 7 Aug 2009 11:49:44 +0200 [thread overview]
Message-ID: <1249638588-10982-18-git-send-email-joerg.roedel@amd.com> (raw)
In-Reply-To: <1249638588-10982-1-git-send-email-joerg.roedel@amd.com>
This patch moves the handling for special nested vmexits like #pf to a
separate function. This makes the kvm_override parameter obsolete and
makes the code more readable.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/kvm/svm.c | 80 ++++++++++++++++++++++++++++++++-------------------
1 files changed, 50 insertions(+), 30 deletions(-)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index cad7582..1839c19 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -47,6 +47,10 @@ MODULE_LICENSE("GPL");
#define SVM_FEATURE_LBRV (1 << 1)
#define SVM_FEATURE_SVML (1 << 2)
+#define NESTED_EXIT_HOST 0 /* Exit handled on host level */
+#define NESTED_EXIT_DONE 1 /* Exit caused nested vmexit */
+#define NESTED_EXIT_CONTINUE 2 /* Further checks needed */
+
#define DEBUGCTL_RESERVED_BITS (~(0x3fULL))
/* Turn on to get debugging output*/
@@ -127,7 +131,7 @@ module_param(nested, int, S_IRUGO);
static void svm_flush_tlb(struct kvm_vcpu *vcpu);
static void svm_complete_interrupts(struct vcpu_svm *svm);
-static int nested_svm_exit_handled(struct vcpu_svm *svm, bool kvm_override);
+static int nested_svm_exit_handled(struct vcpu_svm *svm);
static int nested_svm_vmexit(struct vcpu_svm *svm);
static int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
bool has_error_code, u32 error_code);
@@ -1368,7 +1372,7 @@ static int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
svm->vmcb->control.exit_info_1 = error_code;
svm->vmcb->control.exit_info_2 = svm->vcpu.arch.cr2;
- return nested_svm_exit_handled(svm, false);
+ return nested_svm_exit_handled(svm);
}
static inline int nested_svm_intr(struct vcpu_svm *svm)
@@ -1382,7 +1386,7 @@ static inline int nested_svm_intr(struct vcpu_svm *svm)
svm->vmcb->control.exit_code = SVM_EXIT_INTR;
- if (nested_svm_exit_handled(svm, false)) {
+ if (nested_svm_exit_handled(svm)) {
nsvm_printk("VMexit -> INTR\n");
return 1;
}
@@ -1471,31 +1475,39 @@ out:
return ret;
}
-static int nested_svm_exit_handled(struct vcpu_svm *svm, bool kvm_override)
+static int nested_svm_exit_special(struct vcpu_svm *svm)
{
u32 exit_code = svm->vmcb->control.exit_code;
- bool vmexit = false;
- if (kvm_override) {
- switch (exit_code) {
- case SVM_EXIT_INTR:
- case SVM_EXIT_NMI:
- return 0;
+ switch (exit_code) {
+ case SVM_EXIT_INTR:
+ case SVM_EXIT_NMI:
+ return NESTED_EXIT_HOST;
/* For now we are always handling NPFs when using them */
- case SVM_EXIT_NPF:
- if (npt_enabled)
- return 0;
- break;
- /* When we're shadowing, trap PFs */
- case SVM_EXIT_EXCP_BASE + PF_VECTOR:
- if (!npt_enabled)
- return 0;
- break;
- default:
- break;
- }
+ case SVM_EXIT_NPF:
+ if (npt_enabled)
+ return NESTED_EXIT_HOST;
+ break;
+ /* When we're shadowing, trap PFs */
+ case SVM_EXIT_EXCP_BASE + PF_VECTOR:
+ if (!npt_enabled)
+ return NESTED_EXIT_HOST;
+ break;
+ default:
+ break;
}
+ return NESTED_EXIT_CONTINUE;
+}
+
+/*
+ * If this function returns true, this #vmexit was already handled
+ */
+static int nested_svm_exit_handled(struct vcpu_svm *svm)
+{
+ u32 exit_code = svm->vmcb->control.exit_code;
+ int vmexit = NESTED_EXIT_HOST;
+
switch (exit_code) {
case SVM_EXIT_MSR:
vmexit = nested_svm_exit_handled_msr(svm);
@@ -1503,42 +1515,42 @@ static int nested_svm_exit_handled(struct vcpu_svm *svm, bool kvm_override)
case SVM_EXIT_READ_CR0 ... SVM_EXIT_READ_CR8: {
u32 cr_bits = 1 << (exit_code - SVM_EXIT_READ_CR0);
if (svm->nested.intercept_cr_read & cr_bits)
- vmexit = true;
+ vmexit = NESTED_EXIT_DONE;
break;
}
case SVM_EXIT_WRITE_CR0 ... SVM_EXIT_WRITE_CR8: {
u32 cr_bits = 1 << (exit_code - SVM_EXIT_WRITE_CR0);
if (svm->nested.intercept_cr_write & cr_bits)
- vmexit = true;
+ vmexit = NESTED_EXIT_DONE;
break;
}
case SVM_EXIT_READ_DR0 ... SVM_EXIT_READ_DR7: {
u32 dr_bits = 1 << (exit_code - SVM_EXIT_READ_DR0);
if (svm->nested.intercept_dr_read & dr_bits)
- vmexit = true;
+ vmexit = NESTED_EXIT_DONE;
break;
}
case SVM_EXIT_WRITE_DR0 ... SVM_EXIT_WRITE_DR7: {
u32 dr_bits = 1 << (exit_code - SVM_EXIT_WRITE_DR0);
if (svm->nested.intercept_dr_write & dr_bits)
- vmexit = true;
+ vmexit = NESTED_EXIT_DONE;
break;
}
case SVM_EXIT_EXCP_BASE ... SVM_EXIT_EXCP_BASE + 0x1f: {
u32 excp_bits = 1 << (exit_code - SVM_EXIT_EXCP_BASE);
if (svm->nested.intercept_exceptions & excp_bits)
- vmexit = true;
+ vmexit = NESTED_EXIT_DONE;
break;
}
default: {
u64 exit_bits = 1ULL << (exit_code - SVM_EXIT_INTR);
nsvm_printk("exit code: 0x%x\n", exit_code);
if (svm->nested.intercept & exit_bits)
- vmexit = true;
+ vmexit = NESTED_EXIT_DONE;
}
}
- if (vmexit) {
+ if (vmexit == NESTED_EXIT_DONE) {
nsvm_printk("#VMEXIT reason=%04x\n", exit_code);
nested_svm_vmexit(svm);
}
@@ -2316,10 +2328,18 @@ static int handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
trace_kvm_exit(exit_code, svm->vmcb->save.rip);
if (is_nested(svm)) {
+ int vmexit;
+
nsvm_printk("nested handle_exit: 0x%x | 0x%lx | 0x%lx | 0x%lx\n",
exit_code, svm->vmcb->control.exit_info_1,
svm->vmcb->control.exit_info_2, svm->vmcb->save.rip);
- if (nested_svm_exit_handled(svm, true))
+
+ vmexit = nested_svm_exit_special(svm);
+
+ if (vmexit == NESTED_EXIT_CONTINUE)
+ vmexit = nested_svm_exit_handled(svm);
+
+ if (vmexit == NESTED_EXIT_DONE)
return 1;
}
--
1.6.3.3
next prev parent reply other threads:[~2009-08-07 9:50 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-07 9:49 [PATCH 0/21] Nested SVM cleanups v2 Joerg Roedel
2009-08-07 9:49 ` [PATCH 01/21] kvm/svm: add helper functions for global interrupt flag Joerg Roedel
2009-08-07 9:49 ` [PATCH 02/21] kvm/svm: optimize nested #vmexit Joerg Roedel
2009-08-07 9:49 ` [PATCH 03/21] kvm/svm: optimize nested vmrun Joerg Roedel
2009-08-07 9:49 ` [PATCH 04/21] kvm/svm: copy only necessary parts of the control area on vmrun/vmexit Joerg Roedel
2009-08-07 9:49 ` [PATCH 05/21] kvm/svm: complete interrupts after handling nested exits Joerg Roedel
2009-08-07 9:49 ` [PATCH 06/21] kvm/svm: move nested svm state into seperate struct Joerg Roedel
2009-08-07 9:49 ` [PATCH 07/21] kvm/svm: cache nested intercepts Joerg Roedel
2009-08-07 9:49 ` [PATCH 08/21] kvm/svm: consolidate nested_svm_exit_handled Joerg Roedel
2009-08-07 9:49 ` [PATCH 09/21] kvm/svm: do nested vmexit in nested_svm_exit_handled Joerg Roedel
2009-08-07 9:49 ` [PATCH 10/21] kvm/svm: simplify nested_svm_check_exception Joerg Roedel
2009-08-07 9:49 ` [PATCH 11/21] kvm/svm: get rid of nested_svm_vmexit_real Joerg Roedel
2009-08-07 9:49 ` [PATCH 12/21] kvm/svm: clean up nested_svm_exit_handled_msr Joerg Roedel
2009-08-07 9:49 ` [PATCH 13/21] kvm/svm: clean up nestec vmload/vmsave paths Joerg Roedel
2009-08-07 9:49 ` [PATCH 14/21] kvm/svm: clean up nested vmrun path Joerg Roedel
2009-08-07 9:49 ` [PATCH 15/21] kvm/svm: remove nested_svm_do and helper functions Joerg Roedel
2009-08-07 9:49 ` [PATCH 16/21] kvm/svm: handle errors in vmrun emulation path appropriatly Joerg Roedel
2009-08-07 9:49 ` Joerg Roedel [this message]
2009-08-07 9:49 ` [PATCH 18/21] kvm/svm: remove unnecessary is_nested check from svm_cpu_run Joerg Roedel
2009-08-07 9:49 ` [PATCH 19/21] kvm/svm: move nested_svm_intr main logic out of if-clause Joerg Roedel
2009-08-07 9:49 ` [PATCH 20/21] kvm/svm: check for nested VINTR flag in svm_interrupt_allowed Joerg Roedel
2009-08-07 9:49 ` [PATCH 21/21] kvm/svm: enable nested svm by default Joerg Roedel
2009-08-09 9:41 ` [PATCH 0/21] Nested SVM cleanups v2 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=1249638588-10982-18-git-send-email-joerg.roedel@amd.com \
--to=joerg.roedel@amd.com \
--cc=agraf@suse.de \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®