1. 06 1月, 2022 2 次提交
  2. 20 12月, 2021 3 次提交
    • S
      KVM: selftests: Add test to verify TRIPLE_FAULT on invalid L2 guest state · ab1ef344
      Sean Christopherson 提交于
      Add a selftest to attempt to enter L2 with invalid guests state by
      exiting to userspace via I/O from L2, and then using KVM_SET_SREGS to set
      invalid guest state (marking TR unusable is arbitrary chosen for its
      relative simplicity).
      
      This is a regression test for a bug introduced by commit c8607e4a
      ("KVM: x86: nVMX: don't fail nested VM entry on invalid guest state if
      !from_vmentry"), which incorrectly set vmx->fail=true when L2 had invalid
      guest state and ultimately triggered a WARN due to nested_vmx_vmexit()
      seeing vmx->fail==true while attempting to synthesize a nested VM-Exit.
      
      The is also a functional test to verify that KVM sythesizes TRIPLE_FAULT
      for L2, which is somewhat arbitrary behavior, instead of emulating L2.
      KVM should never emulate L2 due to invalid guest state, as it's
      architecturally impossible for L1 to run an L2 guest with invalid state
      as nested VM-Enter should always fail, i.e. L1 needs to do the emulation.
      Stuffing state via KVM ioctl() is a non-architctural, out-of-band case,
      hence the TRIPLE_FAULT being rather arbitrary.
      Signed-off-by: NSean Christopherson <seanjc@google.com>
      Message-Id: <20211207193006.120997-5-seanjc@google.com>
      Reviewed-by: NMaxim Levitsky <mlevitsk@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      ab1ef344
    • A
      selftests: KVM: Fix non-x86 compiling · 577e022b
      Andrew Jones 提交于
      Attempting to compile on a non-x86 architecture fails with
      
      include/kvm_util.h: In function ‘vm_compute_max_gfn’:
      include/kvm_util.h:79:21: error: dereferencing pointer to incomplete type ‘struct kvm_vm’
        return ((1ULL << vm->pa_bits) >> vm->page_shift) - 1;
                           ^~
      
      This is because the declaration of struct kvm_vm is in
      lib/kvm_util_internal.h as an effort to make it private to
      the test lib code. We can still provide arch specific functions,
      though, by making the generic function symbols weak. Do that to
      fix the compile error.
      
      Fixes: c8cc43c1 ("selftests: KVM: avoid failures due to reserved HyperTransport region")
      Cc: stable@vger.kernel.org
      Signed-off-by: NAndrew Jones <drjones@redhat.com>
      Message-Id: <20211214151842.848314-1-drjones@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      577e022b
    • V
      KVM: selftests: vmx_pmu_msrs_test: Drop tests mangling guest visible CPUIDs · 0b091a43
      Vitaly Kuznetsov 提交于
      Host initiated writes to MSR_IA32_PERF_CAPABILITIES should not depend
      on guest visible CPUIDs and (incorrect) KVM logic implementing it is
      about to change. Also, KVM_SET_CPUID{,2} after KVM_RUN is now forbidden
      and causes test to fail.
      Reported-by: Nkernel test robot <oliver.sang@intel.com>
      Fixes: feb627e8 ("KVM: x86: Forbid KVM_SET_CPUID{,2} after KVM_RUN")
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20211216165213.338923-2-vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      0b091a43
  3. 10 12月, 2021 3 次提交
  4. 30 11月, 2021 3 次提交
    • P
      KVM: SEV: Prohibit migration of a VM that has mirrors · 17d44a96
      Paolo Bonzini 提交于
      VMs that mirror an encryption context rely on the owner to keep the
      ASID allocated.  Performing a KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM
      would cause a dangling ASID:
      
      1. copy context from A to B (gets ref to A)
      2. move context from A to L (moves ASID from A to L)
      3. close L (releases ASID from L, B still references it)
      
      The right way to do the handoff instead is to create a fresh mirror VM
      on the destination first:
      
      1. copy context from A to B (gets ref to A)
      [later] 2. close B (releases ref to A)
      3. move context from A to L (moves ASID from A to L)
      4. copy context from L to M
      
      So, catch the situation by adding a count of how many VMs are
      mirroring this one's encryption context.
      
      Fixes: 0b020f5a ("KVM: SEV: Add support for SEV-ES intra host migration")
      Message-Id: <20211123005036.2954379-11-pbonzini@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      17d44a96
    • P
      selftests: sev_migrate_tests: add tests for KVM_CAP_VM_COPY_ENC_CONTEXT_FROM · dc79c9f4
      Paolo Bonzini 提交于
      I am putting the tests in sev_migrate_tests because the failure conditions are
      very similar and some of the setup code can be reused, too.
      
      The tests cover both successful creation of a mirror VM, and error
      conditions.
      
      Cc: Peter Gonda <pgonda@google.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Message-Id: <20211123005036.2954379-9-pbonzini@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      dc79c9f4
    • M
      KVM: selftests: page_table_test: fix calculation of guest_test_phys_mem · 81835ee1
      Maciej S. Szmigiero 提交于
      A kvm_page_table_test run with its default settings fails on VMX due to
      memory region add failure:
      > ==== Test Assertion Failure ====
      >  lib/kvm_util.c:952: ret == 0
      >  pid=10538 tid=10538 errno=17 - File exists
      >     1  0x00000000004057d1: vm_userspace_mem_region_add at kvm_util.c:947
      >     2  0x0000000000401ee9: pre_init_before_test at kvm_page_table_test.c:302
      >     3   (inlined by) run_test at kvm_page_table_test.c:374
      >     4  0x0000000000409754: for_each_guest_mode at guest_modes.c:53
      >     5  0x0000000000401860: main at kvm_page_table_test.c:500
      >     6  0x00007f82ae2d8554: ?? ??:0
      >     7  0x0000000000401894: _start at ??:?
      >  KVM_SET_USER_MEMORY_REGION IOCTL failed,
      >  rc: -1 errno: 17
      >  slot: 1 flags: 0x0
      >  guest_phys_addr: 0xc0000000 size: 0x40000000
      
      This is because the memory range that this test is trying to add
      (0x0c0000000 - 0x100000000) conflicts with LAPIC mapping at 0x0fee00000.
      
      Looking at the code it seems that guest_test_*phys*_mem variable gets
      mistakenly overwritten with guest_test_*virt*_mem while trying to adjust
      the former for alignment.
      With the correct variable adjusted this test runs successfully.
      Signed-off-by: NMaciej S. Szmigiero <maciej.szmigiero@oracle.com>
      Message-Id: <52e487458c3172923549bbcf9dfccfbe6faea60b.1637940473.git.maciej.szmigiero@oracle.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      81835ee1
  5. 26 11月, 2021 4 次提交
  6. 18 11月, 2021 1 次提交
    • A
      selftests: KVM: Add /x86_64/sev_migrate_tests to .gitignore · b768f60b
      Arnaldo Carvalho de Melo 提交于
        $ git status
        nothing to commit, working tree clean
        $
        $ make -C tools/testing/selftests/kvm/ > /dev/null 2>&1
        $ git status
      
        Untracked files:
          (use "git add <file>..." to include in what will be committed)
        	tools/testing/selftests/kvm/x86_64/sev_migrate_tests
      
        nothing added to commit but untracked files present (use "git add" to track)
        $
      
      Fixes: 6a581508 ("selftest: KVM: Add intra host migration tests")
      Cc: Brijesh Singh <brijesh.singh@amd.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Marc Orr <marcorr@google.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Peter Gonda <pgonda@google.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Message-Id: <YZPIPfvYgRDCZi/w@kernel.org>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      b768f60b
  7. 16 11月, 2021 17 次提交
  8. 11 11月, 2021 2 次提交
  9. 23 10月, 2021 1 次提交
    • J
      KVM: selftests: Fix nested SVM tests when built with clang · ed290e1c
      Jim Mattson 提交于
      Though gcc conveniently compiles a simple memset to "rep stos," clang
      prefers to call the libc version of memset. If a test is dynamically
      linked, the libc memset isn't available in L1 (nor is the PLT or the
      GOT, for that matter). Even if the test is statically linked, the libc
      memset may choose to use some CPU features, like AVX, which may not be
      enabled in L1. Note that __builtin_memset doesn't solve the problem,
      because (a) the compiler is free to call memset anyway, and (b)
      __builtin_memset may also choose to use features like AVX, which may
      not be available in L1.
      
      To avoid a myriad of problems, use an explicit "rep stos" to clear the
      VMCB in generic_svm_setup(), which is called both from L0 and L1.
      Reported-by: NRicardo Koller <ricarkol@google.com>
      Signed-off-by: NJim Mattson <jmattson@google.com>
      Fixes: 20ba262f ("selftests: KVM: AMD Nested test infrastructure")
      Message-Id: <20210930003649.4026553-1-jmattson@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      ed290e1c
  10. 22 10月, 2021 2 次提交
    • M
      KVM: selftests: set CPUID before setting sregs in vcpu creation · 413eaa4e
      Michael Roth 提交于
      Recent kernels have checks to ensure the GPA values in special-purpose
      registers like CR3 are within the maximum physical address range and
      don't overlap with anything in the upper/reserved range. In the case of
      SEV kselftest guests booting directly into 64-bit mode, CR3 needs to be
      initialized to the GPA of the page table root, with the encryption bit
      set. The kernel accounts for this encryption bit by removing it from
      reserved bit range when the guest advertises the bit position via
      KVM_SET_CPUID*, but kselftests currently call KVM_SET_SREGS as part of
      vm_vcpu_add_default(), before KVM_SET_CPUID*.
      
      As a result, KVM_SET_SREGS will return an error in these cases.
      Address this by moving vcpu_set_cpuid() (which calls KVM_SET_CPUID*)
      ahead of vcpu_setup() (which calls KVM_SET_SREGS).
      
      While there, address a typo in the assertion that triggers when
      KVM_SET_SREGS fails.
      Suggested-by: NSean Christopherson <seanjc@google.com>
      Signed-off-by: NMichael Roth <michael.roth@amd.com>
      Message-Id: <20211006203617.13045-1-michael.roth@amd.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Reviewed-by: NNathan Tempelman <natet@google.com>
      413eaa4e
    • S
      selftests: kvm: fix mismatched fclose() after popen() · c3867ab5
      Shuah Khan 提交于
      get_warnings_count() does fclose() using File * returned from popen().
      Fix it to call pclose() as it should.
      
      tools/testing/selftests/kvm/x86_64/mmio_warning_test
      x86_64/mmio_warning_test.c: In function ‘get_warnings_count’:
      x86_64/mmio_warning_test.c:87:9: warning: ‘fclose’ called on pointer returned from a mismatched allocation function [-Wmismatched-dealloc]
         87 |         fclose(f);
            |         ^~~~~~~~~
      x86_64/mmio_warning_test.c:84:13: note: returned from ‘popen’
         84 |         f = popen("dmesg | grep \"WARNING:\" | wc -l", "r");
            |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Signed-off-by: NShuah Khan <skhan@linuxfoundation.org>
      Acked-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NShuah Khan <skhan@linuxfoundation.org>
      c3867ab5
  11. 21 10月, 2021 2 次提交