From patchwork Fri Oct 20 11:37:48 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: 156057 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp992346vqb; Fri, 20 Oct 2023 04:42:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRkiYCNGTv7GnXpums75L0uy8fMfZLe9M8ebeENYVWBbe9blWHGHUbZf7A5Gef0lqOyRTM X-Received: by 2002:a05:6a00:1a4e:b0:68f:e810:e86f with SMTP id h14-20020a056a001a4e00b0068fe810e86fmr1268826pfv.28.1697802127782; Fri, 20 Oct 2023 04:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697802127; cv=none; d=google.com; s=arc-20160816; b=OwGHIHeCaDOCCtBC/G0ofKXmeNG9ZK8ZfkLvOgK4YPD7rV0sLQC4NK6IUadIDer7J4 8oeJL/nVjRyagfk4D2MRuBOF15NVfZbh8p5nxrm2EWb1angikWa/8c5kowNbjk2Sva5u UwMK+nOblc0j7k7D9jqgNyQ2U5+0M2Sg+RYlUkNhSdJnc/YgyZ5aPRSmbQ5eiYFhNu2x 0Y6WMxkFAba1DfXhx2NVj+ifSXeJGu9TTivmDv1lgvRGWZ+iUp0S8UYfY+fVgrm7BbdQ TDxTK7ByqbvQXnJJ+mmUENKBKnNGHkVWBeB4Xewm+oaxOh01ivUxOzRzGVMguKhw9Jid bUOg== 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=dmk5p82kG18c4EKbp8804yVk4HTTWAMOcj8cob+yyGs=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=jK3zW9+vS0+e1VPh15xmHwCmQU26oYeAnHGGEOQg0UgGOHxlB/0PxF4rxeG7kzDdrH qosaWOKvOElHUtsnu7RY/jf1cqWwMDaZs1ffmVPvrC6mJSXprzpimFwn4TNQTjeQPW4j 6Z6JIEHz6kd8T4aTrBFVH5AY6GGDixc95Jxvw7aBLMvXuO1pdsyzvLs2SF2bD+7a3gMG 5rmjvMEfyRepxnN+TA6nldicDEvdGCU0ixTyLkrwqMeKfWGdfdMc0Vz4ZHvIiOGgnBRo BfFamzL70zyqY2hryCvv9U7A9tkxWFpFQelhxsswT03fVoe7XkMvrRNnbnKZdgpxmKgj 2gNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wjw9CRN9; dkim=neutral (no key) header.i=@linutronix.de; 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id r22-20020aa79636000000b00690c23d353asi1699384pfg.217.2023.10.20.04.42.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:42:07 -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=wjw9CRN9; dkim=neutral (no key) header.i=@linutronix.de; 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 C1B0D819AC49; Fri, 20 Oct 2023 04:40:10 -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 S1377319AbjJTLjT (ORCPT + 25 others); Fri, 20 Oct 2023 07:39:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377378AbjJTLir (ORCPT ); Fri, 20 Oct 2023 07:38:47 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C7E71FC8; Fri, 20 Oct 2023 04:38:03 -0700 (PDT) Date: Fri, 20 Oct 2023 11:37:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697801869; 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=dmk5p82kG18c4EKbp8804yVk4HTTWAMOcj8cob+yyGs=; b=wjw9CRN9um9Ts8JYJhcpwnV4hK/6kzUQhwOsIpC5RWjJcq5ZAcW+ezZ8EiB1/mlO5O3HQ7 jZKvhk+43/eXQNkLg7Fg0YVLQa0RSSexlZeJSZjLFjf0UNCm+WrFmZfaEfxycfc+aRbCOL IhKIIruE46TN9ufxKWi+uoFY2BwxA8l1HXNqzBKUu9tiOl4QWtypZleR7lQfCYmQ0OqTkt J8fFwH8Sn5hSPrG2FnvIMWB+TZbgwd7tFJEgwEGjtmwHZTURgkfMNZ3I/eaZo1yqBpozNp CwGd+i/TonfFOzDGyvj6/XQyUT3rk6saDLKz/7luFzAI4pRtKfEO4W/LWnI6uA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697801869; 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=dmk5p82kG18c4EKbp8804yVk4HTTWAMOcj8cob+yyGs=; b=NCV0hOzjEifUhMbisDVQiWeonedUKhMtyBuDdjwPsFMj7WkqNjNvhEjJ8waUToNKzkRGPE xkq7BbEiRtmyTyBQ== 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: <169780186874.3135.2613425967401988698.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 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]); Fri, 20 Oct 2023 04:40:10 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779281153816422709 X-GMAIL-MSGID: 1780274563586295457 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: e1ce0eb22dc24da625fc59be2a382d133ddcf17f Gitweb: https://git.kernel.org/tip/e1ce0eb22dc24da625fc59be2a382d133ddcf17f Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 14:00:03 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 19 Oct 2023 15:59:08 +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