Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 
0003 #ifndef __KVM_TYPES_H__
0004 #define __KVM_TYPES_H__
0005 
0006 struct kvm;
0007 struct kvm_async_pf;
0008 struct kvm_device_ops;
0009 struct kvm_interrupt;
0010 struct kvm_irq_routing_table;
0011 struct kvm_memory_slot;
0012 struct kvm_one_reg;
0013 struct kvm_run;
0014 struct kvm_userspace_memory_region;
0015 struct kvm_vcpu;
0016 struct kvm_vcpu_init;
0017 struct kvm_memslots;
0018 
0019 enum kvm_mr_change;
0020 
0021 #include <linux/bits.h>
0022 #include <linux/mutex.h>
0023 #include <linux/types.h>
0024 #include <linux/spinlock_types.h>
0025 
0026 #include <asm/kvm_types.h>
0027 
0028 /*
0029  * Address types:
0030  *
0031  *  gva - guest virtual address
0032  *  gpa - guest physical address
0033  *  gfn - guest frame number
0034  *  hva - host virtual address
0035  *  hpa - host physical address
0036  *  hfn - host frame number
0037  */
0038 
0039 typedef unsigned long  gva_t;
0040 typedef u64            gpa_t;
0041 typedef u64            gfn_t;
0042 
0043 #define GPA_INVALID (~(gpa_t)0)
0044 
0045 typedef unsigned long  hva_t;
0046 typedef u64            hpa_t;
0047 typedef u64            hfn_t;
0048 
0049 typedef hfn_t kvm_pfn_t;
0050 
0051 enum pfn_cache_usage {
0052     KVM_GUEST_USES_PFN = BIT(0),
0053     KVM_HOST_USES_PFN  = BIT(1),
0054     KVM_GUEST_AND_HOST_USE_PFN = KVM_GUEST_USES_PFN | KVM_HOST_USES_PFN,
0055 };
0056 
0057 struct gfn_to_hva_cache {
0058     u64 generation;
0059     gpa_t gpa;
0060     unsigned long hva;
0061     unsigned long len;
0062     struct kvm_memory_slot *memslot;
0063 };
0064 
0065 struct gfn_to_pfn_cache {
0066     u64 generation;
0067     gpa_t gpa;
0068     unsigned long uhva;
0069     struct kvm_memory_slot *memslot;
0070     struct kvm_vcpu *vcpu;
0071     struct list_head list;
0072     rwlock_t lock;
0073     struct mutex refresh_lock;
0074     void *khva;
0075     kvm_pfn_t pfn;
0076     enum pfn_cache_usage usage;
0077     bool active;
0078     bool valid;
0079 };
0080 
0081 #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE
0082 /*
0083  * Memory caches are used to preallocate memory ahead of various MMU flows,
0084  * e.g. page fault handlers.  Gracefully handling allocation failures deep in
0085  * MMU flows is problematic, as is triggering reclaim, I/O, etc... while
0086  * holding MMU locks.  Note, these caches act more like prefetch buffers than
0087  * classical caches, i.e. objects are not returned to the cache on being freed.
0088  *
0089  * The @capacity field and @objects array are lazily initialized when the cache
0090  * is topped up (__kvm_mmu_topup_memory_cache()).
0091  */
0092 struct kvm_mmu_memory_cache {
0093     int nobjs;
0094     gfp_t gfp_zero;
0095     gfp_t gfp_custom;
0096     struct kmem_cache *kmem_cache;
0097     int capacity;
0098     void **objects;
0099 };
0100 #endif
0101 
0102 #define HALT_POLL_HIST_COUNT            32
0103 
0104 struct kvm_vm_stat_generic {
0105     u64 remote_tlb_flush;
0106     u64 remote_tlb_flush_requests;
0107 };
0108 
0109 struct kvm_vcpu_stat_generic {
0110     u64 halt_successful_poll;
0111     u64 halt_attempted_poll;
0112     u64 halt_poll_invalid;
0113     u64 halt_wakeup;
0114     u64 halt_poll_success_ns;
0115     u64 halt_poll_fail_ns;
0116     u64 halt_wait_ns;
0117     u64 halt_poll_success_hist[HALT_POLL_HIST_COUNT];
0118     u64 halt_poll_fail_hist[HALT_POLL_HIST_COUNT];
0119     u64 halt_wait_hist[HALT_POLL_HIST_COUNT];
0120     u64 blocking;
0121 };
0122 
0123 #define KVM_STATS_NAME_SIZE 48
0124 
0125 #endif /* __KVM_TYPES_H__ */