hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/tools/testing/selftests/kvm/lib/kvm_util_internal.h
....@@ -1,30 +1,18 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
2
- * tools/testing/selftests/kvm/lib/kvm_util.c
3
+ * tools/testing/selftests/kvm/lib/kvm_util_internal.h
34 *
45 * Copyright (C) 2018, Google LLC.
5
- *
6
- * This work is licensed under the terms of the GNU GPL, version 2.
76 */
87
9
-#ifndef KVM_UTIL_INTERNAL_H
10
-#define KVM_UTIL_INTERNAL_H 1
8
+#ifndef SELFTEST_KVM_UTIL_INTERNAL_H
9
+#define SELFTEST_KVM_UTIL_INTERNAL_H
1110
1211 #include "sparsebit.h"
1312
14
-#ifndef BITS_PER_BYTE
15
-#define BITS_PER_BYTE 8
16
-#endif
13
+#define KVM_DEV_PATH "/dev/kvm"
1714
18
-#ifndef BITS_PER_LONG
19
-#define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long))
20
-#endif
21
-
22
-#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
23
-#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_LONG)
24
-
25
-/* Concrete definition of struct kvm_vm. */
2615 struct userspace_mem_region {
27
- struct userspace_mem_region *next, *prev;
2816 struct kvm_userspace_memory_region region;
2917 struct sparsebit *unused_phy_pages;
3018 int fd;
....@@ -32,10 +20,11 @@
3220 void *host_mem;
3321 void *mmap_start;
3422 size_t mmap_size;
23
+ struct list_head list;
3524 };
3625
3726 struct vcpu {
38
- struct vcpu *next, *prev;
27
+ struct list_head list;
3928 uint32_t id;
4029 int fd;
4130 struct kvm_run *state;
....@@ -43,30 +32,82 @@
4332
4433 struct kvm_vm {
4534 int mode;
35
+ unsigned long type;
4636 int kvm_fd;
4737 int fd;
38
+ unsigned int pgtable_levels;
4839 unsigned int page_size;
4940 unsigned int page_shift;
41
+ unsigned int pa_bits;
42
+ unsigned int va_bits;
5043 uint64_t max_gfn;
51
- struct vcpu *vcpu_head;
52
- struct userspace_mem_region *userspace_mem_region_head;
44
+ struct list_head vcpus;
45
+ struct list_head userspace_mem_regions;
5346 struct sparsebit *vpages_valid;
5447 struct sparsebit *vpages_mapped;
55
-
5648 bool has_irqchip;
5749 bool pgd_created;
5850 vm_paddr_t pgd;
5951 vm_vaddr_t gdt;
6052 vm_vaddr_t tss;
53
+ vm_vaddr_t idt;
54
+ vm_vaddr_t handlers;
6155 };
6256
63
-struct vcpu *vcpu_find(struct kvm_vm *vm,
64
- uint32_t vcpuid);
65
-void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_memslot);
66
-void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
67
-void regs_dump(FILE *stream, struct kvm_regs *regs,
68
- uint8_t indent);
69
-void sregs_dump(FILE *stream, struct kvm_sregs *sregs,
70
- uint8_t indent);
57
+struct vcpu *vcpu_find(struct kvm_vm *vm, uint32_t vcpuid);
7158
72
-#endif
59
+/*
60
+ * Virtual Translation Tables Dump
61
+ *
62
+ * Input Args:
63
+ * stream - Output FILE stream
64
+ * vm - Virtual Machine
65
+ * indent - Left margin indent amount
66
+ *
67
+ * Output Args: None
68
+ *
69
+ * Return: None
70
+ *
71
+ * Dumps to the FILE stream given by @stream, the contents of all the
72
+ * virtual translation tables for the VM given by @vm.
73
+ */
74
+void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
75
+
76
+/*
77
+ * Register Dump
78
+ *
79
+ * Input Args:
80
+ * stream - Output FILE stream
81
+ * regs - Registers
82
+ * indent - Left margin indent amount
83
+ *
84
+ * Output Args: None
85
+ *
86
+ * Return: None
87
+ *
88
+ * Dumps the state of the registers given by @regs, to the FILE stream
89
+ * given by @stream.
90
+ */
91
+void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent);
92
+
93
+/*
94
+ * System Register Dump
95
+ *
96
+ * Input Args:
97
+ * stream - Output FILE stream
98
+ * sregs - System registers
99
+ * indent - Left margin indent amount
100
+ *
101
+ * Output Args: None
102
+ *
103
+ * Return: None
104
+ *
105
+ * Dumps the state of the system registers given by @sregs, to the FILE stream
106
+ * given by @stream.
107
+ */
108
+void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent);
109
+
110
+struct userspace_mem_region *
111
+memslot2region(struct kvm_vm *vm, uint32_t memslot);
112
+
113
+#endif /* SELFTEST_KVM_UTIL_INTERNAL_H */