From patchwork Tue Oct 24 13:20:52 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: 157450 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1937465vqx; Tue, 24 Oct 2023 06:22:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQXQXa9ZXFWV1Su0ZoVfn3xlpr4N/USky0mH+Pb6mGRW1JMbSmXhakm0SmBMFwaociG/4l X-Received: by 2002:a17:902:c40a:b0:1c4:44a0:5c03 with SMTP id k10-20020a170902c40a00b001c444a05c03mr11567325plk.9.1698153725740; Tue, 24 Oct 2023 06:22:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698153725; cv=none; d=google.com; s=arc-20160816; b=eD1k4aXQfOZ7obA0fCdxUN3maA+CpZ3W16+E1orFtaP2wmqCStocSsWrERPGERnin5 jV6R2kk+g7c/3GZOqpswN5uXsMS+3cmYXb0q6mN6VG1TR/gtnNq9sFOiQRUro4/AOUsR CTVUY03VEDY3jr8z0i3gyioZidYawIwrlNW5m3c/APno+c/o5Wi7oVDE3vYg75JVsLYk 8bMaJQXKOSdepNAy9TP0sy0AABl6cnmQxo91iE1KCjXWawedlRFU5/iXgp/e27jWDsg5 pNr3SKfTHTDN3aSONZ3ktxhGEuAPf56PrDv9+D6vm/D5twDyxqde4UngM22SBUURAH5T H/NA== 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=3HRwjwSDCstpcUBGnUCVNfDdoW5MMSv2b52r2sciB7A=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=Bgd4iPDhs29lgqFZs48W7aiQGes7zX4U+Pdst8NaiE4Oa+qt7skhC5DqpxBuqJvPoZ jAa/9C1HfWtPtm+TrsJa+cakm7XgJBFB41fRMPab7Qh8BG5Mri0OEnNd55b9QZ/XiGSe KEEU0Jxn0+PZI7arZGCN1knB6lNsKGmPOQLxAKIm6wGDeoARDN79pBqqkoXVAz1L64mR y2qiiouf8cOzOkraq+w9rU6lFQDa58BRypHO3F5KBRWiES/JfPIIRkKSTTGYmazdE9sH fM/EWsDGUNH1LSFj0+RzYrKhgvNxzsOoWQOyzJnMtQAroWgzKzrWLykZlwK4/iT6w4cL FJfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YimTm0OG; 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 u14-20020a170902e5ce00b001c61226fe40si8683886plf.392.2023.10.24.06.22.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 06:22:05 -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=YimTm0OG; 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 E5280802C7C9; Tue, 24 Oct 2023 06:22:04 -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 S234574AbjJXNVv (ORCPT + 26 others); Tue, 24 Oct 2023 09:21:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234544AbjJXNVA (ORCPT ); Tue, 24 Oct 2023 09:21:00 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C2D210C9; Tue, 24 Oct 2023 06:20:55 -0700 (PDT) Date: Tue, 24 Oct 2023 13:20:52 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1698153653; 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=3HRwjwSDCstpcUBGnUCVNfDdoW5MMSv2b52r2sciB7A=; b=YimTm0OGQ041F0Qu+ap0GIA+LuMAU3sF8JLC6k1pMKa01nPyN+R/hzB281ajncmk6WMMFb 4pmCse7kmGaZhtbqMuqm4Aw7+HOhCfR6RiLMlni3hIFKr5s5ZrErG42TgfnyklbsVgZEsa OtnPwhnvIHf8P41TRSl4wJ5xNzSQWl7HVLeiOhE3wdnBXY58EGSbRKgsnO0dVlLOdjGPat IgNmGp2w7gMKnHxoznBD/SDzXOEX8g2BNBx60kmya7Ui9AXg60jhK+hL0aNk254mlhkoKo 0j8ecAx/X1yA++u44fMHjRKwe1HtDN4CQGKjAbkqW8m9K8JZgVygs04eSG5Uxw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1698153653; 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=3HRwjwSDCstpcUBGnUCVNfDdoW5MMSv2b52r2sciB7A=; b=QUZrUBsKTZ7sLz30pmCEhinra6QmHudUvo7TSRht0/KYQcj02CP/PJ8FW8oiZzTfhOKQft /wDlgXPyvlGUzfDw== 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: Replace the all-in-one rendevous handler Cc: Thomas Gleixner , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231002115903.433704135@linutronix.de> References: <20231002115903.433704135@linutronix.de> MIME-Version: 1.0 Message-ID: <169815365245.3135.13257369178148876293.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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]); Tue, 24 Oct 2023 06:22:05 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779281153816422709 X-GMAIL-MSGID: 1780643240976062799 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: 0bf871651211b58c7b19f40b746b646d5311e2ec Gitweb: https://git.kernel.org/tip/0bf871651211b58c7b19f40b746b646d5311e2ec Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 14:00:03 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 24 Oct 2023 15:05:55 +02:00 x86/microcode: Replace the all-in-one rendevous handler with a new handler which just separates the control flow of primary and secondary CPUs. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20231002115903.433704135@linutronix.de --- arch/x86/kernel/cpu/microcode/core.c | 51 ++++----------------------- 1 file changed, 9 insertions(+), 42 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c index 1ff38f9..1c2710b 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -268,7 +268,7 @@ struct microcode_ctrl { }; static DEFINE_PER_CPU(struct microcode_ctrl, ucode_ctrl); -static atomic_t late_cpus_in, late_cpus_out; +static atomic_t late_cpus_in; static bool wait_for_cpus(atomic_t *cnt) { @@ -304,7 +304,7 @@ static bool wait_for_ctrl(void) return false; } -static __maybe_unused void load_secondary(unsigned int cpu) +static void load_secondary(unsigned int cpu) { unsigned int ctrl_cpu = this_cpu_read(ucode_ctrl.ctrl_cpu); enum ucode_state ret; @@ -339,7 +339,7 @@ static __maybe_unused void load_secondary(unsigned int cpu) this_cpu_write(ucode_ctrl.ctrl, SCTRL_DONE); } -static __maybe_unused void load_primary(unsigned int cpu) +static void load_primary(unsigned int cpu) { struct cpumask *secondaries = topology_sibling_cpumask(cpu); enum sibling_ctrl ctrl; @@ -376,46 +376,14 @@ static __maybe_unused void load_primary(unsigned int cpu) static int load_cpus_stopped(void *unused) { - int cpu = smp_processor_id(); - enum ucode_state ret; - - /* - * Wait for all CPUs to arrive. A load will not be attempted unless all - * CPUs show up. - * */ - if (!wait_for_cpus(&late_cpus_in)) { - this_cpu_write(ucode_ctrl.result, UCODE_TIMEOUT); - return 0; - } - - /* - * On an SMT system, it suffices to load the microcode on one sibling of - * the core because the microcode engine is shared between the threads. - * Synchronization still needs to take place so that no concurrent - * loading attempts happen on multiple threads of an SMT core. See - * below. - */ - if (cpumask_first(topology_sibling_cpumask(cpu)) != cpu) - goto wait_for_siblings; + unsigned int cpu = smp_processor_id(); - ret = microcode_ops->apply_microcode(cpu); - this_cpu_write(ucode_ctrl.result, ret); - -wait_for_siblings: - if (!wait_for_cpus(&late_cpus_out)) - panic("Timeout during microcode update!\n"); - - /* - * At least one thread has completed update on each core. - * For others, simply call the update to make sure the - * per-cpu cpuinfo can be updated with right microcode - * revision. - */ - if (cpumask_first(topology_sibling_cpumask(cpu)) == cpu) - return 0; + if (this_cpu_read(ucode_ctrl.ctrl_cpu) == cpu) + load_primary(cpu); + else + load_secondary(cpu); - ret = microcode_ops->apply_microcode(cpu); - this_cpu_write(ucode_ctrl.result, ret); + /* No point to wait here. The CPUs will all wait in stop_machine(). */ return 0; } @@ -429,7 +397,6 @@ static int load_late_stop_cpus(void) pr_err("You should switch to early loading, if possible.\n"); atomic_set(&late_cpus_in, num_online_cpus()); - atomic_set(&late_cpus_out, num_online_cpus()); /* * Take a snapshot before the microcode update in order to compare and