Skip to content

Commit 019dfeb

Browse files
vishals4ghsean-jc
authored andcommitted
KVM: selftests: x86: Use host's native hypercall instruction in kvm_hypercall()
Use the host CPU's native hypercall instruction, i.e. VMCALL vs. VMMCALL, in kvm_hypercall(), as relying on KVM to patch in the native hypercall on a #UD for the "wrong" hypercall requires KVM_X86_QUIRK_FIX_HYPERCALL_INSN to be enabled and flat out doesn't work if guest memory is encrypted with a private key, e.g. for SEV VMs. Suggested-by: Sean Christopherson <seanjc@google.com> Reviewed-by: David Matlack <dmatlack@google.com> Signed-off-by: Vishal Annapurve <vannapurve@google.com> Link: https://lore.kernel.org/r/20230111004445.416840-4-vannapurve@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 832ffb3 commit 019dfeb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,9 +1144,15 @@ uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
11441144
{
11451145
uint64_t r;
11461146

1147-
asm volatile("vmcall"
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:"
11481153
: "=a"(r)
1149-
: "a"(nr), "b"(a0), "c"(a1), "d"(a2), "S"(a3));
1154+
: "a"(nr), "b"(a0), "c"(a1), "d"(a2), "S"(a3),
1155+
[use_vmmcall] "r" (host_cpu_is_amd));
11501156
return r;
11511157
}
11521158

0 commit comments

Comments
 (0)