aboutsummaryrefslogtreecommitdiff
path: root/arch/x86/kernel/cpu/microcode/core.c
diff options
context:
space:
mode:
authorThomas Gleixner <[email protected]>2023-10-02 13:59:56 +0200
committerBorislav Petkov (AMD) <[email protected]>2023-10-24 15:05:54 +0200
commit634ac23ad609b3ddd9e0e478bd5afbf49d3a2556 (patch)
treeb67c0fab5a46a5fa3f0dd9a7a37aa4f105ca026d /arch/x86/kernel/cpu/microcode/core.c
parentba48aa32388ac652256baa8d0a6092d350160da0 (diff)
x86/microcode: Handle "nosmt" correctly
On CPUs where microcode loading is not NMI-safe the SMT siblings which are parked in one of the play_dead() variants still react to NMIs. So if an NMI hits while the primary thread updates the microcode the resulting behaviour is undefined. The default play_dead() implementation on modern CPUs is using MWAIT which is not guaranteed to be safe against a microcode update which affects MWAIT. Take the cpus_booted_once_mask into account to detect this case and refuse to load late if the vendor specific driver does not advertise that late loading is NMI safe. AMD stated that this is safe, so mark the AMD driver accordingly. This requirement will be partially lifted in later changes. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
Diffstat (limited to 'arch/x86/kernel/cpu/microcode/core.c')
-rw-r--r--arch/x86/kernel/cpu/microcode/core.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index e306feeb374f..7af1b60527ec 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -254,23 +254,6 @@ static struct platform_device *microcode_pdev;
*/
#define SPINUNIT 100 /* 100 nsec */
-static int check_online_cpus(void)
-{
- unsigned int cpu;
-
- /*
- * Make sure all CPUs are online. It's fine for SMT to be disabled if
- * all the primary threads are still online.
- */
- for_each_present_cpu(cpu) {
- if (topology_is_primary_thread(cpu) && !cpu_online(cpu)) {
- pr_err("Not all CPUs online, aborting microcode update.\n");
- return -EINVAL;
- }
- }
-
- return 0;
-}
static atomic_t late_cpus_in;
static atomic_t late_cpus_out;
@@ -387,6 +370,35 @@ static int microcode_reload_late(void)
return ret;
}
+/*
+ * Ensure that all required CPUs which are present and have been booted
+ * once are online.
+ *
+ * To pass this check, all primary threads must be online.
+ *
+ * If the microcode load is not safe against NMI then all SMT threads
+ * must be online as well because they still react to NMIs when they are
+ * soft-offlined and parked in one of the play_dead() variants. So if a
+ * NMI hits while the primary thread updates the microcode the resulting
+ * behaviour is undefined. The default play_dead() implementation on
+ * modern CPUs uses MWAIT, which is also not guaranteed to be safe
+ * against a microcode update which affects MWAIT.
+ */
+static bool ensure_cpus_are_online(void)
+{
+ unsigned int cpu;
+
+ for_each_cpu_and(cpu, cpu_present_mask, &cpus_booted_once_mask) {
+ if (!cpu_online(cpu)) {
+ if (topology_is_primary_thread(cpu) || !microcode_ops->nmi_safe) {
+ pr_err("CPU %u not online\n", cpu);
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
static ssize_t reload_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
@@ -402,9 +414,10 @@ static ssize_t reload_store(struct device *dev,
cpus_read_lock();
- ret = check_online_cpus();
- if (ret)
+ if (!ensure_cpus_are_online()) {
+ ret = -EBUSY;
goto put;
+ }
tmp_ret = microcode_ops->request_microcode_fw(bsp, &microcode_pdev->dev);
if (tmp_ret != UCODE_NEW)