All of lore.kernel.org
 help / color / mirror / Atom feed
From: Krish Sadhukhan <krish.sadhukhan@oracle.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com
Subject: [PATCH 2/3] nVMX: Add helper functions to set/unset host RFLAGS.TF on the VMRUN instruction
Date: Tue,  2 Feb 2021 20:28:41 -0500	[thread overview]
Message-ID: <20210203012842.101447-3-krish.sadhukhan@oracle.com> (raw)
In-Reply-To: <20210203012842.101447-1-krish.sadhukhan@oracle.com>

Add helper functions to set host RFLAGS.TF immediately before the VMRUN
instruction. These will be used  by the next patch to test Single Stepping
on the VMRUN instruction from the host's perspective.

Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
---
 x86/svm.c       | 24 ++++++++++++++++++++++--
 x86/svm.h       |  3 +++
 x86/svm_tests.c |  1 -
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/x86/svm.c b/x86/svm.c
index a1808c7..547f62a 100644
--- a/x86/svm.c
+++ b/x86/svm.c
@@ -179,6 +179,17 @@ void vmcb_ident(struct vmcb *vmcb)
 	}
 }
 
+static bool ss_bp_on_vmrun = false;
+void set_ss_bp_on_vmrun(void)
+{
+	ss_bp_on_vmrun = true;
+}
+
+void unset_ss_bp_on_vmrun(void)
+{
+	ss_bp_on_vmrun = false;
+}
+
 struct regs regs;
 
 struct regs get_regs(void)
@@ -215,6 +226,12 @@ struct svm_test *v2_test;
                 "mov regs, %%r15\n\t"           \
                 "mov %%r15, 0x1f8(%%rax)\n\t"   \
                 LOAD_GPR_C                      \
+                "cmpb $0, %[ss_bp]\n\t"         \
+                "je 1f\n\t"                     \
+                "pushf; pop %%r8\n\t"           \
+                "or $0x100, %%r8\n\t"           \
+                "push %%r8; popf\n\t"           \
+                "1: "                           \
                 "vmrun %%rax\n\t"               \
                 SAVE_GPR_C                      \
                 "mov 0x170(%%rax), %%r15\n\t"   \
@@ -234,7 +251,8 @@ int svm_vmrun(void)
 	asm volatile (
 		ASM_VMRUN_CMD
 		:
-		: "a" (virt_to_phys(vmcb))
+		: "a" (virt_to_phys(vmcb)),
+		[ss_bp]"m"(ss_bp_on_vmrun)
 		: "memory", "r15");
 
 	return (vmcb->control.exit_code);
@@ -253,6 +271,7 @@ static void test_run(struct svm_test *test)
 	do {
 		struct svm_test *the_test = test;
 		u64 the_vmcb = vmcb_phys;
+
 		asm volatile (
 			"clgi;\n\t" // semi-colon needed for LLVM compatibility
 			"sti \n\t"
@@ -266,7 +285,8 @@ static void test_run(struct svm_test *test)
 			"=b" (the_vmcb)             // callee save register!
 			: [test] "0" (the_test),
 			[vmcb_phys] "1"(the_vmcb),
-			[PREPARE_GIF_CLEAR] "i" (offsetof(struct svm_test, prepare_gif_clear))
+			[PREPARE_GIF_CLEAR] "i" (offsetof(struct svm_test, prepare_gif_clear)),
+			[ss_bp]"m"(ss_bp_on_vmrun)
 			: "rax", "rcx", "rdx", "rsi",
 			"r8", "r9", "r10", "r11" , "r12", "r13", "r14", "r15",
 			"memory");
diff --git a/x86/svm.h b/x86/svm.h
index a0863b8..d521972 100644
--- a/x86/svm.h
+++ b/x86/svm.h
@@ -391,6 +391,9 @@ void vmcb_ident(struct vmcb *vmcb);
 struct regs get_regs(void);
 void vmmcall(void);
 int svm_vmrun(void);
+int svm_vmrun1(void);
+void set_ss_bp_on_vmrun(void);
+void unset_ss_bp_on_vmrun(void);
 void test_set_guest(test_guest_func func);
 
 extern struct vmcb *vmcb;
diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index 29a0b59..7bf3624 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -2046,7 +2046,6 @@ static void basic_guest_main(struct svm_test *test)
 {
 }
 
-
 #define SVM_TEST_REG_RESERVED_BITS(start, end, inc, str_name, reg, val,	\
 				   resv_mask)				\
 {									\
-- 
2.27.0


  parent reply	other threads:[~2021-02-03  2:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03  1:28 [PATCH 0/3] nSVM: Test host RFLAGS.TF on VMRUN Krish Sadhukhan
2021-02-03  1:28 ` [PATCH 1/3] KVM: SVM: Replace hard-coded value with #define Krish Sadhukhan
2021-02-03  1:28 ` Krish Sadhukhan [this message]
2021-02-03  8:15   ` [PATCH 2/3] nVMX: Add helper functions to set/unset host RFLAGS.TF on the VMRUN instruction Paolo Bonzini
2021-02-05  0:20     ` Krish Sadhukhan
2021-02-05  8:21       ` Paolo Bonzini
2021-02-23 20:10         ` Krish Sadhukhan
2021-02-03  1:28 ` [PATCH 3/3] nSVM: Test effect of host RFLAGS.TF on VMRUN Krish Sadhukhan

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=20210203012842.101447-3-krish.sadhukhan@oracle.com \
    --to=krish.sadhukhan@oracle.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.