KVM
Classes | Macros | Enumerations | Functions | Variables
reverse_cpuid.h File Reference
#include <uapi/asm/kvm.h>
#include <asm/cpufeature.h>
#include <asm/cpufeatures.h>
Include dependency graph for reverse_cpuid.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cpuid_reg
 

Macros

#define KVM_X86_FEATURE(w, f)   ((w)*32 + (f))
 
#define KVM_X86_FEATURE_SGX1   KVM_X86_FEATURE(CPUID_12_EAX, 0)
 
#define KVM_X86_FEATURE_SGX2   KVM_X86_FEATURE(CPUID_12_EAX, 1)
 
#define KVM_X86_FEATURE_SGX_EDECCSSA   KVM_X86_FEATURE(CPUID_12_EAX, 11)
 
#define X86_FEATURE_AVX_VNNI_INT8   KVM_X86_FEATURE(CPUID_7_1_EDX, 4)
 
#define X86_FEATURE_AVX_NE_CONVERT   KVM_X86_FEATURE(CPUID_7_1_EDX, 5)
 
#define X86_FEATURE_AMX_COMPLEX   KVM_X86_FEATURE(CPUID_7_1_EDX, 8)
 
#define X86_FEATURE_PREFETCHITI   KVM_X86_FEATURE(CPUID_7_1_EDX, 14)
 
#define X86_FEATURE_INTEL_PSFD   KVM_X86_FEATURE(CPUID_7_2_EDX, 0)
 
#define X86_FEATURE_IPRED_CTRL   KVM_X86_FEATURE(CPUID_7_2_EDX, 1)
 
#define KVM_X86_FEATURE_RRSBA_CTRL   KVM_X86_FEATURE(CPUID_7_2_EDX, 2)
 
#define X86_FEATURE_DDPD_U   KVM_X86_FEATURE(CPUID_7_2_EDX, 3)
 
#define KVM_X86_FEATURE_BHI_CTRL   KVM_X86_FEATURE(CPUID_7_2_EDX, 4)
 
#define X86_FEATURE_MCDT_NO   KVM_X86_FEATURE(CPUID_7_2_EDX, 5)
 
#define KVM_X86_FEATURE_CONSTANT_TSC   KVM_X86_FEATURE(CPUID_8000_0007_EDX, 8)
 
#define KVM_X86_FEATURE_PERFMON_V2   KVM_X86_FEATURE(CPUID_8000_0022_EAX, 0)
 
#define KVM_X86_TRANSLATE_FEATURE(f)    case X86_FEATURE_##f: return KVM_X86_FEATURE_##f
 
#define feature_bit(name)   __feature_bit(X86_FEATURE_##name)
 

Enumerations

enum  kvm_only_cpuid_leafs {
  CPUID_12_EAX = NCAPINTS , CPUID_7_1_EDX , CPUID_8000_0007_EDX , CPUID_8000_0022_EAX ,
  CPUID_7_2_EDX , NR_KVM_CPU_CAPS , NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS
}
 

Functions

static __always_inline void reverse_cpuid_check (unsigned int x86_leaf)
 
static __always_inline u32 __feature_translate (int x86_feature)
 
static __always_inline u32 __feature_leaf (int x86_feature)
 
static __always_inline u32 __feature_bit (int x86_feature)
 
static __always_inline struct cpuid_reg x86_feature_cpuid (unsigned int x86_feature)
 
static __always_inline u32 * __cpuid_entry_get_reg (struct kvm_cpuid_entry2 *entry, u32 reg)
 
static __always_inline u32 * cpuid_entry_get_reg (struct kvm_cpuid_entry2 *entry, unsigned int x86_feature)
 
static __always_inline u32 cpuid_entry_get (struct kvm_cpuid_entry2 *entry, unsigned int x86_feature)
 
static __always_inline bool cpuid_entry_has (struct kvm_cpuid_entry2 *entry, unsigned int x86_feature)
 
static __always_inline void cpuid_entry_clear (struct kvm_cpuid_entry2 *entry, unsigned int x86_feature)
 
static __always_inline void cpuid_entry_set (struct kvm_cpuid_entry2 *entry, unsigned int x86_feature)
 
static __always_inline void cpuid_entry_change (struct kvm_cpuid_entry2 *entry, unsigned int x86_feature, bool set)
 

Variables

static const struct cpuid_reg reverse_cpuid []
 

Macro Definition Documentation

◆ feature_bit

#define feature_bit (   name)    __feature_bit(X86_FEATURE_##name)

Definition at line 156 of file reverse_cpuid.h.

◆ KVM_X86_FEATURE

#define KVM_X86_FEATURE (   w,
 
)    ((w)*32 + (f))

Definition at line 37 of file reverse_cpuid.h.

◆ KVM_X86_FEATURE_BHI_CTRL

#define KVM_X86_FEATURE_BHI_CTRL   KVM_X86_FEATURE(CPUID_7_2_EDX, 4)

Definition at line 55 of file reverse_cpuid.h.

◆ KVM_X86_FEATURE_CONSTANT_TSC

#define KVM_X86_FEATURE_CONSTANT_TSC   KVM_X86_FEATURE(CPUID_8000_0007_EDX, 8)

Definition at line 59 of file reverse_cpuid.h.

◆ KVM_X86_FEATURE_PERFMON_V2

#define KVM_X86_FEATURE_PERFMON_V2   KVM_X86_FEATURE(CPUID_8000_0022_EAX, 0)

Definition at line 62 of file reverse_cpuid.h.

◆ KVM_X86_FEATURE_RRSBA_CTRL

#define KVM_X86_FEATURE_RRSBA_CTRL   KVM_X86_FEATURE(CPUID_7_2_EDX, 2)

Definition at line 53 of file reverse_cpuid.h.

◆ KVM_X86_FEATURE_SGX1

#define KVM_X86_FEATURE_SGX1   KVM_X86_FEATURE(CPUID_12_EAX, 0)

Definition at line 40 of file reverse_cpuid.h.

◆ KVM_X86_FEATURE_SGX2

#define KVM_X86_FEATURE_SGX2   KVM_X86_FEATURE(CPUID_12_EAX, 1)

Definition at line 41 of file reverse_cpuid.h.

◆ KVM_X86_FEATURE_SGX_EDECCSSA

#define KVM_X86_FEATURE_SGX_EDECCSSA   KVM_X86_FEATURE(CPUID_12_EAX, 11)

Definition at line 42 of file reverse_cpuid.h.

◆ KVM_X86_TRANSLATE_FEATURE

#define KVM_X86_TRANSLATE_FEATURE (   f)     case X86_FEATURE_##f: return KVM_X86_FEATURE_##f

◆ X86_FEATURE_AMX_COMPLEX

#define X86_FEATURE_AMX_COMPLEX   KVM_X86_FEATURE(CPUID_7_1_EDX, 8)

Definition at line 47 of file reverse_cpuid.h.

◆ X86_FEATURE_AVX_NE_CONVERT

#define X86_FEATURE_AVX_NE_CONVERT   KVM_X86_FEATURE(CPUID_7_1_EDX, 5)

Definition at line 46 of file reverse_cpuid.h.

◆ X86_FEATURE_AVX_VNNI_INT8

#define X86_FEATURE_AVX_VNNI_INT8   KVM_X86_FEATURE(CPUID_7_1_EDX, 4)

Definition at line 45 of file reverse_cpuid.h.

◆ X86_FEATURE_DDPD_U

#define X86_FEATURE_DDPD_U   KVM_X86_FEATURE(CPUID_7_2_EDX, 3)

Definition at line 54 of file reverse_cpuid.h.

◆ X86_FEATURE_INTEL_PSFD

#define X86_FEATURE_INTEL_PSFD   KVM_X86_FEATURE(CPUID_7_2_EDX, 0)

Definition at line 51 of file reverse_cpuid.h.

◆ X86_FEATURE_IPRED_CTRL

#define X86_FEATURE_IPRED_CTRL   KVM_X86_FEATURE(CPUID_7_2_EDX, 1)

Definition at line 52 of file reverse_cpuid.h.

◆ X86_FEATURE_MCDT_NO

#define X86_FEATURE_MCDT_NO   KVM_X86_FEATURE(CPUID_7_2_EDX, 5)

Definition at line 56 of file reverse_cpuid.h.

◆ X86_FEATURE_PREFETCHITI

#define X86_FEATURE_PREFETCHITI   KVM_X86_FEATURE(CPUID_7_1_EDX, 14)

Definition at line 48 of file reverse_cpuid.h.

Enumeration Type Documentation

◆ kvm_only_cpuid_leafs

Enumerator
CPUID_12_EAX 
CPUID_7_1_EDX 
CPUID_8000_0007_EDX 
CPUID_8000_0022_EAX 
CPUID_7_2_EDX 
NR_KVM_CPU_CAPS 
NKVMCAPINTS 

Definition at line 14 of file reverse_cpuid.h.

14  {
15  CPUID_12_EAX = NCAPINTS,
21 
22  NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS,
23 };
@ CPUID_7_1_EDX
Definition: reverse_cpuid.h:16
@ CPUID_7_2_EDX
Definition: reverse_cpuid.h:19
@ CPUID_8000_0022_EAX
Definition: reverse_cpuid.h:18
@ NR_KVM_CPU_CAPS
Definition: reverse_cpuid.h:20
@ CPUID_12_EAX
Definition: reverse_cpuid.h:15
@ NKVMCAPINTS
Definition: reverse_cpuid.h:22
@ CPUID_8000_0007_EDX
Definition: reverse_cpuid.h:17

Function Documentation

◆ __cpuid_entry_get_reg()

static __always_inline u32* __cpuid_entry_get_reg ( struct kvm_cpuid_entry2 *  entry,
u32  reg 
)
static

Definition at line 166 of file reverse_cpuid.h.

168 {
169  switch (reg) {
170  case CPUID_EAX:
171  return &entry->eax;
172  case CPUID_EBX:
173  return &entry->ebx;
174  case CPUID_ECX:
175  return &entry->ecx;
176  case CPUID_EDX:
177  return &entry->edx;
178  default:
179  BUILD_BUG();
180  return NULL;
181  }
182 }
Here is the caller graph for this function:

◆ __feature_bit()

static __always_inline u32 __feature_bit ( int  x86_feature)
static

Definition at line 148 of file reverse_cpuid.h.

149 {
150  x86_feature = __feature_translate(x86_feature);
151 
152  reverse_cpuid_check(x86_feature / 32);
153  return 1 << (x86_feature & 31);
154 }
static __always_inline u32 __feature_translate(int x86_feature)
static __always_inline void reverse_cpuid_check(unsigned int x86_leaf)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __feature_leaf()

static __always_inline u32 __feature_leaf ( int  x86_feature)
static

Definition at line 137 of file reverse_cpuid.h.

138 {
139  return __feature_translate(x86_feature) / 32;
140 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __feature_translate()

static __always_inline u32 __feature_translate ( int  x86_feature)
static

Definition at line 119 of file reverse_cpuid.h.

120 {
121 #define KVM_X86_TRANSLATE_FEATURE(f) \
122  case X86_FEATURE_##f: return KVM_X86_FEATURE_##f
123 
124  switch (x86_feature) {
127  KVM_X86_TRANSLATE_FEATURE(SGX_EDECCSSA);
128  KVM_X86_TRANSLATE_FEATURE(CONSTANT_TSC);
129  KVM_X86_TRANSLATE_FEATURE(PERFMON_V2);
130  KVM_X86_TRANSLATE_FEATURE(RRSBA_CTRL);
131  KVM_X86_TRANSLATE_FEATURE(BHI_CTRL);
132  default:
133  return x86_feature;
134  }
135 }
#define KVM_X86_TRANSLATE_FEATURE(f)
Here is the caller graph for this function:

◆ cpuid_entry_change()

static __always_inline void cpuid_entry_change ( struct kvm_cpuid_entry2 *  entry,
unsigned int  x86_feature,
bool  set 
)
static

Definition at line 222 of file reverse_cpuid.h.

225 {
226  u32 *reg = cpuid_entry_get_reg(entry, x86_feature);
227 
228  /*
229  * Open coded instead of using cpuid_entry_{clear,set}() to coerce the
230  * compiler into using CMOV instead of Jcc when possible.
231  */
232  if (set)
233  *reg |= __feature_bit(x86_feature);
234  else
235  *reg &= ~__feature_bit(x86_feature);
236 }
static __always_inline u32 * cpuid_entry_get_reg(struct kvm_cpuid_entry2 *entry, unsigned int x86_feature)
static __always_inline u32 __feature_bit(int x86_feature)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpuid_entry_clear()

static __always_inline void cpuid_entry_clear ( struct kvm_cpuid_entry2 *  entry,
unsigned int  x86_feature 
)
static

Definition at line 206 of file reverse_cpuid.h.

208 {
209  u32 *reg = cpuid_entry_get_reg(entry, x86_feature);
210 
211  *reg &= ~__feature_bit(x86_feature);
212 }
Here is the call graph for this function:

◆ cpuid_entry_get()

static __always_inline u32 cpuid_entry_get ( struct kvm_cpuid_entry2 *  entry,
unsigned int  x86_feature 
)
static

Definition at line 192 of file reverse_cpuid.h.

194 {
195  u32 *reg = cpuid_entry_get_reg(entry, x86_feature);
196 
197  return *reg & __feature_bit(x86_feature);
198 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpuid_entry_get_reg()

static __always_inline u32* cpuid_entry_get_reg ( struct kvm_cpuid_entry2 *  entry,
unsigned int  x86_feature 
)
static

Definition at line 184 of file reverse_cpuid.h.

186 {
187  const struct cpuid_reg cpuid = x86_feature_cpuid(x86_feature);
188 
189  return __cpuid_entry_get_reg(entry, cpuid.reg);
190 }
static __always_inline struct cpuid_reg x86_feature_cpuid(unsigned int x86_feature)
static __always_inline u32 * __cpuid_entry_get_reg(struct kvm_cpuid_entry2 *entry, u32 reg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpuid_entry_has()

static __always_inline bool cpuid_entry_has ( struct kvm_cpuid_entry2 *  entry,
unsigned int  x86_feature 
)
static

Definition at line 200 of file reverse_cpuid.h.

202 {
203  return cpuid_entry_get(entry, x86_feature);
204 }
static __always_inline u32 cpuid_entry_get(struct kvm_cpuid_entry2 *entry, unsigned int x86_feature)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpuid_entry_set()

static __always_inline void cpuid_entry_set ( struct kvm_cpuid_entry2 *  entry,
unsigned int  x86_feature 
)
static

Definition at line 214 of file reverse_cpuid.h.

216 {
217  u32 *reg = cpuid_entry_get_reg(entry, x86_feature);
218 
219  *reg |= __feature_bit(x86_feature);
220 }
Here is the call graph for this function:

◆ reverse_cpuid_check()

static __always_inline void reverse_cpuid_check ( unsigned int  x86_leaf)
static

Definition at line 103 of file reverse_cpuid.h.

104 {
105  BUILD_BUG_ON(NR_CPUID_WORDS != NCAPINTS);
106  BUILD_BUG_ON(x86_leaf == CPUID_LNX_1);
107  BUILD_BUG_ON(x86_leaf == CPUID_LNX_2);
108  BUILD_BUG_ON(x86_leaf == CPUID_LNX_3);
109  BUILD_BUG_ON(x86_leaf == CPUID_LNX_4);
110  BUILD_BUG_ON(x86_leaf == CPUID_LNX_5);
111  BUILD_BUG_ON(x86_leaf >= ARRAY_SIZE(reverse_cpuid));
112  BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);
113 }
static const struct cpuid_reg reverse_cpuid[]
Definition: reverse_cpuid.h:70
Here is the caller graph for this function:

◆ x86_feature_cpuid()

static __always_inline struct cpuid_reg x86_feature_cpuid ( unsigned int  x86_feature)
static

Definition at line 158 of file reverse_cpuid.h.

159 {
160  unsigned int x86_leaf = __feature_leaf(x86_feature);
161 
162  reverse_cpuid_check(x86_leaf);
163  return reverse_cpuid[x86_leaf];
164 }
static __always_inline u32 __feature_leaf(int x86_feature)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ reverse_cpuid

const struct cpuid_reg reverse_cpuid[]
static
Initial value:
= {
[CPUID_1_EDX] = { 1, 0, CPUID_EDX},
[CPUID_8000_0001_EDX] = {0x80000001, 0, CPUID_EDX},
[CPUID_8086_0001_EDX] = {0x80860001, 0, CPUID_EDX},
[CPUID_1_ECX] = { 1, 0, CPUID_ECX},
[CPUID_C000_0001_EDX] = {0xc0000001, 0, CPUID_EDX},
[CPUID_8000_0001_ECX] = {0x80000001, 0, CPUID_ECX},
[CPUID_7_0_EBX] = { 7, 0, CPUID_EBX},
[CPUID_D_1_EAX] = { 0xd, 1, CPUID_EAX},
[CPUID_8000_0008_EBX] = {0x80000008, 0, CPUID_EBX},
[CPUID_6_EAX] = { 6, 0, CPUID_EAX},
[CPUID_8000_000A_EDX] = {0x8000000a, 0, CPUID_EDX},
[CPUID_7_ECX] = { 7, 0, CPUID_ECX},
[CPUID_8000_0007_EBX] = {0x80000007, 0, CPUID_EBX},
[CPUID_7_EDX] = { 7, 0, CPUID_EDX},
[CPUID_7_1_EAX] = { 7, 1, CPUID_EAX},
[CPUID_12_EAX] = {0x00000012, 0, CPUID_EAX},
[CPUID_8000_001F_EAX] = {0x8000001f, 0, CPUID_EAX},
[CPUID_7_1_EDX] = { 7, 1, CPUID_EDX},
[CPUID_8000_0007_EDX] = {0x80000007, 0, CPUID_EDX},
[CPUID_8000_0021_EAX] = {0x80000021, 0, CPUID_EAX},
[CPUID_8000_0022_EAX] = {0x80000022, 0, CPUID_EAX},
[CPUID_7_2_EDX] = { 7, 2, CPUID_EDX},
}

Definition at line 1 of file reverse_cpuid.h.