From patchwork Mon Oct 2 12:00:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 147521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1721524vqb; Mon, 2 Oct 2023 15:16:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEr+xXEfZmiD9bw0Sn8xoFbh7HeXwsOLk8kJg0vWgEqSqRdY7KBboCS+EU9EE+kYhWfzPiF X-Received: by 2002:a05:6a20:9746:b0:157:609f:6057 with SMTP id hs6-20020a056a20974600b00157609f6057mr10373997pzc.27.1696284966811; Mon, 02 Oct 2023 15:16:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696284966; cv=none; d=google.com; s=arc-20160816; b=JYDHtd6cR3hTPXuhIe1EUIi1GSM9fxM5aEcOE8GG7jAP7FgopPUqL4KSrc6FKcEp2I Fcq+W7BRmERjptjwWFI5TENsVMkvK7pdjOer3YsuiI0ivOXtrapdLixbJ/JjqpHWej+9 B4qQZ1h0blB8AzFHwm9/SznzECFnX2IwxIBTRdZ5AL8X7DxKN7ho7LjiqMzUUJXndcQ5 PwsJKBvjP3fGE+3BX9CpfuGpDvHmSVaV4G3NnXMucbmuQ/JQzhoGkXqQETyprPMbdw7I Kynrp0QTHJzsTonxuPr/xm8gK7Lwtju5h6LaWY+zYhMzzBjheK89gPFvWUNSC3QvWeFA 9UKw== 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=wKKYiTE48a7OwEb1vlvH36sR8XqCrTrFsE1Q8U0VLR4=; fh=u57tXYamzTrJA+Ht8n1u7SfTMptrQaIb6LVW+jsaYf4=; b=xvxp7XzDo7H7j1Gb+Sqn9HgC5kY0h9o3arg8bAhT6bvmE76zZq40JIxIkStElqL4NI JtsmBnI2aymaj0ZbGpxl1JEpouciHXehLdRVL6pnrzRq0PpepUa4oVGmJ+eqwNNX/enq Cqg1q08LcHw5djH/FGCukC13dNYR9fYqRNNeSfkxrzhHUVvif5EU1kXDGt1l6IRkmx2E F8qtwBaJhxZh2tQ6vWky3Xz8VGHTash/uemjm6VJ+0YjrO3573CI/ugK/oukdGQwM5Ui 9PHYab5Plyl+TW2Cw0i67KUW/SM2VrbmvRQvomjylRFUwiLdFqqzc7ms9pDSN67qAghf 3W4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IVjvQ16M; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=uWCOZ98b; 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 n13-20020a65488d000000b005777bea0b6asi27881278pgs.859.2023.10.02.15.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 15:16:06 -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=IVjvQ16M; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=uWCOZ98b; 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 A053781121D2; Mon, 2 Oct 2023 05:01:18 -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 S236999AbjJBMAv (ORCPT + 18 others); Mon, 2 Oct 2023 08:00:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236940AbjJBMAZ (ORCPT ); Mon, 2 Oct 2023 08:00:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19230CEB for ; Mon, 2 Oct 2023 05:00:03 -0700 (PDT) Message-ID: <20231002115903.319959519@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696248001; 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=wKKYiTE48a7OwEb1vlvH36sR8XqCrTrFsE1Q8U0VLR4=; b=IVjvQ16MNF8vUmza7Z3GeGDYlgJISJ9FX/IDbArQLQzy3j6fdQYZ8G1WU0FfAxbvG8zBBx XhYXx/fInBVJlcbFJYYWzTdkOYxzjaLOvBuLpPiG9/MNp7bqD+/2d5tb6oyPSWBmFyr+pP wolg9Y0/s/X+HdgAAJmIabFicBeHa2+zYoZBy0OUiWfpjnWQh44aJWK8OQl8sfvI9qNlXq a1wqW97jx2hkMyr9/Xf6yNY1jECuouiPlxFZEtYSwUDewuz84U5Xvz+6G1h9B8YVYQsWoC DmrETpReNvQgVtJfIIog0etQL35Lv4a3/MQTZYui4I8PolBE12nHUlu3N6YpTg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696248001; 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=wKKYiTE48a7OwEb1vlvH36sR8XqCrTrFsE1Q8U0VLR4=; b=uWCOZ98b8YS9Caz23vxnKKM0cXrwnhmjFwplYnzlXCKqxlPGM8/Tt4XKskQF9qr4xl3eRQ dXk9/uNpTNGvVNDw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov , "Chang S. Bae" , Arjan van de Ven , Nikolay Borisov Subject: [patch V4 22/30] x86/microcode: Add per CPU control field References: <20231002115506.217091296@linutronix.de> MIME-Version: 1.0 Date: Mon, 2 Oct 2023 14:00:01 +0200 (CEST) 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, 02 Oct 2023 05:01:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778683705325153100 X-GMAIL-MSGID: 1778683705325153100 From: Thomas Gleixner Add a per CPU control field to ucode_ctrl and define constants for it which are going to be used to control the loading state machine. In theory this could be a global control field, but a global control does not cover the following case: 15 primary CPUs load microcode successfully 1 primary CPU fails and returns with an error code With global control the sibling of the failed CPU would either try again or the whole operation would be aborted with the consequence that the 15 siblings do not invoke the apply path and end up with inconsistent software state. The result in dmesg would be inconsistent too. There are two additional fields added and initialized: ctrl_cpu and secondaries. ctrl_cpu is the CPU number of the primary thread for now, but with the upcoming uniform loading at package or system scope this will be one CPU per package or just one CPU. Secondaries hands the control CPU a CPU mask which will be required to release the secondary CPUs out of the wait loop. Preparatory change for implementing a properly split control flow for primary and secondary CPUs. Signed-off-by: Thomas Gleixner --- V4: Simplify control CPU selection --- arch/x86/kernel/cpu/microcode/core.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) --- --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -281,8 +281,19 @@ static struct platform_device *microcode * requirement can be relaxed in the future. Right now, this is conservative * and good. */ +enum sibling_ctrl { + /* Spinwait with timeout */ + SCTRL_WAIT, + /* Invoke the microcode_apply() callback */ + SCTRL_APPLY, + /* Proceed without invoking the microcode_apply() callback */ + SCTRL_DONE, +}; + struct microcode_ctrl { + enum sibling_ctrl ctrl; enum ucode_state result; + unsigned int ctrl_cpu; }; static DEFINE_PER_CPU(struct microcode_ctrl, ucode_ctrl); @@ -427,7 +438,7 @@ static int load_late_stop_cpus(void) */ static bool setup_cpus(void) { - struct microcode_ctrl ctrl = { .result = -1, }; + struct microcode_ctrl ctrl = { .ctrl = SCTRL_WAIT, .result = -1, }; unsigned int cpu; for_each_cpu_and(cpu, cpu_present_mask, &cpus_booted_once_mask) { @@ -437,7 +448,12 @@ static bool setup_cpus(void) return false; } } - /* Initialize the per CPU state */ + + /* + * Initialize the per CPU state. This is core scope for now, + * but prepared to take package or system scope into account. + */ + ctrl.ctrl_cpu = cpumask_first(topology_sibling_cpumask(cpu)); per_cpu(ucode_ctrl, cpu) = ctrl; } return true;