* [PATCH] x86/mm: Fix phys_to_target_node() export
@ 2020-10-30 2:29 Dan Williams
2020-10-30 3:05 ` Randy Dunlap
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: Dan Williams @ 2020-10-30 2:29 UTC (permalink / raw)
To: akpm
Cc: Randy Dunlap, Thomas Gleixner, kernel test robot, Joao Martins,
x86, linux-mm, linux-nvdimm
The core-mm has a default __weak implementation of phys_to_target_node()
when the architecture does not override it. 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
Always export the symbol from the CONFIG_NUMA_KEEP_MEMINFO section of
arch/x86/mm/numa.c, and teach mm/memory_hotplug.c to optionally export
in case arch/x86/mm/numa.c has already performed the export.
The dependency on NUMA_KEEP_MEMINFO for DEV_DAX_HMEM_DEVICES is invalid
now that the symbol is properly exported in all combinations of
CONFIG_NUMA_KEEP_MEMINFO and CONFIG_MEMORY_HOTPLUG. Note that in the
CONFIG_NUMA=n case no export is needed since their is a dummy static
inline implementation of phys_to_target_node() in that case.
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Reported-by: Thomas Gleixner <tglx@linutronix.de>
Reported-by: kernel test robot <lkp@intel.com>
Fixes: a035b6bf863e ("mm/memory_hotplug: introduce default phys_to_target_node() implementation")
Cc: Joao Martins <joao.m.martins@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: x86@kernel.org
Cc: Vishal Verma <vishal.l.verma@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
arch/x86/mm/numa.c | 1 +
drivers/dax/Kconfig | 1 -
mm/memory_hotplug.c | 5 +++++
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index 44148691d78b..e025947f19e0 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -938,6 +938,7 @@ int phys_to_target_node(phys_addr_t start)
return meminfo_to_nid(&numa_reserved_meminfo, start);
}
+EXPORT_SYMBOL_GPL(phys_to_target_node);
int memory_add_physaddr_to_nid(u64 start)
{
diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig
index 567428e10b7b..d2834c2cfa10 100644
--- a/drivers/dax/Kconfig
+++ b/drivers/dax/Kconfig
@@ -50,7 +50,6 @@ config DEV_DAX_HMEM
Say M if unsure.
config DEV_DAX_HMEM_DEVICES
- depends on NUMA_KEEP_MEMINFO # for phys_to_target_node()
depends on DEV_DAX_HMEM && DAX=y
def_bool y
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index b44d4c7ba73b..ed326b489674 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -365,9 +365,14 @@ int __weak phys_to_target_node(u64 start)
start);
return 0;
}
+
+/* If the arch did not export a strong symbol, export the weak one. */
+#ifndef CONFIG_NUMA_KEEP_MEMINFO
EXPORT_SYMBOL_GPL(phys_to_target_node);
#endif
+#endif
+
/* find the smallest valid pfn in the range [start_pfn, end_pfn) */
static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
unsigned long start_pfn,
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] x86/mm: Fix phys_to_target_node() export
2020-10-30 2:29 [PATCH] x86/mm: Fix phys_to_target_node() export Dan Williams
@ 2020-10-30 3:05 ` Randy Dunlap
2020-10-30 11:34 ` David Hildenbrand
` (2 subsequent siblings)
3 siblings, 0 replies; 13+ messages in thread
From: Randy Dunlap @ 2020-10-30 3:05 UTC (permalink / raw)
To: Dan Williams, akpm
Cc: Thomas Gleixner, kernel test robot, Joao Martins, x86, linux-mm,
linux-nvdimm
On 10/29/20 7:29 PM, Dan Williams wrote:
> The core-mm has a default __weak implementation of phys_to_target_node()
> when the architecture does not override it. 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
>
> Always export the symbol from the CONFIG_NUMA_KEEP_MEMINFO section of
> arch/x86/mm/numa.c, and teach mm/memory_hotplug.c to optionally export
> in case arch/x86/mm/numa.c has already performed the export.
>
> The dependency on NUMA_KEEP_MEMINFO for DEV_DAX_HMEM_DEVICES is invalid
> now that the symbol is properly exported in all combinations of
> CONFIG_NUMA_KEEP_MEMINFO and CONFIG_MEMORY_HOTPLUG. Note that in the
> CONFIG_NUMA=n case no export is needed since their is a dummy static
> inline implementation of phys_to_target_node() in that case.
>
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Reported-by: Thomas Gleixner <tglx@linutronix.de>
> Reported-by: kernel test robot <lkp@intel.com>
> Fixes: a035b6bf863e ("mm/memory_hotplug: introduce default phys_to_target_node() implementation")
> Cc: Joao Martins <joao.m.martins@oracle.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: x86@kernel.org
> Cc: Vishal Verma <vishal.l.verma@intel.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Looks good. Thanks.
Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
> ---
> arch/x86/mm/numa.c | 1 +
> drivers/dax/Kconfig | 1 -
> mm/memory_hotplug.c | 5 +++++
> 3 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
> index 44148691d78b..e025947f19e0 100644
> --- a/arch/x86/mm/numa.c
> +++ b/arch/x86/mm/numa.c
> @@ -938,6 +938,7 @@ int phys_to_target_node(phys_addr_t start)
>
> return meminfo_to_nid(&numa_reserved_meminfo, start);
> }
> +EXPORT_SYMBOL_GPL(phys_to_target_node);
>
> int memory_add_physaddr_to_nid(u64 start)
> {
> diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig
> index 567428e10b7b..d2834c2cfa10 100644
> --- a/drivers/dax/Kconfig
> +++ b/drivers/dax/Kconfig
> @@ -50,7 +50,6 @@ config DEV_DAX_HMEM
> Say M if unsure.
>
> config DEV_DAX_HMEM_DEVICES
> - depends on NUMA_KEEP_MEMINFO # for phys_to_target_node()
> depends on DEV_DAX_HMEM && DAX=y
> def_bool y
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index b44d4c7ba73b..ed326b489674 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -365,9 +365,14 @@ int __weak phys_to_target_node(u64 start)
> start);
> return 0;
> }
> +
> +/* If the arch did not export a strong symbol, export the weak one. */
> +#ifndef CONFIG_NUMA_KEEP_MEMINFO
> EXPORT_SYMBOL_GPL(phys_to_target_node);
> #endif
>
> +#endif
> +
> /* find the smallest valid pfn in the range [start_pfn, end_pfn) */
> static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
> unsigned long start_pfn,
>
>
--
~Randy
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] x86/mm: Fix phys_to_target_node() export
2020-10-30 2:29 [PATCH] x86/mm: Fix phys_to_target_node() export Dan Williams
2020-10-30 3:05 ` Randy Dunlap
@ 2020-10-30 11:34 ` David Hildenbrand
2020-10-31 1:54 ` Dan Williams
2020-10-31 9:10 ` Christoph Hellwig
3 siblings, 0 replies; 13+ messages in thread
From: David Hildenbrand @ 2020-10-30 11:34 UTC (permalink / raw)
To: Dan Williams, akpm
Cc: Randy Dunlap, Thomas Gleixner, kernel test robot, Joao Martins,
x86, linux-mm, linux-nvdimm
On 30.10.20 03:29, Dan Williams wrote:
> The core-mm has a default __weak implementation of phys_to_target_node()
> when the architecture does not override it. 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
>
> Always export the symbol from the CONFIG_NUMA_KEEP_MEMINFO section of
> arch/x86/mm/numa.c, and teach mm/memory_hotplug.c to optionally export
> in case arch/x86/mm/numa.c has already performed the export.
>
> The dependency on NUMA_KEEP_MEMINFO for DEV_DAX_HMEM_DEVICES is invalid
> now that the symbol is properly exported in all combinations of
> CONFIG_NUMA_KEEP_MEMINFO and CONFIG_MEMORY_HOTPLUG. Note that in the
> CONFIG_NUMA=n case no export is needed since their is a dummy static
> inline implementation of phys_to_target_node() in that case.
>
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Reported-by: Thomas Gleixner <tglx@linutronix.de>
> Reported-by: kernel test robot <lkp@intel.com>
> Fixes: a035b6bf863e ("mm/memory_hotplug: introduce default phys_to_target_node() implementation")
> Cc: Joao Martins <joao.m.martins@oracle.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: x86@kernel.org
> Cc: Vishal Verma <vishal.l.verma@intel.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
> arch/x86/mm/numa.c | 1 +
> drivers/dax/Kconfig | 1 -
> mm/memory_hotplug.c | 5 +++++
> 3 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
> index 44148691d78b..e025947f19e0 100644
> --- a/arch/x86/mm/numa.c
> +++ b/arch/x86/mm/numa.c
> @@ -938,6 +938,7 @@ int phys_to_target_node(phys_addr_t start)
>
> return meminfo_to_nid(&numa_reserved_meminfo, start);
> }
> +EXPORT_SYMBOL_GPL(phys_to_target_node);
>
> int memory_add_physaddr_to_nid(u64 start)
> {
> diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig
> index 567428e10b7b..d2834c2cfa10 100644
> --- a/drivers/dax/Kconfig
> +++ b/drivers/dax/Kconfig
> @@ -50,7 +50,6 @@ config DEV_DAX_HMEM
> Say M if unsure.
>
> config DEV_DAX_HMEM_DEVICES
> - depends on NUMA_KEEP_MEMINFO # for phys_to_target_node()
> depends on DEV_DAX_HMEM && DAX=y
> def_bool y
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index b44d4c7ba73b..ed326b489674 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -365,9 +365,14 @@ int __weak phys_to_target_node(u64 start)
> start);
> return 0;
> }
> +
> +/* If the arch did not export a strong symbol, export the weak one. */
> +#ifndef CONFIG_NUMA_KEEP_MEMINFO
> EXPORT_SYMBOL_GPL(phys_to_target_node);
> #endif
>
> +#endif
> +
> /* find the smallest valid pfn in the range [start_pfn, end_pfn) */
> static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
> unsigned long start_pfn,
>
>
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Thanks,
David / dhildenb
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] x86/mm: Fix phys_to_target_node() export
2020-10-30 2:29 [PATCH] x86/mm: Fix phys_to_target_node() export Dan Williams
2020-10-30 3:05 ` Randy Dunlap
2020-10-30 11:34 ` David Hildenbrand
@ 2020-10-31 1:54 ` Dan Williams
2020-10-31 3:01 ` Thomas Gleixner
2020-10-31 9:10 ` Christoph Hellwig
3 siblings, 1 reply; 13+ messages in thread
From: Dan Williams @ 2020-10-31 1:54 UTC (permalink / raw)
To: Andrew Morton
Cc: Randy Dunlap, Thomas Gleixner, kernel test robot, Joao Martins,
X86 ML, Linux MM, linux-nvdimm
On Thu, Oct 29, 2020 at 7:29 PM Dan Williams <dan.j.williams@intel.com> wrote:
>
> The core-mm has a default __weak implementation of phys_to_target_node()
> when the architecture does not override it. 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
>
> Always export the symbol from the CONFIG_NUMA_KEEP_MEMINFO section of
> arch/x86/mm/numa.c, and teach mm/memory_hotplug.c to optionally export
> in case arch/x86/mm/numa.c has already performed the export.
>
> The dependency on NUMA_KEEP_MEMINFO for DEV_DAX_HMEM_DEVICES is invalid
> now that the symbol is properly exported in all combinations of
> CONFIG_NUMA_KEEP_MEMINFO and CONFIG_MEMORY_HOTPLUG. Note that in the
> CONFIG_NUMA=n case no export is needed since their is a dummy static
> inline implementation of phys_to_target_node() in that case.
>
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Reported-by: Thomas Gleixner <tglx@linutronix.de>
> Reported-by: kernel test robot <lkp@intel.com>
> Fixes: a035b6bf863e ("mm/memory_hotplug: introduce default phys_to_target_node() implementation")
> Cc: Joao Martins <joao.m.martins@oracle.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: x86@kernel.org
> Cc: Vishal Verma <vishal.l.verma@intel.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Thomas, do you want to ack this so Andrew can pick it up, or I can
take it through as a device-dax update, but either way the diffstat
warrants x86 + mm acks.
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] x86/mm: Fix phys_to_target_node() export
2020-10-31 1:54 ` Dan Williams
@ 2020-10-31 3:01 ` Thomas Gleixner
2020-10-31 4:45 ` Dan Williams
0 siblings, 1 reply; 13+ messages in thread
From: Thomas Gleixner @ 2020-10-31 3:01 UTC (permalink / raw)
To: Dan Williams, Andrew Morton
Cc: Randy Dunlap, kernel test robot, Joao Martins, X86 ML, Linux MM,
linux-nvdimm
On Fri, Oct 30 2020 at 18:54, Dan Williams wrote:
> Thomas, do you want to ack this so Andrew can pick it up, or I can
> take it through as a device-dax update, but either way the diffstat
> warrants x86 + mm acks.
It's butt ugly but I couldn't come up with anything better right
away. So, FWIW:
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Thomas Gleixner <tglx@linutronix.de>
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] x86/mm: Fix phys_to_target_node() export
2020-10-31 3:01 ` Thomas Gleixner
@ 2020-10-31 4:45 ` Dan Williams
0 siblings, 0 replies; 13+ messages in thread
From: Dan Williams @ 2020-10-31 4:45 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Andrew Morton, Randy Dunlap, kernel test robot, Joao Martins,
X86 ML, Linux MM, linux-nvdimm
On Fri, Oct 30, 2020 at 8:02 PM Thomas Gleixner <tglx@linutronix.de> wrote:
>
> On Fri, Oct 30 2020 at 18:54, Dan Williams wrote:
> > Thomas, do you want to ack this so Andrew can pick it up, or I can
> > take it through as a device-dax update, but either way the diffstat
> > warrants x86 + mm acks.
>
> It's butt ugly but I couldn't come up with anything better right
> away. So, FWIW:
>
> Acked-by: Thomas Gleixner <tglx@linutronix.de>
> Tested-by: Thomas Gleixner <tglx@linutronix.de>
Almost-threw-up-in-my-mouth-a-little-bit-by?
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] x86/mm: Fix phys_to_target_node() export
2020-10-30 2:29 [PATCH] x86/mm: Fix phys_to_target_node() export Dan Williams
` (2 preceding siblings ...)
2020-10-31 1:54 ` Dan Williams
@ 2020-10-31 9:10 ` Christoph Hellwig
2020-11-02 23:52 ` Dan Williams
3 siblings, 1 reply; 13+ messages in thread
From: Christoph Hellwig @ 2020-10-31 9:10 UTC (permalink / raw)
To: Dan Williams
Cc: akpm, Randy Dunlap, Thomas Gleixner, kernel test robot,
Joao Martins, x86, linux-mm, linux-nvdimm
On Thu, Oct 29, 2020 at 07:29:45PM -0700, Dan Williams wrote:
> The core-mm has a default __weak implementation of phys_to_target_node()
> when the architecture does not override it. That symbol is exported
> for modules. However, while the export in mm/memory_hotplug.c exported
> the symbol in the configuration cases of:
Which just means that we should never export weak symbols. So instead
of hacking around this introduce a symbol that indicates that the
architecture impements phys_to_target_node, and don't defined it at all
in common code for that case.
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -365,9 +365,14 @@ int __weak phys_to_target_node(u64 start)
> start);
> return 0;
> }
> +
> +/* If the arch did not export a strong symbol, export the weak one. */
> +#ifndef CONFIG_NUMA_KEEP_MEMINFO
> EXPORT_SYMBOL_GPL(phys_to_target_node);
> #endif
>
> +#endif
i.e. move the ifdef to include the actual phys_to_target_node
definition, and remove the __weak from it here.
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] x86/mm: Fix phys_to_target_node() export
2020-10-31 9:10 ` Christoph Hellwig
@ 2020-11-02 23:52 ` Dan Williams
2020-11-03 0:59 ` Randy Dunlap
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: Dan Williams @ 2020-11-02 23:52 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Andrew Morton, Randy Dunlap, Thomas Gleixner, kernel test robot,
Joao Martins, X86 ML, Linux MM, linux-nvdimm
[-- Attachment #1: Type: text/plain, Size: 1922 bytes --]
On Sat, Oct 31, 2020 at 2:10 AM Christoph Hellwig <hch@infradead.org> wrote:
>
> On Thu, Oct 29, 2020 at 07:29:45PM -0700, Dan Williams wrote:
> > The core-mm has a default __weak implementation of phys_to_target_node()
> > when the architecture does not override it. That symbol is exported
> > for modules. However, while the export in mm/memory_hotplug.c exported
> > the symbol in the configuration cases of:
>
> Which just means that we should never export weak symbols. So instead
> of hacking around this introduce a symbol that indicates that the
> architecture impements phys_to_target_node, and don't defined it at all
> in common code for that case.
So I agree with this, but it made me realize that the way
memory_add_physaddr_to_nid() was defined as an exported weak symbol is
similarly broken.
> > --- a/mm/memory_hotplug.c
> > +++ b/mm/memory_hotplug.c
> > @@ -365,9 +365,14 @@ int __weak phys_to_target_node(u64 start)
> > start);
> > return 0;
> > }
> > +
> > +/* If the arch did not export a strong symbol, export the weak one. */
> > +#ifndef CONFIG_NUMA_KEEP_MEMINFO
> > EXPORT_SYMBOL_GPL(phys_to_target_node);
> > #endif
> >
> > +#endif
>
> i.e. move the ifdef to include the actual phys_to_target_node
> definition, and remove the __weak from it here.
The trick is finding an arch common way to pick up the presence of the
phys_to_target_node() override, and it still has the wart of ifdefery
in C code.
I went a bit deeper and moved all the fallback routines to
linux/numa.h and the overrides in all archs that care to
asm/sparsemem.h. Note that asm/sparsemem.h was not my first choice,
but it happened to be where powerpc was already defining its
phys-addr-to-node-id infrastructure, and my first choice header,
asm/numa.h, is not universally available.
The attached patch is going through some kbuild-robot exposure to make
sure I did not break anything else.
[-- Attachment #2: 0001-x86-mm-Fix-phys_to_target_node-export.patch --]
[-- Type: text/x-patch, Size: 8531 bytes --]
From ec0a0ca84fc4ba64dadc86146d2ac42379a686ff Mon Sep 17 00:00:00 2001
From: Dan Williams <dan.j.williams@intel.com>
Date: Thu, 29 Oct 2020 19:14:07 -0700
Subject: [PATCH] x86/mm: Fix phys_to_target_node() export
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.
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>
Fixes: a035b6bf863e ("mm/memory_hotplug: introduce default phys_to_target_node() implementation")
Cc: Joao Martins <joao.m.martins@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: x86@kernel.org
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>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
arch/ia64/include/asm/sparsemem.h | 4 ++++
arch/powerpc/include/asm/sparsemem.h | 3 ++-
arch/x86/include/asm/sparsemem.h | 10 ++++++++++
arch/x86/mm/numa.c | 2 ++
drivers/dax/Kconfig | 1 -
include/linux/memory_hotplug.h | 14 --------------
include/linux/numa.h | 28 +++++++++++++++++++++++++++-
mm/memory_hotplug.c | 18 ------------------
8 files changed, 45 insertions(+), 35 deletions(-)
diff --git a/arch/ia64/include/asm/sparsemem.h b/arch/ia64/include/asm/sparsemem.h
index 336d0570e1fa..0dfc1511a7a6 100644
--- a/arch/ia64/include/asm/sparsemem.h
+++ b/arch/ia64/include/asm/sparsemem.h
@@ -18,4 +18,8 @@
#endif
#endif /* CONFIG_SPARSEMEM */
+
+int memory_add_physaddr_to_nid(u64 addr);
+#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
+
#endif /* _ASM_IA64_SPARSEMEM_H */
diff --git a/arch/powerpc/include/asm/sparsemem.h b/arch/powerpc/include/asm/sparsemem.h
index 1e6fa371cc38..52519d2c5713 100644
--- a/arch/powerpc/include/asm/sparsemem.h
+++ b/arch/powerpc/include/asm/sparsemem.h
@@ -16,6 +16,8 @@
extern int create_section_mapping(unsigned long start, unsigned long end,
int nid, pgprot_t prot);
extern int remove_section_mapping(unsigned long start, unsigned long end);
+extern int memory_add_physaddr_to_nid(u64 start);
+#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
#ifdef CONFIG_NUMA
extern int hot_add_scn_to_nid(unsigned long scn_addr);
@@ -26,6 +28,5 @@ static inline int hot_add_scn_to_nid(unsigned long scn_addr)
}
#endif /* CONFIG_NUMA */
#endif /* CONFIG_MEMORY_HOTPLUG */
-
#endif /* __KERNEL__ */
#endif /* _ASM_POWERPC_SPARSEMEM_H */
diff --git a/arch/x86/include/asm/sparsemem.h b/arch/x86/include/asm/sparsemem.h
index 6bfc878f6771..6a9ccc1b2be5 100644
--- a/arch/x86/include/asm/sparsemem.h
+++ b/arch/x86/include/asm/sparsemem.h
@@ -28,4 +28,14 @@
#endif
#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 */
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index 44148691d78b..5eb4dc2b97da 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -938,6 +938,7 @@ int phys_to_target_node(phys_addr_t start)
return meminfo_to_nid(&numa_reserved_meminfo, start);
}
+EXPORT_SYMBOL_GPL(phys_to_target_node);
int memory_add_physaddr_to_nid(u64 start)
{
@@ -947,4 +948,5 @@ int memory_add_physaddr_to_nid(u64 start)
nid = numa_meminfo.blk[0].nid;
return nid;
}
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
#endif
diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig
index 567428e10b7b..d2834c2cfa10 100644
--- a/drivers/dax/Kconfig
+++ b/drivers/dax/Kconfig
@@ -50,7 +50,6 @@ config DEV_DAX_HMEM
Say M if unsure.
config DEV_DAX_HMEM_DEVICES
- depends on NUMA_KEEP_MEMINFO # for phys_to_target_node()
depends on DEV_DAX_HMEM && DAX=y
def_bool y
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index d65c6fdc5cfc..551093b74596 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -281,20 +281,6 @@ static inline bool movable_node_is_enabled(void)
}
#endif /* ! CONFIG_MEMORY_HOTPLUG */
-#ifdef CONFIG_NUMA
-extern int memory_add_physaddr_to_nid(u64 start);
-extern int phys_to_target_node(u64 start);
-#else
-static inline int memory_add_physaddr_to_nid(u64 start)
-{
- return 0;
-}
-static inline int phys_to_target_node(u64 start)
-{
- return 0;
-}
-#endif
-
#if defined(CONFIG_MEMORY_HOTPLUG) || defined(CONFIG_DEFERRED_STRUCT_PAGE_INIT)
/*
* pgdat resizing functions
diff --git a/include/linux/numa.h b/include/linux/numa.h
index 8cb33ccfb671..301ff9ee69ed 100644
--- a/include/linux/numa.h
+++ b/include/linux/numa.h
@@ -2,6 +2,7 @@
#ifndef _LINUX_NUMA_H
#define _LINUX_NUMA_H
#include <linux/types.h>
+#include <asm/sparsemem.h>
#ifdef CONFIG_NODES_SHIFT
#define NODES_SHIFT CONFIG_NODES_SHIFT
@@ -23,11 +24,36 @@
#ifdef CONFIG_NUMA
/* Generic implementation available */
int numa_map_to_online_node(int node);
-#else
+
+#ifndef memory_add_physaddr_to_nid
+static inline int memory_add_physaddr_to_nid(u64 start)
+{
+ pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
+ start);
+ return 0;
+}
+#endif
+#ifndef phys_to_target_node
+static inline int phys_to_target_node(u64 start)
+{
+ pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
+ start);
+ return 0;
+}
+#endif
+#else /* !CONFIG_NUMA */
static inline int numa_map_to_online_node(int node)
{
return NUMA_NO_NODE;
}
+static inline int memory_add_physaddr_to_nid(u64 start)
+{
+ return 0;
+}
+static inline int phys_to_target_node(u64 start)
+{
+ return 0;
+}
#endif
#endif /* _LINUX_NUMA_H */
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index b44d4c7ba73b..63b2e46b6555 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -350,24 +350,6 @@ int __ref __add_pages(int nid, unsigned long pfn, unsigned long nr_pages,
return err;
}
-#ifdef CONFIG_NUMA
-int __weak memory_add_physaddr_to_nid(u64 start)
-{
- pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
- start);
- return 0;
-}
-EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
-
-int __weak phys_to_target_node(u64 start)
-{
- pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
- start);
- return 0;
-}
-EXPORT_SYMBOL_GPL(phys_to_target_node);
-#endif
-
/* find the smallest valid pfn in the range [start_pfn, end_pfn) */
static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
unsigned long start_pfn,
--
2.25.4
[-- Attachment #3: Type: text/plain, Size: 167 bytes --]
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] x86/mm: Fix phys_to_target_node() export
2020-11-02 23:52 ` Dan Williams
@ 2020-11-03 0:59 ` Randy Dunlap
2020-11-03 8:33 ` Christoph Hellwig
` (2 subsequent siblings)
3 siblings, 0 replies; 13+ messages in thread
From: Randy Dunlap @ 2020-11-03 0:59 UTC (permalink / raw)
To: Dan Williams, Christoph Hellwig
Cc: Andrew Morton, Thomas Gleixner, kernel test robot, Joao Martins,
X86 ML, Linux MM, linux-nvdimm
On 11/2/20 3:52 PM, Dan Williams wrote:
> On Sat, Oct 31, 2020 at 2:10 AM Christoph Hellwig <hch@infradead.org> wrote:
>>
>> On Thu, Oct 29, 2020 at 07:29:45PM -0700, Dan Williams wrote:
>>> The core-mm has a default __weak implementation of phys_to_target_node()
>>> when the architecture does not override it. That symbol is exported
>>> for modules. However, while the export in mm/memory_hotplug.c exported
>>> the symbol in the configuration cases of:
>>
>> Which just means that we should never export weak symbols. So instead
>> of hacking around this introduce a symbol that indicates that the
>> architecture impements phys_to_target_node, and don't defined it at all
>> in common code for that case.
>
> So I agree with this, but it made me realize that the way
> memory_add_physaddr_to_nid() was defined as an exported weak symbol is
> similarly broken.
>
>>> --- a/mm/memory_hotplug.c
>>> +++ b/mm/memory_hotplug.c
>>> @@ -365,9 +365,14 @@ int __weak phys_to_target_node(u64 start)
>>> start);
>>> return 0;
>>> }
>>> +
>>> +/* If the arch did not export a strong symbol, export the weak one. */
>>> +#ifndef CONFIG_NUMA_KEEP_MEMINFO
>>> EXPORT_SYMBOL_GPL(phys_to_target_node);
>>> #endif
>>>
>>> +#endif
>>
>> i.e. move the ifdef to include the actual phys_to_target_node
>> definition, and remove the __weak from it here.
>
> The trick is finding an arch common way to pick up the presence of the
> phys_to_target_node() override, and it still has the wart of ifdefery
> in C code.
>
> I went a bit deeper and moved all the fallback routines to
> linux/numa.h and the overrides in all archs that care to
> asm/sparsemem.h. Note that asm/sparsemem.h was not my first choice,
> but it happened to be where powerpc was already defining its
> phys-addr-to-node-id infrastructure, and my first choice header,
> asm/numa.h, is not universally available.
>
> The attached patch is going through some kbuild-robot exposure to make
> sure I did not break anything else.
>
Works for me. Thanks.
Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
--
~Randy
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] x86/mm: Fix phys_to_target_node() export
2020-11-02 23:52 ` Dan Williams
2020-11-03 0:59 ` Randy Dunlap
@ 2020-11-03 8:33 ` Christoph Hellwig
2020-11-03 10:39 ` Thomas Gleixner
2020-11-04 1:38 ` Andrew Morton
3 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-11-03 8:33 UTC (permalink / raw)
To: Dan Williams
Cc: Christoph Hellwig, Andrew Morton, Randy Dunlap, Thomas Gleixner,
kernel test robot, Joao Martins, X86 ML, Linux MM, linux-nvdimm
This version looks sensible to me:
Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] x86/mm: Fix phys_to_target_node() export
2020-11-02 23:52 ` Dan Williams
2020-11-03 0:59 ` Randy Dunlap
2020-11-03 8:33 ` Christoph Hellwig
@ 2020-11-03 10:39 ` Thomas Gleixner
2020-11-04 1:38 ` Andrew Morton
3 siblings, 0 replies; 13+ messages in thread
From: Thomas Gleixner @ 2020-11-03 10:39 UTC (permalink / raw)
To: Dan Williams, Christoph Hellwig
Cc: Andrew Morton, Randy Dunlap, kernel test robot, Joao Martins,
X86 ML, Linux MM, linux-nvdimm
On Mon, Nov 02 2020 at 15:52, Dan Williams wrote:
> On Sat, Oct 31, 2020 at 2:10 AM Christoph Hellwig <hch@infradead.org> wrote:
> 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.
>
> 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>
> Fixes: a035b6bf863e ("mm/memory_hotplug: introduce default phys_to_target_node() implementation")
> Cc: Joao Martins <joao.m.martins@oracle.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: x86@kernel.org
> 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>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Tested-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] x86/mm: Fix phys_to_target_node() export
2020-11-02 23:52 ` Dan Williams
` (2 preceding siblings ...)
2020-11-03 10:39 ` Thomas Gleixner
@ 2020-11-04 1:38 ` Andrew Morton
2020-11-04 1:49 ` Dan Williams
3 siblings, 1 reply; 13+ messages in thread
From: Andrew Morton @ 2020-11-04 1:38 UTC (permalink / raw)
To: Dan Williams
Cc: Christoph Hellwig, Randy Dunlap, Thomas Gleixner,
kernel test robot, Joao Martins, X86 ML, Linux MM, linux-nvdimm
On Mon, 2 Nov 2020 15:52:39 -0800 Dan Williams <dan.j.williams@intel.com> wrote:
> The attached patch is going through some kbuild-robot exposure to make
> sure I did not break anything else.
I'll duck this for now - please send it along formally if/when testing
is successful.
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] x86/mm: Fix phys_to_target_node() export
2020-11-04 1:38 ` Andrew Morton
@ 2020-11-04 1:49 ` Dan Williams
0 siblings, 0 replies; 13+ messages in thread
From: Dan Williams @ 2020-11-04 1:49 UTC (permalink / raw)
To: Andrew Morton
Cc: Christoph Hellwig, Randy Dunlap, Thomas Gleixner,
kernel test robot, Joao Martins, X86 ML, Linux MM, linux-nvdimm
On Tue, Nov 3, 2020 at 5:38 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Mon, 2 Nov 2020 15:52:39 -0800 Dan Williams <dan.j.williams@intel.com> wrote:
>
> > The attached patch is going through some kbuild-robot exposure to make
> > sure I did not break anything else.
>
> I'll duck this for now - please send it along formally if/when testing
> is successful.
Yeah, the robots are angry, some reworks needed.
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2020-11-04 1:49 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-30 2:29 [PATCH] x86/mm: Fix phys_to_target_node() export Dan Williams
2020-10-30 3:05 ` Randy Dunlap
2020-10-30 11:34 ` David Hildenbrand
2020-10-31 1:54 ` Dan Williams
2020-10-31 3:01 ` Thomas Gleixner
2020-10-31 4:45 ` Dan Williams
2020-10-31 9:10 ` Christoph Hellwig
2020-11-02 23:52 ` Dan Williams
2020-11-03 0:59 ` Randy Dunlap
2020-11-03 8:33 ` Christoph Hellwig
2020-11-03 10:39 ` Thomas Gleixner
2020-11-04 1:38 ` Andrew Morton
2020-11-04 1:49 ` Dan Williams
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).