[1/4] kvm-unit-test: VMX: Replace hard-coded exit instruction length
diff mbox series

Message ID 20191015001633.8603-2-krish.sadhukhan@oracle.com
State New
Headers show
Series
  • : kvm-unit-test: nVMX: Test deferring of error from VM-entry MSR-load area
Related show

Commit Message

Krish Sadhukhan Oct. 15, 2019, 12:16 a.m. UTC
..with value read from EXI_INST_LEN field.

Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com>
---
 x86/vmx_tests.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

Comments

Jim Mattson Oct. 16, 2019, 4:39 p.m. UTC | #1
On Mon, Oct 14, 2019 at 5:52 PM Krish Sadhukhan
<krish.sadhukhan@oracle.com> wrote:
>
>   ..with value read from EXI_INST_LEN field.
>
> Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> Reviewed-by: Liran Alon <liran.alon@oracle.com>
> Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com>
Reviewed-by: Jim Mattson <jmattson@google.com>

Patch
diff mbox series

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 4aebc3f..7d73ee3 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -87,6 +87,7 @@  static int vmenter_exit_handler(void)
 {
 	u64 guest_rip;
 	ulong reason;
+	u32 insn_len = vmcs_read(EXI_INST_LEN);
 
 	guest_rip = vmcs_read(GUEST_RIP);
 	reason = vmcs_read(EXI_REASON) & 0xff;
@@ -97,7 +98,7 @@  static int vmenter_exit_handler(void)
 			return VMX_TEST_VMEXIT;
 		}
 		regs.rax = 0xFFFF;
-		vmcs_write(GUEST_RIP, guest_rip + 3);
+		vmcs_write(GUEST_RIP, guest_rip + insn_len);
 		return VMX_TEST_RESUME;
 	default:
 		report("test vmresume", 0);
@@ -340,7 +341,9 @@  static int test_ctrl_pat_exit_handler(void)
 	u64 guest_rip;
 	ulong reason;
 	u64 guest_pat;
+	u32 insn_len;
 
+	insn_len = vmcs_read(EXI_INST_LEN);
 	guest_rip = vmcs_read(GUEST_RIP);
 	reason = vmcs_read(EXI_REASON) & 0xff;
 	switch (reason) {
@@ -357,7 +360,7 @@  static int test_ctrl_pat_exit_handler(void)
 		else
 			report("Exit load PAT", rdmsr(MSR_IA32_CR_PAT) == ia32_pat);
 		vmcs_write(GUEST_PAT, ia32_pat);
-		vmcs_write(GUEST_RIP, guest_rip + 3);
+		vmcs_write(GUEST_RIP, guest_rip + insn_len);
 		return VMX_TEST_RESUME;
 	default:
 		printf("ERROR : Undefined exit reason, reason = %ld.\n", reason);
@@ -407,7 +410,9 @@  static int test_ctrl_efer_exit_handler(void)
 	u64 guest_rip;
 	ulong reason;
 	u64 guest_efer;
+	u32 insn_len;
 
+	insn_len = vmcs_read(EXI_INST_LEN);
 	guest_rip = vmcs_read(GUEST_RIP);
 	reason = vmcs_read(EXI_REASON) & 0xff;
 	switch (reason) {
@@ -426,7 +431,7 @@  static int test_ctrl_efer_exit_handler(void)
 			report("Exit load EFER", rdmsr(MSR_EFER) == (ia32_efer ^ EFER_NX));
 		}
 		vmcs_write(GUEST_PAT, ia32_efer);
-		vmcs_write(GUEST_RIP, guest_rip + 3);
+		vmcs_write(GUEST_RIP, guest_rip + insn_len);
 		return VMX_TEST_RESUME;
 	default:
 		printf("ERROR : Undefined exit reason, reason = %ld.\n", reason);
@@ -2076,6 +2081,11 @@  static void disable_rdtscp_main(void)
 static int disable_rdtscp_exit_handler(void)
 {
 	unsigned int reason = vmcs_read(EXI_REASON) & 0xff;
+	u64 guest_rip;
+	u32 insn_len;
+
+	guest_rip = vmcs_read(GUEST_RIP);
+	insn_len = vmcs_read(EXI_INST_LEN);
 
 	switch (reason) {
 	case VMX_VMCALL:
@@ -2086,7 +2096,7 @@  static int disable_rdtscp_exit_handler(void)
 			/* fallthrough */
 		case 1:
 			vmx_inc_test_stage();
-			vmcs_write(GUEST_RIP, vmcs_read(GUEST_RIP) + 3);
+			vmcs_write(GUEST_RIP, guest_rip + insn_len);
 			return VMX_TEST_RESUME;
 		case 2:
 			report("RDPID triggers #UD", false);