Skip to content

Commit

Permalink
KVM: selftests: Remove unnecessary register shuffling in fix_hypercal…
Browse files Browse the repository at this point in the history
…l_test

Use input constraints to load RAX and RBX when testing that KVM correctly
does/doesn't patch the "wrong" hypercall.  There's no need to manually
load RAX and RBX, and no reason to clobber them either (KVM is not
supposed to modify anything other than RAX).

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Message-Id: <20220928233652.783504-4-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Sean Christopherson authored and Paolo Bonzini committed Sep 30, 2022
1 parent 3942650 commit 04f2f60
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ static uint64_t svm_do_sched_yield(uint8_t apic_id)
{
uint64_t ret;

asm volatile("mov %1, %%rax\n\t"
"mov %2, %%rbx\n\t"
"svm_hypercall_insn:\n\t"
asm volatile("svm_hypercall_insn:\n\t"
"vmmcall\n\t"
"mov %%rax, %0\n\t"
: "=r"(ret)
: "r"((uint64_t)KVM_HC_SCHED_YIELD), "r"((uint64_t)apic_id)
: "rax", "rbx", "memory");
: "=a"(ret)
: "a"((uint64_t)KVM_HC_SCHED_YIELD), "b"((uint64_t)apic_id)
: "memory");

return ret;
}
Expand All @@ -47,14 +44,11 @@ static uint64_t vmx_do_sched_yield(uint8_t apic_id)
{
uint64_t ret;

asm volatile("mov %1, %%rax\n\t"
"mov %2, %%rbx\n\t"
"vmx_hypercall_insn:\n\t"
asm volatile("vmx_hypercall_insn:\n\t"
"vmcall\n\t"
"mov %%rax, %0\n\t"
: "=r"(ret)
: "r"((uint64_t)KVM_HC_SCHED_YIELD), "r"((uint64_t)apic_id)
: "rax", "rbx", "memory");
: "=a"(ret)
: "a"((uint64_t)KVM_HC_SCHED_YIELD), "b"((uint64_t)apic_id)
: "memory");

return ret;
}
Expand Down

0 comments on commit 04f2f60

Please sign in to comment.