Skip to content

Commit 1e7ecd1

Browse files
vittyvkbonzini
authored andcommitted
KVM: selftests: state_test: test bare VMXON migration
Split prepare_for_vmx_operation() into prepare_for_vmx_operation() and load_vmcs() so we can inject GUEST_SYNC() in between. Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent a1b0c1c commit 1e7ecd1

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

tools/testing/selftests/kvm/include/x86_64/vmx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,5 +548,6 @@ struct vmx_pages {
548548
struct vmx_pages *vcpu_alloc_vmx(struct kvm_vm *vm, vm_vaddr_t *p_vmx_gva);
549549
bool prepare_for_vmx_operation(struct vmx_pages *vmx);
550550
void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp);
551+
bool load_vmcs(struct vmx_pages *vmx);
551552

552553
#endif /* SELFTEST_KVM_VMX_H */

tools/testing/selftests/kvm/lib/x86_64/vmx.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx)
107107
if (vmxon(vmx->vmxon_gpa))
108108
return false;
109109

110+
return true;
111+
}
112+
113+
bool load_vmcs(struct vmx_pages *vmx)
114+
{
110115
/* Load a VMCS. */
111116
*(uint32_t *)(vmx->vmcs) = vmcs_revision();
112117
if (vmclear(vmx->vmcs_gpa))

tools/testing/selftests/kvm/x86_64/state_test.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ static bool have_nested_state;
2626

2727
void l2_guest_code(void)
2828
{
29-
GUEST_SYNC(5);
29+
GUEST_SYNC(6);
3030

3131
/* Exit to L1 */
3232
vmcall();
3333

3434
/* L1 has now set up a shadow VMCS for us. */
3535
GUEST_ASSERT(vmreadz(GUEST_RIP) == 0xc0ffee);
36-
GUEST_SYNC(9);
36+
GUEST_SYNC(10);
3737
GUEST_ASSERT(vmreadz(GUEST_RIP) == 0xc0ffee);
3838
GUEST_ASSERT(!vmwrite(GUEST_RIP, 0xc0fffee));
39-
GUEST_SYNC(10);
39+
GUEST_SYNC(11);
4040
GUEST_ASSERT(vmreadz(GUEST_RIP) == 0xc0fffee);
4141
GUEST_ASSERT(!vmwrite(GUEST_RIP, 0xc0ffffee));
42-
GUEST_SYNC(11);
42+
GUEST_SYNC(12);
4343

4444
/* Done, exit to L1 and never come back. */
4545
vmcall();
@@ -52,15 +52,17 @@ void l1_guest_code(struct vmx_pages *vmx_pages)
5252

5353
GUEST_ASSERT(vmx_pages->vmcs_gpa);
5454
GUEST_ASSERT(prepare_for_vmx_operation(vmx_pages));
55+
GUEST_SYNC(3);
56+
GUEST_ASSERT(load_vmcs(vmx_pages));
5557
GUEST_ASSERT(vmptrstz() == vmx_pages->vmcs_gpa);
5658

57-
GUEST_SYNC(3);
59+
GUEST_SYNC(4);
5860
GUEST_ASSERT(vmptrstz() == vmx_pages->vmcs_gpa);
5961

6062
prepare_vmcs(vmx_pages, l2_guest_code,
6163
&l2_guest_stack[L2_GUEST_STACK_SIZE]);
6264

63-
GUEST_SYNC(4);
65+
GUEST_SYNC(5);
6466
GUEST_ASSERT(vmptrstz() == vmx_pages->vmcs_gpa);
6567
GUEST_ASSERT(!vmlaunch());
6668
GUEST_ASSERT(vmptrstz() == vmx_pages->vmcs_gpa);
@@ -72,7 +74,7 @@ void l1_guest_code(struct vmx_pages *vmx_pages)
7274
GUEST_ASSERT(!vmresume());
7375
GUEST_ASSERT(vmreadz(VM_EXIT_REASON) == EXIT_REASON_VMCALL);
7476

75-
GUEST_SYNC(6);
77+
GUEST_SYNC(7);
7678
GUEST_ASSERT(vmreadz(VM_EXIT_REASON) == EXIT_REASON_VMCALL);
7779

7880
GUEST_ASSERT(!vmresume());
@@ -85,12 +87,12 @@ void l1_guest_code(struct vmx_pages *vmx_pages)
8587

8688
GUEST_ASSERT(!vmptrld(vmx_pages->shadow_vmcs_gpa));
8789
GUEST_ASSERT(vmlaunch());
88-
GUEST_SYNC(7);
90+
GUEST_SYNC(8);
8991
GUEST_ASSERT(vmlaunch());
9092
GUEST_ASSERT(vmresume());
9193

9294
vmwrite(GUEST_RIP, 0xc0ffee);
93-
GUEST_SYNC(8);
95+
GUEST_SYNC(9);
9496
GUEST_ASSERT(vmreadz(GUEST_RIP) == 0xc0ffee);
9597

9698
GUEST_ASSERT(!vmptrld(vmx_pages->vmcs_gpa));
@@ -101,7 +103,7 @@ void l1_guest_code(struct vmx_pages *vmx_pages)
101103
GUEST_ASSERT(vmreadz(GUEST_RIP) == 0xc0ffffee);
102104
GUEST_ASSERT(vmlaunch());
103105
GUEST_ASSERT(vmresume());
104-
GUEST_SYNC(12);
106+
GUEST_SYNC(13);
105107
GUEST_ASSERT(vmreadz(GUEST_RIP) == 0xc0ffffee);
106108
GUEST_ASSERT(vmlaunch());
107109
GUEST_ASSERT(vmresume());

tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static void l1_guest_code(struct vmx_pages *vmx_pages)
9494
check_ia32_tsc_adjust(-1 * TSC_ADJUST_VALUE);
9595

9696
GUEST_ASSERT(prepare_for_vmx_operation(vmx_pages));
97+
GUEST_ASSERT(load_vmcs(vmx_pages));
9798

9899
/* Prepare the VMCS for L2 execution. */
99100
prepare_vmcs(vmx_pages, l2_guest_code,

0 commit comments

Comments
 (0)