diff mbox series

x86/mm: Fix phys_to_target_node() export

Message ID 160402498564.4173389.2743697400148832021.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show
Series x86/mm: Fix phys_to_target_node() export | expand

Commit Message

Dan Williams Oct. 30, 2020, 2:29 a.m. UTC
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(-)

Comments

Randy Dunlap Oct. 30, 2020, 3:05 a.m. UTC | #1
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,
> 
>
David Hildenbrand Oct. 30, 2020, 11:34 a.m. UTC | #2
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>
Dan Williams Oct. 31, 2020, 1:54 a.m. UTC | #3
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.
Thomas Gleixner Oct. 31, 2020, 3:01 a.m. UTC | #4
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>
Dan Williams Oct. 31, 2020, 4:45 a.m. UTC | #5
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?
Christoph Hellwig Oct. 31, 2020, 9:10 a.m. UTC | #6
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.
Dan Williams Nov. 2, 2020, 11:52 p.m. UTC | #7
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.
Randy Dunlap Nov. 3, 2020, 12:59 a.m. UTC | #8
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
Christoph Hellwig Nov. 3, 2020, 8:33 a.m. UTC | #9
This version looks sensible to me:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Thomas Gleixner Nov. 3, 2020, 10:39 a.m. UTC | #10
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>
Andrew Morton Nov. 4, 2020, 1:38 a.m. UTC | #11
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.
Dan Williams Nov. 4, 2020, 1:49 a.m. UTC | #12
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.
diff mbox series

Patch

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,