From patchwork Mon Oct 9 12:29:45 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: 150052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1833743vqo; Mon, 9 Oct 2023 05:32:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWDC0F5916mmNwAbmA6ssGv03HM3oeSd7+X52xuG8Xl9zbbdMA+DGdq3ITF0wvmRl83t6I X-Received: by 2002:a17:90b:3ecc:b0:276:6be8:8bfe with SMTP id rm12-20020a17090b3ecc00b002766be88bfemr19066502pjb.23.1696854738140; Mon, 09 Oct 2023 05:32:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696854738; cv=none; d=google.com; s=arc-20160816; b=LtfH0OZ+fcH4NHw1SJrw2oRzgNN/vKUZQQfR/fiP5AyfXPaM30sG6CsoNJ4joKqMVo oI9qPZB6955dxAqiYKam9yAYpeWP3C31Xz/nTCEN3fcHvJQ4s57Y2DmTnlU0aIh+lTq9 Z2SBUEe+gNEp3qNOMI1xLVTe6UQ8Yo3Yf8UuzJRbuHmYVyY1GNTWyeAb8Ej3ZysWa7aX Agxf3FL0uAwzLTtH7hx1D5v1f8Zmq8d+RCP93EhbgKTCtVfg6uiPpwujghpO/ay+GCHZ z4auo7JeFxbxbJBoAPUQ1LMY+MWk1nkuGLm15Le4Q7jnFq57/n98nz2sC40zaSjxdBp0 zDzg== 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=lO+E5Hr/wti7KqSpQqfht50cqcdnfkR4G2TU9Y+CIvQ=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=WXAvwrWu2K7tTjpYlYzou0V+hQbwYMBZUu8kbtdOahe1vxghlsb0WelEuinUW5Xlnu rxz9j2/yAASAXqEknDs2VN40CGNiFLo3Is+BmbQgRZwzQ5wcaixlXVVv0+G+VRnqFnUD uw79yofZmbqSHEbqg/HZCG30nxl9/0qpZ/nVZ3i4cs35P9IieM/cnepcGVIsokBFWVR0 snwhk0LB/yVIJdo9apIvw93vd6ydFfwv4Pr39ec4q3Ns14WJf/23cmuyydjW86W4hoWA eNU/Jfh7UQNeBlYa2Eimw+h5ligSLR1mAHzClf+b0ewJnFKBow2sCz+CpNISotrpJ6b3 DOBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ER0Kgkzo; 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 m6-20020a17090a414600b00273f61d8773si9417096pjg.160.2023.10.09.05.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 05:32:18 -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=ER0Kgkzo; 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 B5BE5807478D; Mon, 9 Oct 2023 05:30:17 -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 S1376459AbjJIMaC (ORCPT + 18 others); Mon, 9 Oct 2023 08:30:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346534AbjJIM3u (ORCPT ); Mon, 9 Oct 2023 08:29:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9246F9C; Mon, 9 Oct 2023 05:29:48 -0700 (PDT) Date: Mon, 09 Oct 2023 12:29:45 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696854586; 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=lO+E5Hr/wti7KqSpQqfht50cqcdnfkR4G2TU9Y+CIvQ=; b=ER0Kgkzo8H/EfFiVrJGJ/5oU9Nr3ew1zocNoD9UdoFkP9QLIU+0pJz/A5UB8hwt/82KfLr ZbW893+0AVsg/E486K+K3yCawZq6bRJ5mMO0xBvINmKQ9AGNwY9ovNoc+cBiPsmqxIHUsc +OXryp9yTvuuYqMIkm4KG998oxAgUniSohd+2uhCc2+Vkk381M0FEqu1VpFyE/wYSCmxzz HhKaV2uNHJ/t4HzHAOOgi13l1Y+VcrSZbHVVS3bgYhoZrVK4SxFEAgisbPrXfUvrWxNHQm P4z/CL0uWMScLjEJUyIkKkbCiXXV3AAb1HJx/ifLaYYF17R7OT7jyaZuTCaUvA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696854586; 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=lO+E5Hr/wti7KqSpQqfht50cqcdnfkR4G2TU9Y+CIvQ=; b=gYWIwkxO9JAsaayJswm16VuvMCigJHMfzdT/WIXJMOG1Mwsu0OeJ5tl+vMYzzwKEOt1e0m NtWSI5hOrExn7JDg== 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: <169685458597.3135.7900711190722605219.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:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779281153816422709 X-GMAIL-MSGID: 1779281153816422709 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: 0eccca7cbc7ff614cb57ba26a8704e842c242c38 Gitweb: https://git.kernel.org/tip/0eccca7cbc7ff614cb57ba26a8704e842c242c38 Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 14:00:03 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Fri, 06 Oct 2023 15:12:24 +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 f755b3c..ae23214 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -297,7 +297,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) { @@ -333,7 +333,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; @@ -368,7 +368,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; @@ -405,46 +405,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; } @@ -458,7 +426,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