KVM: selftests: Add operand to vmsave/vmload/vmrun in svm.c
authorRicardo Koller <ricarkol@google.com>
Wed, 10 Feb 2021 03:17:19 +0000 (03:17 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 11 Feb 2021 13:02:08 +0000 (08:02 -0500)
Building the KVM selftests with LLVM's integrated assembler fails with:

  $ CFLAGS=-fintegrated-as make -C tools/testing/selftests/kvm CC=clang
  lib/x86_64/svm.c:77:16: error: too few operands for instruction
          asm volatile ("vmsave\n\t" : : "a" (vmcb_gpa) : "memory");
                        ^
  <inline asm>:1:2: note: instantiated into assembly here
          vmsave
          ^
  lib/x86_64/svm.c:134:3: error: too few operands for instruction
                  "vmload\n\t"
                  ^
  <inline asm>:1:2: note: instantiated into assembly here
          vmload
          ^
This is because LLVM IAS does not currently support calling vmsave,
vmload, or vmload without an explicit %rax operand.

Add an explicit operand to vmsave, vmload, and vmrum in svm.c. Fixing
this was suggested by Sean Christopherson.

Tested: building without this error in clang 11. The following patch
(not queued yet) needs to be applied to solve the other remaining error:
"selftests: kvm: remove reassignment of non-absolute variables".

Suggested-by: Sean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/kvm/X+Df2oQczVBmwEzi@google.com/
Reviewed-by: Jim Mattson <jmattson@google.com>
Signed-off-by: Ricardo Koller <ricarkol@google.com>
Message-Id: <20210210031719.769837-1-ricarkol@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/lib/x86_64/svm.c

index 3a5c72ed2b79287453224f98fe9cc4689ee82942..827fe6028dd42674f82f023ccc240125596708f2 100644 (file)
@@ -74,7 +74,7 @@ void generic_svm_setup(struct svm_test_data *svm, void *guest_rip, void *guest_r
        wrmsr(MSR_VM_HSAVE_PA, svm->save_area_gpa);
 
        memset(vmcb, 0, sizeof(*vmcb));
-       asm volatile ("vmsave\n\t" : : "a" (vmcb_gpa) : "memory");
+       asm volatile ("vmsave %0\n\t" : : "a" (vmcb_gpa) : "memory");
        vmcb_set_seg(&save->es, get_es(), 0, -1U, data_seg_attr);
        vmcb_set_seg(&save->cs, get_cs(), 0, -1U, code_seg_attr);
        vmcb_set_seg(&save->ss, get_ss(), 0, -1U, data_seg_attr);
@@ -131,19 +131,19 @@ void generic_svm_setup(struct svm_test_data *svm, void *guest_rip, void *guest_r
 void run_guest(struct vmcb *vmcb, uint64_t vmcb_gpa)
 {
        asm volatile (
-               "vmload\n\t"
+               "vmload %[vmcb_gpa]\n\t"
                "mov rflags, %%r15\n\t" // rflags
                "mov %%r15, 0x170(%[vmcb])\n\t"
                "mov guest_regs, %%r15\n\t"     // rax
                "mov %%r15, 0x1f8(%[vmcb])\n\t"
                LOAD_GPR_C
-               "vmrun\n\t"
+               "vmrun %[vmcb_gpa]\n\t"
                SAVE_GPR_C
                "mov 0x170(%[vmcb]), %%r15\n\t" // rflags
                "mov %%r15, rflags\n\t"
                "mov 0x1f8(%[vmcb]), %%r15\n\t" // rax
                "mov %%r15, guest_regs\n\t"
-               "vmsave\n\t"
+               "vmsave %[vmcb_gpa]\n\t"
                : : [vmcb] "r" (vmcb), [vmcb_gpa] "a" (vmcb_gpa)
                : "r15", "memory");
 }