Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1477093rdb; Mon, 2 Oct 2023 10:36:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIgM3GHjlOoB4jgx+bNXerLyWto00IESknmYzPSDMNjf01H4r57rMpkdfymUqdm6L5es59 X-Received: by 2002:a05:6830:1050:b0:6b5:ee8f:73af with SMTP id b16-20020a056830105000b006b5ee8f73afmr13222601otp.5.1696268204905; Mon, 02 Oct 2023 10:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696268204; cv=none; d=google.com; s=arc-20160816; b=jksa6fiBUQR+yASvPZ2IVeE3bstl2j3C7gYMUkzBwzu5q+vcmNBW/lnw9PTmuMsFC0 WLLmFBkoFwTP8GGXrlMiHCfBxPQFDT/d/moi1zMTb8GyDthL/IilgQVdoDH7pgXrfef2 Tmmg7DgkywYndmUi4efTW+NqAhpYoU+2FsQ8GJHB77mgkHgY+bG4biNXDMoaIAfUfQsJ VbFy7qSlePUbtQpBsZV3MFUvVyqstEUeg/MAGxvis0bc5DwzHsm9xZ1LkS+2uS8TikIF 18E34/ySWJJsX0Ckn5AFseU3T0wHFc0M4U86ht2OXxBBzQ3kNzAHby8bYsvH2+8hzXrs R5AQ== 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=ieBuqQWksnZY/BH9wf5B9oj4Sl+Y6MDqsZ/PHThlnTM=; fh=u57tXYamzTrJA+Ht8n1u7SfTMptrQaIb6LVW+jsaYf4=; b=qAVv6z6cBOxmNxv9nr0i8+/ntikZrqUptG0t/MZ+VhdMoM0JVkULhElQEOJ90tDTP1 W96xhXEXnXdEBRcYWVfOPGbWB5pvth9F+U0Nu9J+guGF7J9mdt/B/9hoQk2lhk56/pgA WZ5c0ETTWvtpQGaaGFIRn2YWuqz4f9ZYwnA+mInUtg+iDKj/tZYLW+hfQSOw0jlSuO5c palTcPENkXHeDDMnlKJBlXS8r0jHSiDLux0QuvJXYg2pDqfm8ltXYjAnEqgcxl4d00Pp F2mxP2igLEhrD99mlvK99yxcuvM3WzD/dQ9xLPC04Czy5rTgINwVs9g7yOwtT7iNDQF7 Ol9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Q4TE8q8l; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=jnpSpz9u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id j190-20020a6380c7000000b0057745d87b4csi27225560pgd.526.2023.10.02.10.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 10:36:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Q4TE8q8l; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=jnpSpz9u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id DBA43807FC2C; Mon, 2 Oct 2023 05:02:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237071AbjJBMA4 (ORCPT + 99 others); Mon, 2 Oct 2023 08:00:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236914AbjJBMA0 (ORCPT ); Mon, 2 Oct 2023 08:00:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C3FACFC for ; Mon, 2 Oct 2023 05:00:05 -0700 (PDT) Message-ID: <20231002115903.433704135@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696248004; 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=ieBuqQWksnZY/BH9wf5B9oj4Sl+Y6MDqsZ/PHThlnTM=; b=Q4TE8q8l5JiNVhzWFESeoJszo8+qdH8T7XjwskCMAqXgXL7Wgn2blSnXkFketydzCYoDch 36F1qFbJ1+B7zGqwVLuVHxT9yxJ92VlbDghmyq195VQpp6s4xnoEMc8/dr2s2htP/fptcb 3YT4r3pZ8Io1aoqmWJ7xW/0FheDMLo3Awdf+fCBbct9bL31SEQohk6f9tiUNGzXveCKw0E h2VhXlUXS/oTNhCDpBzdXCwRshugTmiTohWb+mz6u8Mnq4oZrX982YdaFAXalkAc3/n6hu /AhoCCtPVXcRyyMKLyh8foywn5+WM6R+KzkJyFNmDsOXTxWJW5ljsSPK5E8JRw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696248004; 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=ieBuqQWksnZY/BH9wf5B9oj4Sl+Y6MDqsZ/PHThlnTM=; b=jnpSpz9uCWSbygDlUogcWaBQGJDOA45yddJGvbtunkIhhEPXQ64SvD5b1C704gPZrfgIM8 k1KwwGfTXiVMGvDA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov , "Chang S. Bae" , Arjan van de Ven , Nikolay Borisov Subject: [patch V4 24/30] x86/microcode: Replace the all in one rendevouz handler References: <20231002115506.217091296@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 2 Oct 2023 14:00:03 +0200 (CEST) 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 02 Oct 2023 05:02:05 -0700 (PDT) From: Thomas Gleixner with a new handler which just separates the control flow of primary and secondary CPUs. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/microcode/core.c | 51 ++++++----------------------------- 1 file changed, 9 insertions(+), 42 deletions(-) --- --- 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_secondar 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( 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