All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaron Lewis <aaronlewis@google.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com,
	Aaron Lewis <aaronlewis@google.com>
Subject: [kvm-unit-tests PATCH v2 4/4] x86: Add test coverage for nested_vmx_reflect_vmexit() testing
Date: Tue, 14 Dec 2021 01:18:23 +0000	[thread overview]
Message-ID: <20211214011823.3277011-5-aaronlewis@google.com> (raw)
In-Reply-To: <20211214011823.3277011-1-aaronlewis@google.com>

Add test cases to ensure exceptions that occur in L2 are forwarded to
the correct place.  Add testing for exceptions: #GP, #UD, #DE, #DB, #BP,
and #AC.

Signed-off-by: Aaron Lewis <aaronlewis@google.com>
---
 x86/vmx_tests.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 018db2f..f795330 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -21,6 +21,7 @@
 #include "smp.h"
 #include "delay.h"
 #include "access.h"
+#include "x86/usermode.h"
 
 #define VPID_CAP_INVVPID_TYPES_SHIFT 40
 
@@ -10701,6 +10702,72 @@ static void vmx_pf_vpid_test(void)
 	__vmx_pf_vpid_test(invalidate_tlb_new_vpid, 1);
 }
 
+static void vmx_l2_gp_test(void)
+{
+	*(volatile u64 *)NONCANONICAL = 0;
+}
+
+static void vmx_l2_ud_test(void)
+{
+	asm volatile ("ud2");
+}
+
+static void vmx_l2_de_test(void)
+{
+	asm volatile (
+		"xor %%eax, %%eax\n\t"
+		"xor %%ebx, %%ebx\n\t"
+		"xor %%edx, %%edx\n\t"
+		"idiv %%ebx\n\t"
+		::: "eax", "ebx", "edx");
+}
+
+static void vmx_l2_bp_test(void)
+{
+	asm volatile ("int3");
+}
+
+static void vmx_db_init(void)
+{
+	enable_tf();
+}
+
+static void vmx_db_uninit(void)
+{
+	disable_tf();
+}
+
+static void vmx_l2_db_test(void)
+{
+}
+
+static uint64_t usermode_callback(void)
+{
+	/* Trigger an #AC by writing 8 bytes to a 4-byte aligned address. */
+	asm volatile(
+		"sub $0x10, %rsp\n\t"
+		"movq $0, 0x4(%rsp)\n\t"
+		"add $0x10, %rsp\n\t");
+
+	return 0;
+}
+
+static void vmx_l2_ac_test(void)
+{
+	u64 old_cr0  = read_cr0();
+	u64 old_rflags = read_rflags();
+	bool raised_vector = false;
+
+	write_cr0(old_cr0 | X86_CR0_AM);
+	write_rflags(old_rflags | X86_EFLAGS_AC);
+
+	run_in_user(usermode_callback, AC_VECTOR, 0, 0, 0, 0, &raised_vector);
+	report(raised_vector, "#AC vector raised from usermode in L2");
+
+	write_cr0(old_cr0);
+	write_rflags(old_rflags);
+}
+
 struct vmx_exception_test {
 	u8 vector;
 	void (*guest_code)(void);
@@ -10709,6 +10776,12 @@ struct vmx_exception_test {
 };
 
 struct vmx_exception_test vmx_exception_tests[] = {
+	{ GP_VECTOR, vmx_l2_gp_test },
+	{ UD_VECTOR, vmx_l2_ud_test },
+	{ DE_VECTOR, vmx_l2_de_test },
+	{ DB_VECTOR, vmx_l2_db_test, vmx_db_init, vmx_db_uninit },
+	{ BP_VECTOR, vmx_l2_bp_test },
+	{ AC_VECTOR, vmx_l2_ac_test },
 };
 
 static u8 vmx_exception_test_vector;
-- 
2.34.1.173.g76aa8bc2d0-goog


  parent reply	other threads:[~2021-12-14  1:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-14  1:18 [kvm-unit-tests PATCH v2 0/4] Add additional testing for routing L2 exceptions Aaron Lewis
2021-12-14  1:18 ` [kvm-unit-tests PATCH v2 1/4] x86: Fix a #GP from occurring in usermode library's exception handlers Aaron Lewis
2021-12-14  1:18 ` [kvm-unit-tests PATCH v2 2/4] x86: Align L2's stacks Aaron Lewis
2022-01-12 19:38   ` Sean Christopherson
2021-12-14  1:18 ` [kvm-unit-tests PATCH v2 3/4] x86: Add a test framework for nested_vmx_reflect_vmexit() testing Aaron Lewis
2022-01-12 20:48   ` Sean Christopherson
2022-01-19 16:57     ` Aaron Lewis
2022-01-20  0:46       ` Sean Christopherson
2021-12-14  1:18 ` Aaron Lewis [this message]
2021-12-14 12:19 ` [kvm-unit-tests PATCH v2 0/4] Add additional testing for routing L2 exceptions 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=20211214011823.3277011-5-aaronlewis@google.com \
    --to=aaronlewis@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.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.