From patchwork Tue Sep 12 07:57:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 138043 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp271694vqx; Tue, 12 Sep 2023 02:05:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFo8FB9NGCE6K63OE9c3kY8XHl1GgTk1VEfyyR++qjE8bDrfMBDSi5OM9MRJdRP9mqukt2S X-Received: by 2002:a05:6808:10cd:b0:3a3:7a28:f841 with SMTP id s13-20020a05680810cd00b003a37a28f841mr17952306ois.41.1694509518817; Tue, 12 Sep 2023 02:05:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694509518; cv=none; d=google.com; s=arc-20160816; b=XY4MHFRO80vByUq3taFZ9oTKQiGY6h3T7gmDRNV26mgvPrwFKRLi65L6lPE4EOtRQc WnGZ1Mdv9/Y0pgQa9B7Dr+ZfIORDBwU2HlipFXCE+CEhgpBj1AsQxfNnKEyJPp7bI6Wa lGShhhflD/lAFcAFk5kYvvADVxgq7H1wkga9pu5o/Gp71E4uKmlRZZIzFiPeIIVQ42pA zgBuZNreQcLeiAw8owvmbgHIOKAmauMXDzQpKxzSJqj0QUMIg2eIBmUtqOAFbbXtncuz 5cqavpVgj3ZxvWolnBHdlCdXpkUBk24y3s8jfFG3sM6yxr03AAbqh7e8Fy/KJSyQ03Py DkVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=HiC6v2fxtRjR8xApH6q4tcaG7wy0kTM5+263Xe7tZgo=; fh=u57tXYamzTrJA+Ht8n1u7SfTMptrQaIb6LVW+jsaYf4=; b=HyYCDJd3xEgshXGZqbEIkoSnm+ZuIEN4LYDpLt9ulskHJY0ZB6U3oX0A+SjiSjGoaD SolQF1e/P1X3UGLfTXG2t+VMB0ocmXqGWOjzpqwES8cEAkTHHMCGheAwHHC13jQIn9zC dIPhTuhpb0F+TVtABEb+YsyljBAjgAJ0C3ou3pz3cHpG5Wb6Ht7qaeqso+wk3qMmqAJg CXfA6ChNhhwo46k5sfyUjzsxlI35WY4PxIiSF6ivcJFe7dVzQNGUmWDYd2sKosckUfmr B261oeGR7K6WtnQxO9MGhyHL+yOUzCnz7x1Ssn12WSckmmTxGh3H9jC/y2VCTEVyVfXk BM2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rH0ZxaSy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=elZFAiMq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id x190-20020a6386c7000000b0056baff5c553si7525137pgd.101.2023.09.12.02.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 02:05:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rH0ZxaSy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=elZFAiMq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id F21AE80E9E99; Tue, 12 Sep 2023 00:59:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232011AbjILH62 (ORCPT + 39 others); Tue, 12 Sep 2023 03:58:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231686AbjILH6S (ORCPT ); Tue, 12 Sep 2023 03:58:18 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F02B510E7 for ; Tue, 12 Sep 2023 00:57:57 -0700 (PDT) Message-ID: <20230912065501.269244004@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694505476; 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=HiC6v2fxtRjR8xApH6q4tcaG7wy0kTM5+263Xe7tZgo=; b=rH0ZxaSyiHJj2ThngUo0cJMEKrtEBxu2se0MHjUZ4H5phU6SL3DXCWUTGFmQzMXTCr9523 +UqAOV2MeOgLYj3MdWkaNCADt5W8kViihKF7sQUJi25bSFo4/ADfS78mohgHsiJA9/TpxP 3yiGP5uQO3zOIAs46zf38p6N1D1mNkqVw66/Mpp9FdDMwu+sD/v1mWPwBJXMyD25VnzLpT h4BxG0Dwm9p458LffjoOUCNS5l+0iWIKGF1VaWALzfKTCBwAnmRKMSh97dObcrKyi2OExR i4opU8tPoiEjKjD2xINIw67/e10YBAGRks6cZW688mrDdIb6WME378DG04lpPg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694505476; 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=HiC6v2fxtRjR8xApH6q4tcaG7wy0kTM5+263Xe7tZgo=; b=elZFAiMqugkD+SD+beAqWnUHSs9h0g52qd3XQmBLlC5T5m7rei6lMNjOY76AC7wh6ACEFA yIcR9Xqz/xfjK0Aw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov , "Chang S. Bae" , Arjan van de Ven , Nikolay Borisov Subject: [patch V3 08/30] x86/microcode/intel: Save the microcode only after a successful late-load References: <20230912065249.695681286@linutronix.de> MIME-Version: 1.0 Date: Tue, 12 Sep 2023 09:57:56 +0200 (CEST) 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 (agentk.vger.email [0.0.0.0]); Tue, 12 Sep 2023 00:59:17 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776822013147274022 X-GMAIL-MSGID: 1776822013147274022 From: Thomas Gleixner There are situations where the late microcode is loaded into memory, but is not applied: 1) The rendevouz 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 from with the late load is attempted and when successful, update the hotplug pointer accordingly via a new micrcode_ops callback. Remove the pointless fallback in the loader to a microcode pointer which is never populated. Signed-off-by: Thomas Gleixner --- 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(-) --- --- 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); --- 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 /* 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_ 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_ 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_microcod 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) --- 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[];