Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1727660rdg; Sat, 12 Aug 2023 13:46:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjTX+vhNrqAEMDjEpxo84CAWKFQyfCkh3mvYswR8QL80pIVHA6lrBPQdbrzBsCJXxHqKLW X-Received: by 2002:a05:6a00:22c8:b0:687:5c3f:d834 with SMTP id f8-20020a056a0022c800b006875c3fd834mr7407556pfj.11.1691873205769; Sat, 12 Aug 2023 13:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691873205; cv=none; d=google.com; s=arc-20160816; b=LSsNpvzmVBZob2kHnQKLXC8TjwzbFKq+bQOG2r5VKwXOz0sAbsQaSq06vDxNLdREuv MPNWH0UzPxbsTvmBbfrsA+qynXnqWQeySRPghL0CiDiCl7FhcbqgUSGV+LKtJJ4C9snd uHsw5ngAEJNIKh7ORzRHgfTm+VixZRkH8+KEA21mEaoDfIDqHDVJI31VSAGHEN0OnwGU DYMdKsW81SdOE4O3tkSutMRQeAu8Jr2C/2CTMbsqgKnHF2BN8X5OtV4cmefRiY1Zkfn1 nb7d7yHNcIIRMe6uTRsa5cG0tEGwXb8txn8+0mra4YkrqHMjvNUZjaf4357W5ZRiy2pe 9Kuw== 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=gvgWHgk38J3qGADoq/3qmkZUlBXc3nLuAkYAzeigZSY=; fh=yVae3u0BRTnDkPuniOcxLkA1wgvMDfOA8XxNsc4ELm4=; b=qHU8gg0WtqNO8HV8IC4GCRcAj4hyS54wDIwNb83JWAGdxoaBIDx/fWIaV5uhXTbRmd IzYTO5x5tRup+5q82r0Z+PRCav+nUXd2rtwo3WCT9meDI8ryLx+J/iJsgR0tVc6QRk66 cPEsnvF/yvN1UHYNZVN8/JhEl9XC9mph3Zj/r2YL1X1nJ5pTEPrFA+A399v0MNRKL/nU Ja9OKIFehStZeiNVGAvXALaBYrjRNlrfO8NABQ046GKQxN36B3WOleF28wbNwxpZnMqB 2PX+n+A4WwwzLft4P7+KVd7SVBkP2LQif+Iam1NAq2xM1A4eI+3Ef04pDVScEvx/HVch H8KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rEREPJTL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=T3qOkHsS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ca26-20020a056a00419a00b006874ec495c5si5477484pfb.173.2023.08.12.13.46.34; Sat, 12 Aug 2023 13:46:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rEREPJTL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=T3qOkHsS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230498AbjHLUCo (ORCPT + 99 others); Sat, 12 Aug 2023 16:02:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230523AbjHLUCn (ORCPT ); Sat, 12 Aug 2023 16:02:43 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 774151FF0 for ; Sat, 12 Aug 2023 13:02:22 -0700 (PDT) Message-ID: <20230812195729.208217580@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691870362; 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=gvgWHgk38J3qGADoq/3qmkZUlBXc3nLuAkYAzeigZSY=; b=rEREPJTL2JY65mizGjNaXmxaCdpAVvnHqW94RU4XCS0ICFRcq0oklA7JVOm5yVG4riYAI9 DRYNMbN3huOlj/3PK/SGOyNDP9H71qbal0V1FujKMDSoA2wHm0WS6zFbSP3TuOlvNyVRSQ 68fNNzr2TR9homzZwVyCigO+igRc8igviIlbO9+b1YiadedBxACCBbetuBs7Cmz1bh4SNT 2oGdqo2jS3dLf9FLdwcz6REX/rS9grRnYEhRMDKgpYug+Yn7ICzj7/Ak1uDvTTjn62v/nP VBZ3Aqnw5jK8wxJTzvxKGh6GPFTorXnEiWhPMo6RK+Gd12/cIVjjk30ZDvBRtA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691870362; 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=gvgWHgk38J3qGADoq/3qmkZUlBXc3nLuAkYAzeigZSY=; b=T3qOkHsSABt5D295p3mTi3l39wGkUzJR1z/+oERTRGS2SWiXuM6otvUK0G6uXXT7bXAV1K zAxBV9JB2065CmBA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov , Ashok Raj , Arjan van de Ven , Nikolay Borisov Subject: [patch V2 29/37] x86/microcode: Add per CPU control field References: <20230812194003.682298127@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Sat, 12 Aug 2023 21:59:21 +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,URIBL_BLOCKED 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 From: Thomas Gleixner Add a per CPU control field to ucode_ctrl and define constants for it: SCTRL_WAIT indicates that the CPU needs to spinwait with timeout SCTRL_APPLY indicates that the CPU needs to invoke the microcode_apply() callback SCTRL_DONE indicates that the CPU can proceed without invoking the microcode_apply() callback. 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 --- 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 @@ -324,8 +324,16 @@ static struct platform_device *microcode * requirement can be relaxed in the future. Right now, this is conservative * and good. */ +enum sibling_ctrl { + SCTRL_WAIT, + SCTRL_APPLY, + SCTRL_DONE, +}; + struct ucode_ctrl { + enum sibling_ctrl ctrl; enum ucode_state result; + unsigned int ctrl_cpu; }; static DEFINE_PER_CPU(struct ucode_ctrl, ucode_ctrl); @@ -468,7 +476,7 @@ static int ucode_load_late_stop_cpus(voi */ static bool ucode_setup_cpus(void) { - struct ucode_ctrl ctrl = { .result = -1, }; + struct ucode_ctrl ctrl = { .ctrl = SCTRL_WAIT, .result = -1, }; unsigned int cpu; for_each_cpu_and(cpu, cpu_present_mask, &cpus_booted_once_mask) { @@ -478,7 +486,15 @@ static bool ucode_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. + */ + if (topology_is_primary_thread(cpu)) + ctrl.ctrl_cpu = cpu; + else + ctrl.ctrl_cpu = cpumask_first(topology_sibling_cpumask(cpu)); per_cpu(ucode_ctrl, cpu) = ctrl; } return true;