.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | /* |
---|
2 | | - * tools/testing/selftests/kvm/lib/kvm_util.c |
---|
| 3 | + * tools/testing/selftests/kvm/lib/kvm_util_internal.h |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2018, Google LLC. |
---|
5 | | - * |
---|
6 | | - * This work is licensed under the terms of the GNU GPL, version 2. |
---|
7 | 6 | */ |
---|
8 | 7 | |
---|
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 |
---|
11 | 10 | |
---|
12 | 11 | #include "sparsebit.h" |
---|
13 | 12 | |
---|
14 | | -#ifndef BITS_PER_BYTE |
---|
15 | | -#define BITS_PER_BYTE 8 |
---|
16 | | -#endif |
---|
| 13 | +#define KVM_DEV_PATH "/dev/kvm" |
---|
17 | 14 | |
---|
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. */ |
---|
26 | 15 | struct userspace_mem_region { |
---|
27 | | - struct userspace_mem_region *next, *prev; |
---|
28 | 16 | struct kvm_userspace_memory_region region; |
---|
29 | 17 | struct sparsebit *unused_phy_pages; |
---|
30 | 18 | int fd; |
---|
.. | .. |
---|
32 | 20 | void *host_mem; |
---|
33 | 21 | void *mmap_start; |
---|
34 | 22 | size_t mmap_size; |
---|
| 23 | + struct list_head list; |
---|
35 | 24 | }; |
---|
36 | 25 | |
---|
37 | 26 | struct vcpu { |
---|
38 | | - struct vcpu *next, *prev; |
---|
| 27 | + struct list_head list; |
---|
39 | 28 | uint32_t id; |
---|
40 | 29 | int fd; |
---|
41 | 30 | struct kvm_run *state; |
---|
.. | .. |
---|
43 | 32 | |
---|
44 | 33 | struct kvm_vm { |
---|
45 | 34 | int mode; |
---|
| 35 | + unsigned long type; |
---|
46 | 36 | int kvm_fd; |
---|
47 | 37 | int fd; |
---|
| 38 | + unsigned int pgtable_levels; |
---|
48 | 39 | unsigned int page_size; |
---|
49 | 40 | unsigned int page_shift; |
---|
| 41 | + unsigned int pa_bits; |
---|
| 42 | + unsigned int va_bits; |
---|
50 | 43 | 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; |
---|
53 | 46 | struct sparsebit *vpages_valid; |
---|
54 | 47 | struct sparsebit *vpages_mapped; |
---|
55 | | - |
---|
56 | 48 | bool has_irqchip; |
---|
57 | 49 | bool pgd_created; |
---|
58 | 50 | vm_paddr_t pgd; |
---|
59 | 51 | vm_vaddr_t gdt; |
---|
60 | 52 | vm_vaddr_t tss; |
---|
| 53 | + vm_vaddr_t idt; |
---|
| 54 | + vm_vaddr_t handlers; |
---|
61 | 55 | }; |
---|
62 | 56 | |
---|
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); |
---|
71 | 58 | |
---|
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 */ |
---|