Skip to content

Commit a927bd6

Browse files
djbwtorvalds
authored andcommitted
mm: fix phys_to_target_node() and memory_add_physaddr_to_nid() exports
The core-mm has a default __weak implementation of phys_to_target_node() to mirror the weak definition of memory_add_physaddr_to_nid(). That symbol is exported for modules. However, while the export in mm/memory_hotplug.c exported the symbol in the configuration cases of: CONFIG_NUMA_KEEP_MEMINFO=y CONFIG_MEMORY_HOTPLUG=y ...and: CONFIG_NUMA_KEEP_MEMINFO=n CONFIG_MEMORY_HOTPLUG=y ...it failed to export the symbol in the case of: CONFIG_NUMA_KEEP_MEMINFO=y CONFIG_MEMORY_HOTPLUG=n Not only is that broken, but Christoph points out that the kernel should not be exporting any __weak symbol, which means that memory_add_physaddr_to_nid() example that phys_to_target_node() copied is broken too. Rework the definition of phys_to_target_node() and memory_add_physaddr_to_nid() to not require weak symbols. Move to the common arch override design-pattern of an asm header defining a symbol to replace the default implementation. The only common header that all memory_add_physaddr_to_nid() producing architectures implement is asm/sparsemem.h. In fact, powerpc already defines its memory_add_physaddr_to_nid() helper in sparsemem.h. Double-down on that observation and define phys_to_target_node() where necessary in asm/sparsemem.h. An alternate consideration that was discarded was to put this override in asm/numa.h, but that entangles with the definition of MAX_NUMNODES relative to the inclusion of linux/nodemask.h, and requires powerpc to grow a new header. The dependency on NUMA_KEEP_MEMINFO for DEV_DAX_HMEM_DEVICES is invalid now that the symbol is properly exported / stubbed in all combinations of CONFIG_NUMA_KEEP_MEMINFO and CONFIG_MEMORY_HOTPLUG. [dan.j.williams@intel.com: v4] Link: https://lkml.kernel.org/r/160461461867.1505359.5301571728749534585.stgit@dwillia2-desk3.amr.corp.intel.com [dan.j.williams@intel.com: powerpc: fix create_section_mapping compile warning] Link: https://lkml.kernel.org/r/160558386174.2948926.2740149041249041764.stgit@dwillia2-desk3.amr.corp.intel.com Fixes: a035b6b ("mm/memory_hotplug: introduce default phys_to_target_node() implementation") Reported-by: Randy Dunlap <rdunlap@infradead.org> Reported-by: Thomas Gleixner <tglx@linutronix.de> Reported-by: kernel test robot <lkp@intel.com> Reported-by: Christoph Hellwig <hch@infradead.org> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Tested-by: Randy Dunlap <rdunlap@infradead.org> Tested-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: Joao Martins <joao.m.martins@oracle.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Vishal Verma <vishal.l.verma@intel.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Link: https://lkml.kernel.org/r/160447639846.1133764.7044090803980177548.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bc2dc44 commit a927bd6

10 files changed

Lines changed: 55 additions & 37 deletions

File tree

arch/ia64/include/asm/sparsemem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@
1818
#endif
1919

2020
#endif /* CONFIG_SPARSEMEM */
21+
22+
#ifdef CONFIG_MEMORY_HOTPLUG
23+
int memory_add_physaddr_to_nid(u64 addr);
24+
#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
25+
#endif
26+
2127
#endif /* _ASM_IA64_SPARSEMEM_H */

arch/powerpc/include/asm/mmzone.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,10 @@ u64 memory_hotplug_max(void);
4646
#define __HAVE_ARCH_RESERVED_KERNEL_PAGES
4747
#endif
4848

49+
#ifdef CONFIG_MEMORY_HOTPLUG
50+
extern int create_section_mapping(unsigned long start, unsigned long end,
51+
int nid, pgprot_t prot);
52+
#endif
53+
4954
#endif /* __KERNEL__ */
5055
#endif /* _ASM_MMZONE_H_ */

arch/powerpc/include/asm/sparsemem.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#endif /* CONFIG_SPARSEMEM */
1414

1515
#ifdef CONFIG_MEMORY_HOTPLUG
16-
extern int create_section_mapping(unsigned long start, unsigned long end,
17-
int nid, pgprot_t prot);
1816
extern int remove_section_mapping(unsigned long start, unsigned long end);
17+
extern int memory_add_physaddr_to_nid(u64 start);
18+
#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
1919

2020
#ifdef CONFIG_NUMA
2121
extern int hot_add_scn_to_nid(unsigned long scn_addr);
@@ -26,6 +26,5 @@ static inline int hot_add_scn_to_nid(unsigned long scn_addr)
2626
}
2727
#endif /* CONFIG_NUMA */
2828
#endif /* CONFIG_MEMORY_HOTPLUG */
29-
3029
#endif /* __KERNEL__ */
3130
#endif /* _ASM_POWERPC_SPARSEMEM_H */

arch/powerpc/mm/mem.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <asm/rtas.h>
5151
#include <asm/kasan.h>
5252
#include <asm/svm.h>
53+
#include <asm/mmzone.h>
5354

5455
#include <mm/mmu_decl.h>
5556

arch/x86/include/asm/sparsemem.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,14 @@
2828
#endif
2929

3030
#endif /* CONFIG_SPARSEMEM */
31+
32+
#ifndef __ASSEMBLY__
33+
#ifdef CONFIG_NUMA_KEEP_MEMINFO
34+
extern int phys_to_target_node(phys_addr_t start);
35+
#define phys_to_target_node phys_to_target_node
36+
extern int memory_add_physaddr_to_nid(u64 start);
37+
#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
38+
#endif
39+
#endif /* __ASSEMBLY__ */
40+
3141
#endif /* _ASM_X86_SPARSEMEM_H */

arch/x86/mm/numa.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ int phys_to_target_node(phys_addr_t start)
938938

939939
return meminfo_to_nid(&numa_reserved_meminfo, start);
940940
}
941+
EXPORT_SYMBOL_GPL(phys_to_target_node);
941942

942943
int memory_add_physaddr_to_nid(u64 start)
943944
{
@@ -947,4 +948,5 @@ int memory_add_physaddr_to_nid(u64 start)
947948
nid = numa_meminfo.blk[0].nid;
948949
return nid;
949950
}
951+
EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
950952
#endif

drivers/dax/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ config DEV_DAX_HMEM
5050
Say M if unsure.
5151

5252
config DEV_DAX_HMEM_DEVICES
53-
depends on NUMA_KEEP_MEMINFO # for phys_to_target_node()
5453
depends on DEV_DAX_HMEM && DAX=y
5554
def_bool y
5655

include/linux/memory_hotplug.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,6 @@ static inline bool movable_node_is_enabled(void)
281281
}
282282
#endif /* ! CONFIG_MEMORY_HOTPLUG */
283283

284-
#ifdef CONFIG_NUMA
285-
extern int memory_add_physaddr_to_nid(u64 start);
286-
extern int phys_to_target_node(u64 start);
287-
#else
288-
static inline int memory_add_physaddr_to_nid(u64 start)
289-
{
290-
return 0;
291-
}
292-
static inline int phys_to_target_node(u64 start)
293-
{
294-
return 0;
295-
}
296-
#endif
297-
298284
#if defined(CONFIG_MEMORY_HOTPLUG) || defined(CONFIG_DEFERRED_STRUCT_PAGE_INIT)
299285
/*
300286
* pgdat resizing functions

include/linux/numa.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,41 @@
2121
#endif
2222

2323
#ifdef CONFIG_NUMA
24+
#include <linux/printk.h>
25+
#include <asm/sparsemem.h>
26+
2427
/* Generic implementation available */
2528
int numa_map_to_online_node(int node);
26-
#else
29+
30+
#ifndef memory_add_physaddr_to_nid
31+
static inline int memory_add_physaddr_to_nid(u64 start)
32+
{
33+
pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
34+
start);
35+
return 0;
36+
}
37+
#endif
38+
#ifndef phys_to_target_node
39+
static inline int phys_to_target_node(u64 start)
40+
{
41+
pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
42+
start);
43+
return 0;
44+
}
45+
#endif
46+
#else /* !CONFIG_NUMA */
2747
static inline int numa_map_to_online_node(int node)
2848
{
2949
return NUMA_NO_NODE;
3050
}
51+
static inline int memory_add_physaddr_to_nid(u64 start)
52+
{
53+
return 0;
54+
}
55+
static inline int phys_to_target_node(u64 start)
56+
{
57+
return 0;
58+
}
3159
#endif
3260

3361
#endif /* _LINUX_NUMA_H */

mm/memory_hotplug.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -350,24 +350,6 @@ int __ref __add_pages(int nid, unsigned long pfn, unsigned long nr_pages,
350350
return err;
351351
}
352352

353-
#ifdef CONFIG_NUMA
354-
int __weak memory_add_physaddr_to_nid(u64 start)
355-
{
356-
pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
357-
start);
358-
return 0;
359-
}
360-
EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
361-
362-
int __weak phys_to_target_node(u64 start)
363-
{
364-
pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
365-
start);
366-
return 0;
367-
}
368-
EXPORT_SYMBOL_GPL(phys_to_target_node);
369-
#endif
370-
371353
/* find the smallest valid pfn in the range [start_pfn, end_pfn) */
372354
static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
373355
unsigned long start_pfn,

0 commit comments

Comments
 (0)