x86.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #ifndef KVM_X86_H
  11. #define KVM_X86_H
  12. #include "kvm.h"
  13. #include <linux/types.h>
  14. #include <linux/mm.h>
  15. #include <linux/kvm.h>
  16. #include <linux/kvm_para.h>
  17. struct kvm_vcpu {
  18. KVM_VCPU_COMM;
  19. u64 host_tsc;
  20. int interrupt_window_open;
  21. unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */
  22. DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);
  23. unsigned long regs[NR_VCPU_REGS]; /* for rsp: vcpu_load_rsp_rip() */
  24. unsigned long rip; /* needs vcpu_load_rsp_rip() */
  25. unsigned long cr0;
  26. unsigned long cr2;
  27. unsigned long cr3;
  28. unsigned long cr4;
  29. unsigned long cr8;
  30. u64 pdptrs[4]; /* pae */
  31. u64 shadow_efer;
  32. u64 apic_base;
  33. struct kvm_lapic *apic; /* kernel irqchip context */
  34. #define VCPU_MP_STATE_RUNNABLE 0
  35. #define VCPU_MP_STATE_UNINITIALIZED 1
  36. #define VCPU_MP_STATE_INIT_RECEIVED 2
  37. #define VCPU_MP_STATE_SIPI_RECEIVED 3
  38. #define VCPU_MP_STATE_HALTED 4
  39. int mp_state;
  40. int sipi_vector;
  41. u64 ia32_misc_enable_msr;
  42. struct kvm_mmu mmu;
  43. struct kvm_mmu_memory_cache mmu_pte_chain_cache;
  44. struct kvm_mmu_memory_cache mmu_rmap_desc_cache;
  45. struct kvm_mmu_memory_cache mmu_page_cache;
  46. struct kvm_mmu_memory_cache mmu_page_header_cache;
  47. gfn_t last_pt_write_gfn;
  48. int last_pt_write_count;
  49. u64 *last_pte_updated;
  50. struct i387_fxsave_struct host_fx_image;
  51. struct i387_fxsave_struct guest_fx_image;
  52. gva_t mmio_fault_cr2;
  53. struct kvm_pio_request pio;
  54. void *pio_data;
  55. struct {
  56. int active;
  57. u8 save_iopl;
  58. struct kvm_save_segment {
  59. u16 selector;
  60. unsigned long base;
  61. u32 limit;
  62. u32 ar;
  63. } tr, es, ds, fs, gs;
  64. } rmode;
  65. int halt_request; /* real mode on Intel only */
  66. int cpuid_nent;
  67. struct kvm_cpuid_entry cpuid_entries[KVM_MAX_CPUID_ENTRIES];
  68. /* emulate context */
  69. struct x86_emulate_ctxt emulate_ctxt;
  70. };
  71. extern struct kvm_x86_ops *kvm_x86_ops;
  72. int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code);
  73. static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
  74. {
  75. if (unlikely(vcpu->kvm->n_free_mmu_pages < KVM_MIN_FREE_MMU_PAGES))
  76. __kvm_mmu_free_some_pages(vcpu);
  77. }
  78. static inline int kvm_mmu_reload(struct kvm_vcpu *vcpu)
  79. {
  80. if (likely(vcpu->mmu.root_hpa != INVALID_PAGE))
  81. return 0;
  82. return kvm_mmu_load(vcpu);
  83. }
  84. static inline int is_long_mode(struct kvm_vcpu *vcpu)
  85. {
  86. #ifdef CONFIG_X86_64
  87. return vcpu->shadow_efer & EFER_LME;
  88. #else
  89. return 0;
  90. #endif
  91. }
  92. static inline int is_pae(struct kvm_vcpu *vcpu)
  93. {
  94. return vcpu->cr4 & X86_CR4_PAE;
  95. }
  96. static inline int is_pse(struct kvm_vcpu *vcpu)
  97. {
  98. return vcpu->cr4 & X86_CR4_PSE;
  99. }
  100. static inline int is_paging(struct kvm_vcpu *vcpu)
  101. {
  102. return vcpu->cr0 & X86_CR0_PG;
  103. }
  104. int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3);
  105. int complete_pio(struct kvm_vcpu *vcpu);
  106. #endif