x86/cpu: Clear SME feature flag when not in use
authorMario Limonciello <mario.limonciello@amd.com>
Wed, 16 Feb 2022 03:44:46 +0000 (21:44 -0600)
committerBorislav Petkov <bp@suse.de>
Wed, 16 Feb 2022 18:45:53 +0000 (19:45 +0100)
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 <mario.limonciello@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Link: https://lore.kernel.org/r/20220216034446.2430634-1-mario.limonciello@amd.com
arch/x86/kernel/cpu/amd.c
arch/x86/kernel/process.c

index bad0fa4c17799741ad530e0e7b91a53eb62ae617..0c0b09796ced30153adbaf5cee1c686ba6063201 100644 (file)
@@ -556,6 +556,8 @@ static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
         *            the SME physical address space reduction value.
         *            If BIOS has not enabled SME then don't advertise the
         *            SME feature (set in scattered.c).
+        *            If the kernel has not enabled SME via any means then
+        *            don't advertise the SME feature.
         *   For SEV: If BIOS has not enabled SEV then don't advertise the
         *            SEV and SEV_ES feature (set in scattered.c).
         *
@@ -578,6 +580,9 @@ static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
                if (IS_ENABLED(CONFIG_X86_32))
                        goto clear_all;
 
+               if (!sme_me_mask)
+                       setup_clear_cpu_cap(X86_FEATURE_SME);
+
                rdmsrl(MSR_K7_HWCR, msr);
                if (!(msr & MSR_K7_HWCR_SMMLOCK))
                        goto clear_sev;
index 81d8ef036637c08dfe56391131f446b59659fb04..e131d71b3cae9a0a48800c3f4368aa4236d2d892 100644 (file)
@@ -765,8 +765,11 @@ void stop_this_cpu(void *dummy)
         * without the encryption bit, they don't race each other when flushed
         * and potentially end up with the wrong entry being committed to
         * memory.
+        *
+        * Test the CPUID bit directly because the machine might've cleared
+        * X86_FEATURE_SME due to cmdline options.
         */
-       if (boot_cpu_has(X86_FEATURE_SME))
+       if (cpuid_eax(0x8000001f) & BIT(0))
                native_wbinvd();
        for (;;) {
                /*