From: "Borislav Petkov (AMD)" <bp@alien8.de>
Prefix it properly so that it is clear which generation it is dealing
with.
No functional changes.
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
---
arch/x86/kernel/cpu/amd.c | 70 +++++++++++++++++----------------------
1 file changed, 30 insertions(+), 40 deletions(-)
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 8d90f5f6b0d9..7cbb108afaf4 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -70,12 +70,6 @@ static const int amd_erratum_383[] =
static const int amd_erratum_1054[] =
AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x17, 0, 0, 0x2f, 0xf));
-static const int amd_zenbleed[] =
- AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x17, 0x30, 0x0, 0x4f, 0xf),
- AMD_MODEL_RANGE(0x17, 0x60, 0x0, 0x7f, 0xf),
- AMD_MODEL_RANGE(0x17, 0x90, 0x0, 0x91, 0xf),
- AMD_MODEL_RANGE(0x17, 0xa0, 0x0, 0xaf, 0xf));
-
static const int amd_div0[] =
AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x17, 0x00, 0x0, 0x2f, 0xf),
AMD_MODEL_RANGE(0x17, 0x50, 0x0, 0x5f, 0xf));
@@ -1039,33 +1033,6 @@ static void init_amd_zen(struct cpuinfo_x86 *c)
}
-static void init_amd_zen2(struct cpuinfo_x86 *c)
-{
- init_amd_zen_common();
- init_spectral_chicken(c);
- fix_erratum_1386(c);
-}
-
-static void init_amd_zen3(struct cpuinfo_x86 *c)
-{
- init_amd_zen_common();
-
- if (!cpu_has(c, X86_FEATURE_HYPERVISOR)) {
- /*
- * Zen3 (Fam19 model < 0x10) parts are not susceptible to
- * Branch Type Confusion, but predate the allocation of the
- * BTC_NO bit.
- */
- if (!cpu_has(c, X86_FEATURE_BTC_NO))
- set_cpu_cap(c, X86_FEATURE_BTC_NO);
- }
-}
-
-static void init_amd_zen4(struct cpuinfo_x86 *c)
-{
- init_amd_zen_common();
-}
-
static bool cpu_has_zenbleed_microcode(void)
{
u32 good_rev = 0;
@@ -1087,11 +1054,8 @@ static bool cpu_has_zenbleed_microcode(void)
return true;
}
-static void zenbleed_check(struct cpuinfo_x86 *c)
+static void zen2_zenbleed_check(struct cpuinfo_x86 *c)
{
- if (!cpu_has_amd_erratum(c, amd_zenbleed))
- return;
-
if (cpu_has(c, X86_FEATURE_HYPERVISOR))
return;
@@ -1106,6 +1070,34 @@ static void zenbleed_check(struct cpuinfo_x86 *c)
}
}
+static void init_amd_zen2(struct cpuinfo_x86 *c)
+{
+ init_amd_zen_common();
+ init_spectral_chicken(c);
+ fix_erratum_1386(c);
+ zen2_zenbleed_check(c);
+}
+
+static void init_amd_zen3(struct cpuinfo_x86 *c)
+{
+ init_amd_zen_common();
+
+ if (!cpu_has(c, X86_FEATURE_HYPERVISOR)) {
+ /*
+ * Zen3 (Fam19 model < 0x10) parts are not susceptible to
+ * Branch Type Confusion, but predate the allocation of the
+ * BTC_NO bit.
+ */
+ if (!cpu_has(c, X86_FEATURE_BTC_NO))
+ set_cpu_cap(c, X86_FEATURE_BTC_NO);
+ }
+}
+
+static void init_amd_zen4(struct cpuinfo_x86 *c)
+{
+ init_amd_zen_common();
+}
+
static void init_amd(struct cpuinfo_x86 *c)
{
u64 vm_cr;
@@ -1227,8 +1219,6 @@ static void init_amd(struct cpuinfo_x86 *c)
cpu_has(c, X86_FEATURE_AUTOIBRS))
WARN_ON_ONCE(msr_set_bit(MSR_EFER, _EFER_AUTOIBRS));
- zenbleed_check(c);
-
if (cpu_has_amd_erratum(c, amd_div0)) {
pr_notice_once("AMD Zen1 DIV0 bug detected. Disable SMT for full protection.\n");
setup_force_cpu_bug(X86_BUG_DIV0);
@@ -1390,7 +1380,7 @@ static void zenbleed_check_cpu(void *unused)
{
struct cpuinfo_x86 *c = &cpu_data(smp_processor_id());
- zenbleed_check(c);
+ zen2_zenbleed_check(c);
}
void amd_check_microcode(void)
--
2.42.0.rc0.25.ga82fb66fed25
On 20.11.23 г. 12:41 ч., Borislav Petkov wrote:
> From: "Borislav Petkov (AMD)" <bp@alien8.de>
>
> Prefix it properly so that it is clear which generation it is dealing
> with.
>
> No functional changes.
>
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
> ---
> arch/x86/kernel/cpu/amd.c | 70 +++++++++++++++++----------------------
> 1 file changed, 30 insertions(+), 40 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
> index 8d90f5f6b0d9..7cbb108afaf4 100644
> --- a/arch/x86/kernel/cpu/amd.c
> +++ b/arch/x86/kernel/cpu/amd.c
> @@ -70,12 +70,6 @@ static const int amd_erratum_383[] =
> static const int amd_erratum_1054[] =
> AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x17, 0, 0, 0x2f, 0xf));
>
> -static const int amd_zenbleed[] =
> - AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x17, 0x30, 0x0, 0x4f, 0xf),
> - AMD_MODEL_RANGE(0x17, 0x60, 0x0, 0x7f, 0xf),
> - AMD_MODEL_RANGE(0x17, 0x90, 0x0, 0x91, 0xf),
> - AMD_MODEL_RANGE(0x17, 0xa0, 0x0, 0xaf, 0xf));
> -
> static const int amd_div0[] =
> AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x17, 0x00, 0x0, 0x2f, 0xf),
> AMD_MODEL_RANGE(0x17, 0x50, 0x0, 0x5f, 0xf));
> @@ -1039,33 +1033,6 @@ static void init_amd_zen(struct cpuinfo_x86 *c)
>
> }
>
> -static void init_amd_zen2(struct cpuinfo_x86 *c)
> -{
> - init_amd_zen_common();
> - init_spectral_chicken(c);
> - fix_erratum_1386(c);
> -}
> -
> -static void init_amd_zen3(struct cpuinfo_x86 *c)
> -{
> - init_amd_zen_common();
> -
> - if (!cpu_has(c, X86_FEATURE_HYPERVISOR)) {
> - /*
> - * Zen3 (Fam19 model < 0x10) parts are not susceptible to
> - * Branch Type Confusion, but predate the allocation of the
> - * BTC_NO bit.
> - */
> - if (!cpu_has(c, X86_FEATURE_BTC_NO))
> - set_cpu_cap(c, X86_FEATURE_BTC_NO);
> - }
> -}
> -
> -static void init_amd_zen4(struct cpuinfo_x86 *c)
> -{
> - init_amd_zen_common();
> -}
nit: If you initially introduced the zen-specific functions right after
zenbleed_check you would have avoided the function move in this patch
which would have reduced the overall diff.
<snip>
On Mon, Nov 20, 2023 at 02:53:54PM +0200, Nikolay Borisov wrote:
> nit: If you initially introduced the zen-specific functions right after
> zenbleed_check you would have avoided the function move in this patch which
> would have reduced the overall diff.
Yap, done, good point.
And thanks for the review.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: f69759be251dce722942594fbc62e53a40822a82
Gitweb: https://git.kernel.org/tip/f69759be251dce722942594fbc62e53a40822a82
Author: Borislav Petkov (AMD) <bp@alien8.de>
AuthorDate: Wed, 01 Nov 2023 12:38:35 +01:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Wed, 29 Nov 2023 12:12:34 +01:00
x86/CPU/AMD: Move Zenbleed check to the Zen2 init function
Prefix it properly so that it is clear which generation it is dealing
with.
No functional changes.
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: http://lore.kernel.org/r/20231120104152.13740-8-bp@alien8.de
---
arch/x86/kernel/cpu/amd.c | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index f53e0a2..3c3b4c1 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -70,12 +70,6 @@ static const int amd_erratum_383[] =
static const int amd_erratum_1054[] =
AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x17, 0, 0, 0x2f, 0xf));
-static const int amd_zenbleed[] =
- AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x17, 0x30, 0x0, 0x4f, 0xf),
- AMD_MODEL_RANGE(0x17, 0x60, 0x0, 0x7f, 0xf),
- AMD_MODEL_RANGE(0x17, 0x90, 0x0, 0x91, 0xf),
- AMD_MODEL_RANGE(0x17, 0xa0, 0x0, 0xaf, 0xf));
-
static const int amd_div0[] =
AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x17, 0x00, 0x0, 0x2f, 0xf),
AMD_MODEL_RANGE(0x17, 0x50, 0x0, 0x5f, 0xf));
@@ -1059,11 +1053,8 @@ static bool cpu_has_zenbleed_microcode(void)
return true;
}
-static void zenbleed_check(struct cpuinfo_x86 *c)
+static void zen2_zenbleed_check(struct cpuinfo_x86 *c)
{
- if (!cpu_has_amd_erratum(c, amd_zenbleed))
- return;
-
if (cpu_has(c, X86_FEATURE_HYPERVISOR))
return;
@@ -1084,6 +1075,7 @@ static void init_amd_zen2(struct cpuinfo_x86 *c)
init_amd_zen_common();
init_spectral_chicken(c);
fix_erratum_1386(c);
+ zen2_zenbleed_check(c);
}
static void init_amd_zen3(struct cpuinfo_x86 *c)
@@ -1227,8 +1219,6 @@ static void init_amd(struct cpuinfo_x86 *c)
cpu_has(c, X86_FEATURE_AUTOIBRS))
WARN_ON_ONCE(msr_set_bit(MSR_EFER, _EFER_AUTOIBRS));
- zenbleed_check(c);
-
if (cpu_has_amd_erratum(c, amd_div0)) {
pr_notice_once("AMD Zen1 DIV0 bug detected. Disable SMT for full protection.\n");
setup_force_cpu_bug(X86_BUG_DIV0);
@@ -1393,7 +1383,7 @@ static void zenbleed_check_cpu(void *unused)
{
struct cpuinfo_x86 *c = &cpu_data(smp_processor_id());
- zenbleed_check(c);
+ zen2_zenbleed_check(c);
}
void amd_check_microcode(void)
© 2016 - 2025 Red Hat, Inc.