2 * tools/testing/selftests/kvm/lib/kvm_util.c
4 * Copyright (C) 2018, Google LLC.
6 * This work is licensed under the terms of the GNU GPL, version 2.
9 #ifndef KVM_UTIL_INTERNAL_H
10 #define KVM_UTIL_INTERNAL_H 1
12 #include "sparsebit.h"
15 #define BITS_PER_BYTE 8
19 #define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long))
22 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
23 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_LONG)
25 /* Concrete definition of struct kvm_vm. */
26 struct userspace_mem_region
{
27 struct userspace_mem_region
*next
, *prev
;
28 struct kvm_userspace_memory_region region
;
29 struct sparsebit
*unused_phy_pages
;
38 struct vcpu
*next
, *prev
;
41 struct kvm_run
*state
;
48 unsigned int page_size
;
49 unsigned int page_shift
;
51 struct vcpu
*vcpu_head
;
52 struct userspace_mem_region
*userspace_mem_region_head
;
53 struct sparsebit
*vpages_valid
;
54 struct sparsebit
*vpages_mapped
;
63 struct vcpu
*vcpu_find(struct kvm_vm
*vm
,
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
,
69 void sregs_dump(FILE *stream
, struct kvm_sregs
*sregs
,