diff mbox

[kvm-unit-tests,3/4] x86: vmx: clean up vm{launch,resume} asm

Message ID c8c2048e10974b77d5bc710dd1d1c68a50867f62.1458340713.git.pfeiner@google.com (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Feiner March 18, 2016, 10:39 p.m. UTC
Did a few things to make the code easier to fllow:

	* named I/O operands
	* removed pointless LOAD_RFLAGS
	* replaced global host_rflags with local
	* only save rflags when they're meaningful (i.e., after early failure)
	* got rid of unecessary %rsi scratch register

Signed-off-by: Peter Feiner <pfeiner@google.com>
---
 x86/vmx.c | 23 +++++++++++------------
 x86/vmx.h |  8 --------
 2 files changed, 11 insertions(+), 20 deletions(-)
diff mbox

Patch

diff --git a/x86/vmx.c b/x86/vmx.c
index 27e85eb..67f8650 100644
--- a/x86/vmx.c
+++ b/x86/vmx.c
@@ -46,7 +46,6 @@  struct regs regs;
 struct vmx_test *current;
 u64 hypercall_field;
 bool launched;
-u64 host_rflags;
 
 union vmx_basic basic;
 union vmx_ctrl_msr ctrl_pin_rev;
@@ -909,33 +908,33 @@  static int exit_handler()
 static int vmx_run()
 {
 	u32 ret = 0, fail = 0;
+	unsigned long host_rflags;
 
 	while (1) {
 
 		asm volatile (
-			"mov %%rsp, %%rsi\n\t"
-			"mov %2, %%rdi\n\t"
-			"vmwrite %%rsi, %%rdi\n\t"
-
+			"mov %[HOST_RSP], %%rdi\n\t"
+			"vmwrite %%rsp, %%rdi\n\t"
 			LOAD_GPR_C
-			"cmpl $0, %1\n\t"
+			"cmpl $0, %[launched]\n\t"
 			"jne 1f\n\t"
-			LOAD_RFLAGS
 			"vmlaunch\n\t"
 			"jmp 2f\n\t"
 			"1: "
 			"vmresume\n\t"
 			"2: "
 			SAVE_GPR_C
-			"movl $1, %0\n\t"
+			"pushf\n\t"
+			"pop %%rdi\n\t"
+			"mov %%rdi, %[host_rflags]\n\t"
+			"movl $1, %[fail]\n\t"
 			"jmp 3f\n\t"
 			"vmx_return:\n\t"
 			SAVE_GPR_C
 			"3: \n\t"
-			SAVE_RFLAGS
-			: "+m"(fail)
-			: "m"(launched), "i"(HOST_RSP)
-			: "rdi", "rsi", "memory", "cc"
+			: [fail]"+m"(fail), [host_rflags]"=m"(host_rflags)
+			: [launched]"m"(launched), [HOST_RSP]"i"(HOST_RSP)
+			: "rdi", "memory", "cc"
 
 		);
 		if (fail)
diff --git a/x86/vmx.h b/x86/vmx.h
index 34e9be4..aba5642 100644
--- a/x86/vmx.h
+++ b/x86/vmx.h
@@ -396,14 +396,6 @@  enum Ctrl1 {
 
 #define LOAD_GPR_C	SAVE_GPR_C
 
-#define SAVE_RFLAGS		\
-	"pushf\n\t"		\
-	"pop host_rflags\n\t"
-
-#define LOAD_RFLAGS		\
-	"push host_rflags\n\t"	\
-	"popf\n\t"
-
 #define VMX_IO_SIZE_MASK	0x7
 #define _VMX_IO_BYTE		0
 #define _VMX_IO_WORD		1