Skip to content

Commit 4009e0b

Browse files
sean-jcbonzini
authored andcommitted
KVM: selftests: Move the guts of kvm_hypercall() to a separate macro
Extract the guts of kvm_hypercall() to a macro so that Xen hypercalls, which have a different register ABI, can reuse the VMCALL vs. VMMCALL logic. No functional change intended. Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent c281794 commit 4009e0b

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,21 +1139,26 @@ const struct kvm_cpuid_entry2 *get_cpuid_entry(const struct kvm_cpuid2 *cpuid,
11391139
return NULL;
11401140
}
11411141

1142+
#define X86_HYPERCALL(inputs...) \
1143+
({ \
1144+
uint64_t r; \
1145+
\
1146+
asm volatile("test %[use_vmmcall], %[use_vmmcall]\n\t" \
1147+
"jnz 1f\n\t" \
1148+
"vmcall\n\t" \
1149+
"jmp 2f\n\t" \
1150+
"1: vmmcall\n\t" \
1151+
"2:" \
1152+
: "=a"(r) \
1153+
: [use_vmmcall] "r" (host_cpu_is_amd), inputs); \
1154+
\
1155+
r; \
1156+
})
1157+
11421158
uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
11431159
uint64_t a3)
11441160
{
1145-
uint64_t r;
1146-
1147-
asm volatile("test %[use_vmmcall], %[use_vmmcall]\n\t"
1148-
"jnz 1f\n\t"
1149-
"vmcall\n\t"
1150-
"jmp 2f\n\t"
1151-
"1: vmmcall\n\t"
1152-
"2:"
1153-
: "=a"(r)
1154-
: "a"(nr), "b"(a0), "c"(a1), "d"(a2), "S"(a3),
1155-
[use_vmmcall] "r" (host_cpu_is_amd));
1156-
return r;
1161+
return X86_HYPERCALL("a"(nr), "b"(a0), "c"(a1), "d"(a2), "S"(a3));
11571162
}
11581163

11591164
const struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void)

0 commit comments

Comments
 (0)