1/* SPDX-License-Identifier: GPL-2.0-only */ 2 3#ifndef __KVM_TYPES_H__ 4#define __KVM_TYPES_H__ 5 6struct kvm; 7struct kvm_async_pf; 8struct kvm_device_ops; 9struct kvm_gfn_range; 10struct kvm_interrupt; 11struct kvm_irq_routing_table; 12struct kvm_memory_slot; 13struct kvm_one_reg; 14struct kvm_run; 15struct kvm_userspace_memory_region; 16struct kvm_vcpu; 17struct kvm_vcpu_init; 18struct kvm_memslots; 19 20enum kvm_mr_change; 21 22#include <linux/bits.h> 23#include <linux/mutex.h> 24#include <linux/types.h> 25#include <linux/spinlock_types.h> 26 27#include <asm/kvm_types.h> 28 29/* 30 * Address types: 31 * 32 * gva - guest virtual address 33 * gpa - guest physical address 34 * gfn - guest frame number 35 * hva - host virtual address 36 * hpa - host physical address 37 * hfn - host frame number 38 */ 39 40typedef unsigned long gva_t; 41typedef u64 gpa_t; 42typedef u64 gfn_t; 43 44#define INVALID_GPA (~(gpa_t)0) 45 46typedef unsigned long hva_t; 47typedef u64 hpa_t; 48typedef u64 hfn_t; 49 50typedef hfn_t kvm_pfn_t; 51 52struct gfn_to_hva_cache { 53 u64 generation; 54 gpa_t gpa; 55 unsigned long hva; 56 unsigned long len; 57 struct kvm_memory_slot *memslot; 58}; 59 60struct gfn_to_pfn_cache { 61 u64 generation; 62 gpa_t gpa; 63 unsigned long uhva; 64 struct kvm_memory_slot *memslot; 65 struct kvm *kvm; 66 struct list_head list; 67 rwlock_t lock; 68 struct mutex refresh_lock; 69 void *khva; 70 kvm_pfn_t pfn; 71 bool active; 72 bool valid; 73}; 74 75#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 76/* 77 * Memory caches are used to preallocate memory ahead of various MMU flows, 78 * e.g. page fault handlers. Gracefully handling allocation failures deep in 79 * MMU flows is problematic, as is triggering reclaim, I/O, etc... while 80 * holding MMU locks. Note, these caches act more like prefetch buffers than 81 * classical caches, i.e. objects are not returned to the cache on being freed. 82 * 83 * The @capacity field and @objects array are lazily initialized when the cache 84 * is topped up (__kvm_mmu_topup_memory_cache()). 85 */ 86struct kvm_mmu_memory_cache { 87 gfp_t gfp_zero; 88 gfp_t gfp_custom; 89 struct kmem_cache *kmem_cache; 90 int capacity; 91 int nobjs; 92 void **objects; 93}; 94#endif 95 96#define HALT_POLL_HIST_COUNT 32 97 98struct kvm_vm_stat_generic { 99 u64 remote_tlb_flush; 100 u64 remote_tlb_flush_requests; 101}; 102 103struct 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__ */ 120