From patchwork Fri Oct 20 11:37:59 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: 156078 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp995411vqb; Fri, 20 Oct 2023 04:48:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfrvqVEO4NPZnWgrakkBDzOdjCwGjhb5S6rN795phlm9Ve/BvI+/EH8maZKpf61ehmwbg8 X-Received: by 2002:a05:6a00:1a86:b0:68e:4303:edb8 with SMTP id e6-20020a056a001a8600b0068e4303edb8mr1268222pfv.30.1697802519745; Fri, 20 Oct 2023 04:48:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697802519; cv=none; d=google.com; s=arc-20160816; b=gtYrO63kbr0RLtgTGgUovWDmcw2qtL76XgPh67gJ2xUYK+cvSz1Mv5fWLCeOMPSv0T B5YbP4CmV1k0qVMI54t8I7uOZpsJtyyXeuBPLKmj/0pEY6JAdnjO2PnP5+RjwX4K7SPS vSqiNxbHU/097FrKRQMbtdb3oVPx58HD+OsNgMKtKv/hXgcvL99+Nc9moWp0FlWR/XWA AwAa2Rbg4p6EB9gMdWRGot/0o9YKC7YcU1tGtZs1gw1cDx9n7vw3w7MmqOIVUEkKq9ZM 8nauCndXfF31ZEpMm8Jnytl/QnSYeNVRQik+lO33rF/BJq/rUS7dg5B/b1TcfwKV08ch 1FnQ== 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=H3OP++RJI8kU9Lsnn3h2TfE2n/gvupRkhkSC9l2/MvI=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=ATU7WRWUHGsvLYLyWjU4Np/P3ENgI8wGe1zr+rpIYrVq9tcd5Xxz89DADeaZFzkyhG PqTmUj7/3jvisBuwsL8cfVs9JPtX3M2T8LSTTqXFF93bdFIz/wEKC+e1KjIQGvD16uWO cJA/5t+WK1kOI3dvIeuDd7a6bU7PSaDV8CH6lkuAo1F7PI9y5h/oRMGwHEXPfgzD+MtL GEl8TS1AJ5EysGyNWwjrtQ0flEUCKBJnyP4r0y47lsLrCFJ4FA4h1VFywb5iKY+cxmdy ho4+DJfm2Pw4XShkRhpFluVXbndW4Gxo/qRXvzxFxQkrnzFTCKlVddm1OMut0T4IthNH LoCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TryOOopw; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id y17-20020a056a00191100b0068fce4338bdsi1820541pfi.62.2023.10.20.04.48.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:48:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TryOOopw; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 9623C83014A3; Fri, 20 Oct 2023 04:48:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377372AbjJTLsZ (ORCPT + 25 others); Fri, 20 Oct 2023 07:48:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377368AbjJTLsN (ORCPT ); Fri, 20 Oct 2023 07:48:13 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C52E12D4C; Fri, 20 Oct 2023 04:38:30 -0700 (PDT) Date: Fri, 20 Oct 2023 11:37:59 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697801880; 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=H3OP++RJI8kU9Lsnn3h2TfE2n/gvupRkhkSC9l2/MvI=; b=TryOOopwrTwe0mAGFVMb/q77esum8lDaV5pY2Uc8rqLoQvV6rTEpLX28OknFVQ3Yrc3o13 WUUndxvTdFM9jBRdNYnfXWyIUVdaplCZKP678+vMCbUx/IcmcmuxErh+uRklVvKIgV2Dmm VynwzZZ457S9VTLXsYXOpHnvJu2ILW3iUic7kZlAY3nqMOAAyQ0y7+z22bRVxVvjhtC4uW s06j2WEeD0frW7d+qgB0+IhBfbWURnYsLzG20WcKfA3uR5pwUnaGAYAYFxBItruozEWBhV yD/2dKkm8jJ0JKwPtYaVkSSA4THZlMLJyEBl1++8OiViPEfrWTwaoq4C22hL9Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697801880; 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=H3OP++RJI8kU9Lsnn3h2TfE2n/gvupRkhkSC9l2/MvI=; b=mCd2ywvYHwFwk2MmwuPVc6dn4/opa76Hhemn5UoWZdcjunOghs5i9G6M6R2pztSPqHaQhV SESvDwiIqAFek8AA== 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/intel: Save the microcode only after a successful late-load Cc: Thomas Gleixner , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231002115902.505491309@linutronix.de> References: <20231002115902.505491309@linutronix.de> MIME-Version: 1.0 Message-ID: <169780187951.3135.16662695399510377839.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 groat.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 (groat.vger.email [0.0.0.0]); Fri, 20 Oct 2023 04:48:36 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778645722338788849 X-GMAIL-MSGID: 1780274975090819968 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: 81473520ac894010c012c6c1ecc9ed86d91a234b Gitweb: https://git.kernel.org/tip/81473520ac894010c012c6c1ecc9ed86d91a234b Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 13:59:44 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 19 Oct 2023 14:21:29 +02:00 x86/microcode/intel: Save the microcode only after a successful late-load There are situations where the late microcode is loaded into memory but is not applied: 1) The rendezvous fails 2) The microcode is rejected by the CPUs If any of this happens then the pointer which was updated at firmware load time is stale and subsequent CPU hotplug operations either fail to update or create inconsistent microcode state. Save the loaded microcode in a separate pointer before the late load is attempted and when successful, update the hotplug pointer accordingly via a new microcode_ops callback. Remove the pointless fallback in the loader to a microcode pointer which is never populated. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20231002115902.505491309@linutronix.de --- arch/x86/kernel/cpu/microcode/core.c | 4 +++- arch/x86/kernel/cpu/microcode/intel.c | 30 +++++++++++------------ arch/x86/kernel/cpu/microcode/internal.h | 1 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index de3eb97..2b742fe 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -397,6 +397,10 @@ static int microcode_reload_late(void) store_cpu_caps(&prev_info); ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask); + + if (microcode_ops->finalize_late_load) + microcode_ops->finalize_late_load(ret); + if (!ret) { pr_info("Reload succeeded, microcode revision: 0x%x -> 0x%x\n", old, boot_cpu_data.microcode); diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c index e6a3ebb..c587b67 100644 --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -34,6 +34,7 @@ static const char ucode_path[] = "kernel/x86/microcode/GenuineIntel.bin"; /* Current microcode patch used in early patching on the APs. */ static struct microcode_intel *ucode_patch_va __read_mostly; +static struct microcode_intel *ucode_patch_late __read_mostly; /* last level cache size per core */ static unsigned int llc_size_per_core __ro_after_init; @@ -454,12 +455,9 @@ static enum ucode_state apply_microcode_intel(int cpu) if (WARN_ON(raw_smp_processor_id() != cpu)) return UCODE_ERROR; - mc = ucode_patch_va; - if (!mc) { - mc = uci->mc; - if (!mc) - return UCODE_NFOUND; - } + mc = ucode_patch_late; + if (!mc) + return UCODE_NFOUND; /* * Save us the MSR write below - which is a particular expensive @@ -578,15 +576,7 @@ static enum ucode_state parse_microcode_blobs(int cpu, struct iov_iter *iter) if (!new_mc) return UCODE_NFOUND; - /* Save for CPU hotplug */ - save_microcode_patch((struct microcode_intel *)new_mc); - uci->mc = ucode_patch_va; - - vfree(new_mc); - - pr_debug("CPU%d found a matching microcode update with version 0x%x (current=0x%x)\n", - cpu, cur_rev, uci->cpu_sig.rev); - + ucode_patch_late = (struct microcode_intel *)new_mc; return UCODE_NEW; } @@ -643,10 +633,20 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device) return ret; } +static void finalize_late_load(int result) +{ + if (!result) + save_microcode_patch(ucode_patch_late); + + vfree(ucode_patch_late); + ucode_patch_late = NULL; +} + static struct microcode_ops microcode_intel_ops = { .request_microcode_fw = request_microcode_fw, .collect_cpu_info = collect_cpu_info, .apply_microcode = apply_microcode_intel, + .finalize_late_load = finalize_late_load, }; static __init void calc_llc_size_per_core(struct cpuinfo_x86 *c) diff --git a/arch/x86/kernel/cpu/microcode/internal.h b/arch/x86/kernel/cpu/microcode/internal.h index 1cfc6ec..32f6ad5 100644 --- a/arch/x86/kernel/cpu/microcode/internal.h +++ b/arch/x86/kernel/cpu/microcode/internal.h @@ -31,6 +31,7 @@ struct microcode_ops { */ enum ucode_state (*apply_microcode)(int cpu); int (*collect_cpu_info)(int cpu, struct cpu_signature *csig); + void (*finalize_late_load)(int result); }; extern struct ucode_cpu_info ucode_cpu_info[];