[15/50] kernel/numa.c: Move logging out of numa.h

Message ID 20231216032651.3553101-5-kent.overstreet@linux.dev
State New
Headers
Series big header dependency cleanup targeting sched.h |

Commit Message

Kent Overstreet Dec. 16, 2023, 3:26 a.m. UTC
  Moving these stub functions to a .c file means we can kill a sched.h
dependency on printk.h.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 include/linux/numa.h | 18 +++++-------------
 kernel/Makefile      |  1 +
 kernel/numa.c        | 24 ++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 13 deletions(-)
 create mode 100644 kernel/numa.c
  

Comments

Nathan Chancellor Dec. 19, 2023, 4:36 p.m. UTC | #1
On Fri, Dec 15, 2023 at 10:26:14PM -0500, Kent Overstreet wrote:
> Moving these stub functions to a .c file means we can kill a sched.h
> dependency on printk.h.
> 
> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
> ---
>  include/linux/numa.h | 18 +++++-------------
>  kernel/Makefile      |  1 +
>  kernel/numa.c        | 24 ++++++++++++++++++++++++
>  3 files changed, 30 insertions(+), 13 deletions(-)
>  create mode 100644 kernel/numa.c
> 
> diff --git a/include/linux/numa.h b/include/linux/numa.h
> index a904861de800..aeab3d9f57ae 100644
> --- a/include/linux/numa.h
> +++ b/include/linux/numa.h
> @@ -22,34 +22,26 @@
>  #endif
>  
>  #ifdef CONFIG_NUMA
> -#include <linux/printk.h>
>  #include <asm/sparsemem.h>
>  
>  /* Generic implementation available */
>  int numa_nearest_node(int node, unsigned int state);
>  
>  #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;
> -}
> +int memory_add_physaddr_to_nid(u64 start);
>  #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;
> -}
> +int phys_to_target_node(u64 start);
>  #endif
> +
>  #ifndef numa_fill_memblks
>  static inline int __init numa_fill_memblks(u64 start, u64 end)
>  {
>  	return NUMA_NO_MEMBLK;
>  }
>  #endif
> +
>  #else /* !CONFIG_NUMA */
>  static inline int numa_nearest_node(int node, unsigned int state)
>  {
> diff --git a/kernel/Makefile b/kernel/Makefile
> index 3947122d618b..ce105a5558fc 100644
> --- a/kernel/Makefile
> +++ b/kernel/Makefile
> @@ -114,6 +114,7 @@ obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o
>  obj-$(CONFIG_HAVE_STATIC_CALL) += static_call.o
>  obj-$(CONFIG_HAVE_STATIC_CALL_INLINE) += static_call_inline.o
>  obj-$(CONFIG_CFI_CLANG) += cfi.o
> +obj-$(CONFIG_NUMA) += numa.o
>  
>  obj-$(CONFIG_PERF_EVENTS) += events/
>  
> diff --git a/kernel/numa.c b/kernel/numa.c
> new file mode 100644
> index 000000000000..c24c72f45989
> --- /dev/null
> +++ b/kernel/numa.c
> @@ -0,0 +1,24 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +
> +#include <linux/printk.h>
> +#include <linux/numa.h>
> +
> +/* Stub functions: */
> +
> +#ifndef memory_add_physaddr_to_nid
> +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
> +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
> -- 
> 2.43.0
> 

These need EXPORT_SYMBOL_GPL() now like the architecture specific
implementations because they are no longer inlined. My arm64 builds fail
with:

  ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/acpi/nfit/nfit.ko] undefined!
  ERROR: modpost: "phys_to_target_node" [drivers/acpi/nfit/nfit.ko] undefined!
  ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/virtio/virtio_mem.ko] undefined!
  ERROR: modpost: "phys_to_target_node" [drivers/dax/dax_cxl.ko] undefined!
  ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/dax/dax_cxl.ko] undefined!
  ERROR: modpost: "phys_to_target_node" [drivers/cxl/cxl_acpi.ko] undefined!
  ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/cxl/cxl_pmem.ko] undefined!
  ERROR: modpost: "phys_to_target_node" [drivers/cxl/cxl_pmem.ko] undefined!
  ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/hv/hv_balloon.ko] undefined!

Cheers,
Nathan
  
Kent Overstreet Dec. 19, 2023, 9:02 p.m. UTC | #2
On Tue, Dec 19, 2023 at 09:36:44AM -0700, Nathan Chancellor wrote:
> On Fri, Dec 15, 2023 at 10:26:14PM -0500, Kent Overstreet wrote:
> These need EXPORT_SYMBOL_GPL() now like the architecture specific
> implementations because they are no longer inlined. My arm64 builds fail
> with:
> 
>   ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/acpi/nfit/nfit.ko] undefined!
>   ERROR: modpost: "phys_to_target_node" [drivers/acpi/nfit/nfit.ko] undefined!
>   ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/virtio/virtio_mem.ko] undefined!
>   ERROR: modpost: "phys_to_target_node" [drivers/dax/dax_cxl.ko] undefined!
>   ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/dax/dax_cxl.ko] undefined!
>   ERROR: modpost: "phys_to_target_node" [drivers/cxl/cxl_acpi.ko] undefined!
>   ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/cxl/cxl_pmem.ko] undefined!
>   ERROR: modpost: "phys_to_target_node" [drivers/cxl/cxl_pmem.ko] undefined!
>   ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/hv/hv_balloon.ko] undefined!

Applied the following:


commit 7ae175e405b44b9897c04bbf177e3e08ab25710a
Author: Kent Overstreet <kent.overstreet@linux.dev>
Date:   Tue Dec 19 16:02:26 2023 -0500

    fixup! kernel/numa.c: Move logging out of numa.h

diff --git a/kernel/numa.c b/kernel/numa.c
index c24c72f45989..67ca6b8585c0 100644
--- a/kernel/numa.c
+++ b/kernel/numa.c
@@ -12,6 +12,7 @@ int memory_add_physaddr_to_nid(u64 start)
 			start);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
 #endif
 
 #ifndef phys_to_target_node
@@ -21,4 +22,5 @@ int phys_to_target_node(u64 start)
 			start);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(phys_to_target_node);
 #endif
  
Matthew Wilcox Dec. 19, 2023, 10:52 p.m. UTC | #3
On Fri, Dec 15, 2023 at 10:26:14PM -0500, Kent Overstreet wrote:
> diff --git a/kernel/numa.c b/kernel/numa.c
> new file mode 100644
> index 000000000000..c24c72f45989
> --- /dev/null
> +++ b/kernel/numa.c

Should this be a new file or would these functions fit better in, eg,
mempolicy.c which is already built only if CONFIG_NUMA?
  
Kent Overstreet Dec. 20, 2023, 12:37 a.m. UTC | #4
On Tue, Dec 19, 2023 at 10:52:33PM +0000, Matthew Wilcox wrote:
> On Fri, Dec 15, 2023 at 10:26:14PM -0500, Kent Overstreet wrote:
> > diff --git a/kernel/numa.c b/kernel/numa.c
> > new file mode 100644
> > index 000000000000..c24c72f45989
> > --- /dev/null
> > +++ b/kernel/numa.c
> 
> Should this be a new file or would these functions fit better in, eg,
> mempolicy.c which is already built only if CONFIG_NUMA?

that does look like a bit of a disorganized dumping ground though, I
wonder if anyone would want to start mm/numa/ and do a bit of
organizing?
  

Patch

diff --git a/include/linux/numa.h b/include/linux/numa.h
index a904861de800..aeab3d9f57ae 100644
--- a/include/linux/numa.h
+++ b/include/linux/numa.h
@@ -22,34 +22,26 @@ 
 #endif
 
 #ifdef CONFIG_NUMA
-#include <linux/printk.h>
 #include <asm/sparsemem.h>
 
 /* Generic implementation available */
 int numa_nearest_node(int node, unsigned int state);
 
 #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;
-}
+int memory_add_physaddr_to_nid(u64 start);
 #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;
-}
+int phys_to_target_node(u64 start);
 #endif
+
 #ifndef numa_fill_memblks
 static inline int __init numa_fill_memblks(u64 start, u64 end)
 {
 	return NUMA_NO_MEMBLK;
 }
 #endif
+
 #else /* !CONFIG_NUMA */
 static inline int numa_nearest_node(int node, unsigned int state)
 {
diff --git a/kernel/Makefile b/kernel/Makefile
index 3947122d618b..ce105a5558fc 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -114,6 +114,7 @@  obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o
 obj-$(CONFIG_HAVE_STATIC_CALL) += static_call.o
 obj-$(CONFIG_HAVE_STATIC_CALL_INLINE) += static_call_inline.o
 obj-$(CONFIG_CFI_CLANG) += cfi.o
+obj-$(CONFIG_NUMA) += numa.o
 
 obj-$(CONFIG_PERF_EVENTS) += events/
 
diff --git a/kernel/numa.c b/kernel/numa.c
new file mode 100644
index 000000000000..c24c72f45989
--- /dev/null
+++ b/kernel/numa.c
@@ -0,0 +1,24 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/printk.h>
+#include <linux/numa.h>
+
+/* Stub functions: */
+
+#ifndef memory_add_physaddr_to_nid
+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
+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