784f37cbf33e63db5bd8d909ca8ea981c027287b
[linux-2.6-microblaze.git] / include / linux / kvm_types.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #ifndef __KVM_TYPES_H__
4 #define __KVM_TYPES_H__
5
6 struct kvm;
7 struct kvm_async_pf;
8 struct kvm_device_ops;
9 struct kvm_interrupt;
10 struct kvm_irq_routing_table;
11 struct kvm_memory_slot;
12 struct kvm_one_reg;
13 struct kvm_run;
14 struct kvm_userspace_memory_region;
15 struct kvm_vcpu;
16 struct kvm_vcpu_init;
17 struct kvm_memslots;
18
19 enum kvm_mr_change;
20
21 #include <linux/bits.h>
22 #include <linux/types.h>
23 #include <linux/spinlock_types.h>
24
25 #include <asm/kvm_types.h>
26
27 /*
28  * Address types:
29  *
30  *  gva - guest virtual address
31  *  gpa - guest physical address
32  *  gfn - guest frame number
33  *  hva - host virtual address
34  *  hpa - host physical address
35  *  hfn - host frame number
36  */
37
38 typedef unsigned long  gva_t;
39 typedef u64            gpa_t;
40 typedef u64            gfn_t;
41
42 #define GPA_INVALID     (~(gpa_t)0)
43
44 typedef unsigned long  hva_t;
45 typedef u64            hpa_t;
46 typedef u64            hfn_t;
47
48 typedef hfn_t kvm_pfn_t;
49
50 enum pfn_cache_usage {
51         KVM_GUEST_USES_PFN = BIT(0),
52         KVM_HOST_USES_PFN  = BIT(1),
53         KVM_GUEST_AND_HOST_USE_PFN = KVM_GUEST_USES_PFN | KVM_HOST_USES_PFN,
54 };
55
56 struct gfn_to_hva_cache {
57         u64 generation;
58         gpa_t gpa;
59         unsigned long hva;
60         unsigned long len;
61         struct kvm_memory_slot *memslot;
62 };
63
64 struct gfn_to_pfn_cache {
65         u64 generation;
66         gpa_t gpa;
67         unsigned long uhva;
68         struct kvm_memory_slot *memslot;
69         struct kvm_vcpu *vcpu;
70         struct list_head list;
71         rwlock_t lock;
72         void *khva;
73         kvm_pfn_t pfn;
74         enum pfn_cache_usage usage;
75         bool active;
76         bool valid;
77         bool dirty;
78 };
79
80 #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE
81 /*
82  * Memory caches are used to preallocate memory ahead of various MMU flows,
83  * e.g. page fault handlers.  Gracefully handling allocation failures deep in
84  * MMU flows is problematic, as is triggering reclaim, I/O, etc... while
85  * holding MMU locks.  Note, these caches act more like prefetch buffers than
86  * classical caches, i.e. objects are not returned to the cache on being freed.
87  */
88 struct kvm_mmu_memory_cache {
89         int nobjs;
90         gfp_t gfp_zero;
91         struct kmem_cache *kmem_cache;
92         void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE];
93 };
94 #endif
95
96 #define HALT_POLL_HIST_COUNT                    32
97
98 struct kvm_vm_stat_generic {
99         u64 remote_tlb_flush;
100         u64 remote_tlb_flush_requests;
101 };
102
103 struct kvm_vcpu_stat_generic {
104         u64 halt_successful_poll;
105         u64 halt_attempted_poll;
106         u64 halt_poll_invalid;
107         u64 halt_wakeup;
108         u64 halt_poll_success_ns;
109         u64 halt_poll_fail_ns;
110         u64 halt_wait_ns;
111         u64 halt_poll_success_hist[HALT_POLL_HIST_COUNT];
112         u64 halt_poll_fail_hist[HALT_POLL_HIST_COUNT];
113         u64 halt_wait_hist[HALT_POLL_HIST_COUNT];
114         u64 blocking;
115 };
116
117 #define KVM_STATS_NAME_SIZE     48
118
119 #endif /* __KVM_TYPES_H__ */