From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17A8641324F for ; Fri, 27 Feb 2026 14:06:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772201190; cv=none; b=Ati1hTLkZsI8YgRz1gKfUKDFIjUAfjWpw7vNnaF1BfNLx+wyAqS1amXWARnCVaRRqAFxdXc4TI7chYkKUEVwRj0vmlbSDiRxztYB8EatcQDMS7CJbaXOFGcANLyzp9aJ0DRNz9ZImMOzesEsHAsYNY45+Segqb/GoMWJwiTKoe0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772201190; c=relaxed/simple; bh=vDOoSY+0LCo7teZUbeOVQ5l5M9pni6kqKoM0Wu7yh2s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kw2bq1KuEfOugWjB+OkMYA8Sl0wMeZN0nBdD7z/Uixhf5vFIwsmgJFbmSQr581ktkjJs+oGoe2vM6kP+Mc6G8jcmthBODcqOxw1v/3pZDOcMzVmjHiNnMYnolY701/JFAsHUNVwq3A4MaQP2Ak5qGAE8m0AFgW/JXNxihH+rcgA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=sBQcP1lE; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="sBQcP1lE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ado4TESwtK0mqwPsXJWPaf4dkjlvBGNzNgtTID9dRDE=; b=sBQcP1lE3EB4A8G/T+ZoPHO+4V lGrnx9Be03zVC+wvCv/mpIXjSUmIy5ZuRc23sF4zxs94EzTiWbmHcjrGKAFU/l1MbBDELyCcFxRX6 qMYQ/9PmalMhwG/tZD/RdVj0RjSo38urqoe6FGJSdjGTbUE4PbfD1floecOQdKD7E2iWhgN/IR2eO OE9nkIjfHqyNm5MdzNYWV/5ZF2SlwlsnTQGcVkwx9qx/vTS9nA8YxsG6mQHFzc0R/URwlv1V6p6Hh zpSTUYl7JxX+AI5vnpnTLsA0bvDFwcqesS0ICw5K+LOvh/ehWdPr1wzyGRhcrSHsPiYNdOBYDSVKZ l/LcAsQA==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vvyU0-00000004fod-1t8i; Fri, 27 Feb 2026 14:06:20 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 60E2B300CDE; Fri, 27 Feb 2026 15:06:14 +0100 (CET) Date: Fri, 27 Feb 2026 15:06:14 +0100 From: Peter Zijlstra To: K Prateek Nayak Cc: x86@kernel.org, tglx@kernel.org, linux-kernel@vger.kernel.org, tim.c.chen@linux.intel.com, yu.c.chen@intel.com, kyle.meyer@hpe.com, vinicius.gomes@intel.com, brgerst@gmail.com, hpa@zytor.com, patryk.wlazlyn@linux.intel.com, rafael.j.wysocki@intel.com, russ.anderson@hpe.com, zhao1.liu@intel.com, tony.luck@intel.com Subject: Re: [RFC][PATCH 2/6] x86/topo: Add TOPO_NUMA_DOMAIN Message-ID: <20260227140614.GF1282955@noisy.programming.kicks-ass.net> References: <20260226104909.675623579@infradead.org> <20260226105052.355756378@infradead.org> <76776da9-2552-49de-91c7-41e767c248fa@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <76776da9-2552-49de-91c7-41e767c248fa@amd.com> On Fri, Feb 27, 2026 at 06:49:36PM +0530, K Prateek Nayak wrote: > Hello Peter, > > On 2/26/2026 4:19 PM, Peter Zijlstra wrote: > > @@ -88,6 +89,14 @@ static inline u32 topo_apicid(u32 apicid > > { > > if (dom == TOPO_SMT_DOMAIN) > > return apicid; > > +#ifdef CONFIG_NUMA > > + if (dom == TOPO_NUMA_DOMAIN) { > > + int nid = __apicid_to_phys_node[apicid]; > > + if (nid == NUMA_NO_NODE) > > + nid = 0; > > + return nid; > > + } > > +#endif > > I'm not digging this override - simply because topo_apicid() was not > meant to handle these kinds of cases where we cannot derive a topology > ID by simply shifting and masking the APICID. > > Looking at the series, all we need is an equivalent of: > > domain_weight(TOPO_NUMA_DOMAIN) Fair enough; but then lets replace patch 1 and 2 with something like that. But I must note that the nodemask API is crap; it has both node_set() and __node_set() be the atomic version :-( Let me go rework the other patches to fit on this. --- diff --git a/arch/x86/include/asm/numa.h b/arch/x86/include/asm/numa.h index 53ba39ce010c..a9063f332fa6 100644 --- a/arch/x86/include/asm/numa.h +++ b/arch/x86/include/asm/numa.h @@ -22,6 +22,7 @@ extern int numa_off; */ extern s16 __apicid_to_node[MAX_LOCAL_APIC]; extern nodemask_t numa_nodes_parsed __initdata; +extern nodemask_t numa_phys_nodes_parsed __initdata; static inline void set_apicid_to_node(int apicid, s16 node) { @@ -48,6 +49,7 @@ extern void __init init_cpu_to_node(void); extern void numa_add_cpu(unsigned int cpu); extern void numa_remove_cpu(unsigned int cpu); extern void init_gi_nodes(void); +extern int num_phys_nodes(void); #else /* CONFIG_NUMA */ static inline void numa_set_node(int cpu, int node) { } static inline void numa_clear_node(int cpu) { } @@ -55,6 +57,10 @@ static inline void init_cpu_to_node(void) { } static inline void numa_add_cpu(unsigned int cpu) { } static inline void numa_remove_cpu(unsigned int cpu) { } static inline void init_gi_nodes(void) { } +static inline int num_phys_nodes(void) +{ + return 1; +} #endif /* CONFIG_NUMA */ #ifdef CONFIG_DEBUG_PER_CPU_MAPS diff --git a/arch/x86/kernel/cpu/topology.c b/arch/x86/kernel/cpu/topology.c index 23190a786d31..bfcd33127789 100644 --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "cpu.h" diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c index 7a97327140df..99d0a9332c14 100644 --- a/arch/x86/mm/numa.c +++ b/arch/x86/mm/numa.c @@ -48,6 +48,8 @@ s16 __apicid_to_node[MAX_LOCAL_APIC] = { [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE }; +nodemask_t numa_phys_nodes_parsed __initdata; + int numa_cpu_node(int cpu) { u32 apicid = early_per_cpu(x86_cpu_to_apicid, cpu); @@ -57,6 +59,11 @@ int numa_cpu_node(int cpu) return NUMA_NO_NODE; } +int __init num_phys_nodes(void) +{ + return bitmap_weight(numa_phys_nodes_parsed.bits, MAX_NUMNODES); +} + cpumask_var_t node_to_cpumask_map[MAX_NUMNODES]; EXPORT_SYMBOL(node_to_cpumask_map); @@ -210,6 +217,7 @@ static int __init dummy_numa_init(void) 0LLU, PFN_PHYS(max_pfn) - 1); node_set(0, numa_nodes_parsed); + node_set(0, numa_phys_nodes_parsed); numa_add_memblk(0, 0, PFN_PHYS(max_pfn)); return 0; diff --git a/arch/x86/mm/srat.c b/arch/x86/mm/srat.c index 6f8e0f21c710..44ca66651756 100644 --- a/arch/x86/mm/srat.c +++ b/arch/x86/mm/srat.c @@ -57,6 +57,7 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa) } set_apicid_to_node(apic_id, node); node_set(node, numa_nodes_parsed); + node_set(node, numa_phys_nodes_parsed); pr_debug("SRAT: PXM %u -> APIC 0x%04x -> Node %u\n", pxm, apic_id, node); } @@ -97,6 +98,7 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) set_apicid_to_node(apic_id, node); node_set(node, numa_nodes_parsed); + node_set(node, numa_phys_nodes_parsed); pr_debug("SRAT: PXM %u -> APIC 0x%02x -> Node %u\n", pxm, apic_id, node); }