From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011042.outbound.protection.outlook.com [40.107.208.42]) (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 691E88462 for ; Fri, 27 Feb 2026 13:19:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.42 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772198396; cv=fail; b=L+BVoRrNvEzKzFHAYIahDF7Xj4SCslasL3ClEGM98zJF33x4IXL2qZSNrTedbITuRyd05G/lM4OWamgIK2oRg8e1UApnGnqklt2yURzD9trtAXdGMXfyvihtqV58MxIgZ9VKvkwuyb8XR8lDUxm0GhowZd3W0JqBKXLlPLOeF9s= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772198396; c=relaxed/simple; bh=mkJcyb7TeOx2AQ6p5/5c5ABuSRlM/lQWU3UbxPpiXGQ=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=ZPGigHEfszuibvnAB+qIqnURPXIbLvugw2G5Js14WeCB5k/aWCzKc4+latRfnsqYfeZFUaU5HDZNkrXb9NB3Cd2Wjn7gkEhKivmsVJJm+cAHHCG+1NKX7gGEdZ75xG2L5LGxAwgyXuXcl9pSWNffv+jb0q4nWbcDDEZ0NaES/70= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=fyf4aItk; arc=fail smtp.client-ip=40.107.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="fyf4aItk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YZzHSMy5g+RdSA8NzwVm7O/g5AIXJlQCr92/iOA3gmLvj4cuVFzTTN7w+XL768I5YYiNJ8BrTeys4EsZmbjaAZN0Aa5VAcXn71MoFsRnWvNE4so/UWM4MbjnRQW/LjjeGIyg1ntvvOg5tzX0Z2TGFJS02IOzep/wQkdjUw0EZsOtg/wbBRnetYYx0K1/Qtj4Xt4PKjVCew8c/7xA9ndH+xL2s8hK3VUZTJax/e9LYz840Nkebpl7in/e6wmP9MHzP33wS2KqT/1CtsfGSTIt7tVDTwgEyBiaMtol5yiWYjXic7VBCbk7nfxmNob7BtNClRCEpnkCgQDFacDoXzdZVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xUQav/jx9m4bHzs4EilPkpUZgCEmjyrryR0ihzO9M38=; b=G7KOZg5gKjtXNn5fRqleAC9ti1bhMrAX2uC8+S/jqq/hvPo0b4BpOriC7lYGLUYBwdmRoQ0RMDcL7uk76nZ/CxpnxxirqAMUhHAcJo4frHqO08DndqQyU9D0LaHNvkbUcgNc6BrgtvbBC53CWoAZAnztQbZYLPmkK3x8bCyQQGN1AMXljFTNx5gA5lYMLnjzR8Zt72ElBbu/p66L8UigH3pUKIjWSUKI6G/HvA66ygKugREpTdksKSnGIpD15/BV6ahx6D9cPJmWRSlOeJycMq+0qUYaEtCEMxOZ7ZQFdb9Kyg43MjB1wAeSPBFHWlBY5hyl7VxAK7b4CmnAmrNYfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xUQav/jx9m4bHzs4EilPkpUZgCEmjyrryR0ihzO9M38=; b=fyf4aItkhGgR1+s4BXt1OQtQ61Ics9k2EfE2vPJq8MYKgEeVkW7VoZ1Eo7vbeB69apABoS0P4fGuHaBDZs5bsCBZJZk3bry+awPMLtxqHxGVxYHqxMpQZSlfLPkCQZqB4FiBeH3MR2iEjJFyO8yKuLF00nRpXLFpGODxGS1ueqw= Received: from BL1PR13CA0332.namprd13.prod.outlook.com (2603:10b6:208:2c6::7) by CH3PR12MB7619.namprd12.prod.outlook.com (2603:10b6:610:14b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.15; Fri, 27 Feb 2026 13:19:50 +0000 Received: from BL02EPF0001A100.namprd03.prod.outlook.com (2603:10b6:208:2c6:cafe::15) by BL1PR13CA0332.outlook.office365.com (2603:10b6:208:2c6::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9654.14 via Frontend Transport; Fri, 27 Feb 2026 13:19:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BL02EPF0001A100.mail.protection.outlook.com (10.167.242.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.16 via Frontend Transport; Fri, 27 Feb 2026 13:19:50 +0000 Received: from Satlexmb09.amd.com (10.181.42.218) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Fri, 27 Feb 2026 07:19:48 -0600 Received: from satlexmb07.amd.com (10.181.42.216) by satlexmb09.amd.com (10.181.42.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Fri, 27 Feb 2026 05:19:48 -0800 Received: from [172.31.184.125] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Fri, 27 Feb 2026 07:19:42 -0600 Message-ID: <76776da9-2552-49de-91c7-41e767c248fa@amd.com> Date: Fri, 27 Feb 2026 18:49:36 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC][PATCH 2/6] x86/topo: Add TOPO_NUMA_DOMAIN To: Peter Zijlstra , , CC: , , , , , , , , , , , References: <20260226104909.675623579@infradead.org> <20260226105052.355756378@infradead.org> Content-Language: en-US From: K Prateek Nayak In-Reply-To: <20260226105052.355756378@infradead.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A100:EE_|CH3PR12MB7619:EE_ X-MS-Office365-Filtering-Correlation-Id: 63a087eb-6ea4-4c9d-cd76-08de7602e2f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: h1kqn9xWyU5jrybUzBdxb6I5mXZk36fzLvQIU+8u2LX1+LFCKmT2DkGnaipkB4ln+MA3c8qfJCighECGqLZaUuklJtFxVxUlNFKGSXOz3dZ1Tgrhd4ZMm77YZBhfr7p+qqbYCBOqJN4U87ssIbWizEq0flEQ5bDCDZnEL2fmLPVmTizHAQ9+78dTVXZV00jkqrrnYx1PB0dybwBob2unhM5PTEjkc5Dz5SwaplJ+6pRLoXlRuIFCEyBNX3+X+skCtwISOdLRyJ2C2WTFIdGU+09qFw7ksX7TxOWHT3fG/8TF+wMyX7B3NYI+3k7b2ibZHz3eVOy1Z9/uMVz+/V/2q2Z9NH9eILM2VOIraDODUNpN4oIDv/sOeNF2M3gW2N/E9EEtxB0Fe2aLh4ycrAffjt2pDWtEqIYwDkOuLI74PvJdG/ROQkTHtfxzgGp4sGAwqplBhI/T9SkEnZl0whdBlWE+DYLpQJ9KOqXCwdRszWNUMNEy1U0ImlILQmvTN0aptqhTezAMgujXYV00gm/y6eLVj5n5VZFRzSeDghsk8S+ibLGODDCm4YfSvv9h5Ua+f1iOjuyOa6IHPCUSvza4sIidsUw6o7b7HXFNVXklpMGS8EIJwFBOQR0S1qfrWEHInV7DWLUWr7ULVNeO/hVcYc8d+FWzVpaejng3UuefQpObn86crrnBZAhUHsFTcAQKM1UOKsSkMm1yIERW+yAWEqV+l8wfA0aW5wB6K9NjejCPO/68H6r5qveGl8WZWHLxZfdNzcn+q5WcBxf8k2dO/nviUQMH7K4fXJqrXzP9F+44Z1niA4a7Rbmuce265xYfFZYG4jPcSMSK56D6UYUMIw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HpJiNXJ4NJsr5V87Z4z7QVVl/moImLpd7KDPG6kbvG7DjVRXV7vvCmgYXSf7hjMc5JTX9BkDS+sC3MHAP7Ysz5F/a2WKVR4L5If12eBffwbxAikrG8ACx4G5c3uEh+oeNVXrBBi7u2Pw69TwG347La/F+oedKgQfkqy1xM1bSGCN461F7ortg6B0jvR4eerOO2w46SbMPoPY2LZm9QqXsDBbNhjWt25W+9v0LFJrUYLHcYdqHKaoLKgOlgJ4TmYUd3F4IqiZoG0oXWRmcEa9li5S6an0qn1CGom7a463yolPrPXzUs9/+lA/zo3TTWb9Kva7g5hbGfsZTJnPrR4pZv/Ll0d71ubWwAGDeRDON9ml/zIL69LQQES0mN3QOYnHfgD2pezLDNymUGdiiqk2hoj3ewXZEsoC3uhUxc4V/6sPiu8Jjaqx8TFrViBlWJ3P X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2026 13:19:50.2403 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63a087eb-6ea4-4c9d-cd76-08de7602e2f3 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A100.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7619 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) so can we do something like the following on top of the changes in this series: (!CONFIG_NUMA has only been build tested) diff --git a/arch/x86/include/asm/numa.h b/arch/x86/include/asm/numa.h index 5d6da2ad84e5..05461e2cd931 100644 --- a/arch/x86/include/asm/numa.h +++ b/arch/x86/include/asm/numa.h @@ -53,6 +53,8 @@ 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 void __init topo_register_apic_phys_node(int apicid); +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) { } @@ -60,6 +62,11 @@ 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 void __init topo_register_apic_phys_node(int apicid) { } +static inline int num_phys_nodes(void) +{ + return 1; +} #endif /* CONFIG_NUMA */ #ifdef CONFIG_DEBUG_PER_CPU_MAPS diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h index 7fe9ea4ee1e7..9b3f92c5f0e0 100644 --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -111,9 +111,6 @@ enum x86_topology_domains { TOPO_DIE_DOMAIN, TOPO_DIEGRP_DOMAIN, TOPO_PKG_DOMAIN, -#ifdef CONFIG_NUMA - TOPO_NUMA_DOMAIN, -#endif TOPO_MAX_DOMAIN, }; diff --git a/arch/x86/kernel/cpu/topology.c b/arch/x86/kernel/cpu/topology.c index 399388213bc0..1d3bed3ae40e 100644 --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -89,14 +89,6 @@ static inline u32 topo_apicid(u32 apicid, enum x86_topology_domains dom) { 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 return apicid & (UINT_MAX << x86_topo_system.dom_shifts[dom - 1]); } @@ -254,6 +246,8 @@ static __init void topo_register_apic(u32 apic_id, u32 acpi_id, bool present) */ for (dom = TOPO_SMT_DOMAIN; dom < TOPO_MAX_DOMAIN; dom++) set_bit(topo_apicid(apic_id, dom), apic_maps[dom].map); + + topo_register_apic_phys_node(apic_id); } /** @@ -501,7 +495,7 @@ void __init topology_init_possible_cpus(void) set_nr_cpu_ids(allowed); cnta = domain_weight(TOPO_PKG_DOMAIN); - cntb = domain_weight(TOPO_NUMA_DOMAIN); + cntb = num_phys_nodes(); __num_nodes_per_package = DIV_ROUND_UP(cntb, cnta); diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c index 4556a1561aa0..b60076745a32 100644 --- a/arch/x86/mm/numa.c +++ b/arch/x86/mm/numa.c @@ -52,6 +52,8 @@ s16 __apicid_to_phys_node[MAX_LOCAL_APIC] = { [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE }; +static nodemask_t apic_phys_node_map __ro_after_init; + int numa_cpu_node(int cpu) { u32 apicid = early_per_cpu(x86_cpu_to_apicid, cpu); @@ -61,6 +63,24 @@ int numa_cpu_node(int cpu) return NUMA_NO_NODE; } +static int topo_apicid_to_node(int apicid) +{ + int nid = __apicid_to_phys_node[apicid]; + if (nid == NUMA_NO_NODE) + nid = 0; + return nid; +} + +void __init topo_register_apic_phys_node(int apicid) +{ + set_bit(topo_apicid_to_node(apicid), apic_phys_node_map.bits); +} + +int __init num_phys_nodes(void) +{ + return bitmap_weight(apic_phys_node_map.bits, MAX_NUMNODES); +} + cpumask_var_t node_to_cpumask_map[MAX_NUMNODES]; EXPORT_SYMBOL(node_to_cpumask_map); --- Slightly larger diffstat but all the NUMA bits are together. Thoughts? > return apicid & (UINT_MAX << x86_topo_system.dom_shifts[dom - 1]); > } > -- Thanks and Regards, Prateek