mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: linux-kernel@vger.kernel.org
Cc: x86@kernel.org, tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, kevin.shu@intel.com,
	chang.seok.bae@intel.com
Subject: [PATCH RFC v1 7/8] x86/microcode/intel: Support uniform scope for early loading
Date: Sat, 12 Sep 2026 00:08:13 +0000	[thread overview]
Message-ID: <20260912000815.997720-8-chang.seok.bae@intel.com> (raw)
In-Reply-To: <20260912000815.997720-1-chang.seok.bae@intel.com>

The parallel bringup facility queries whether the architecture provides a
custom set of primary CPUs. Extend x86 hooks with the Intel-specific
logic so that the primary CPU selection matches the uniform loading
scope.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
---
 arch/x86/kernel/cpu/microcode/core.c     |  9 +++
 arch/x86/kernel/cpu/microcode/intel.c    | 70 ++++++++++++++++++++++++
 arch/x86/kernel/cpu/microcode/internal.h |  4 ++
 3 files changed, 83 insertions(+)

diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index dfa311a2edbd..ed547f2b4601 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -906,14 +906,23 @@ static int mc_cpu_down_prep(unsigned int cpu)
 /*
  * Queried by the parallel bringup code to determine whether x86 provides a
  * custom primary CPU mask for early loading.
+ *
+ * Uniform loading scope is Intel-specific, so let the vendor code determine the
+ * primary CPU selection.
  */
 bool __init arch_cpuhp_primary_aware(void)
 {
+	if (x86_cpuid_vendor() == X86_VENDOR_INTEL)
+		return intel_primary_aware();
+
 	return __max_threads_per_core > 1;
 }
 
 const struct cpumask *__init arch_cpuhp_get_primary_cpus(void)
 {
+	if (x86_cpuid_vendor() == X86_VENDOR_INTEL)
+		return intel_get_primary_cpus();
+
 	return cpu_primary_thread_mask;
 }
 
diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
index 4b5feee14712..6178bddb7f60 100644
--- a/arch/x86/kernel/cpu/microcode/intel.c
+++ b/arch/x86/kernel/cpu/microcode/intel.c
@@ -989,6 +989,76 @@ static __init bool staging_available(void)
 	return !!(val & MCU_STAGING);
 }
 
+bool __init intel_primary_aware(void)
+{
+	if (!microcode_intel_ops.use_uniform)
+		return __max_threads_per_core > 1;
+
+	switch (microcode_intel_ops.uniform_scope) {
+	case UNIFORM_SYS:
+		/*
+		 * The boot CPU performs the update for the entire system. But,
+		 * returning false would fall back to the SMT primary mask.
+		 * Return true to indicate the primary CPU clearly.
+		 */
+		return true;
+	case UNIFORM_PKG:
+		/* One primary core per package participates. */
+		return true;
+	case UNIFORM_DEFAULT:
+	case UNIFORM_CORE:
+		/*
+		 * Fallback to the legacy per-core loading, where the primary
+		 * CPU distinction matters only when SMT is on.
+		 */
+		break;
+	default:
+		/* Unknown scopes fall back to the legacy per-core scope. */
+		WARN_ON_ONCE(1);
+	}
+
+	return __max_threads_per_core > 1;
+}
+
+static struct cpumask primary_cpus __initdata;
+
+static void __init set_primary_cpus(void)
+{
+	if (!microcode_intel_ops.use_uniform) {
+		cpumask_copy(&primary_cpus, cpu_primary_thread_mask);
+		return;
+	}
+
+	switch (microcode_intel_ops.uniform_scope) {
+	case UNIFORM_SYS:
+		/*
+		 * CPU0 is guaranteed to be online and acts as the system
+		 * primary.
+		 */
+		cpumask_set_cpu(0, &primary_cpus);
+		break;
+	case UNIFORM_PKG:
+		/* One CPU per package is sufficient. */
+		cpumask_and(&primary_cpus, cpu_primary_core_mask, cpu_primary_thread_mask);
+		break;
+	case UNIFORM_DEFAULT:
+	case UNIFORM_CORE:
+	default:
+		cpumask_copy(&primary_cpus, cpu_primary_thread_mask);
+	}
+}
+
+/*
+ * The bringup code may query the mask more than once. Compute it on first use.
+ */
+const struct cpumask *__init intel_get_primary_cpus(void)
+{
+	if (cpumask_empty(&primary_cpus))
+		set_primary_cpus();
+
+	return &primary_cpus;
+}
+
 struct microcode_ops * __init init_intel_microcode(void)
 {
 	struct cpuinfo_x86 *c = &boot_cpu_data;
diff --git a/arch/x86/kernel/cpu/microcode/internal.h b/arch/x86/kernel/cpu/microcode/internal.h
index 0a74794e0245..0552d66f4012 100644
--- a/arch/x86/kernel/cpu/microcode/internal.h
+++ b/arch/x86/kernel/cpu/microcode/internal.h
@@ -128,11 +128,15 @@ static inline void exit_amd_microcode(void) { }
 void load_ucode_intel_bsp(struct early_load_data *ed);
 void load_ucode_intel_ap(void);
 void reload_ucode_intel(void);
+bool intel_primary_aware(void);
+const struct cpumask *intel_get_primary_cpus(void);
 struct microcode_ops *init_intel_microcode(void);
 #else /* CONFIG_CPU_SUP_INTEL */
 static inline void load_ucode_intel_bsp(struct early_load_data *ed) { }
 static inline void load_ucode_intel_ap(void) { }
 static inline void reload_ucode_intel(void) { }
+static inline bool intel_primary_aware(void) { return false; }
+static inline const struct cpumask *intel_get_primary_cpus(void) { return cpu_none_mask; }
 static inline struct microcode_ops *init_intel_microcode(void) { return NULL; }
 #endif  /* !CONFIG_CPU_SUP_INTEL */
 
-- 
2.53.0


  parent reply	other threads:[~2026-09-12  0:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-12  0:08 [PATCH RFC v1 0/8] x86/microcode: Enable uniform feature Chang S. Bae
2026-09-12  0:08 ` [PATCH RFC v1 1/8] cpu/hotplug: Allow architecture-specific primary CPU bringup Chang S. Bae
2026-09-12  0:08 ` [PATCH RFC v1 2/8] x86/hotplug: Implement SMT-primary selection for parallel bringup Chang S. Bae
2026-09-12  0:08 ` [PATCH RFC v1 3/8] x86/cpu/topology: Introduce primary core mask Chang S. Bae
2026-09-12  0:08 ` [PATCH RFC v1 4/8] x86/microcode: Extend struct microcode_ops for uniform loading Chang S. Bae
2026-09-12  0:08 ` [PATCH RFC v1 5/8] x86/microcode: Clarify online enforcement with " Chang S. Bae
2026-09-12  0:08 ` [PATCH RFC v1 6/8] x86/microcode: Support uniform scope for late loading Chang S. Bae
2026-09-12  0:08 ` Chang S. Bae [this message]
2026-09-12  0:08 ` [PATCH RFC v1 8/8] x86/microcode/intel: Enable uniform loading Chang S. Bae
2026-09-16  0:45 ` [PATCH RFC v1 0/8] x86/microcode: Enable uniform feature Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260912000815.997720-8-chang.seok.bae@intel.com \
    --to=chang.seok.bae@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=kevin.shu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®