]> www.infradead.org Git - users/willy/xarray.git/commitdiff
mm: make range-to-target_node lookup facility a part of numa_memblks
authorMike Rapoport (Microsoft) <rppt@kernel.org>
Wed, 7 Aug 2024 06:41:09 +0000 (09:41 +0300)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 4 Sep 2024 04:15:32 +0000 (21:15 -0700)
The x86 implementation of range-to-target_node lookup (i.e.
phys_to_target_node() and memory_add_physaddr_to_nid()) relies on
numa_memblks.

Since numa_memblks are now part of the generic code, move these functions
from x86 to mm/numa_memblks.c and select CONFIG_NUMA_KEEP_MEMINFO when
CONFIG_NUMA_MEMBLKS=y for dax and cxl.

[rppt@kernel.org: fix build]
Link: https://lkml.kernel.org/r/ZtVfSt_zloPdDqVB@kernel.org
Link: https://lkml.kernel.org/r/20240807064110.1003856-26-rppt@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Zi Yan <ziy@nvidia.com> # for x86_64 and arm64
Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> [arm64 + CXL via QEMU]
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: David S. Miller <davem@davemloft.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Rafael J. Wysocki <rafael@kernel.org>
Cc: Rob Herring (Arm) <robh@kernel.org>
Cc: Samuel Holland <samuel.holland@sifive.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/x86/include/asm/sparsemem.h
arch/x86/mm/numa.c
drivers/cxl/Kconfig
drivers/dax/Kconfig
include/linux/numa_memblks.h
mm/numa.c
mm/numa_memblks.c

index 64df897c0ee30f9332bd332ba9e484877bebe551..3918c7a434f5b81298373176a51c8f892a12219b 100644 (file)
 
 #endif /* CONFIG_SPARSEMEM */
 
-#ifndef __ASSEMBLY__
-#ifdef CONFIG_NUMA_KEEP_MEMINFO
-extern int phys_to_target_node(phys_addr_t start);
-#define phys_to_target_node phys_to_target_node
-extern int memory_add_physaddr_to_nid(u64 start);
-#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
-#endif
-#endif /* __ASSEMBLY__ */
-
 #endif /* _ASM_X86_SPARSEMEM_H */
index d232876114499f64c2a64d768e84c22e9860648c..64e5cdb2460ac24c37df5af46a4dd3cdc0bf6975 100644 (file)
@@ -453,41 +453,3 @@ u64 __init numa_emu_dma_end(void)
        return PFN_PHYS(MAX_DMA32_PFN);
 }
 #endif /* CONFIG_NUMA_EMU */
-
-#ifdef CONFIG_NUMA_KEEP_MEMINFO
-static int meminfo_to_nid(struct numa_meminfo *mi, u64 start)
-{
-       int i;
-
-       for (i = 0; i < mi->nr_blks; i++)
-               if (mi->blk[i].start <= start && mi->blk[i].end > start)
-                       return mi->blk[i].nid;
-       return NUMA_NO_NODE;
-}
-
-int phys_to_target_node(phys_addr_t start)
-{
-       int nid = meminfo_to_nid(&numa_meminfo, start);
-
-       /*
-        * Prefer online nodes, but if reserved memory might be
-        * hot-added continue the search with reserved ranges.
-        */
-       if (nid != NUMA_NO_NODE)
-               return nid;
-
-       return meminfo_to_nid(&numa_reserved_meminfo, start);
-}
-EXPORT_SYMBOL_GPL(phys_to_target_node);
-
-int memory_add_physaddr_to_nid(u64 start)
-{
-       int nid = meminfo_to_nid(&numa_meminfo, start);
-
-       if (nid == NUMA_NO_NODE)
-               nid = numa_meminfo.blk[0].nid;
-       return nid;
-}
-EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
-
-#endif
index 99b5c25be079430b8215af4301ef4b58c9500b03..29c192f20082cb82a513a42ad8dac5c44b8ff0a4 100644 (file)
@@ -6,7 +6,7 @@ menuconfig CXL_BUS
        select FW_UPLOAD
        select PCI_DOE
        select FIRMWARE_TABLE
-       select NUMA_KEEP_MEMINFO if (NUMA && X86)
+       select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS
        help
          CXL is a bus that is electrically compatible with PCI Express, but
          layers three protocols on that signalling (CXL.io, CXL.cache, and
index a887442441498937b441e65fb8fe36b60f7011d9..d656e4c0eb8463d72f9663655f74b2572e31bc6d 100644 (file)
@@ -30,7 +30,7 @@ config DEV_DAX_PMEM
 config DEV_DAX_HMEM
        tristate "HMEM DAX: direct access to 'specific purpose' memory"
        depends on EFI_SOFT_RESERVE
-       select NUMA_KEEP_MEMINFO if (NUMA && X86)
+       select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS
        default DEV_DAX
        help
          EFI 2.8 platforms, and others, may advertise 'specific purpose'
index 5c6e12ad0b7a2e5074a392d01e836afdcaad0871..cfad6ce7e1bd1e76d870c5ebb2acb24398e01878 100644 (file)
@@ -46,6 +46,13 @@ static inline int numa_emu_cmdline(char *str)
 }
 #endif /* CONFIG_NUMA_EMU */
 
+#ifdef CONFIG_NUMA_KEEP_MEMINFO
+extern int phys_to_target_node(u64 start);
+#define phys_to_target_node phys_to_target_node
+extern int memory_add_physaddr_to_nid(u64 start);
+#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
+#endif /* CONFIG_NUMA_KEEP_MEMINFO */
+
 #endif /* CONFIG_NUMA_MEMBLKS */
 
 #endif /* __NUMA_MEMBLKS_H */
index 1f1582dcdf4ab39d924b0669d0c41281a466f1f0..e2eec07707d1ae06303468b13806c236239df7e7 100644 (file)
--- a/mm/numa.c
+++ b/mm/numa.c
@@ -3,6 +3,7 @@
 #include <linux/memblock.h>
 #include <linux/printk.h>
 #include <linux/numa.h>
+#include <linux/numa_memblks.h>
 
 struct pglist_data *node_data[MAX_NUMNODES];
 EXPORT_SYMBOL(node_data);
index c4037faa438b3003692743a498ffa3af0e491264..be52b93a9c5804c8499dc6741f48482c76877b18 100644 (file)
@@ -531,3 +531,41 @@ int __init numa_fill_memblks(u64 start, u64 end)
        }
        return 0;
 }
+
+#ifdef CONFIG_NUMA_KEEP_MEMINFO
+static int meminfo_to_nid(struct numa_meminfo *mi, u64 start)
+{
+       int i;
+
+       for (i = 0; i < mi->nr_blks; i++)
+               if (mi->blk[i].start <= start && mi->blk[i].end > start)
+                       return mi->blk[i].nid;
+       return NUMA_NO_NODE;
+}
+
+int phys_to_target_node(u64 start)
+{
+       int nid = meminfo_to_nid(&numa_meminfo, start);
+
+       /*
+        * Prefer online nodes, but if reserved memory might be
+        * hot-added continue the search with reserved ranges.
+        */
+       if (nid != NUMA_NO_NODE)
+               return nid;
+
+       return meminfo_to_nid(&numa_reserved_meminfo, start);
+}
+EXPORT_SYMBOL_GPL(phys_to_target_node);
+
+int memory_add_physaddr_to_nid(u64 start)
+{
+       int nid = meminfo_to_nid(&numa_meminfo, start);
+
+       if (nid == NUMA_NO_NODE)
+               nid = numa_meminfo.blk[0].nid;
+       return nid;
+}
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
+
+#endif /* CONFIG_NUMA_KEEP_MEMINFO */