x86/cpu: clear SME feature flag when not in use
PATCH v4 1/1 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 is 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.
---
Changes from v3->v4:
* Update block comment to explain SME can get turned off
* Reword commit message
arch/x86/kernel/cpu/amd.c | 5 +++++ arch/x86/kernel/process.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/amd.c +5 -0
@@ -585,6 +585,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). *
@@ -607,6 +609,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;
arch/x86/kernel/process.c +4 -1
@@ -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 (;;) {/*
Signature · 1 line
2.34.1
Borislav Petkov
maintainerarch/x86/kernel/cpu/amd.c static void early_detect_mem_encrypt(struct cpuinfo_x86 *c) · line 613
Quoted 6 lines · Mario Limonciello
arch/x86/kernel/cpu/amd.c +2
-0@@ -607,6 +609,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 );
Why not "goto clear_all;" ?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 10 lines · Borislav Petkov
arch/x86/kernel/cpu/amd.c static void early_detect_mem_encrypt(struct cpuinfo_x86 *c) · line 613
Quoted 6 lines · Mario Limonciello
arch/x86/kernel/cpu/amd.c +2
-0@@ -607,6 +609,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 );Why not "goto
clear_all;" ?
"clear_all" clears SEV and SEV_ES as well which as pointed out in v2 is incorrect.
Quoted 8 lines · Mario Limonciello
Currently the SME CPU feature flag is reflective of whether the CPU supports the feature but not whether is 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.
Quoted 5 lines
As the feature flag is cleared on systems where SME isn't active use CPUID
0x8000001fto confirm SME availability before callingnative_wbinvd.Signed-off-by Mario Limonciello <[email protected]>
Quoted 1 line
---
[tip: x86/cpu] x86/cpu: Clear SME feature flag when not in use
In reply to Mario LimoncielloThe following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 08f253ec3767bcfafc5d32617a92cee57c63968e Gitweb: https://git.kernel.org/tip/08f253ec3767bcfafc5d32617a92cee57c63968e Author: Mario Limonciello <[email protected]> AuthorDate: Tue, 15 Feb 2022 21:44:46 -06:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Wed, 16 Feb 2022 19:45:53 +01:00
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().
--- arch/x86/kernel/cpu/amd.c | 5 +++++ arch/x86/kernel/process.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/amd.c +5 -0
@@ -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;
arch/x86/kernel/process.c +4 -1
@@ -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 (;;) {/*