From patchwork Fri Oct 20 11:37:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 156054 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp992180vqb; Fri, 20 Oct 2023 04:41:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFagJeBQfdFgIloiDWMSxnWwuva91J0V6Iy+OykK0wum1oHP7Umb84lWaQ47efuhj4cowrD X-Received: by 2002:a05:6a21:78a7:b0:153:353e:5e39 with SMTP id bf39-20020a056a2178a700b00153353e5e39mr1503138pzc.51.1697802109572; Fri, 20 Oct 2023 04:41:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697802109; cv=none; d=google.com; s=arc-20160816; b=fxer52o7h9RAXLahFMZ/p4Oj7rWcaCfn8f8hD1pKP7m5b1DcsOmEnrPa4CDeRGIqlQ BlcWQ7c/ozW/RyBjUskQDj5dI1bGpah34Lv7orAb/SDMhzKKyF9PURq/c1hr1TxmaGxv UsBYP6jnVWvlGC7PhRHYXoUcjHX8t/0Kz9c2SuysRLe+mUmwZUPs4JF+QBXTozaQjvRF yS/j0pS4uqx3O31CDWfT5A+XNRt5r3VD4xQPL9Clt/b9C9HOFrzwigNhaOX2SceRsww5 EpGzDKyUSefiVsn6/6q50LBHpRQRNKx5v03KUpVXlCFvBVzkLrXfRvMSsQQytRn0KtN6 qYOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=ZJEiMv+yGvjXavP+5UL88PcuB6INdYL/mDcwY2xtrQU=; fh=sb4qIpjvq8lbMgujEGaFliPojITybYXhCiHHIn/zgx0=; b=u+suj8jgqVwx29EP4xbtU+ejNpt0MRt14PEKPDxGzlYGOpmWe1FudlimAqpX2yIpFf 4H7mAU/9ntbtkrg0fV6AebK1ozlB4QRkrLu44/7tdG7MCRnfV0iXh2JAARonzoNueHcO mI3ckwBplOjpHxadmDI4bchWoXnak1uBIeWUNA8z2LiDLjPKIQOPSziAAgSrzmao1hkp yvDmMyYjyDNRBJP0HB3pkv4b5JC7cuS1I2RerriKQbuNVTyQRc115j7atbiSplg2t4KS gfC++c1rwvo3C9y2kmw1xrneuoe71E9mGIWEqbFql0t8AjHrvdA4j0BHjdBEeM89u5v7 PrYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EgBUSpGX; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=q8oT3t4e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id r20-20020a6560d4000000b005ac8d44bad4si1545231pgv.592.2023.10.20.04.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:41:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EgBUSpGX; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=q8oT3t4e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 64FF983C23B2; Fri, 20 Oct 2023 04:41:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377411AbjJTLjf (ORCPT + 25 others); Fri, 20 Oct 2023 07:39:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377350AbjJTLiu (ORCPT ); Fri, 20 Oct 2023 07:38:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33B091FD6; Fri, 20 Oct 2023 04:38:06 -0700 (PDT) Date: Fri, 20 Oct 2023 11:37:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697801872; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZJEiMv+yGvjXavP+5UL88PcuB6INdYL/mDcwY2xtrQU=; b=EgBUSpGXYikaGjKHzvcC9rLOsm3QI0mI26AsZPyevJP5b8cl39c1QLMZe/EePNwZ2kh22R kbTpORcbA2sAKo345wAIjoolLtqNLlfNotakrHVwpYqTIT0aZXEPRWi+x47YFN8RHA4GFM jXma4kCV5nGw9+rvb4dPUFY7+thDBAvdOyLfZI9QnZNpCccKoPR58sKMuIe8Dsa8IMcgrh 2q4Or8NMbpeb2kBmXvEtugQtxI59NVXvqaWmFfg/1ICny+954o30gU3Wc/Hv6BKxqXxFLR Ya2u1bGqj5NRudpsTwCmp+DAhxvyTbgCA9t3pFixj3SZYhZyixkjoLWdTXtHQA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697801872; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZJEiMv+yGvjXavP+5UL88PcuB6INdYL/mDcwY2xtrQU=; b=q8oT3t4eaOMzWSmnDPnByE6urfnP3HBaxY6yosB4tjeaT4QC5tsgEgoAOrm73hg6GyLzoM cvwDeh3I/qr8QyBw== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/microcode] x86/microcode: Clarify the late load logic Cc: Thomas Gleixner , "Borislav Petkov (AMD)" , Nikolay Borisov , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231002115903.145048840@linutronix.de> References: <20231002115903.145048840@linutronix.de> MIME-Version: 1.0 Message-ID: <169780187144.3135.16239776923838554576.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 04:41:00 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778652351422059088 X-GMAIL-MSGID: 1780274545131125988 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: 838c0817392e5d459a4aa90d6fbb4fb571024929 Gitweb: https://git.kernel.org/tip/838c0817392e5d459a4aa90d6fbb4fb571024929 Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 13:59:57 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 19 Oct 2023 15:55:26 +02:00 x86/microcode: Clarify the late load logic 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 rendezvous fails, then nothing happened and there is no reason for tainting. - Return useful error codes Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Nikolay Borisov Link: https://lore.kernel.org/r/20231002115903.145048840@linutronix.de --- arch/x86/kernel/cpu/microcode/core.c | 41 ++++++++++++--------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index 7af1b60..63c4e12 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -362,11 +362,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; } @@ -399,40 +399,37 @@ static bool ensure_cpus_are_online(void) return true; } +static int ucode_load_late_locked(void) +{ + if (!ensure_cpus_are_online()) + return -EBUSY; + + switch (microcode_ops->request_microcode_fw(0, µcode_pdev->dev)) { + case UCODE_NEW: + return microcode_reload_late(); + case UCODE_NFOUND: + return -ENOENT; + default: + return -EBADFD; + } +} + static ssize_t reload_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { - enum ucode_state tmp_ret = UCODE_OK; - int bsp = boot_cpu_data.cpu_index; unsigned long val; - ssize_t ret = 0; + ssize_t ret; ret = kstrtoul(buf, 0, &val); if (ret || val != 1) return -EINVAL; cpus_read_lock(); - - if (!ensure_cpus_are_online()) { - ret = -EBUSY; - goto put; - } - - tmp_ret = microcode_ops->request_microcode_fw(bsp, µcode_pdev->dev); - if (tmp_ret != UCODE_NEW) - goto put; - - ret = microcode_reload_late(); -put: + ret = ucode_load_late_locked(); cpus_read_unlock(); - if (ret == 0) - ret = size; - - add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); - - return ret; + return ret ? : size; } static DEVICE_ATTR_WO(reload);