From: Borislav Petkov <bp@alien8.de>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Jiri Olsa <jolsa@redhat.com>, X86 ML <x86@kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/5] x86/bugs: Separate AMD E400 erratum and C1E bug
Date: Fri, 9 Dec 2016 19:29:09 +0100 [thread overview]
Message-ID: <20161209182912.2726-3-bp@alien8.de> (raw)
In-Reply-To: <20161209182912.2726-1-bp@alien8.de>
From: Thomas Gleixner <tglx@linutronix.de>
We need two bits of information in order to properly apply the Erratum
400 workaround:
1. X86_BUG_AMD_E400 - to be able to select the proper idle routine
2. X86_BUG_AMD_APIC_C1E - to actually note that the platform we're currently
running on is actually affected by E400.
I say "actually affected" because the bug manifests itself in LAPIC
timer stopping in C1E. But the mere decision whether the platform enters
C1E is made by the firmware. Thus the dancing through hoops we're doing
with this series.
IOW, if the platform firmware decides *not* to enable C1E, we're not
affected even if the CPU f/m/s is among the affected ones - we just
don't enter C1E.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
---
arch/x86/include/asm/cpufeatures.h | 2 ++
arch/x86/kernel/cpu/amd.c | 20 +++++++++++++-------
arch/x86/kernel/process.c | 3 +--
3 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 53e27a12ceb6..eafee3161d1c 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -319,4 +319,6 @@
#define X86_BUG_NULL_SEG X86_BUG(10) /* Nulling a selector preserves the base */
#define X86_BUG_SWAPGS_FENCE X86_BUG(11) /* SWAPGS without input dep on GS */
#define X86_BUG_MONITOR X86_BUG(12) /* IPI required to wake up remote CPU */
+#define X86_BUG_AMD_E400 X86_BUG(13) /* CPU is among the affected by Erratum 400 */
+
#endif /* _ASM_X86_CPUFEATURES_H */
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 4daad1e39352..71cae73a5076 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -20,6 +20,10 @@
#include "cpu.h"
+static const int amd_erratum_383[];
+static const int amd_erratum_400[];
+static bool cpu_has_amd_erratum(struct cpuinfo_x86 *cpu, const int *erratum);
+
/*
* nodes_per_socket: Stores the number of nodes per socket.
* Refer to Fam15h Models 00-0fh BKDG - CPUID Fn8000_001E_ECX
@@ -592,11 +596,16 @@ static void early_init_amd(struct cpuinfo_x86 *c)
/* F16h erratum 793, CVE-2013-6885 */
if (c->x86 == 0x16 && c->x86_model <= 0xf)
msr_set_bit(MSR_AMD64_LS_CFG, 15);
-}
-static const int amd_erratum_383[];
-static const int amd_erratum_400[];
-static bool cpu_has_amd_erratum(struct cpuinfo_x86 *cpu, const int *erratum);
+ /*
+ * Check whether the machine is affected by erratum 400. This is
+ * used to select the proper idle routine and to enable the check
+ * whether the machine is affected in arch_post_acpi_init(), which
+ * sets the X86_BUG_AMD_APIC_C1E bug depending on the MSR check.
+ */
+ if (cpu_has_amd_erratum(c, amd_erratum_400))
+ set_cpu_bug(c, X86_BUG_AMD_E400);
+}
static void init_amd_k8(struct cpuinfo_x86 *c)
{
@@ -777,9 +786,6 @@ static void init_amd(struct cpuinfo_x86 *c)
if (c->x86 > 0x11)
set_cpu_cap(c, X86_FEATURE_ARAT);
- if (cpu_has_amd_erratum(c, amd_erratum_400))
- set_cpu_bug(c, X86_BUG_AMD_APIC_C1E);
-
rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy);
/* 3DNow or LM implies PREFETCHW */
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 7423acf15b04..bf1a0bab9187 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -402,8 +402,7 @@ void select_idle_routine(const struct cpuinfo_x86 *c)
if (x86_idle || boot_option_idle_override == IDLE_POLL)
return;
- if (cpu_has_bug(c, X86_BUG_AMD_APIC_C1E)) {
- /* E400: APIC timer interrupt does not wake up CPU from C1e */
+ if (boot_cpu_has_bug(X86_BUG_AMD_E400)) {
pr_info("using AMD E400 aware idle routine\n");
x86_idle = amd_e400_idle;
} else if (prefer_mwait_c1_over_halt(c)) {
--
2.11.0
next prev parent reply other threads:[~2016-12-09 18:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-09 18:29 [PATCH 0/5] x86/CPU: Improve AMD Erratum 400 workaround Borislav Petkov
2016-12-09 18:29 ` [PATCH 1/5] x86/cpufeature: Provide helper to set bugs bits Borislav Petkov
2016-12-09 20:30 ` [tip:x86/idle] " tip-bot for Borislav Petkov
2016-12-09 18:29 ` Borislav Petkov [this message]
2016-12-09 20:31 ` [tip:x86/idle] x86/bugs: Separate AMD E400 erratum and C1E bug tip-bot for Thomas Gleixner
2016-12-09 18:29 ` [PATCH 3/5] x86/amd: Check for the C1E bug post ACPI subsystem init Borislav Petkov
2016-12-09 20:31 ` [tip:x86/idle] " tip-bot for Thomas Gleixner
2016-12-09 18:29 ` [PATCH 4/5] x86/amd: Simplify AMD E400 aware idle routine Borislav Petkov
2016-12-09 20:32 ` [tip:x86/idle] " tip-bot for Borislav Petkov
2016-12-09 18:29 ` [PATCH 5/5] x86: Remove empty idle.h header Borislav Petkov
2016-12-09 20:32 ` [tip:x86/idle] " tip-bot for Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161209182912.2726-3-bp@alien8.de \
--to=bp@alien8.de \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox