From patchwork Mon Oct 9 12:29:53 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: 150049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1833458vqo; Mon, 9 Oct 2023 05:31:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHd2t9jJeZAiFfd9hc33km8tfqdSjr9HfoImM9GD+h20SaJ9hxq5QNRtdpn8Me6/xoATHjY X-Received: by 2002:a05:6a20:8402:b0:161:22c0:541 with SMTP id c2-20020a056a20840200b0016122c00541mr20313215pzd.25.1696854715194; Mon, 09 Oct 2023 05:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696854715; cv=none; d=google.com; s=arc-20160816; b=bn0fobSAE6bpV4+YooRiohTjgtdc6Q69MWEhx5yExVSTHPD3cIvdvbZG7Nu8767P1J byaT2nop5DmPk9gpKzuOziFpQsj1t6xe5TTQu8W6Y4SN3WCUOKGHkqybiuCA3jYrxkfu S1+bkDpZxUPW425Yl3EMvfkuM83tQsnwbv8bX09zt2HDuCzVThng61xkBRcldskp3nL4 4bDiKbbaf4XrNM42FWLwfudfbSOw8VMcP6mqp3Bb07bt/dJKhxv4XcEARiruSpWeqmet RitdQid+QVnG2kL+ekGwojjyXqs+agqfzUSLX7UCt/VbnuirhykavB/cZYon3pMgrIaM YtnA== 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=Sz2ng7ugJ2McXeNm4hHr3Jvo6nokt73rbNPX1El6YdY=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=NVQU1EqZS12YohKmeDddXYtOqgWLgbXAGFY6uaUZOQYtWDSfrE0mlNGZUsxhMaTg5s zwrHMPRcM85y6Uk8Z9WOmCO28qcI/PJlrTZvnTjot4T9rHhCMICCvD67MWG6U88c9bPf VQcoqRybi6scGxaESiWnDIk8JdBcCl3v1QyrZomCRLQjymsRxAwxmWRarYWoCflcLZxQ TrtP0CI3Ck/Br2+jD5xpewAS6t6h5Mwz4/uFOpxZdD4q0a0DkVVyGfLF/c6RGKXUWlD2 DMQps9zOwmq8T52zXwIiSrPtTNE/nwRsWvVhcdxh2opMjJ8GjsU5inQYsmZskYIiGmNY DhKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GegtX2hS; dkim=neutral (no key) header.i=@linutronix.de header.b=jr5wrOnb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id x29-20020a056a00189d00b0068fcb7125e1si7441236pfh.242.2023.10.09.05.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 05:31:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GegtX2hS; dkim=neutral (no key) header.i=@linutronix.de header.b=jr5wrOnb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 7FC268097A7B; Mon, 9 Oct 2023 05:31:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376658AbjJIMbD (ORCPT + 18 others); Mon, 9 Oct 2023 08:31:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376441AbjJIMaC (ORCPT ); Mon, 9 Oct 2023 08:30:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F45BFF; Mon, 9 Oct 2023 05:29:55 -0700 (PDT) Date: Mon, 09 Oct 2023 12:29:53 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696854594; 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=Sz2ng7ugJ2McXeNm4hHr3Jvo6nokt73rbNPX1El6YdY=; b=GegtX2hSEfBLjE0sFBP+t3GQdTxDkVtT1T6BcDXuYb1CEs69Sk0V7E2sJgnZARRyTTukHe /X9/ilTJxf/uAJ6n1NE0dGcd1i8cmFWOdeNls7JlK63iDCyGLDWda2yCHfUDMuElTGMxQt B2a86/yv2V0umjwuoHGg87swsRfTEOWJaT1QAZepy74+3yyUGiZbLBJNe2D2a8i0ClEdTt ZbogifdFz3v8X3YwimQPi0IHqW6SBMpWZIsLxioeJG2mrmJsHFH36BUzGUAY15tjxXBf4T cptoCg53zsrvANsNBYu7gwP5BSyGY+noxSQGZiF1xAUCLQaCBvGP8v3hxbvipQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696854594; 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=Sz2ng7ugJ2McXeNm4hHr3Jvo6nokt73rbNPX1El6YdY=; b=jr5wrOnb8Ik6rWl1GLo8PvSS7UBT/n3B+0pE6Rdv3+pqffTBslZVlnb0gFG9oLxhnjcF2g je63AkqvBsqsptAw== 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: <169685459342.3135.578180378589368912.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Mon, 09 Oct 2023 05:31:28 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778645722338788849 X-GMAIL-MSGID: 1779281129958587170 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: ed1a85d984ac1543349da617dce65f4190839f9f Gitweb: https://git.kernel.org/tip/ed1a85d984ac1543349da617dce65f4190839f9f Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 13:59:44 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 03 Oct 2023 15:58:25 +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 5d8ac8b..0d99d5e 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -400,6 +400,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 a80c019..2d88929 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; @@ -461,12 +462,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 @@ -585,15 +583,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; } @@ -650,10 +640,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 1033176..051b795 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[];