1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * tools/testing/selftests/kvm/lib/kvm_util_internal.h
5 * Copyright (C) 2018, Google LLC.
8 #ifndef SELFTEST_KVM_UTIL_INTERNAL_H
9 #define SELFTEST_KVM_UTIL_INTERNAL_H
11 #include "linux/hashtable.h"
12 #include "linux/rbtree.h"
14 #include "sparsebit.h"
16 struct userspace_mem_region {
17 struct kvm_userspace_memory_region region;
18 struct sparsebit *unused_phy_pages;
24 struct rb_node gpa_node;
25 struct rb_node hva_node;
26 struct hlist_node slot_node;
30 struct list_head list;
33 struct kvm_run *state;
34 struct kvm_dirty_gfn *dirty_gfns;
36 uint32_t dirty_gfns_count;
39 struct userspace_mem_regions {
40 struct rb_root gpa_tree;
41 struct rb_root hva_tree;
42 DECLARE_HASHTABLE(slot_hash, 9);
50 unsigned int pgtable_levels;
51 unsigned int page_size;
52 unsigned int page_shift;
56 struct list_head vcpus;
57 struct userspace_mem_regions regions;
58 struct sparsebit *vpages_valid;
59 struct sparsebit *vpages_mapped;
67 uint32_t dirty_ring_size;
70 struct vcpu *vcpu_find(struct kvm_vm *vm, uint32_t vcpuid);
73 * Virtual Translation Tables Dump
76 * stream - Output FILE stream
77 * vm - Virtual Machine
78 * indent - Left margin indent amount
84 * Dumps to the FILE stream given by @stream, the contents of all the
85 * virtual translation tables for the VM given by @vm.
87 void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
93 * stream - Output FILE stream
95 * indent - Left margin indent amount
101 * Dumps the state of the registers given by @regs, to the FILE stream
104 void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent);
107 * System Register Dump
110 * stream - Output FILE stream
111 * sregs - System registers
112 * indent - Left margin indent amount
118 * Dumps the state of the system registers given by @sregs, to the FILE stream
121 void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent);
123 struct userspace_mem_region *
124 memslot2region(struct kvm_vm *vm, uint32_t memslot);
126 #endif /* SELFTEST_KVM_UTIL_INTERNAL_H */