[PATCH] [v2] alloc_tag: hide execmem_vmap() on !MMU

Arnd Bergmann posted 1 patch 3 weeks, 6 days ago
mm/execmem.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
[PATCH] [v2] alloc_tag: hide execmem_vmap() on !MMU
Posted by Arnd Bergmann 3 weeks, 6 days ago
From: Arnd Bergmann <arnd@arndb.de>

The newly added function fails to link on nommu kernels, but is also
not needed there:

ld.lld-20: error: undefined symbol: __get_vm_area_node
>>> referenced by execmem.c
>>>               mm/execmem.o:(execmem_vmap) in archive vmlinux.a
>>> referenced by execmem.c
>>>               mm/execmem.o:(execmem_vmap) in archive vmlinux.a

Move it into the #ifdef block along with execmem_vmalloc().

Fixes: 57bc3834fb6f ("alloc_tag: populate memory for module tags as needed")
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 mm/execmem.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/mm/execmem.c b/mm/execmem.c
index 5c0f9f2d6f83..317b6a8d35be 100644
--- a/mm/execmem.c
+++ b/mm/execmem.c
@@ -64,6 +64,22 @@ static void *execmem_vmalloc(struct execmem_range *range, size_t size,
 
 	return p;
 }
+
+struct vm_struct *execmem_vmap(size_t size)
+{
+	struct execmem_range *range = &execmem_info->ranges[EXECMEM_MODULE_DATA];
+	struct vm_struct *area;
+
+	area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
+				  range->start, range->end, NUMA_NO_NODE,
+				  GFP_KERNEL, __builtin_return_address(0));
+	if (!area && range->fallback_start)
+		area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
+					  range->fallback_start, range->fallback_end,
+					  NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0));
+
+	return area;
+}
 #else
 static void *execmem_vmalloc(struct execmem_range *range, size_t size,
 			     pgprot_t pgprot, unsigned long vm_flags)
@@ -368,22 +384,6 @@ void execmem_free(void *ptr)
 		vfree(ptr);
 }
 
-struct vm_struct *execmem_vmap(size_t size)
-{
-	struct execmem_range *range = &execmem_info->ranges[EXECMEM_MODULE_DATA];
-	struct vm_struct *area;
-
-	area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
-				  range->start, range->end, NUMA_NO_NODE,
-				  GFP_KERNEL, __builtin_return_address(0));
-	if (!area && range->fallback_start)
-		area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
-					  range->fallback_start, range->fallback_end,
-					  NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0));
-
-	return area;
-}
-
 void *execmem_update_copy(void *dst, const void *src, size_t size)
 {
 	return text_poke_copy(dst, src, size);
-- 
2.39.5
Re: [PATCH] [v2] alloc_tag: hide execmem_vmap() on !MMU
Posted by Suren Baghdasaryan 3 weeks, 6 days ago
On Mon, Oct 28, 2024 at 8:04 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> The newly added function fails to link on nommu kernels, but is also
> not needed there:
>
> ld.lld-20: error: undefined symbol: __get_vm_area_node
> >>> referenced by execmem.c
> >>>               mm/execmem.o:(execmem_vmap) in archive vmlinux.a
> >>> referenced by execmem.c
> >>>               mm/execmem.o:(execmem_vmap) in archive vmlinux.a
>
> Move it into the #ifdef block along with execmem_vmalloc().
>
> Fixes: 57bc3834fb6f ("alloc_tag: populate memory for module tags as needed")
> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Sorry, replied to your older version. Copying here:

Thanks for the fix but execmem_vmap() is used if
CONFIG_MEM_ALLOC_PROFILING=y. Please give me an hour to post a fix
dealing with that.

> ---
>  mm/execmem.c | 32 ++++++++++++++++----------------
>  1 file changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/mm/execmem.c b/mm/execmem.c
> index 5c0f9f2d6f83..317b6a8d35be 100644
> --- a/mm/execmem.c
> +++ b/mm/execmem.c
> @@ -64,6 +64,22 @@ static void *execmem_vmalloc(struct execmem_range *range, size_t size,
>
>         return p;
>  }
> +
> +struct vm_struct *execmem_vmap(size_t size)
> +{
> +       struct execmem_range *range = &execmem_info->ranges[EXECMEM_MODULE_DATA];
> +       struct vm_struct *area;
> +
> +       area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
> +                                 range->start, range->end, NUMA_NO_NODE,
> +                                 GFP_KERNEL, __builtin_return_address(0));
> +       if (!area && range->fallback_start)
> +               area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
> +                                         range->fallback_start, range->fallback_end,
> +                                         NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0));
> +
> +       return area;
> +}
>  #else
>  static void *execmem_vmalloc(struct execmem_range *range, size_t size,
>                              pgprot_t pgprot, unsigned long vm_flags)
> @@ -368,22 +384,6 @@ void execmem_free(void *ptr)
>                 vfree(ptr);
>  }
>
> -struct vm_struct *execmem_vmap(size_t size)
> -{
> -       struct execmem_range *range = &execmem_info->ranges[EXECMEM_MODULE_DATA];
> -       struct vm_struct *area;
> -
> -       area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
> -                                 range->start, range->end, NUMA_NO_NODE,
> -                                 GFP_KERNEL, __builtin_return_address(0));
> -       if (!area && range->fallback_start)
> -               area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
> -                                         range->fallback_start, range->fallback_end,
> -                                         NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0));
> -
> -       return area;
> -}
> -
>  void *execmem_update_copy(void *dst, const void *src, size_t size)
>  {
>         return text_poke_copy(dst, src, size);
> --
> 2.39.5
>
Re: [PATCH] [v2] alloc_tag: hide execmem_vmap() on !MMU
Posted by Suren Baghdasaryan 3 weeks, 6 days ago
On Mon, Oct 28, 2024 at 11:53 AM Suren Baghdasaryan <surenb@google.com> wrote:
>
> On Mon, Oct 28, 2024 at 8:04 AM Arnd Bergmann <arnd@kernel.org> wrote:
> >
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > The newly added function fails to link on nommu kernels, but is also
> > not needed there:
> >
> > ld.lld-20: error: undefined symbol: __get_vm_area_node
> > >>> referenced by execmem.c
> > >>>               mm/execmem.o:(execmem_vmap) in archive vmlinux.a
> > >>> referenced by execmem.c
> > >>>               mm/execmem.o:(execmem_vmap) in archive vmlinux.a
> >
> > Move it into the #ifdef block along with execmem_vmalloc().
> >
> > Fixes: 57bc3834fb6f ("alloc_tag: populate memory for module tags as needed")
> > Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Sorry, replied to your older version. Copying here:
>
> Thanks for the fix but execmem_vmap() is used if
> CONFIG_MEM_ALLOC_PROFILING=y. Please give me an hour to post a fix
> dealing with that.

The fix that will work with CONFIG_MEM_ALLOC_PROFILING is posted at
https://lore.kernel.org/all/20241028202935.1047017-1-surenb@google.com/

>
> > ---
> >  mm/execmem.c | 32 ++++++++++++++++----------------
> >  1 file changed, 16 insertions(+), 16 deletions(-)
> >
> > diff --git a/mm/execmem.c b/mm/execmem.c
> > index 5c0f9f2d6f83..317b6a8d35be 100644
> > --- a/mm/execmem.c
> > +++ b/mm/execmem.c
> > @@ -64,6 +64,22 @@ static void *execmem_vmalloc(struct execmem_range *range, size_t size,
> >
> >         return p;
> >  }
> > +
> > +struct vm_struct *execmem_vmap(size_t size)
> > +{
> > +       struct execmem_range *range = &execmem_info->ranges[EXECMEM_MODULE_DATA];
> > +       struct vm_struct *area;
> > +
> > +       area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
> > +                                 range->start, range->end, NUMA_NO_NODE,
> > +                                 GFP_KERNEL, __builtin_return_address(0));
> > +       if (!area && range->fallback_start)
> > +               area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
> > +                                         range->fallback_start, range->fallback_end,
> > +                                         NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0));
> > +
> > +       return area;
> > +}
> >  #else
> >  static void *execmem_vmalloc(struct execmem_range *range, size_t size,
> >                              pgprot_t pgprot, unsigned long vm_flags)
> > @@ -368,22 +384,6 @@ void execmem_free(void *ptr)
> >                 vfree(ptr);
> >  }
> >
> > -struct vm_struct *execmem_vmap(size_t size)
> > -{
> > -       struct execmem_range *range = &execmem_info->ranges[EXECMEM_MODULE_DATA];
> > -       struct vm_struct *area;
> > -
> > -       area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
> > -                                 range->start, range->end, NUMA_NO_NODE,
> > -                                 GFP_KERNEL, __builtin_return_address(0));
> > -       if (!area && range->fallback_start)
> > -               area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
> > -                                         range->fallback_start, range->fallback_end,
> > -                                         NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0));
> > -
> > -       return area;
> > -}
> > -
> >  void *execmem_update_copy(void *dst, const void *src, size_t size)
> >  {
> >         return text_poke_copy(dst, src, size);
> > --
> > 2.39.5
> >