Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: make range-to-target_node lookup facility a part of numa_memblks

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>

authored by

Mike Rapoport (Microsoft) and committed by
Andrew Morton
1b5695b0 76750765

+48 -49
-9
arch/x86/include/asm/sparsemem.h
··· 31 31 32 32 #endif /* CONFIG_SPARSEMEM */ 33 33 34 - #ifndef __ASSEMBLY__ 35 - #ifdef CONFIG_NUMA_KEEP_MEMINFO 36 - extern int phys_to_target_node(phys_addr_t start); 37 - #define phys_to_target_node phys_to_target_node 38 - extern int memory_add_physaddr_to_nid(u64 start); 39 - #define memory_add_physaddr_to_nid memory_add_physaddr_to_nid 40 - #endif 41 - #endif /* __ASSEMBLY__ */ 42 - 43 34 #endif /* _ASM_X86_SPARSEMEM_H */
-38
arch/x86/mm/numa.c
··· 453 453 return PFN_PHYS(MAX_DMA32_PFN); 454 454 } 455 455 #endif /* CONFIG_NUMA_EMU */ 456 - 457 - #ifdef CONFIG_NUMA_KEEP_MEMINFO 458 - static int meminfo_to_nid(struct numa_meminfo *mi, u64 start) 459 - { 460 - int i; 461 - 462 - for (i = 0; i < mi->nr_blks; i++) 463 - if (mi->blk[i].start <= start && mi->blk[i].end > start) 464 - return mi->blk[i].nid; 465 - return NUMA_NO_NODE; 466 - } 467 - 468 - int phys_to_target_node(phys_addr_t start) 469 - { 470 - int nid = meminfo_to_nid(&numa_meminfo, start); 471 - 472 - /* 473 - * Prefer online nodes, but if reserved memory might be 474 - * hot-added continue the search with reserved ranges. 475 - */ 476 - if (nid != NUMA_NO_NODE) 477 - return nid; 478 - 479 - return meminfo_to_nid(&numa_reserved_meminfo, start); 480 - } 481 - EXPORT_SYMBOL_GPL(phys_to_target_node); 482 - 483 - int memory_add_physaddr_to_nid(u64 start) 484 - { 485 - int nid = meminfo_to_nid(&numa_meminfo, start); 486 - 487 - if (nid == NUMA_NO_NODE) 488 - nid = numa_meminfo.blk[0].nid; 489 - return nid; 490 - } 491 - EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); 492 - 493 - #endif
+1 -1
drivers/cxl/Kconfig
··· 6 6 select FW_UPLOAD 7 7 select PCI_DOE 8 8 select FIRMWARE_TABLE 9 - select NUMA_KEEP_MEMINFO if (NUMA && X86) 9 + select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS 10 10 help 11 11 CXL is a bus that is electrically compatible with PCI Express, but 12 12 layers three protocols on that signalling (CXL.io, CXL.cache, and
+1 -1
drivers/dax/Kconfig
··· 30 30 config DEV_DAX_HMEM 31 31 tristate "HMEM DAX: direct access to 'specific purpose' memory" 32 32 depends on EFI_SOFT_RESERVE 33 - select NUMA_KEEP_MEMINFO if (NUMA && X86) 33 + select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS 34 34 default DEV_DAX 35 35 help 36 36 EFI 2.8 platforms, and others, may advertise 'specific purpose'
+7
include/linux/numa_memblks.h
··· 46 46 } 47 47 #endif /* CONFIG_NUMA_EMU */ 48 48 49 + #ifdef CONFIG_NUMA_KEEP_MEMINFO 50 + extern int phys_to_target_node(u64 start); 51 + #define phys_to_target_node phys_to_target_node 52 + extern int memory_add_physaddr_to_nid(u64 start); 53 + #define memory_add_physaddr_to_nid memory_add_physaddr_to_nid 54 + #endif /* CONFIG_NUMA_KEEP_MEMINFO */ 55 + 49 56 #endif /* CONFIG_NUMA_MEMBLKS */ 50 57 51 58 #endif /* __NUMA_MEMBLKS_H */
+1
mm/numa.c
··· 3 3 #include <linux/memblock.h> 4 4 #include <linux/printk.h> 5 5 #include <linux/numa.h> 6 + #include <linux/numa_memblks.h> 6 7 7 8 struct pglist_data *node_data[MAX_NUMNODES]; 8 9 EXPORT_SYMBOL(node_data);
+38
mm/numa_memblks.c
··· 531 531 } 532 532 return 0; 533 533 } 534 + 535 + #ifdef CONFIG_NUMA_KEEP_MEMINFO 536 + static int meminfo_to_nid(struct numa_meminfo *mi, u64 start) 537 + { 538 + int i; 539 + 540 + for (i = 0; i < mi->nr_blks; i++) 541 + if (mi->blk[i].start <= start && mi->blk[i].end > start) 542 + return mi->blk[i].nid; 543 + return NUMA_NO_NODE; 544 + } 545 + 546 + int phys_to_target_node(u64 start) 547 + { 548 + int nid = meminfo_to_nid(&numa_meminfo, start); 549 + 550 + /* 551 + * Prefer online nodes, but if reserved memory might be 552 + * hot-added continue the search with reserved ranges. 553 + */ 554 + if (nid != NUMA_NO_NODE) 555 + return nid; 556 + 557 + return meminfo_to_nid(&numa_reserved_meminfo, start); 558 + } 559 + EXPORT_SYMBOL_GPL(phys_to_target_node); 560 + 561 + int memory_add_physaddr_to_nid(u64 start) 562 + { 563 + int nid = meminfo_to_nid(&numa_meminfo, start); 564 + 565 + if (nid == NUMA_NO_NODE) 566 + nid = numa_meminfo.blk[0].nid; 567 + return nid; 568 + } 569 + EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); 570 + 571 + #endif /* CONFIG_NUMA_KEEP_MEMINFO */