From patchwork Mon Oct 9 12:29:48 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: 150056 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1833927vqo; Mon, 9 Oct 2023 05:32:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXvBT/AeBGogD8vigTaXAp/h5m7eE9dsN8K/yUbes0ln9ugHD2MiQimsusbfbZA/l0maGA X-Received: by 2002:a9d:774b:0:b0:6bd:603:797f with SMTP id t11-20020a9d774b000000b006bd0603797fmr14161510otl.37.1696854757319; Mon, 09 Oct 2023 05:32:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696854757; cv=none; d=google.com; s=arc-20160816; b=G72S/F82BxswvnmxcuXrvTefwfopn99qvkLByzXX46wl3NklmZLlVQ2e2olXK/BVzg XwFj4+OMhfhVTT0jPXsgu+m7Kqnn4K5psZfUm0pkSJXCC81fTR/rTJhfKNKqiDij+nYr JoatcafqvRIOE0TkBZtPOkz4MFDqplVep3B8dRPCMNhN94A9U9JCTiWKWP2jWU7DYFfN 7eY4FFKxSX/+ZmGKmBOreal+ogyIQ4fX86+i0peSWl+9Z6CPB1dJb8quk2rUsZ1SGOSH 8SaI+ba5cWb+hnX78fygisjQviTdB/GcWLmtG4cO86tL15iYV7erZzRAwkxJ7qZT4/LR XY7g== 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=EXhdpgwjWyporZWyLmEhrdJWuPsKhHaJ7ztA3tdWGz4=; fh=sb4qIpjvq8lbMgujEGaFliPojITybYXhCiHHIn/zgx0=; b=B3EHmVz6FWrjLZfQ3svPsFkyZ0ib5eClUIiATaM1W9xVAO720ZqrroHrVpZkrvEiuc 8hp7al4Uhw23CEH4hl3xQT83/P0IyzhiMu7T48uZbpTK/WIRH4U6iE4ki5tzskG6fYts pMGqdOrRGfRrU/P35D8d7oaiMCya3iF0FRXw9R9rddaWvJj7yJrRBHrbFBHBHjShCD3E ZvGx8nfZveVnrdzEtNASBgOiWtzBDp92V0BLCzfpcwIM/uPHrTnPpcoSqsxkgJvmiL6k JJ2OVor4dyiHxWAJ7UNF9k9i7AsXd1Q6/9WPXHbakzFRQmLcQKu0zT0BImi2w90qXKIS KzsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3b3pb7Js; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id o2-20020a634102000000b00573ed0023e1si9474945pga.333.2023.10.09.05.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 05:32:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3b3pb7Js; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id E8D2E80A73F2; Mon, 9 Oct 2023 05:30:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376635AbjJIMar (ORCPT + 18 others); Mon, 9 Oct 2023 08:30:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346578AbjJIM3z (ORCPT ); Mon, 9 Oct 2023 08:29:55 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36428AB; Mon, 9 Oct 2023 05:29:51 -0700 (PDT) Date: Mon, 09 Oct 2023 12:29:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696854589; 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=EXhdpgwjWyporZWyLmEhrdJWuPsKhHaJ7ztA3tdWGz4=; b=3b3pb7Js6Y6SHyZeyGp/ju0bvtZDoVYBMyoMNDydkjMPzv+LLm7fxlosVg79JSXQlxNp1Y Blsrhhd/VkP6XeTi2neLbm2so3SmnY5fPtQaMfdoEFLYClM7M5yaKoPCPXKxD/hIPRJrES weq6b9ahC//Ka+Dj/h4Zr75K06ZBt4sLgsAuTaGGGknSZcvOzJ9meen1Rd4vct5gFsF7G+ 7R3NB9qUFsG4Y1aVSaUMvsbQ6qRusUMxX10mnt7zzUrI/DcSYGhu44C/HRQ3SyNgM8bmgX YqLiac4v0fBZ+1+Y/uWxP81kezfwXl5LAbCdHTg+bGk49Xj2ck7piddm4Frciw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696854589; 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=EXhdpgwjWyporZWyLmEhrdJWuPsKhHaJ7ztA3tdWGz4=; b=1JkYwof3kV6EbPeF4zpczha4yyaEef6HuO3mnahvcw9EDhhvT4vQOeJLpk2SclMkCspmpW L6Mp89T+goGV50Bg== 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: <169685458837.3135.11309041430023311324.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 09 Oct 2023 05:30:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778652351422059088 X-GMAIL-MSGID: 1779281173967114923 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: f696f2fbae3dd52a4e79f0a02b8cb31fe0dc69ce Gitweb: https://git.kernel.org/tip/f696f2fbae3dd52a4e79f0a02b8cb31fe0dc69ce Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 13:59:57 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Fri, 06 Oct 2023 15:12:23 +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 02e9e5d..d82d763 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -391,11 +391,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; } @@ -428,40 +428,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);