Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2465502rdb; Tue, 12 Sep 2023 02:46:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5lNzOzv2+Z0FUxEWmBjfe3VwCAPmiQ8QVzRqwFzbHneU3uEClApnHgk9uNvwaENfJ/d9b X-Received: by 2002:a05:6a20:3d2a:b0:14c:7b3:9ac6 with SMTP id y42-20020a056a203d2a00b0014c07b39ac6mr15558271pzi.41.1694512000265; Tue, 12 Sep 2023 02:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694512000; cv=none; d=google.com; s=arc-20160816; b=EVqlNvAxkKqnSdQrajVXnN2IHUgvtdWnkhFosKvTXpQZ7136X4WOmNVEAGMgBNETI3 c5+5bslQLgLuA9o2SNQRtB6nLoQ0GEz9Vhgt3RDk+gYmaiZXWQEqUlL02y1FOh5Xjp1l iVoUS1xAiw1wasz7DAf4v0CdkFw+TMdARQdBKtiP7xFi7P4cO6Af5doQUO8CoNNLQ5hC zN2nv6VOAb4kc6/hPpbI27JF7K/O14Cpvb2apCcYh+8d1dt3DnrjNmDGkoy1vnDC3ADC dk0Kpd5fIFmtg7TPvzg76t0ZirX77VBC2fG6yy+WlKFnpZRbHjOED+teZNGrdPFw1vGF GoJQ== 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=u57tXYamzTrJA+Ht8n1u7SfTMptrQaIb6LVW+jsaYf4=; b=k5XEl/qTtIIPwJe9gsZoXoGo8wmLHl1nwTQY4mClJ+B3NAQdWtXj0iUjf1eFg46W+g IXzC6Y0lWcT/5g6XCtaalzHsNi9FnPvljOVIEs+UkvWXGJAKr0YE+Cjqtqd3mUALCpVO yKMSp9q0Ami1yk0XJEik5RHWZucM+ZP6WFh+9fIM9pFhlO+qmmcF+VxbUyeTcMIWWczg Zu2Zc/ZKf7sCuzon4gKtb8iWtGsdQfeOYk/nv42RmKTWDCvRET016F9saO7e6TB1CydV pv1JjyJ4ixKhd/17O2P2Kv9etF4mM2yKNdz+nbnj8lMA5j5zOKi18D6Vs+1sSx8qhEog prZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SWeVI0WK; 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 Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id eb10-20020a056a004c8a00b0068fb75d68dcsi4419790pfb.206.2023.09.12.02.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 02:46:40 -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=SWeVI0WK; 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 B9F9281972DC; Tue, 12 Sep 2023 01:01:23 -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 S232211AbjILIAa (ORCPT + 99 others); Tue, 12 Sep 2023 04:00:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232075AbjILH7I (ORCPT ); Tue, 12 Sep 2023 03:59:08 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7655269E for ; Tue, 12 Sep 2023 00:58:20 -0700 (PDT) Message-ID: <20230912065502.143157215@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694505499; 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=SWeVI0WK8cMrRFB6TR1C+N3NwUVDWm5AVEvmrYmAlTtkOxeZsnexP4ezkMSAciU+eNl3ar v5bKyHND27TzTXabykHUbt2rFrl1Zo6AT9zJHn08MumRY6bP37ei3vUtrp9g9sALQdTEUI JzUDN+lx6PWoDxGZQTym/+yI8uMx++rnqoV5oxW8zmJ1CWTij03I+2fMjFvCKUHbykNKH3 GGF9aE6AvMPqajGwRpdjcEMXECHz2wuZRpoRrlPpBmqBlf2B/pePmS/N/G82Eakr6AWwGW N1XxvNwGWLowdh/b2Lwh6RFhYEr5wbzpxVG5frq1dsD1kzaXv6CvBSYzMT1lRA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694505499; 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=4O+bGAnHVHvrD+IwSwWv138yd9cTQPjIWL+EY3XqskIPxyDIl4ucC4C57Zb4vI4Jeij/u4 j4YCHTvq+ybbyqDA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Borislav Petkov , "Chang S. Bae" , Arjan van de Ven , Nikolay Borisov Subject: [patch V3 22/30] x86/microcode: Add per CPU control field References: <20230912065249.695681286@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Tue, 12 Sep 2023 09:58:18 +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 (lipwig.vger.email [0.0.0.0]); Tue, 12 Sep 2023 01:01:23 -0700 (PDT) X-Spam-Status: No, score=-0.9 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 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;