KVM: selftests: Get rid of kvm_util_internal.h
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>
This commit is contained in:
committed by
Paolo Bonzini
parent
b938cafdde
commit
b530eba14c
@ -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"
|
||||
@ -21,15 +25,94 @@
|
||||
|
||||
#define NSEC_PER_SEC 1000000000L
|
||||
|
||||
/*
|
||||
* Callers of kvm_util only have an incomplete/opaque description of the
|
||||
* structure kvm_util is using to maintain the state of a VM.
|
||||
*/
|
||||
struct kvm_vm;
|
||||
|
||||
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);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
/* Minimum allocated guest virtual and physical addresses */
|
||||
#define KVM_UTIL_MIN_VADDR 0x2000
|
||||
#define KVM_GUEST_PAGE_TABLE_MIN_PADDR 0x180000
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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>
|
||||
|
@ -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 */
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "processor.h"
|
||||
#include "kvm_util.h"
|
||||
#include "../kvm_util_internal.h"
|
||||
|
||||
#define PAGES_PER_REGION 4
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "test_util.h"
|
||||
#include "kvm_util.h"
|
||||
#include "../kvm_util_internal.h"
|
||||
#include "processor.h"
|
||||
|
||||
#ifndef NUM_INTERRUPTS
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include "test_util.h"
|
||||
#include "kvm_util.h"
|
||||
#include "../kvm_util_internal.h"
|
||||
#include "processor.h"
|
||||
#include "svm_util.h"
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "test_util.h"
|
||||
#include "kvm_util.h"
|
||||
#include "../kvm_util_internal.h"
|
||||
#include "processor.h"
|
||||
#include "vmx.h"
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
#include "kvm_util.h"
|
||||
#include "../lib/kvm_util_internal.h"
|
||||
|
||||
#define MAX_VCPU_ID 2
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user