KVM
Macros | Functions
kvm_cache_regs.h File Reference
#include <linux/kvm_host.h>
Include dependency graph for kvm_cache_regs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define KVM_POSSIBLE_CR0_GUEST_BITS   (X86_CR0_TS | X86_CR0_WP)
 
#define KVM_POSSIBLE_CR4_GUEST_BITS
 
#define X86_CR0_PDPTR_BITS   (X86_CR0_CD | X86_CR0_NW | X86_CR0_PG)
 
#define X86_CR4_TLBFLUSH_BITS   (X86_CR4_PGE | X86_CR4_PCIDE | X86_CR4_PAE | X86_CR4_SMEP)
 
#define X86_CR4_PDPTR_BITS   (X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_SMEP)
 
#define BUILD_KVM_GPR_ACCESSORS(lname, uname)
 

Functions

static bool kvm_register_is_available (struct kvm_vcpu *vcpu, enum kvm_reg reg)
 
static bool kvm_register_is_dirty (struct kvm_vcpu *vcpu, enum kvm_reg reg)
 
static void kvm_register_mark_available (struct kvm_vcpu *vcpu, enum kvm_reg reg)
 
static void kvm_register_mark_dirty (struct kvm_vcpu *vcpu, enum kvm_reg reg)
 
static __always_inline bool kvm_register_test_and_mark_available (struct kvm_vcpu *vcpu, enum kvm_reg reg)
 
static unsigned long kvm_register_read_raw (struct kvm_vcpu *vcpu, int reg)
 
static void kvm_register_write_raw (struct kvm_vcpu *vcpu, int reg, unsigned long val)
 
static unsigned long kvm_rip_read (struct kvm_vcpu *vcpu)
 
static void kvm_rip_write (struct kvm_vcpu *vcpu, unsigned long val)
 
static unsigned long kvm_rsp_read (struct kvm_vcpu *vcpu)
 
static void kvm_rsp_write (struct kvm_vcpu *vcpu, unsigned long val)
 
static u64 kvm_pdptr_read (struct kvm_vcpu *vcpu, int index)
 
static void kvm_pdptr_write (struct kvm_vcpu *vcpu, int index, u64 value)
 
static ulong kvm_read_cr0_bits (struct kvm_vcpu *vcpu, ulong mask)
 
static __always_inline bool kvm_is_cr0_bit_set (struct kvm_vcpu *vcpu, unsigned long cr0_bit)
 
static ulong kvm_read_cr0 (struct kvm_vcpu *vcpu)
 
static ulong kvm_read_cr4_bits (struct kvm_vcpu *vcpu, ulong mask)
 
static __always_inline bool kvm_is_cr4_bit_set (struct kvm_vcpu *vcpu, unsigned long cr4_bit)
 
static ulong kvm_read_cr3 (struct kvm_vcpu *vcpu)
 
static ulong kvm_read_cr4 (struct kvm_vcpu *vcpu)
 
static u64 kvm_read_edx_eax (struct kvm_vcpu *vcpu)
 
static void enter_guest_mode (struct kvm_vcpu *vcpu)
 
static void leave_guest_mode (struct kvm_vcpu *vcpu)
 
static bool is_guest_mode (struct kvm_vcpu *vcpu)
 

Macro Definition Documentation

◆ BUILD_KVM_GPR_ACCESSORS

#define BUILD_KVM_GPR_ACCESSORS (   lname,
  uname 
)
Value:
static __always_inline unsigned long kvm_##lname##_read(struct kvm_vcpu *vcpu)\
{ \
return vcpu->arch.regs[VCPU_REGS_##uname]; \
} \
static __always_inline void kvm_##lname##_write(struct kvm_vcpu *vcpu, \
unsigned long val) \
{ \
vcpu->arch.regs[VCPU_REGS_##uname] = val; \
}

Definition at line 18 of file kvm_cache_regs.h.

◆ KVM_POSSIBLE_CR0_GUEST_BITS

#define KVM_POSSIBLE_CR0_GUEST_BITS   (X86_CR0_TS | X86_CR0_WP)

Definition at line 7 of file kvm_cache_regs.h.

◆ KVM_POSSIBLE_CR4_GUEST_BITS

#define KVM_POSSIBLE_CR4_GUEST_BITS
Value:
(X86_CR4_PVI | X86_CR4_DE | X86_CR4_PCE | X86_CR4_OSFXSR \
| X86_CR4_OSXMMEXCPT | X86_CR4_PGE | X86_CR4_TSD | X86_CR4_FSGSBASE)

Definition at line 8 of file kvm_cache_regs.h.

◆ X86_CR0_PDPTR_BITS

#define X86_CR0_PDPTR_BITS   (X86_CR0_CD | X86_CR0_NW | X86_CR0_PG)

Definition at line 12 of file kvm_cache_regs.h.

◆ X86_CR4_PDPTR_BITS

#define X86_CR4_PDPTR_BITS   (X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_SMEP)

Definition at line 14 of file kvm_cache_regs.h.

◆ X86_CR4_TLBFLUSH_BITS

#define X86_CR4_TLBFLUSH_BITS   (X86_CR4_PGE | X86_CR4_PCIDE | X86_CR4_PAE | X86_CR4_SMEP)

Definition at line 13 of file kvm_cache_regs.h.

Function Documentation

◆ enter_guest_mode()

static void enter_guest_mode ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 208 of file kvm_cache_regs.h.

209 {
210  vcpu->arch.hflags |= HF_GUEST_MASK;
211  vcpu->stat.guest_mode = 1;
212 }
Here is the caller graph for this function:

◆ is_guest_mode()

static bool is_guest_mode ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 226 of file kvm_cache_regs.h.

227 {
228  return vcpu->arch.hflags & HF_GUEST_MASK;
229 }

◆ kvm_is_cr0_bit_set()

static __always_inline bool kvm_is_cr0_bit_set ( struct kvm_vcpu *  vcpu,
unsigned long  cr0_bit 
)
static

Definition at line 160 of file kvm_cache_regs.h.

162 {
163  BUILD_BUG_ON(!is_power_of_2(cr0_bit));
164 
165  return !!kvm_read_cr0_bits(vcpu, cr0_bit);
166 }
static ulong kvm_read_cr0_bits(struct kvm_vcpu *vcpu, ulong mask)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_is_cr4_bit_set()

static __always_inline bool kvm_is_cr4_bit_set ( struct kvm_vcpu *  vcpu,
unsigned long  cr4_bit 
)
static

Definition at line 182 of file kvm_cache_regs.h.

184 {
185  BUILD_BUG_ON(!is_power_of_2(cr4_bit));
186 
187  return !!kvm_read_cr4_bits(vcpu, cr4_bit);
188 }
static ulong kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_pdptr_read()

static u64 kvm_pdptr_read ( struct kvm_vcpu *  vcpu,
int  index 
)
inlinestatic

Definition at line 136 of file kvm_cache_regs.h.

137 {
138  might_sleep(); /* on svm */
139 
140  if (!kvm_register_is_available(vcpu, VCPU_EXREG_PDPTR))
141  static_call(kvm_x86_cache_reg)(vcpu, VCPU_EXREG_PDPTR);
142 
143  return vcpu->arch.walk_mmu->pdptrs[index];
144 }
static bool kvm_register_is_available(struct kvm_vcpu *vcpu, enum kvm_reg reg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_pdptr_write()

static void kvm_pdptr_write ( struct kvm_vcpu *  vcpu,
int  index,
u64  value 
)
inlinestatic

Definition at line 146 of file kvm_cache_regs.h.

147 {
148  vcpu->arch.walk_mmu->pdptrs[index] = value;
149 }
Here is the caller graph for this function:

◆ kvm_read_cr0()

static ulong kvm_read_cr0 ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 168 of file kvm_cache_regs.h.

169 {
170  return kvm_read_cr0_bits(vcpu, ~0UL);
171 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_read_cr0_bits()

static ulong kvm_read_cr0_bits ( struct kvm_vcpu *  vcpu,
ulong  mask 
)
inlinestatic

Definition at line 151 of file kvm_cache_regs.h.

152 {
153  ulong tmask = mask & KVM_POSSIBLE_CR0_GUEST_BITS;
154  if ((tmask & vcpu->arch.cr0_guest_owned_bits) &&
155  !kvm_register_is_available(vcpu, VCPU_EXREG_CR0))
156  static_call(kvm_x86_cache_reg)(vcpu, VCPU_EXREG_CR0);
157  return vcpu->arch.cr0 & mask;
158 }
#define KVM_POSSIBLE_CR0_GUEST_BITS
Definition: kvm_cache_regs.h:7
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_read_cr3()

static ulong kvm_read_cr3 ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 190 of file kvm_cache_regs.h.

191 {
192  if (!kvm_register_is_available(vcpu, VCPU_EXREG_CR3))
193  static_call(kvm_x86_cache_reg)(vcpu, VCPU_EXREG_CR3);
194  return vcpu->arch.cr3;
195 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_read_cr4()

static ulong kvm_read_cr4 ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 197 of file kvm_cache_regs.h.

198 {
199  return kvm_read_cr4_bits(vcpu, ~0UL);
200 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_read_cr4_bits()

static ulong kvm_read_cr4_bits ( struct kvm_vcpu *  vcpu,
ulong  mask 
)
inlinestatic

Definition at line 173 of file kvm_cache_regs.h.

174 {
175  ulong tmask = mask & KVM_POSSIBLE_CR4_GUEST_BITS;
176  if ((tmask & vcpu->arch.cr4_guest_owned_bits) &&
177  !kvm_register_is_available(vcpu, VCPU_EXREG_CR4))
178  static_call(kvm_x86_cache_reg)(vcpu, VCPU_EXREG_CR4);
179  return vcpu->arch.cr4 & mask;
180 }
#define KVM_POSSIBLE_CR4_GUEST_BITS
Definition: kvm_cache_regs.h:8
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_read_edx_eax()

static u64 kvm_read_edx_eax ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 202 of file kvm_cache_regs.h.

203 {
204  return (kvm_rax_read(vcpu) & -1u)
205  | ((u64)(kvm_rdx_read(vcpu) & -1u) << 32);
206 }
Here is the caller graph for this function:

◆ kvm_register_is_available()

static bool kvm_register_is_available ( struct kvm_vcpu *  vcpu,
enum kvm_reg  reg 
)
inlinestatic

Definition at line 53 of file kvm_cache_regs.h.

55 {
56  return test_bit(reg, (unsigned long *)&vcpu->arch.regs_avail);
57 }
Here is the caller graph for this function:

◆ kvm_register_is_dirty()

static bool kvm_register_is_dirty ( struct kvm_vcpu *  vcpu,
enum kvm_reg  reg 
)
inlinestatic

Definition at line 59 of file kvm_cache_regs.h.

61 {
62  return test_bit(reg, (unsigned long *)&vcpu->arch.regs_dirty);
63 }
Here is the caller graph for this function:

◆ kvm_register_mark_available()

static void kvm_register_mark_available ( struct kvm_vcpu *  vcpu,
enum kvm_reg  reg 
)
inlinestatic

Definition at line 65 of file kvm_cache_regs.h.

67 {
68  __set_bit(reg, (unsigned long *)&vcpu->arch.regs_avail);
69 }
Here is the caller graph for this function:

◆ kvm_register_mark_dirty()

static void kvm_register_mark_dirty ( struct kvm_vcpu *  vcpu,
enum kvm_reg  reg 
)
inlinestatic

Definition at line 71 of file kvm_cache_regs.h.

73 {
74  __set_bit(reg, (unsigned long *)&vcpu->arch.regs_avail);
75  __set_bit(reg, (unsigned long *)&vcpu->arch.regs_dirty);
76 }
Here is the caller graph for this function:

◆ kvm_register_read_raw()

static unsigned long kvm_register_read_raw ( struct kvm_vcpu *  vcpu,
int  reg 
)
inlinestatic

Definition at line 95 of file kvm_cache_regs.h.

96 {
97  if (WARN_ON_ONCE((unsigned int)reg >= NR_VCPU_REGS))
98  return 0;
99 
100  if (!kvm_register_is_available(vcpu, reg))
101  static_call(kvm_x86_cache_reg)(vcpu, reg);
102 
103  return vcpu->arch.regs[reg];
104 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_register_test_and_mark_available()

static __always_inline bool kvm_register_test_and_mark_available ( struct kvm_vcpu *  vcpu,
enum kvm_reg  reg 
)
static

Definition at line 84 of file kvm_cache_regs.h.

86 {
87  return arch___test_and_set_bit(reg, (unsigned long *)&vcpu->arch.regs_avail);
88 }
Here is the caller graph for this function:

◆ kvm_register_write_raw()

static void kvm_register_write_raw ( struct kvm_vcpu *  vcpu,
int  reg,
unsigned long  val 
)
inlinestatic

Definition at line 106 of file kvm_cache_regs.h.

108 {
109  if (WARN_ON_ONCE((unsigned int)reg >= NR_VCPU_REGS))
110  return;
111 
112  vcpu->arch.regs[reg] = val;
113  kvm_register_mark_dirty(vcpu, reg);
114 }
static void kvm_register_mark_dirty(struct kvm_vcpu *vcpu, enum kvm_reg reg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_rip_read()

static unsigned long kvm_rip_read ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 116 of file kvm_cache_regs.h.

117 {
118  return kvm_register_read_raw(vcpu, VCPU_REGS_RIP);
119 }
static unsigned long kvm_register_read_raw(struct kvm_vcpu *vcpu, int reg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_rip_write()

static void kvm_rip_write ( struct kvm_vcpu *  vcpu,
unsigned long  val 
)
inlinestatic

Definition at line 121 of file kvm_cache_regs.h.

122 {
123  kvm_register_write_raw(vcpu, VCPU_REGS_RIP, val);
124 }
static void kvm_register_write_raw(struct kvm_vcpu *vcpu, int reg, unsigned long val)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_rsp_read()

static unsigned long kvm_rsp_read ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 126 of file kvm_cache_regs.h.

127 {
128  return kvm_register_read_raw(vcpu, VCPU_REGS_RSP);
129 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_rsp_write()

static void kvm_rsp_write ( struct kvm_vcpu *  vcpu,
unsigned long  val 
)
inlinestatic

Definition at line 131 of file kvm_cache_regs.h.

132 {
133  kvm_register_write_raw(vcpu, VCPU_REGS_RSP, val);
134 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ leave_guest_mode()

static void leave_guest_mode ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 214 of file kvm_cache_regs.h.

215 {
216  vcpu->arch.hflags &= ~HF_GUEST_MASK;
217 
218  if (vcpu->arch.load_eoi_exitmap_pending) {
219  vcpu->arch.load_eoi_exitmap_pending = false;
220  kvm_make_request(KVM_REQ_LOAD_EOI_EXITMAP, vcpu);
221  }
222 
223  vcpu->stat.guest_mode = 0;
224 }
Here is the caller graph for this function: