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 f5bfdf0..c0199f3 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 d28cc12..388bd7d 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 00be3ef..868ebab 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 25d1ec6..c34f0f1 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 13e8e3d..9f54c09 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 c7df8ba..a57958a 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 c89e6b1..5ee8250 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 c2ed59f..48d91b7 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 7cc1051..53c4139 100644 (file)
@@ -7,7 +7,6 @@
 
 #include "processor.h"
 #include "kvm_util.h"
-#include "../kvm_util_internal.h"
 
 #define PAGES_PER_REGION 4
 
index e258524..f525427 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 31293db..02266b8 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 736ee4a..01a9d83 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 b77a01d..fdca123 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 e83afd4..419fbdc 100644 (file)
@@ -8,7 +8,6 @@
  */
 
 #include "kvm_util.h"
-#include "../lib/kvm_util_internal.h"
 
 #define MAX_VCPU_ID    2
 
index 7424bec..5b565aa 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 f94f1b4..1806167 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