@@ -833,6 +833,8 @@ void vm_set_page_table_entry(struct kvm_vm *vm, struct kvm_vcpu *vcpu,
uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
uint64_t a3);
+void nested_guest_vmcall(void);
+
void __vm_xsave_require_permission(int bit, const char *name);
#define vm_xsave_require_permission(perm) \
@@ -480,15 +480,6 @@ static inline int vmresume(void)
return ret;
}
-static inline void vmcall(void)
-{
- /* Currently, L1 destroys our GPRs during vmexits. */
- __asm__ __volatile__("push %%rbp; vmcall; pop %%rbp" : : :
- "rax", "rbx", "rcx", "rdx",
- "rsi", "rdi", "r8", "r9", "r10", "r11", "r12",
- "r13", "r14", "r15");
-}
-
static inline int vmread(uint64_t encoding, uint64_t *value)
{
uint64_t tmp;
@@ -18,7 +18,7 @@
void perf_test_l2_guest_code(uint64_t vcpu_id)
{
perf_test_guest_code(vcpu_id);
- vmcall();
+ nested_guest_vmcall();
}
extern char perf_test_l2_guest_entry[];
@@ -1195,6 +1195,21 @@ uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
return r;
}
+void nested_guest_vmcall(void)
+{
+ /* Currently, L1 destroys our GPRs during vmexits. */
+ if (is_amd_cpu())
+ __asm__ __volatile__("push %%rbp; vmmcall; pop %%rbp" : : :
+ "rax", "rbx", "rcx", "rdx",
+ "rsi", "rdi", "r8", "r9", "r10", "r11", "r12",
+ "r13", "r14", "r15");
+ else
+ __asm__ __volatile__("push %%rbp; vmcall; pop %%rbp" : : :
+ "rax", "rbx", "rcx", "rdx",
+ "rsi", "rdi", "r8", "r9", "r10", "r11", "r12",
+ "r13", "r14", "r15");
+}
+
const struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void)
{
static struct kvm_cpuid2 *cpuid;
@@ -61,7 +61,7 @@ static void l2_guest_code(void)
sync_with_host(10);
- vmcall();
+ nested_guest_vmcall();
}
static void guest_code(void *arg)
@@ -26,10 +26,10 @@ void svm_l2_guest_code(void)
{
GUEST_SYNC(4);
/* Exit to L1 */
- vmcall();
+ nested_guest_vmcall();
GUEST_SYNC(6);
/* Done, exit to L1 and never come back. */
- vmcall();
+ nested_guest_vmcall();
}
static void svm_l1_guest_code(struct svm_test_data *svm)
@@ -57,7 +57,7 @@ void vmx_l2_guest_code(void)
GUEST_SYNC(6);
/* Exit to L1 */
- vmcall();
+ nested_guest_vmcall();
/* L1 has now set up a shadow VMCS for us. */
GUEST_ASSERT(vmreadz(GUEST_RIP) == 0xc0ffee);
@@ -70,7 +70,7 @@ void vmx_l2_guest_code(void)
GUEST_SYNC(12);
/* Done, exit to L1 and never come back. */
- vmcall();
+ nested_guest_vmcall();
}
static void vmx_l1_guest_code(struct vmx_pages *vmx_pages)
@@ -42,7 +42,7 @@ static void l2_guest_code(void)
GUEST_SYNC(false);
/* Exit to L1 and never come back. */
- vmcall();
+ nested_guest_vmcall();
}
void l1_guest_code(struct vmx_pages *vmx)
@@ -38,7 +38,7 @@ void l2_guest_code(void)
{
u64 vmx_pt_delta;
- vmcall();
+ nested_guest_vmcall();
l2_vmx_pt_start = (rdtsc() >> vmx_pt_rate) << vmx_pt_rate;
/*
Execute vmcall/vmmcall from nested guests according to the cpu type. This avoid exit to KVM which would anyway patch the hypercall instruction according to the cpu type. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Vishal Annapurve <vannapurve@google.com> --- .../selftests/kvm/include/x86_64/processor.h | 2 ++ tools/testing/selftests/kvm/include/x86_64/vmx.h | 9 --------- .../selftests/kvm/lib/x86_64/perf_test_util.c | 2 +- .../testing/selftests/kvm/lib/x86_64/processor.c | 15 +++++++++++++++ tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +- tools/testing/selftests/kvm/x86_64/state_test.c | 8 ++++---- .../selftests/kvm/x86_64/vmx_dirty_log_test.c | 2 +- .../kvm/x86_64/vmx_preemption_timer_test.c | 2 +- 8 files changed, 25 insertions(+), 17 deletions(-)