[RFC PATCH 1/8] arm64: numa: Introduce a memory_add_physaddr_to_nid()

Jonathan Cameron Jonathan.Cameron at huawei.com
Wed May 29 10:12:29 PDT 2024


From: Dan Williams <dan.j.williams at intel.com>

Based heavily on Dan William's earlier attempt to introduce this
infrastruture for all architectures so I've kept his authorship. [1]

arm64 stores it's numa data in memblock. Add a memblock generic
way to interrogate that data for memory_Add_physaddr_to_nid.

Cc: Mike Rapoport <rppt at linux.ibm.com>
Cc: Jia He <justin.he at arm.com>
Cc: Will Deacon <will at kernel.org>
Cc: David Hildenbrand <david at redhat.com>
Cc: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Dan Williams <dan.j.williams at intel.com>
Link: https://lore.kernel.org/r/159457120334.754248.12908401960465408733.stgit@dwillia2-desk3.amr.corp.intel.com [1]
Signed-off-by: Jonathan Cameron <Jonathan.Cameron at huawei.com>
---
 arch/arm64/include/asm/sparsemem.h |  4 ++++
 arch/arm64/mm/init.c               | 29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/arch/arm64/include/asm/sparsemem.h b/arch/arm64/include/asm/sparsemem.h
index 8a8acc220371..8dd1b6a718fa 100644
--- a/arch/arm64/include/asm/sparsemem.h
+++ b/arch/arm64/include/asm/sparsemem.h
@@ -26,4 +26,8 @@
 #define SECTION_SIZE_BITS 27
 #endif /* CONFIG_ARM64_64K_PAGES */
 
+#ifndef __ASSEMBLY__
+extern int memory_add_physaddr_to_nid(u64 addr);
+#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
+#endif /* __ASSEMBLY__ */
 #endif
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 9b5ab6818f7f..f310cbd349ba 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -48,6 +48,35 @@
 #include <asm/alternative.h>
 #include <asm/xen/swiotlb-xen.h>
 
+#ifdef CONFIG_NUMA
+
+static int __memory_add_physaddr_to_nid(u64 addr)
+{
+	unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
+	int nid;
+
+	for_each_online_node(nid) {
+		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
+		if (pfn >= start_pfn && pfn <= end_pfn)
+			return nid;
+	}
+	return NUMA_NO_NODE;
+}
+
+int memory_add_physaddr_to_nid(u64 start)
+{
+	int nid = __memory_add_physaddr_to_nid(start);
+
+	/* Default to node0 as not all callers are prepared for this to fail */
+	if (nid == NUMA_NO_NODE)
+		return 0;
+
+	return nid;
+}
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
+
+#endif /* CONFIG_NUMA */
+
 /*
  * We need to be able to catch inadvertent references to memstart_addr
  * that occur (potentially in generic code) before arm64_memblock_init()
-- 
2.39.2




More information about the linux-arm-kernel mailing list