All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: Gleb Natapov <gleb@kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm <kvm@vger.kernel.org>
Subject: [PATCH 05/13] lib/x86: Move exception test code into library
Date: Sat,  4 Jan 2014 18:59:11 +0100	[thread overview]
Message-ID: <5b43f96a1996b19ae304f27de0bc27f0dac7e19a.1388858359.git.jan.kiszka@web.de> (raw)
In-Reply-To: <cover.1388858359.git.jan.kiszka@web.de>
In-Reply-To: <cover.1388858359.git.jan.kiszka@web.de>

From: Jan Kiszka <jan.kiszka@siemens.com>

Will also be used by the APIC test. Moving exception_return assignment
out of line, we can drop the explicit compiler barrier.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 lib/x86/desc.c | 24 ++++++++++++++++++++++++
 lib/x86/desc.h |  4 ++++
 x86/vmx.c      | 34 +++++++---------------------------
 3 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/lib/x86/desc.c b/lib/x86/desc.c
index 7c5c721..f75ec1d 100644
--- a/lib/x86/desc.c
+++ b/lib/x86/desc.c
@@ -353,3 +353,27 @@ void print_current_tss_info(void)
                tr, tss[0].prev, tss[i].prev);
 }
 #endif
+
+static bool exception;
+static void *exception_return;
+
+static void exception_handler(struct ex_regs *regs)
+{
+	exception = true;
+	regs->rip = (unsigned long)exception_return;
+}
+
+bool test_for_exception(unsigned int ex, void (*trigger_func)(void *data),
+			void *data)
+{
+	handle_exception(ex, exception_handler);
+	exception = false;
+	trigger_func(data);
+	handle_exception(ex, NULL);
+	return exception;
+}
+
+void set_exception_return(void *addr)
+{
+	exception_return = addr;
+}
diff --git a/lib/x86/desc.h b/lib/x86/desc.h
index f819452..5c850b2 100644
--- a/lib/x86/desc.h
+++ b/lib/x86/desc.h
@@ -84,4 +84,8 @@ void set_intr_task_gate(int e, void *fn);
 void print_current_tss_info(void);
 void handle_exception(u8 v, void (*func)(struct ex_regs *regs));
 
+bool test_for_exception(unsigned int ex, void (*trigger_func)(void *data),
+			void *data);
+void set_exception_return(void *addr);
+
 #endif
diff --git a/x86/vmx.c b/x86/vmx.c
index f9d5493..4f0bb8d 100644
--- a/x86/vmx.c
+++ b/x86/vmx.c
@@ -538,38 +538,18 @@ static void init_vmx(void)
 	memset(guest_syscall_stack, 0, PAGE_SIZE);
 }
 
-static bool exception;
-static void *exception_return;
-
-static void exception_handler(struct ex_regs *regs)
+static void do_vmxon_off(void *data)
 {
-	exception = true;
-	regs->rip = (u64)exception_return;
-}
-
-static int test_for_exception(unsigned int ex, void (*func)(void))
-{
-	handle_exception(ex, exception_handler);
-	exception = false;
-	func();
-	handle_exception(ex, NULL);
-	return exception;
-}
-
-static void do_vmxon_off(void)
-{
-	exception_return = &&resume;
-	barrier();
+	set_exception_return(&&resume);
 	vmx_on();
 	vmx_off();
 resume:
 	barrier();
 }
 
-static void do_write_feature_control(void)
+static void do_write_feature_control(void *data)
 {
-	exception_return = &&resume;
-	barrier();
+	set_exception_return(&&resume);
 	wrmsr(MSR_IA32_FEATURE_CONTROL, 0);
 resume:
 	barrier();
@@ -592,18 +572,18 @@ static int test_vmx_feature_control(void)
 
 	wrmsr(MSR_IA32_FEATURE_CONTROL, 0);
 	report("test vmxon with FEATURE_CONTROL cleared",
-	       test_for_exception(GP_VECTOR, &do_vmxon_off));
+	       test_for_exception(GP_VECTOR, &do_vmxon_off, NULL));
 
 	wrmsr(MSR_IA32_FEATURE_CONTROL, 0x4);
 	report("test vmxon without FEATURE_CONTROL lock",
-	       test_for_exception(GP_VECTOR, &do_vmxon_off));
+	       test_for_exception(GP_VECTOR, &do_vmxon_off, NULL));
 
 	wrmsr(MSR_IA32_FEATURE_CONTROL, 0x5);
 	vmx_enabled = ((rdmsr(MSR_IA32_FEATURE_CONTROL) & 0x5) == 0x5);
 	report("test enable VMX in FEATURE_CONTROL", vmx_enabled);
 
 	report("test FEATURE_CONTROL lock bit",
-	       test_for_exception(GP_VECTOR, &do_write_feature_control));
+	       test_for_exception(GP_VECTOR, &do_write_feature_control, NULL));
 
 	return !vmx_enabled;
 }
-- 
1.8.1.1.298.ge7eed54


  parent reply	other threads:[~2014-01-04 17:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-04 17:59 [PATCH 00/13] kvm-unit-tests: Various improvements for x86 tests Jan Kiszka
2014-01-04 17:59 ` [PATCH 01/13] VMX: Add test cases around interrupt injection and halting Jan Kiszka
2014-01-04 17:59 ` [PATCH 02/13] VMX: Extend preemption timer tests Jan Kiszka
2014-01-04 17:59 ` [PATCH 03/13] apic: Remove redundant enable_apic Jan Kiszka
2014-01-04 17:59 ` [PATCH 04/13] VMX: Fix return label in fault-triggering handlers Jan Kiszka
2014-01-22 15:00   ` Paolo Bonzini
2014-01-22 17:21     ` Paolo Bonzini
2014-01-04 17:59 ` Jan Kiszka [this message]
2014-01-04 17:59 ` [PATCH 06/13] x2apic: Test for invalid state transitions Jan Kiszka
2014-01-04 17:59 ` [PATCH 07/13] lib/x86/apic: Consolidate over MSR_IA32_APICBASE Jan Kiszka
2014-01-04 17:59 ` [PATCH 08/13] apic: Add test case for relocation and writing reserved bits Jan Kiszka
2014-01-04 17:59 ` [PATCH 09/13] VMX: Check unconditional I/O exiting Jan Kiszka
2014-01-04 17:59 ` [PATCH 10/13] Provide common report and report_summary services Jan Kiszka
2014-01-04 17:59 ` [PATCH 11/13] Ignore *.elf build outputs Jan Kiszka
2014-01-04 17:59 ` [PATCH 12/13] svm: Add missing build dependency Jan Kiszka
2014-01-04 17:59 ` [PATCH 13/13] x86: Add debug facility test case Jan Kiszka
2014-01-22 17:23 ` [PATCH 00/13] kvm-unit-tests: Various improvements for x86 tests Paolo Bonzini
2014-02-25 14:35 ` Paolo Bonzini

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=5b43f96a1996b19ae304f27de0bc27f0dac7e19a.1388858359.git.jan.kiszka@web.de \
    --to=jan.kiszka@web.de \
    --cc=gleb@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.