KVM: selftests: Get rid of kvm_util_internal.h
authorSean Christopherson <seanjc@google.com>
Tue, 15 Feb 2022 21:21:19 +0000 (13:21 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 11 Jun 2022 15:46:19 +0000 (11:46 -0400)
Fold kvm_util_internal.h into kvm_util_base.h, i.e. make all KVM utility
stuff "public".  Hiding struct implementations from tests has been a
massive failure, as it has led to pointless and poorly named wrappers,
unnecessarily opaque code, etc...

Not to mention that the approach was a complete failure as evidenced by
the non-zero number of tests that were including kvm_util_internal.h.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
17 files changed:
tools/testing/selftests/kvm/include/kvm_util_base.h
tools/testing/selftests/kvm/lib/aarch64/processor.c
tools/testing/selftests/kvm/lib/aarch64/ucall.c
tools/testing/selftests/kvm/lib/aarch64/vgic.c
tools/testing/selftests/kvm/lib/elf.c
tools/testing/selftests/kvm/lib/kvm_util.c
tools/testing/selftests/kvm/lib/kvm_util_internal.h [deleted file]
tools/testing/selftests/kvm/lib/riscv/processor.c
tools/testing/selftests/kvm/lib/riscv/ucall.c
tools/testing/selftests/kvm/lib/s390x/processor.c
tools/testing/selftests/kvm/lib/x86_64/perf_test_util.c
tools/testing/selftests/kvm/lib/x86_64/processor.c
tools/testing/selftests/kvm/lib/x86_64/svm.c
tools/testing/selftests/kvm/lib/x86_64/vmx.c
tools/testing/selftests/kvm/x86_64/max_vcpuid_cap_test.c
tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c
tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c

index f5bfdf0b45485f627a259ecf77c74a08f952a18b..c0199f3b59bb2e27619254e73fab1b1fbb637a5e 100644 (file)
@@ -9,9 +9,13 @@
 
 #include "test_util.h"
 
-#include "asm/kvm.h"
+#include <linux/compiler.h>
+#include "linux/hashtable.h"
 #include "linux/list.h"
-#include "linux/kvm.h"
+#include <linux/kernel.h>
+#include <linux/kvm.h>
+#include "linux/rbtree.h"
+
 #include <sys/ioctl.h>
 
 #include "sparsebit.h"
 
 #define NSEC_PER_SEC 1000000000L
 
+typedef uint64_t vm_paddr_t; /* Virtual Machine (Guest) physical address */
+typedef uint64_t vm_vaddr_t; /* Virtual Machine (Guest) virtual address */
+
+struct userspace_mem_region {
+       struct kvm_userspace_memory_region region;
+       struct sparsebit *unused_phy_pages;
+       int fd;
+       off_t offset;
+       void *host_mem;
+       void *host_alias;
+       void *mmap_start;
+       void *mmap_alias;
+       size_t mmap_size;
+       struct rb_node gpa_node;
+       struct rb_node hva_node;
+       struct hlist_node slot_node;
+};
+
+struct vcpu {
+       struct list_head list;
+       uint32_t id;
+       int fd;
+       struct kvm_run *state;
+       struct kvm_dirty_gfn *dirty_gfns;
+       uint32_t fetch_index;
+       uint32_t dirty_gfns_count;
+};
+
+struct userspace_mem_regions {
+       struct rb_root gpa_tree;
+       struct rb_root hva_tree;
+       DECLARE_HASHTABLE(slot_hash, 9);
+};
+
+struct kvm_vm {
+       int mode;
+       unsigned long type;
+       int kvm_fd;
+       int fd;
+       unsigned int pgtable_levels;
+       unsigned int page_size;
+       unsigned int page_shift;
+       unsigned int pa_bits;
+       unsigned int va_bits;
+       uint64_t max_gfn;
+       struct list_head vcpus;
+       struct userspace_mem_regions regions;
+       struct sparsebit *vpages_valid;
+       struct sparsebit *vpages_mapped;
+       bool has_irqchip;
+       bool pgd_created;
+       vm_paddr_t pgd;
+       vm_vaddr_t gdt;
+       vm_vaddr_t tss;
+       vm_vaddr_t idt;
+       vm_vaddr_t handlers;
+       uint32_t dirty_ring_size;
+};
+
+
+#define kvm_for_each_vcpu(vm, i, vcpu)                 \
+       for ((i) = 0; (i) <= (vm)->last_vcpu_id; (i)++) \
+               if (!((vcpu) = vm->vcpus[i]))           \
+                       continue;                       \
+               else
+
+struct vcpu *vcpu_get(struct kvm_vm *vm, uint32_t vcpuid);
+
 /*
- * Callers of kvm_util only have an incomplete/opaque description of the
- * structure kvm_util is using to maintain the state of a VM.
+ * Virtual Translation Tables Dump
+ *
+ * Input Args:
+ *   stream - Output FILE stream
+ *   vm     - Virtual Machine
+ *   indent - Left margin indent amount
+ *
+ * Output Args: None
+ *
+ * Return: None
+ *
+ * Dumps to the FILE stream given by @stream, the contents of all the
+ * virtual translation tables for the VM given by @vm.
  */
-struct kvm_vm;
+void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
 
-typedef uint64_t vm_paddr_t; /* Virtual Machine (Guest) physical address */
-typedef uint64_t vm_vaddr_t; /* Virtual Machine (Guest) virtual address */
+struct userspace_mem_region *
+memslot2region(struct kvm_vm *vm, uint32_t memslot);
 
 /* Minimum allocated guest virtual and physical addresses */
 #define KVM_UTIL_MIN_VADDR             0x2000
index d28cc12cea1d87254ac792a6398291d426fcfe08..388bd7d87c02eb8d846f523588819c04557dbb72 100644 (file)
@@ -10,7 +10,6 @@
 
 #include "guest_modes.h"
 #include "kvm_util.h"
-#include "../kvm_util_internal.h"
 #include "processor.h"
 
 #define DEFAULT_ARM64_GUEST_STACK_VADDR_MIN    0xac0000
index 00be3ef195ca5b72520b851e2cb95fdede42b10d..868ebab5369e4517b39308e951494bdea4ad97df 100644 (file)
@@ -5,7 +5,6 @@
  * Copyright (C) 2018, Red Hat, Inc.
  */
 #include "kvm_util.h"
-#include "../kvm_util_internal.h"
 
 static vm_vaddr_t *ucall_exit_mmio_addr;
 
index 25d1ec65621d8c2b2704434372ed67ebdcbcc6cd..c34f0f116f39944f21165f82a3aff88fac337869 100644 (file)
@@ -9,7 +9,6 @@
 #include <asm/kvm.h>
 
 #include "kvm_util.h"
-#include "../kvm_util_internal.h"
 #include "vgic.h"
 #include "gic.h"
 #include "gic_v3.h"
index 13e8e3dcf984ec663c351d2f02f1158cc39ff54a..9f54c098d9d08ac095fae7e56fc7ceef4d5660aa 100644 (file)
@@ -11,7 +11,6 @@
 #include <linux/elf.h>
 
 #include "kvm_util.h"
-#include "kvm_util_internal.h"
 
 static void elfhdr_get(const char *filename, Elf64_Ehdr *hdrp)
 {
index c7df8ba04ec55b78379e0eed29cc9004504d0154..a57958a39c1b32f813c0079d9c9841b0eaa618d8 100644 (file)
@@ -8,7 +8,6 @@
 #define _GNU_SOURCE /* for program_invocation_name */
 #include "test_util.h"
 #include "kvm_util.h"
-#include "kvm_util_internal.h"
 #include "processor.h"
 
 #include <assert.h>
diff --git a/tools/testing/selftests/kvm/lib/kvm_util_internal.h b/tools/testing/selftests/kvm/lib/kvm_util_internal.h
deleted file mode 100644 (file)
index 544b90d..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * tools/testing/selftests/kvm/lib/kvm_util_internal.h
- *
- * Copyright (C) 2018, Google LLC.
- */
-
-#ifndef SELFTEST_KVM_UTIL_INTERNAL_H
-#define SELFTEST_KVM_UTIL_INTERNAL_H
-
-#include "linux/hashtable.h"
-#include "linux/rbtree.h"
-
-#include "sparsebit.h"
-
-struct userspace_mem_region {
-       struct kvm_userspace_memory_region region;
-       struct sparsebit *unused_phy_pages;
-       int fd;
-       off_t offset;
-       void *host_mem;
-       void *host_alias;
-       void *mmap_start;
-       void *mmap_alias;
-       size_t mmap_size;
-       struct rb_node gpa_node;
-       struct rb_node hva_node;
-       struct hlist_node slot_node;
-};
-
-struct vcpu {
-       struct list_head list;
-       uint32_t id;
-       int fd;
-       struct kvm_run *state;
-       struct kvm_dirty_gfn *dirty_gfns;
-       uint32_t fetch_index;
-       uint32_t dirty_gfns_count;
-};
-
-struct userspace_mem_regions {
-       struct rb_root gpa_tree;
-       struct rb_root hva_tree;
-       DECLARE_HASHTABLE(slot_hash, 9);
-};
-
-struct kvm_vm {
-       int mode;
-       unsigned long type;
-       int kvm_fd;
-       int fd;
-       unsigned int pgtable_levels;
-       unsigned int page_size;
-       unsigned int page_shift;
-       unsigned int pa_bits;
-       unsigned int va_bits;
-       uint64_t max_gfn;
-       struct list_head vcpus;
-       struct userspace_mem_regions regions;
-       struct sparsebit *vpages_valid;
-       struct sparsebit *vpages_mapped;
-       bool has_irqchip;
-       bool pgd_created;
-       vm_paddr_t pgd;
-       vm_vaddr_t gdt;
-       vm_vaddr_t tss;
-       vm_vaddr_t idt;
-       vm_vaddr_t handlers;
-       uint32_t dirty_ring_size;
-};
-
-struct vcpu *vcpu_get(struct kvm_vm *vm, uint32_t vcpuid);
-
-/*
- * Virtual Translation Tables Dump
- *
- * Input Args:
- *   stream - Output FILE stream
- *   vm     - Virtual Machine
- *   indent - Left margin indent amount
- *
- * Output Args: None
- *
- * Return: None
- *
- * Dumps to the FILE stream given by @stream, the contents of all the
- * virtual translation tables for the VM given by @vm.
- */
-void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
-
-struct userspace_mem_region *
-memslot2region(struct kvm_vm *vm, uint32_t memslot);
-
-#endif /* SELFTEST_KVM_UTIL_INTERNAL_H */
index c89e6b1fbfb1bb28b58bac84b7bd4848343872e5..5ee8250dd74cfdcb9d3e38f33a4c7c4b0d1255ae 100644 (file)
@@ -9,7 +9,6 @@
 #include <assert.h>
 
 #include "kvm_util.h"
-#include "../kvm_util_internal.h"
 #include "processor.h"
 
 #define DEFAULT_RISCV_GUEST_STACK_VADDR_MIN    0xac0000
index c2ed59f5783d06087263d83eecab11e9f22eb2f8..48d91b77fa1dbd6dfa19b5df3c3868bdf5abe0f5 100644 (file)
@@ -8,7 +8,6 @@
 #include <linux/kvm.h>
 
 #include "kvm_util.h"
-#include "../kvm_util_internal.h"
 #include "processor.h"
 
 void ucall_init(struct kvm_vm *vm, void *arg)
index 7cc1051c4b714409e9a537ea5fe9e74b1635ea42..53c413932f64a1e8e5eef61ccf5308b3f977f1de 100644 (file)
@@ -7,7 +7,6 @@
 
 #include "processor.h"
 #include "kvm_util.h"
-#include "../kvm_util_internal.h"
 
 #define PAGES_PER_REGION 4
 
index e258524435a0659d5352993a18c4c9c975a8aff1..f525427a37c4f978c16566e1a741fa2775cee814 100644 (file)
@@ -12,7 +12,6 @@
 #include "test_util.h"
 #include "kvm_util.h"
 #include "perf_test_util.h"
-#include "../kvm_util_internal.h"
 #include "processor.h"
 #include "vmx.h"
 
index 31293dbe10ec1f8aa0fe6d21f395bdea590e5ef8..02266b8123df3e4f3896db98d049e2a931085561 100644 (file)
@@ -7,7 +7,6 @@
 
 #include "test_util.h"
 #include "kvm_util.h"
-#include "../kvm_util_internal.h"
 #include "processor.h"
 
 #ifndef NUM_INTERRUPTS
index 736ee4a23df62e5c4095724646dced3d8c699c51..01a9d831da13a9dbc422457721f52475fb5c2a8b 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "test_util.h"
 #include "kvm_util.h"
-#include "../kvm_util_internal.h"
 #include "processor.h"
 #include "svm_util.h"
 
index b77a01d0a27139b94845286361dc5750417a8f0c..fdca123397e465c4ad532a302e5b31735fc65051 100644 (file)
@@ -7,7 +7,6 @@
 
 #include "test_util.h"
 #include "kvm_util.h"
-#include "../kvm_util_internal.h"
 #include "processor.h"
 #include "vmx.h"
 
index e83afd4bb4cf080bae1a043181e25e47c5f7b502..419fbdc51246e20ed3fd006f4c29af5ef270676e 100644 (file)
@@ -8,7 +8,6 @@
  */
 
 #include "kvm_util.h"
-#include "../lib/kvm_util_internal.h"
 
 #define MAX_VCPU_ID    2
 
index 7424bec5ae2395bef8528dffb1671ef878bf03a2..5b565aa11e32ce27103f4c671429233dcf52764d 100644 (file)
@@ -12,7 +12,6 @@
 #include "processor.h"
 #include "svm_util.h"
 #include "kselftest.h"
-#include "../lib/kvm_util_internal.h"
 
 #define SEV_POLICY_ES 0b100
 
index f94f1b449aef4331ef6253e54e4b06054c778c0b..18061677154f9df3c4f439605362ba650ffc2498 100644 (file)
@@ -17,7 +17,6 @@
 #include "processor.h"
 #include "svm_util.h"
 #include "test_util.h"
-#include "../lib/kvm_util_internal.h"
 
 #define VCPU_ID                0
 #define INT_NR                 0x20