Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3421699rdg; Tue, 17 Oct 2023 14:26:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHRiGvfz9iQaIie+mY1AVgg8hgYS96jlF6x9/tPifGsC/Dssa0BZCjFoKHwB19bM95h10cF X-Received: by 2002:a17:903:6c4:b0:1c7:2f33:7ccd with SMTP id kj4-20020a17090306c400b001c72f337ccdmr2982153plb.33.1697577997653; Tue, 17 Oct 2023 14:26:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697577997; cv=none; d=google.com; s=arc-20160816; b=XHhBdkIh+JG6IcSmk3rvHZ0IkXe8APenSpcztVPcAzDrkup6r9OImHRwXdsfOHI3GQ bTnOfKjpdBnEYdcAwT0Y6clZlqPlIS2j7FPX1U1pfHsusx0RaoQClzNNjxWgch1VA7wc 8JmF0rFcgMIQI967COdUY2aUD4RHalmiHsnJDtNPUzcQTfEGsenWEse3dkYYnQrfkClN w1fUIGI5r8vrH+i/NuFdy09pkqaf0ptxChtDN3j2pdwwW6FFQk8XvqzVxlpJI8Hz87dm zv0bBj3EIh4e3R1p3NPQPDX2ZLjbCkjMGslpcZbSR2jhQ/WTEnangJg2FgMY2t6wTTaI HL0A== 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=1dgZfFCQy1fCsT2A7+aTGFWxyq9HxCOqu34JaoQN2i8=; fh=8iy+GLBXZdpcs/hIddJ7mbUapYjefwP9Gb111pAzFms=; b=oVKkHBM9U+I1Uw5uYE+NVTUXBPe1AIx4aI8T8FarNg4XA3tc+i5copKDXHF3MQAxhT 0N8nEA/QVbUgCj/gJW2hsv8rS6dQ3SEctqOWdQbVafjyiUk5+h2CB9nblJVlbaihWIpX YNyH7+tJisWTKCrThnVd9x/F6hZPycCAqPqUcMXEjiHgmPQil9Pn89jgYmgimvKeS5AM zHkU8c9wD1v1e9ILgv0pZoD/J8JnINctWiN2F+Pa5+O1SyA6XEcbX5f5nWIAUmHm+MMP nr75xbMIqj+D3xg0HqhZKIcG6tmciNKtFW8gMUS9wT8553opvG7ZSnE9lKJ9QJ6ewUAw RbOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=F0fcouqt; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+fAUrz66; 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 o2-20020a170902bcc200b001c9d7d70d7bsi2430371pls.4.2023.10.17.14.26.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 14:26:37 -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=F0fcouqt; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+fAUrz66; 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 4EDB480C8430; Tue, 17 Oct 2023 14:26:21 -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 S1344365AbjJQV0E (ORCPT + 99 others); Tue, 17 Oct 2023 17:26:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344341AbjJQVZT (ORCPT ); Tue, 17 Oct 2023 17:25:19 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22375125 for ; Tue, 17 Oct 2023 14:24:11 -0700 (PDT) Message-ID: <20231017211723.801060436@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697577849; 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=1dgZfFCQy1fCsT2A7+aTGFWxyq9HxCOqu34JaoQN2i8=; b=F0fcouqtvhw5TK5MccA+4303A21LGeZiPkIw3v/6NzCKhetM+MygQaku+nsX5FOLijB1xO nSzqXI6d7F3sAsSOhYzpqA2uCJvRucTG/udlG03+r6QnBWtW9cGu+An9f4Eey+Uhs2fC1x NvSw+b9DL2fKADWJ0fUSG8IQaZrSET76hTx07HrWJxE8LO5vC1jzqPwx+AF82/IIoWWQGG jO1eIidfTP/R92zoVh6dhDrdNj1RoC9qxyyYURXzv+7xOJn2QEEp+/frQJVZQmqdH7ws0Y D4Xu2EyZCRksXY/Z3+36NgucrBYSS5yOvikcGZ3AONeV7+rVQn5u+JtR4Ak8cw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697577849; 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=1dgZfFCQy1fCsT2A7+aTGFWxyq9HxCOqu34JaoQN2i8=; b=+fAUrz66BW4vQLt7ylctRn6mSAkuVtze16T6+r+Ju1+GpTLsv3CO26ykrUwXgan/88S6AM XDQ/wGDAxsZncpAg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov Subject: [patch V5 33/39] x86/microcode: Replace the all-in-one rendevous handler References: <20231017200758.877560658@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Tue, 17 Oct 2023 23:24:09 +0200 (CEST) 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]); Tue, 17 Oct 2023 14:26:21 -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 @@ -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_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; @@ -376,46 +376,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; } @@ -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