From nobody Fri Dec 19 04:51:05 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25BA3CA0EDA for ; Tue, 12 Sep 2023 07:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232057AbjILH72 (ORCPT ); Tue, 12 Sep 2023 03:59:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231984AbjILH6u (ORCPT ); Tue, 12 Sep 2023 03:58:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFE0F10D7 for ; Tue, 12 Sep 2023 00:58:15 -0700 (PDT) Message-ID: <20230912065501.961705755@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694505494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=1lBdPitYyTH3fsPE7V/4ABSpwPZct6295smjQAkgNa4=; b=ftqcaC+bXsFBXJg518lIMU2YZ+XCbYlWfLkJDQ+ggwR43AVjKULRrKmYqwJVuRHIfb9IM8 mRAN/rfy8F+TTDo+w80gLMR0HUkB2fOzPpk7idfojOGhkANnQSJNq6G8X+7/8WN7fd/ubu 2WBVMLsVVy8Dqgnwus1NkyiVBZTdTwfxUxkVCSjBiOa+ygV4uzKKS4ckvXOMygvDTer8yD XiCG7wG8BjFEKXY1m0Pzq2+Ox47uWhp7NEFECWlTlvqgsHnlwCdjkQGjhFGK1GIEKTQeUG /P/7cmGlDzlyObunNmqVYkjH4X6O3OcRgTakYCtW935HRbXuv5T/GQ8Tm6Y27w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694505494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=1lBdPitYyTH3fsPE7V/4ABSpwPZct6295smjQAkgNa4=; b=5TFRvLxvtYwar2kxPLc4wxw6Uxwqbs5L/fMbICJx4ZHjBGNBNX0dKeScZkx4F7bKzPRf39 ngy7S5oODr13RlDA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov , "Chang S. Bae" , Arjan van de Ven , Nikolay Borisov Subject: [patch V3 19/30] x86/microcode: Clarify the late load logic References: <20230912065249.695681286@linutronix.de> MIME-Version: 1.0 Date: Tue, 12 Sep 2023 09:58:13 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner reload_store() is way too complicated. Split the inner workings out and make the following enhancements: - Taint the kernel only when the microcode was actually updated. If. e.g. the rendevouz fails, then nothing happened and there is no reason for tainting. - Return useful error codes Signed-off-by: Thomas Gleixner Reviewed-by: Nikolay Borisov --- arch/x86/kernel/cpu/microcode/core.c | 39 +++++++++++++++---------------= ----- 1 file changed, 17 insertions(+), 22 deletions(-) --- --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -434,11 +434,11 @@ static int microcode_reload_late(void) pr_info("Reload succeeded, microcode revision: 0x%x -> 0x%x\n", old, boot_cpu_data.microcode); microcode_check(&prev_info); + add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); } else { pr_info("Reload failed, current microcode revision: 0x%x\n", boot_cpu_data.microcode); } - return ret; } =20 @@ -471,40 +471,35 @@ static bool ensure_cpus_are_online(void) return true; } =20 +static int ucode_load_late_locked(void) +{ + int ret; + + if (!ensure_cpus_are_online()) + return -EBUSY; + + ret =3D microcode_ops->request_microcode_fw(0, µcode_pdev->dev); + if (ret !=3D UCODE_NEW) + return ret =3D=3D UCODE_NFOUND ? -ENOENT : -EBADFD; + return microcode_reload_late(); +} + static ssize_t reload_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { - enum ucode_state tmp_ret =3D UCODE_OK; - int bsp =3D boot_cpu_data.cpu_index; unsigned long val; - ssize_t ret =3D 0; + ssize_t ret; =20 ret =3D kstrtoul(buf, 0, &val); if (ret || val !=3D 1) return -EINVAL; =20 cpus_read_lock(); - - if (!ensure_cpus_are_online()) { - ret =3D -EBUSY; - goto put; - } - - tmp_ret =3D microcode_ops->request_microcode_fw(bsp, µcode_pdev->dev= ); - if (tmp_ret !=3D UCODE_NEW) - goto put; - - ret =3D microcode_reload_late(); -put: + ret =3D ucode_load_late_locked(); cpus_read_unlock(); =20 - if (ret =3D=3D 0) - ret =3D size; - - add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); - - return ret; + return ret ? : size; } =20 static DEVICE_ATTR_WO(reload);