]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/kvm/x86.h
KVM: Portability: MMU initialization and teardown split
[mirror_ubuntu-bionic-kernel.git] / drivers / kvm / x86.h
CommitLineData
043405e1
CO
1#/*
2 * Kernel-based Virtual Machine driver for Linux
3 *
4 * This header defines architecture specific interfaces, x86 version
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2. See
7 * the COPYING file in the top-level directory.
8 *
9 */
10
11#ifndef KVM_X86_H
12#define KVM_X86_H
13
14#include "kvm.h"
15
34c16eec
ZX
16#include <linux/types.h>
17#include <linux/mm.h>
18
19#include <linux/kvm.h>
20#include <linux/kvm_para.h>
21
e9b11c17
ZX
22extern spinlock_t kvm_lock;
23extern struct list_head vm_list;
24
34c16eec
ZX
25struct kvm_vcpu {
26 KVM_VCPU_COMM;
27 u64 host_tsc;
28 int interrupt_window_open;
29 unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */
30 DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);
31 unsigned long regs[NR_VCPU_REGS]; /* for rsp: vcpu_load_rsp_rip() */
32 unsigned long rip; /* needs vcpu_load_rsp_rip() */
33
34 unsigned long cr0;
35 unsigned long cr2;
36 unsigned long cr3;
37 unsigned long cr4;
38 unsigned long cr8;
39 u64 pdptrs[4]; /* pae */
40 u64 shadow_efer;
41 u64 apic_base;
42 struct kvm_lapic *apic; /* kernel irqchip context */
43#define VCPU_MP_STATE_RUNNABLE 0
44#define VCPU_MP_STATE_UNINITIALIZED 1
45#define VCPU_MP_STATE_INIT_RECEIVED 2
46#define VCPU_MP_STATE_SIPI_RECEIVED 3
47#define VCPU_MP_STATE_HALTED 4
48 int mp_state;
49 int sipi_vector;
50 u64 ia32_misc_enable_msr;
51
52 struct kvm_mmu mmu;
53
54 struct kvm_mmu_memory_cache mmu_pte_chain_cache;
55 struct kvm_mmu_memory_cache mmu_rmap_desc_cache;
56 struct kvm_mmu_memory_cache mmu_page_cache;
57 struct kvm_mmu_memory_cache mmu_page_header_cache;
58
59 gfn_t last_pt_write_gfn;
60 int last_pt_write_count;
61 u64 *last_pte_updated;
62
63
64 struct i387_fxsave_struct host_fx_image;
65 struct i387_fxsave_struct guest_fx_image;
66
67 gva_t mmio_fault_cr2;
68 struct kvm_pio_request pio;
69 void *pio_data;
70
71 struct {
72 int active;
73 u8 save_iopl;
74 struct kvm_save_segment {
75 u16 selector;
76 unsigned long base;
77 u32 limit;
78 u32 ar;
79 } tr, es, ds, fs, gs;
80 } rmode;
81 int halt_request; /* real mode on Intel only */
82
83 int cpuid_nent;
84 struct kvm_cpuid_entry cpuid_entries[KVM_MAX_CPUID_ENTRIES];
85
86 /* emulate context */
87
88 struct x86_emulate_ctxt emulate_ctxt;
89};
90
97896d04
ZX
91extern struct kvm_x86_ops *kvm_x86_ops;
92
3067714c 93int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code);
34c16eec
ZX
94
95static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
96{
97 if (unlikely(vcpu->kvm->n_free_mmu_pages < KVM_MIN_FREE_MMU_PAGES))
98 __kvm_mmu_free_some_pages(vcpu);
99}
100
101static inline int kvm_mmu_reload(struct kvm_vcpu *vcpu)
102{
103 if (likely(vcpu->mmu.root_hpa != INVALID_PAGE))
104 return 0;
105
106 return kvm_mmu_load(vcpu);
107}
108
109static inline int is_long_mode(struct kvm_vcpu *vcpu)
110{
111#ifdef CONFIG_X86_64
112 return vcpu->shadow_efer & EFER_LME;
113#else
114 return 0;
115#endif
116}
117
118static inline int is_pae(struct kvm_vcpu *vcpu)
119{
120 return vcpu->cr4 & X86_CR4_PAE;
121}
122
123static inline int is_pse(struct kvm_vcpu *vcpu)
124{
125 return vcpu->cr4 & X86_CR4_PSE;
126}
127
128static inline int is_paging(struct kvm_vcpu *vcpu)
129{
130 return vcpu->cr0 & X86_CR0_PG;
131}
132
a03490ed 133int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3);
de7d789a 134int complete_pio(struct kvm_vcpu *vcpu);
043405e1 135#endif