From patchwork Tue Sep 12 07:58:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 138646 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp863301vqx; Tue, 12 Sep 2023 22:20:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjdu5tF+cze21xB7kPJADS1AgMMiur11vdpYUq9H7mJrgrkw9FLXwpdD0od3MsMvIaLK7t X-Received: by 2002:a05:6358:98a7:b0:13e:ea2a:40aa with SMTP id q39-20020a05635898a700b0013eea2a40aamr1861181rwa.8.1694582415348; Tue, 12 Sep 2023 22:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694582415; cv=none; d=google.com; s=arc-20160816; b=gzGVn1QIpQjaBkcnI0FD+vJng6oVFMtskkqktTVv7rw4qIkW+Pk7g3oTn1KOpZxi+r fN0p62y0ijOTAsgj+skLTk4Lt8K5ImxGfQCA+XYyPcylY15BlbFp28eT98Ik6dYQ8esd 1+q8+aBXfGzT0dxVFroHadsLxsyAugEWVieBR3bKIsd+xRlD7yGY+v7PnrWDiOocs71/ ZNqfjRUkwzwrd/TPapmFFKxvcRxOBCDuuQ9WO2OowtLBLM0mf7MKV7SejuEZi6k2nCP8 RMjFPkC+MeE1HSfipi+SyE7yIS0rP8lqltcEbfwuvaebw2WdURmRKAAbrb1eQkJcbBf4 0qtQ== 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=tBiZyVFg2RByesw9s33ESky6BK8jMzTV8d/B5WDIvI8=; fh=u57tXYamzTrJA+Ht8n1u7SfTMptrQaIb6LVW+jsaYf4=; b=FwYT/DPEpOxLASTVQF+n+iA2+iy7Y8qkeYr/uOP7qZQHcNSG0tVji9H+76xdDic9va FovGAvl2BGoiqN11LpFQUf/EXUSNZuj4YvmDux1Hm6RjCZjioue8xmQEBYINez4gbkSj Dg9AvnlhkenWyoP3Hcl1y6NmJUEuYAOrC++34VC2bvzA8AMEOWxGlvCanuPU1ML/S+KE rABaNdRMMKI892sBcCVVAG+etXNY1oEk+PH20XglIf0z9Sn21uiiKmUi0gdzlyZFe0sZ g5OBqae/Cgmvt8W+FmUH+mQuRntjao/0qTO5begkpSkdOxKY99v2VbtwRMXzAxkPWc6b jc1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZZG7THSJ; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id s17-20020a056a00195100b0068c0300a3f7si9397423pfk.279.2023.09.12.22.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 22:20:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZZG7THSJ; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 81564851B9FE; Tue, 12 Sep 2023 01:00:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232040AbjILIAj (ORCPT + 39 others); Tue, 12 Sep 2023 04:00:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232220AbjILH7P (ORCPT ); Tue, 12 Sep 2023 03:59:15 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C9142701 for ; Tue, 12 Sep 2023 00:58:23 -0700 (PDT) Message-ID: <20230912065502.265405353@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694505502; 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=tBiZyVFg2RByesw9s33ESky6BK8jMzTV8d/B5WDIvI8=; b=ZZG7THSJj1FSt3wSuX5xQNdGvOs2Cwn2089apJGMssuXfq1xxC47x5KnycQ14WAZUlpObq LG5K2NafGw0BeRifHaJcCodesPMLMGynYR4o4236a2UaIW9VnDPAq01dgYkzt5RLBTVY2N 5gBcFasCpmB8jV/tWJlSr+yHG4puA3xZanxYvLiykuIriKgKb3P+COP0Ty2ZKWiN3hbRCu 3U5uwZb5B7hTJOUsMfXAVcg8fgkHy63KICgOoeOQQtNitjngK5j15G+ejJbP3dRxoXM0o6 PZeAUb1OQ+RESWgmxzLAsZdaGMkbZkWJzI0uXO2fskyM3sEBJgr48qE3Ki3+Kg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694505502; 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=tBiZyVFg2RByesw9s33ESky6BK8jMzTV8d/B5WDIvI8=; b=V/LNYjqIkgOictOpkJfjKYzl3XBC7Nbi3r6Hl6Hajb8CDdxUNdn5x2wQuVSDeT7swWQP5E KEHjxvrP2sdVZGCA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov , "Chang S. Bae" , Arjan van de Ven , Nikolay Borisov Subject: [patch V3 24/30] x86/microcode: Replace the all in one rendevouz handler References: <20230912065249.695681286@linutronix.de> MIME-Version: 1.0 Date: Tue, 12 Sep 2023 09:58:21 +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 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 01:00:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776898450532169233 X-GMAIL-MSGID: 1776898450532169233 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 @@ -337,7 +337,7 @@ struct ucode_ctrl { }; static DEFINE_PER_CPU(struct ucode_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) { @@ -371,7 +371,7 @@ static bool wait_for_ctrl(void) return false; } -static __maybe_unused void ucode_load_secondary(unsigned int cpu) +static void ucode_load_secondary(unsigned int cpu) { unsigned int ctrl_cpu = this_cpu_read(ucode_ctrl.ctrl_cpu); enum ucode_state ret; @@ -407,7 +407,7 @@ static __maybe_unused void ucode_load_se this_cpu_write(ucode_ctrl.ctrl, SCTRL_DONE); } -static __maybe_unused void ucode_load_primary(unsigned int cpu) +static void ucode_load_primary(unsigned int cpu) { struct cpumask *secondaries = topology_sibling_cpumask(cpu); enum sibling_ctrl ctrl; @@ -445,46 +445,14 @@ static __maybe_unused void ucode_load_pr static int ucode_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) + ucode_load_primary(cpu); + else + ucode_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; } @@ -498,7 +466,6 @@ static int ucode_load_late_stop_cpus(voi 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