Skip to content

Commit d43d2c9

Browse files
yonghuahlijinxia
authored andcommitted
HV: add CPU capabilities detection for L1TF mitigation
- detect if current processor is affected by L1TF - detect the presence of of "IA32_FLUSH_CMD(MSR 0x10B) if processor is affected by L1TF. Tracked-On: #1672 Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
1 parent 2731628 commit d43d2c9

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ uint64_t pcpu_active_bitmap = 0UL;
3030

3131
/* X2APIC mode is disabled by default. */
3232
bool x2apic_enabled = false;
33+
static bool skip_l1dfl_vmentry;
34+
static uint64_t x86_arch_capabilities;
3335

3436
/* TODO: add more capability per requirement */
3537
/* APICv features */
@@ -418,6 +420,18 @@ void bsp_boot_init(void)
418420

419421
static bool check_cpu_security_config(void)
420422
{
423+
if (cpu_has_cap(X86_FEATURE_ARCH_CAP)) {
424+
x86_arch_capabilities = msr_read(MSR_IA32_ARCH_CAPABILITIES);
425+
skip_l1dfl_vmentry = ((x86_arch_capabilities
426+
& IA32_ARCH_CAP_SKIP_L1DFL_VMENTRY) != 0UL);
427+
} else {
428+
return false;
429+
}
430+
431+
if ((!cpu_has_cap(X86_FEATURE_L1D_FLUSH)) && (!skip_l1dfl_vmentry)) {
432+
return false;
433+
}
434+
421435
if (!cpu_has_cap(X86_FEATURE_IBRS_IBPB) &&
422436
!cpu_has_cap(X86_FEATURE_STIBP)) {
423437
return false;

hypervisor/include/arch/x86/cpufeatures.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
/* Intel-defined CPU features, CPUID level 0x00000007 (EDX)*/
7878
#define X86_FEATURE_IBRS_IBPB ((FEAT_7_0_EDX << 5U) + 26U)
7979
#define X86_FEATURE_STIBP ((FEAT_7_0_EDX << 5U) + 27U)
80+
#define X86_FEATURE_L1D_FLUSH ((FEAT_7_0_EDX << 5U) + 28U)
81+
#define X86_FEATURE_ARCH_CAP ((FEAT_7_0_EDX << 5U) + 29U)
8082

8183
/* Intel-defined CPU features, CPUID level 0x80000001 (EDX)*/
8284
#define X86_FEATURE_NX ((FEAT_8000_0001_EDX << 5U) + 20U)

hypervisor/include/arch/x86/msr.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#define MSR_IA32_APERF 0x000000E8U
4545
/* Actual performance clock counter */
4646
#define MSR_IA32_MTRR_CAP 0x000000FEU /* MTRR capability */
47+
#define MSR_IA32_ARCH_CAPABILITIES 0x0000010AU
48+
#define MSR_IA32_FLUSH_CMD 0x0000010BU
4749
#define MSR_IA32_SYSENTER_CS 0x00000174U /* CS for sysenter */
4850
#define MSR_IA32_SYSENTER_ESP 0x00000175U /* ESP for sysenter */
4951
#define MSR_IA32_SYSENTER_EIP 0x00000176U /* EIP for sysenter */
@@ -567,4 +569,14 @@ static inline bool pat_mem_type_invalid(uint64_t x)
567569
#define SPEC_ENABLE_STIBP (1U<<1U)
568570
#define PRED_SET_IBPB (1U<<0U)
569571

572+
/* IA32 ARCH Capabilities bit */
573+
#define IA32_ARCH_CAP_RDCL_NO (1U << 0U)
574+
#define IA32_ARCH_CAP_IBRS_ALL (1U << 1U)
575+
#define IA32_ARCH_CAP_RSBA (1U << 2U)
576+
#define IA32_ARCH_CAP_SKIP_L1DFL_VMENTRY (1U << 3U)
577+
#define IA32_ARCH_CAP_SSB_NO (1U << 4U)
578+
579+
/* Flush L1 D-cache */
580+
#define IA32_L1D_FLUSH (1UL << 0U)
581+
570582
#endif /* MSR_H */

0 commit comments

Comments
 (0)