summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-03-15 18:00:28 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-03-15 18:00:28 -0400
commit636deed6c0bc137a7c4f4a97ae1fcf0ad75323da (patch)
tree7bd27189b8e30e3c1466f7730831a08db65f8646 /tools
parentaa2e3ac64ace127f403be85aa4d6015b859385f2 (diff)
parent4a605bc08e98381d8df61c30a4acb2eac15eb7da (diff)
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM updates from Paolo Bonzini: "ARM: - some cleanups - direct physical timer assignment - cache sanitization for 32-bit guests s390: - interrupt cleanup - introduction of the Guest Information Block - preparation for processor subfunctions in cpu models PPC: - bug fixes and improvements, especially related to machine checks and protection keys x86: - many, many cleanups, including removing a bunch of MMU code for unnecessary optimizations - AVIC fixes Generic: - memcg accounting" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (147 commits) kvm: vmx: fix formatting of a comment KVM: doc: Document the life cycle of a VM and its resources MAINTAINERS: Add KVM selftests to existing KVM entry Revert "KVM/MMU: Flush tlb directly in the kvm_zap_gfn_range()" KVM: PPC: Book3S: Add count cache flush parameters to kvmppc_get_cpu_char() KVM: PPC: Fix compilation when KVM is not enabled KVM: Minor cleanups for kvm_main.c KVM: s390: add debug logging for cpu model subfunctions KVM: s390: implement subfunction processor calls arm64: KVM: Fix architecturally invalid reset value for FPEXC32_EL2 KVM: arm/arm64: Remove unused timer variable KVM: PPC: Book3S: Improve KVM reference counting KVM: PPC: Book3S HV: Fix build failure without IOMMU support Revert "KVM: Eliminate extra function calls in kvm_get_dirty_log_protect()" x86: kvmguest: use TSC clocksource if invariant TSC is exposed KVM: Never start grow vCPU halt_poll_ns from value below halt_poll_ns_grow_start KVM: Expose the initial start value in grow_halt_poll_ns() as a module parameter KVM: grow_halt_poll_ns() should never shrink vCPU halt_poll_ns KVM: x86/mmu: Consolidate kvm_mmu_zap_all() and kvm_mmu_zap_mmio_sptes() KVM: x86/mmu: WARN if zapping a MMIO spte results in zapping children ...
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/kvm/.gitignore1
-rw-r--r--tools/testing/selftests/kvm/Makefile1
-rw-r--r--tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c95
3 files changed, 97 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore
index 6210ba41c29e..2689d1ea6d7a 100644
--- a/tools/testing/selftests/kvm/.gitignore
+++ b/tools/testing/selftests/kvm/.gitignore
@@ -3,6 +3,7 @@
3/x86_64/platform_info_test 3/x86_64/platform_info_test
4/x86_64/set_sregs_test 4/x86_64/set_sregs_test
5/x86_64/sync_regs_test 5/x86_64/sync_regs_test
6/x86_64/vmx_close_while_nested_test
6/x86_64/vmx_tsc_adjust_test 7/x86_64/vmx_tsc_adjust_test
7/x86_64/state_test 8/x86_64/state_test
8/dirty_log_test 9/dirty_log_test
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index f9a0e9938480..3c1f4bdf9000 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -16,6 +16,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/cr4_cpuid_sync_test
16TEST_GEN_PROGS_x86_64 += x86_64/state_test 16TEST_GEN_PROGS_x86_64 += x86_64/state_test
17TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test 17TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test
18TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid 18TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid
19TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test
19TEST_GEN_PROGS_x86_64 += dirty_log_test 20TEST_GEN_PROGS_x86_64 += dirty_log_test
20TEST_GEN_PROGS_x86_64 += clear_dirty_log_test 21TEST_GEN_PROGS_x86_64 += clear_dirty_log_test
21 22
diff --git a/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c b/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c
new file mode 100644
index 000000000000..6edec6fd790b
--- /dev/null
+++ b/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c
@@ -0,0 +1,95 @@
1/*
2 * vmx_close_while_nested
3 *
4 * Copyright (C) 2019, Red Hat, Inc.
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2.
7 *
8 * Verify that nothing bad happens if a KVM user exits with open
9 * file descriptors while executing a nested guest.
10 */
11
12#include "test_util.h"
13#include "kvm_util.h"
14#include "processor.h"
15#include "vmx.h"
16
17#include <string.h>
18#include <sys/ioctl.h>
19
20#include "kselftest.h"
21
22#define VCPU_ID 5
23
24enum {
25 PORT_L0_EXIT = 0x2000,
26};
27
28/* The virtual machine object. */
29static struct kvm_vm *vm;
30
31static void l2_guest_code(void)
32{
33 /* Exit to L0 */
34 asm volatile("inb %%dx, %%al"
35 : : [port] "d" (PORT_L0_EXIT) : "rax");
36}
37
38static void l1_guest_code(struct vmx_pages *vmx_pages)
39{
40#define L2_GUEST_STACK_SIZE 64
41 unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE];
42 uint32_t control;
43 uintptr_t save_cr3;
44
45 GUEST_ASSERT(prepare_for_vmx_operation(vmx_pages));
46 GUEST_ASSERT(load_vmcs(vmx_pages));
47
48 /* Prepare the VMCS for L2 execution. */
49 prepare_vmcs(vmx_pages, l2_guest_code,
50 &l2_guest_stack[L2_GUEST_STACK_SIZE]);
51
52 GUEST_ASSERT(!vmlaunch());
53 GUEST_ASSERT(0);
54}
55
56int main(int argc, char *argv[])
57{
58 struct vmx_pages *vmx_pages;
59 vm_vaddr_t vmx_pages_gva;
60 struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1);
61
62 if (!(entry->ecx & CPUID_VMX)) {
63 fprintf(stderr, "nested VMX not enabled, skipping test\n");
64 exit(KSFT_SKIP);
65 }
66
67 vm = vm_create_default(VCPU_ID, 0, (void *) l1_guest_code);
68 vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
69
70 /* Allocate VMX pages and shared descriptors (vmx_pages). */
71 vmx_pages = vcpu_alloc_vmx(vm, &vmx_pages_gva);
72 vcpu_args_set(vm, VCPU_ID, 1, vmx_pages_gva);
73
74 for (;;) {
75 volatile struct kvm_run *run = vcpu_state(vm, VCPU_ID);
76 struct ucall uc;
77
78 vcpu_run(vm, VCPU_ID);
79 TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
80 "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
81 run->exit_reason,
82 exit_reason_str(run->exit_reason));
83
84 if (run->io.port == PORT_L0_EXIT)
85 break;
86
87 switch (get_ucall(vm, VCPU_ID, &uc)) {
88 case UCALL_ABORT:
89 TEST_ASSERT(false, "%s", (const char *)uc.args[0]);
90 /* NOT REACHED */
91 default:
92 TEST_ASSERT(false, "Unknown ucall 0x%x.", uc.cmd);
93 }
94 }
95}