Skip to content

Commit 08f253e

Browse files
superm1suryasaimadhu
authored andcommitted
x86/cpu: Clear SME feature flag when not in use
Currently, the SME CPU feature flag is reflective of whether the CPU supports the feature but not whether it has been activated by the kernel. Change this around to clear the SME feature flag if the kernel is not using it so userspace can determine if it is available and in use from /proc/cpuinfo. As the feature flag is cleared on systems where SME isn't active, use CPUID 0x8000001f to confirm SME availability before calling native_wbinvd(). Signed-off-by: Mario Limonciello <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Tom Lendacky <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fa31a4d commit 08f253e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

arch/x86/kernel/cpu/amd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,8 @@ static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
556556
* the SME physical address space reduction value.
557557
* If BIOS has not enabled SME then don't advertise the
558558
* SME feature (set in scattered.c).
559+
* If the kernel has not enabled SME via any means then
560+
* don't advertise the SME feature.
559561
* For SEV: If BIOS has not enabled SEV then don't advertise the
560562
* SEV and SEV_ES feature (set in scattered.c).
561563
*
@@ -578,6 +580,9 @@ static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
578580
if (IS_ENABLED(CONFIG_X86_32))
579581
goto clear_all;
580582

583+
if (!sme_me_mask)
584+
setup_clear_cpu_cap(X86_FEATURE_SME);
585+
581586
rdmsrl(MSR_K7_HWCR, msr);
582587
if (!(msr & MSR_K7_HWCR_SMMLOCK))
583588
goto clear_sev;

arch/x86/kernel/process.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,11 @@ void stop_this_cpu(void *dummy)
765765
* without the encryption bit, they don't race each other when flushed
766766
* and potentially end up with the wrong entry being committed to
767767
* memory.
768+
*
769+
* Test the CPUID bit directly because the machine might've cleared
770+
* X86_FEATURE_SME due to cmdline options.
768771
*/
769-
if (boot_cpu_has(X86_FEATURE_SME))
772+
if (cpuid_eax(0x8000001f) & BIT(0))
770773
native_wbinvd();
771774
for (;;) {
772775
/*

0 commit comments

Comments
 (0)