• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * tools/testing/selftests/kvm/lib/kvm_util_internal.h
4  *
5  * Copyright (C) 2018, Google LLC.
6  */
7 
8 #ifndef SELFTEST_KVM_UTIL_INTERNAL_H
9 #define SELFTEST_KVM_UTIL_INTERNAL_H
10 
11 #include "sparsebit.h"
12 
13 #define KVM_DEV_PATH		"/dev/kvm"
14 
15 struct userspace_mem_region {
16 	struct kvm_userspace_memory_region region;
17 	struct sparsebit *unused_phy_pages;
18 	int fd;
19 	off_t offset;
20 	void *host_mem;
21 	void *mmap_start;
22 	size_t mmap_size;
23 	struct list_head list;
24 };
25 
26 struct vcpu {
27 	struct list_head list;
28 	uint32_t id;
29 	int fd;
30 	struct kvm_run *state;
31 };
32 
33 struct kvm_vm {
34 	int mode;
35 	unsigned long type;
36 	int kvm_fd;
37 	int fd;
38 	unsigned int pgtable_levels;
39 	unsigned int page_size;
40 	unsigned int page_shift;
41 	unsigned int pa_bits;
42 	unsigned int va_bits;
43 	uint64_t max_gfn;
44 	struct list_head vcpus;
45 	struct list_head userspace_mem_regions;
46 	struct sparsebit *vpages_valid;
47 	struct sparsebit *vpages_mapped;
48 	bool has_irqchip;
49 	bool pgd_created;
50 	vm_paddr_t pgd;
51 	vm_vaddr_t gdt;
52 	vm_vaddr_t tss;
53 	vm_vaddr_t idt;
54 	vm_vaddr_t handlers;
55 };
56 
57 struct vcpu *vcpu_find(struct kvm_vm *vm, uint32_t vcpuid);
58 
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 */
114