Skip to content

Commit 54f0805

Browse files
hanliyangWangYuli
authored andcommitted
x86/cpu: Detect memory encryption features on Hygon CPUs
hygon inclusion category: feature CVE: NA --------------------------- Hygon SME is identified by CPUID 0x8000001f, but requires BIOS support to enable it (set bit 23 of MSR_AMD64_SYSCFG). Hygon CSV and CSV2 are identified by CPUID 0x8000001f, but requires BIOS support to enable it (set bit 23 of MSR_AMD64_SYSCFG and set bit 0 of MSR_K7_HWCR). Only show the SME, CSV, CSV2 features as available if reported by CPUID and enabled by BIOS. Signed-off-by: hanliyang <hanliyang@hygon.cn>
1 parent 8ab045c commit 54f0805

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

arch/x86/kernel/cpu/hygon.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,50 @@ static void bsp_init_hygon(struct cpuinfo_x86 *c)
246246
resctrl_cpu_detect(c);
247247
}
248248

249+
static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
250+
{
251+
u64 msr;
252+
u32 eax;
253+
254+
eax = cpuid_eax(0x8000001f);
255+
256+
/* Check whether SME or CSV is supported */
257+
if (!(eax & (BIT(0) | BIT(1))))
258+
return;
259+
260+
/* If BIOS has not enabled SME then don't advertise the SME feature. */
261+
rdmsrl(MSR_AMD64_SYSCFG, msr);
262+
if (!(msr & MSR_AMD64_SYSCFG_MEM_ENCRYPT))
263+
goto clear_all;
264+
265+
/*
266+
* Always adjust physical address bits. Even though this will be a
267+
* value above 32-bits this is still done for CONFIG_X86_32 so that
268+
* accurate values are reported.
269+
*/
270+
c->x86_phys_bits -= (cpuid_ebx(0x8000001f) >> 6) & 0x3f;
271+
272+
/* Don't advertise SME and CSV features under CONFIG_X86_32. */
273+
if (IS_ENABLED(CONFIG_X86_32))
274+
goto clear_all;
275+
276+
/*
277+
* If BIOS has not enabled CSV then don't advertise the CSV and CSV2
278+
* feature.
279+
*/
280+
rdmsrl(MSR_K7_HWCR, msr);
281+
if (!(msr & MSR_K7_HWCR_SMMLOCK))
282+
goto clear_csv;
283+
284+
return;
285+
286+
clear_all:
287+
setup_clear_cpu_cap(X86_FEATURE_SME);
288+
clear_csv:
289+
setup_clear_cpu_cap(X86_FEATURE_SEV);
290+
setup_clear_cpu_cap(X86_FEATURE_SEV_ES);
291+
}
292+
249293
static void early_init_hygon(struct cpuinfo_x86 *c)
250294
{
251295
u32 dummy;
@@ -294,6 +338,8 @@ static void early_init_hygon(struct cpuinfo_x86 *c)
294338
set_cpu_cap(c, X86_FEATURE_VMMCALL);
295339

296340
hygon_get_topology_early(c);
341+
342+
early_detect_mem_encrypt(c);
297343
}
298344

299345
static void init_hygon(struct cpuinfo_x86 *c)

arch/x86/kernel/cpu/proc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,14 @@ static int show_cpuinfo(struct seq_file *m, void *v)
100100

101101
seq_puts(m, "flags\t\t:");
102102
for (i = 0; i < 32*NCAPINTS; i++)
103-
if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
104-
seq_printf(m, " %s", x86_cap_flags[i]);
103+
if (cpu_has(c, i) && x86_cap_flags[i] != NULL) {
104+
if (c->x86_vendor == X86_VENDOR_HYGON)
105+
seq_printf(m, " %s", i == X86_FEATURE_SEV ? "csv" :
106+
(i == X86_FEATURE_SEV_ES ? "csv2" :
107+
x86_cap_flags[i]));
108+
else
109+
seq_printf(m, " %s", x86_cap_flags[i]);
110+
}
105111

106112
#ifdef CONFIG_X86_VMX_FEATURE_NAMES
107113
if (cpu_has(c, X86_FEATURE_VMX) && c->vmx_capability[0]) {

0 commit comments

Comments
 (0)