x86.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #ifndef ARCH_X86_KVM_X86_H
  2. #define ARCH_X86_KVM_X86_H
  3. #include <linux/kvm_host.h>
  4. #include "kvm_cache_regs.h"
  5. static inline void kvm_clear_exception_queue(struct kvm_vcpu *vcpu)
  6. {
  7. vcpu->arch.exception.pending = false;
  8. }
  9. static inline void kvm_queue_interrupt(struct kvm_vcpu *vcpu, u8 vector,
  10. bool soft)
  11. {
  12. vcpu->arch.interrupt.pending = true;
  13. vcpu->arch.interrupt.soft = soft;
  14. vcpu->arch.interrupt.nr = vector;
  15. }
  16. static inline void kvm_clear_interrupt_queue(struct kvm_vcpu *vcpu)
  17. {
  18. vcpu->arch.interrupt.pending = false;
  19. }
  20. static inline bool kvm_event_needs_reinjection(struct kvm_vcpu *vcpu)
  21. {
  22. return vcpu->arch.exception.pending || vcpu->arch.interrupt.pending ||
  23. vcpu->arch.nmi_injected;
  24. }
  25. static inline bool kvm_exception_is_soft(unsigned int nr)
  26. {
  27. return (nr == BP_VECTOR) || (nr == OF_VECTOR);
  28. }
  29. struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
  30. u32 function, u32 index);
  31. static inline bool is_protmode(struct kvm_vcpu *vcpu)
  32. {
  33. return kvm_read_cr0_bits(vcpu, X86_CR0_PE);
  34. }
  35. static inline int is_long_mode(struct kvm_vcpu *vcpu)
  36. {
  37. #ifdef CONFIG_X86_64
  38. return vcpu->arch.efer & EFER_LMA;
  39. #else
  40. return 0;
  41. #endif
  42. }
  43. static inline bool mmu_is_nested(struct kvm_vcpu *vcpu)
  44. {
  45. return vcpu->arch.walk_mmu == &vcpu->arch.nested_mmu;
  46. }
  47. static inline int is_pae(struct kvm_vcpu *vcpu)
  48. {
  49. return kvm_read_cr4_bits(vcpu, X86_CR4_PAE);
  50. }
  51. static inline int is_pse(struct kvm_vcpu *vcpu)
  52. {
  53. return kvm_read_cr4_bits(vcpu, X86_CR4_PSE);
  54. }
  55. static inline int is_paging(struct kvm_vcpu *vcpu)
  56. {
  57. return kvm_read_cr0_bits(vcpu, X86_CR0_PG);
  58. }
  59. static inline u32 bit(int bitno)
  60. {
  61. return 1 << (bitno & 31);
  62. }
  63. static inline void vcpu_cache_mmio_info(struct kvm_vcpu *vcpu,
  64. gva_t gva, gfn_t gfn, unsigned access)
  65. {
  66. vcpu->arch.mmio_gva = gva & PAGE_MASK;
  67. vcpu->arch.access = access;
  68. vcpu->arch.mmio_gfn = gfn;
  69. }
  70. /*
  71. * Clear the mmio cache info for the given gva,
  72. * specially, if gva is ~0ul, we clear all mmio cache info.
  73. */
  74. static inline void vcpu_clear_mmio_info(struct kvm_vcpu *vcpu, gva_t gva)
  75. {
  76. if (gva != (~0ul) && vcpu->arch.mmio_gva != (gva & PAGE_MASK))
  77. return;
  78. vcpu->arch.mmio_gva = 0;
  79. }
  80. static inline bool vcpu_match_mmio_gva(struct kvm_vcpu *vcpu, unsigned long gva)
  81. {
  82. if (vcpu->arch.mmio_gva && vcpu->arch.mmio_gva == (gva & PAGE_MASK))
  83. return true;
  84. return false;
  85. }
  86. static inline bool vcpu_match_mmio_gpa(struct kvm_vcpu *vcpu, gpa_t gpa)
  87. {
  88. if (vcpu->arch.mmio_gfn && vcpu->arch.mmio_gfn == gpa >> PAGE_SHIFT)
  89. return true;
  90. return false;
  91. }
  92. void kvm_before_handle_nmi(struct kvm_vcpu *vcpu);
  93. void kvm_after_handle_nmi(struct kvm_vcpu *vcpu);
  94. int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip);
  95. void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data);
  96. int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt,
  97. gva_t addr, void *val, unsigned int bytes,
  98. struct x86_exception *exception);
  99. int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
  100. gva_t addr, void *val, unsigned int bytes,
  101. struct x86_exception *exception);
  102. #endif