Skip to content

Commit 70e37ed

Browse files
miczyg1SergiiDmytruk
authored andcommitted
x86/cpu: report SMX, TXT and SKINIT capabilities
Report TXT capabilities so that dom0 can query the Intel TXT or AMD SKINIT support information using xl dmesg. Signed-off-by: Michał Żygowski <[email protected]> Signed-off-by: Sergii Dmytruk <[email protected]>
1 parent e37ec26 commit 70e37ed

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

xen/arch/x86/cpu/amd.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,19 @@ void amd_log_freq(const struct cpuinfo_x86 *c)
671671
#undef FREQ
672672
}
673673

674+
void amd_log_skinit(const struct cpuinfo_x86 *c)
675+
{
676+
/* Run only on BSP to report the capability only once */
677+
if ( smp_processor_id() )
678+
return;
679+
680+
printk("CPU: SKINIT capability ");
681+
if ( !test_bit(X86_FEATURE_SKINIT, &boot_cpu_data.x86_capability) )
682+
printk("not supported\n");
683+
else
684+
printk("supported\n");
685+
}
686+
674687
void cf_check early_init_amd(struct cpuinfo_x86 *c)
675688
{
676689
if (c == &boot_cpu_data)
@@ -1320,6 +1333,7 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)
13201333
check_syscfg_dram_mod_en();
13211334

13221335
amd_log_freq(c);
1336+
amd_log_skinit(c);
13231337
}
13241338

13251339
const struct cpu_dev __initconst_cf_clobber amd_cpu_dev = {

xen/arch/x86/cpu/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern bool detect_extended_topology(struct cpuinfo_x86 *c);
2020

2121
void cf_check early_init_amd(struct cpuinfo_x86 *c);
2222
void amd_log_freq(const struct cpuinfo_x86 *c);
23+
void amd_log_skinit(const struct cpuinfo_x86 *c);
2324
void amd_init_lfence(struct cpuinfo_x86 *c);
2425
void amd_init_ssbd(const struct cpuinfo_x86 *c);
2526
void amd_init_spectral_chicken(void);

xen/arch/x86/cpu/hygon.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static void cf_check init_hygon(struct cpuinfo_x86 *c)
8585
}
8686

8787
amd_log_freq(c);
88+
amd_log_skinit(c);
8889
}
8990

9091
const struct cpu_dev __initconst_cf_clobber hygon_cpu_dev = {

xen/arch/x86/cpu/intel.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <asm/apic.h>
1414
#include <asm/i387.h>
1515
#include <asm/trampoline.h>
16+
#include <asm/intel_txt.h>
1617

1718
#include "cpu.h"
1819

@@ -571,6 +572,47 @@ static void init_intel_perf(struct cpuinfo_x86 *c)
571572
}
572573
}
573574

575+
/*
576+
* Print out the SMX and TXT capabilties, so that dom0 can determine if the
577+
* system is DRTM-capable.
578+
*/
579+
static void intel_log_smx_txt(struct cpuinfo_x86 *c)
580+
{
581+
unsigned long cr4_val, getsec_caps;
582+
583+
/* Run only on BSP to report the SMX/TXT caps only once */
584+
if ( smp_processor_id() )
585+
return;
586+
587+
printk("CPU: SMX capability ");
588+
if ( !test_bit(X86_FEATURE_SMX, &boot_cpu_data.x86_capability) )
589+
{
590+
printk("not supported\n");
591+
return;
592+
}
593+
printk("supported\n");
594+
595+
/* Can't run GETSEC without VMX and SMX */
596+
if ( !test_bit(X86_FEATURE_VMX, &boot_cpu_data.x86_capability) )
597+
return;
598+
599+
cr4_val = read_cr4();
600+
if ( !(cr4_val & X86_CR4_SMXE) )
601+
write_cr4(cr4_val | X86_CR4_SMXE);
602+
603+
asm volatile ("getsec\n"
604+
: "=a" (getsec_caps)
605+
: "a" (GETSEC_CAPABILITIES), "b" (0) :);
606+
607+
if ( getsec_caps & GETSEC_CAP_TXT_CHIPSET )
608+
printk("Chipset supports TXT\n");
609+
else
610+
printk("Chipset does not support TXT\n");
611+
612+
if ( !(cr4_val & X86_CR4_SMXE) )
613+
write_cr4(cr4_val & ~X86_CR4_SMXE);
614+
}
615+
574616
static void cf_check init_intel(struct cpuinfo_x86 *c)
575617
{
576618
/* Detect the extended topology information if available */
@@ -585,6 +627,8 @@ static void cf_check init_intel(struct cpuinfo_x86 *c)
585627
detect_ht(c);
586628
}
587629

630+
intel_log_smx_txt(c);
631+
588632
/* Work around errata */
589633
Intel_errata_workarounds(c);
590634

xen/arch/x86/include/asm/intel_txt.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
#define TXT_AP_BOOT_CS 0x0030
8383
#define TXT_AP_BOOT_DS 0x0038
8484

85+
/* EAX value for GETSEC leaf functions. Intel SDM: GETSEC[CAPABILITIES] */
86+
#define GETSEC_CAPABILITIES 0
87+
/* Intel SDM: GETSEC Capability Result Encoding */
88+
#define GETSEC_CAP_TXT_CHIPSET 1
89+
8590
#ifndef __ASSEMBLY__
8691

8792
#include <xen/slr_table.h>

0 commit comments

Comments
 (0)