[PATCH] mm: change vma_alloc_folio_noprof() macro to inline function

Arnd Bergmann posted 1 patch 1 month ago
include/linux/gfp.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
[PATCH] mm: change vma_alloc_folio_noprof() macro to inline function
Posted by Arnd Bergmann 1 month ago
From: Arnd Bergmann <arnd@arndb.de>

In a few rare configurations with extra warnings eanbled, the new
drm_pagemap_migrate_populate_ram_pfn() calls vma_alloc_folio_noprof()
but that does not use all the arguments, leading to a harmless warning:

drivers/gpu/drm/drm_pagemap.c: In function 'drm_pagemap_migrate_populate_ram_pfn':
drivers/gpu/drm/drm_pagemap.c:701:63: error: parameter 'addr' set but not used [-Werror=unused-but-set-parameter=]
  701 |                                                 unsigned long addr)
      |                                                 ~~~~~~~~~~~~~~^~~~

Replace the macro with an inline function so the compiler can see
how the argument would be used, but is still able to optimize out
the assignments.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 include/linux/gfp.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 6ecf6dda93e0..23240208a91f 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -335,8 +335,11 @@ static inline struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int orde
 {
 	return folio_alloc_noprof(gfp, order);
 }
-#define vma_alloc_folio_noprof(gfp, order, vma, addr)		\
-	folio_alloc_noprof(gfp, order)
+static inline struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order,
+		struct vm_area_struct *vma, unsigned long addr)
+{
+	return folio_alloc_noprof(gfp, order);
+}
 #endif
 
 #define alloc_pages(...)			alloc_hooks(alloc_pages_noprof(__VA_ARGS__))
-- 
2.39.5
Re: [PATCH] mm: change vma_alloc_folio_noprof() macro to inline function
Posted by Zi Yan 1 month ago
On 16 Feb 2026, at 7:17, Arnd Bergmann wrote:

> From: Arnd Bergmann <arnd@arndb.de>
>
> In a few rare configurations with extra warnings eanbled, the new

s/eanbled/enabled

> drm_pagemap_migrate_populate_ram_pfn() calls vma_alloc_folio_noprof()
> but that does not use all the arguments, leading to a harmless warning:
>
> drivers/gpu/drm/drm_pagemap.c: In function 'drm_pagemap_migrate_populate_ram_pfn':
> drivers/gpu/drm/drm_pagemap.c:701:63: error: parameter 'addr' set but not used [-Werror=unused-but-set-parameter=]
>   701 |                                                 unsigned long addr)
>       |                                                 ~~~~~~~~~~~~~~^~~~
>

But addr is used at line 739 or line 741:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/drm_pagemap.c#n739

I wonder why compiler reported the error.

> Replace the macro with an inline function so the compiler can see
> how the argument would be used, but is still able to optimize out
> the assignments.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  include/linux/gfp.h | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/gfp.h b/include/linux/gfp.h
> index 6ecf6dda93e0..23240208a91f 100644
> --- a/include/linux/gfp.h
> +++ b/include/linux/gfp.h
> @@ -335,8 +335,11 @@ static inline struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int orde
>  {
>  	return folio_alloc_noprof(gfp, order);
>  }
> -#define vma_alloc_folio_noprof(gfp, order, vma, addr)		\
> -	folio_alloc_noprof(gfp, order)
> +static inline struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order,
> +		struct vm_area_struct *vma, unsigned long addr)
> +{
> +	return folio_alloc_noprof(gfp, order);
> +}
>  #endif
>
>  #define alloc_pages(...)			alloc_hooks(alloc_pages_noprof(__VA_ARGS__))
> -- 
> 2.39.5

The changes look good to me.

Acked-by: Zi Yan <ziy@nvidia.com>

--
Best Regards,
Yan, Zi
Re: [PATCH] mm: change vma_alloc_folio_noprof() macro to inline function
Posted by Suren Baghdasaryan 1 month ago
On Mon, Feb 16, 2026 at 4:58 PM Zi Yan <ziy@nvidia.com> wrote:
>
> On 16 Feb 2026, at 7:17, Arnd Bergmann wrote:
>
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > In a few rare configurations with extra warnings eanbled, the new
>
> s/eanbled/enabled
>
> > drm_pagemap_migrate_populate_ram_pfn() calls vma_alloc_folio_noprof()
> > but that does not use all the arguments, leading to a harmless warning:
> >
> > drivers/gpu/drm/drm_pagemap.c: In function 'drm_pagemap_migrate_populate_ram_pfn':
> > drivers/gpu/drm/drm_pagemap.c:701:63: error: parameter 'addr' set but not used [-Werror=unused-but-set-parameter=]
> >   701 |                                                 unsigned long addr)
> >       |                                                 ~~~~~~~~~~~~~~^~~~
> >
>
> But addr is used at line 739 or line 741:
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/gpu/drm/drm_pagemap.c#n739
>
> I wonder why compiler reported the error.
>
> > Replace the macro with an inline function so the compiler can see
> > how the argument would be used, but is still able to optimize out
> > the assignments.
> >
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> >  include/linux/gfp.h | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/linux/gfp.h b/include/linux/gfp.h
> > index 6ecf6dda93e0..23240208a91f 100644
> > --- a/include/linux/gfp.h
> > +++ b/include/linux/gfp.h
> > @@ -335,8 +335,11 @@ static inline struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int orde
> >  {
> >       return folio_alloc_noprof(gfp, order);
> >  }
> > -#define vma_alloc_folio_noprof(gfp, order, vma, addr)                \
> > -     folio_alloc_noprof(gfp, order)
> > +static inline struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order,
> > +             struct vm_area_struct *vma, unsigned long addr)
> > +{
> > +     return folio_alloc_noprof(gfp, order);
> > +}
> >  #endif
> >
> >  #define alloc_pages(...)                     alloc_hooks(alloc_pages_noprof(__VA_ARGS__))
> > --
> > 2.39.5
>
> The changes look good to me.
>
> Acked-by: Zi Yan <ziy@nvidia.com>

LGTM. _noprof() functions don't need to be macros.

Reviewed-by: Suren Baghdasaryan <surenb@google.com>


>
> --
> Best Regards,
> Yan, Zi
Re: [PATCH] mm: change vma_alloc_folio_noprof() macro to inline function
Posted by Lorenzo Stoakes 1 month ago
On Mon, Feb 16, 2026 at 01:17:44PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> In a few rare configurations with extra warnings eanbled, the new
> drm_pagemap_migrate_populate_ram_pfn() calls vma_alloc_folio_noprof()
> but that does not use all the arguments, leading to a harmless warning:
>
> drivers/gpu/drm/drm_pagemap.c: In function 'drm_pagemap_migrate_populate_ram_pfn':
> drivers/gpu/drm/drm_pagemap.c:701:63: error: parameter 'addr' set but not used [-Werror=unused-but-set-parameter=]
>   701 |                                                 unsigned long addr)
>       |                                                 ~~~~~~~~~~~~~~^~~~
>
> Replace the macro with an inline function so the compiler can see
> how the argument would be used, but is still able to optimize out
> the assignments.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

It'd be good if we could find a way to avoid these horrible _noprof things, but
I guess that ship's sailed for now...

Anyway, LGTM, so:

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

> ---
>  include/linux/gfp.h | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/gfp.h b/include/linux/gfp.h
> index 6ecf6dda93e0..23240208a91f 100644
> --- a/include/linux/gfp.h
> +++ b/include/linux/gfp.h
> @@ -335,8 +335,11 @@ static inline struct folio *folio_alloc_mpol_noprof(gfp_t gfp, unsigned int orde
>  {
>  	return folio_alloc_noprof(gfp, order);
>  }
> -#define vma_alloc_folio_noprof(gfp, order, vma, addr)		\
> -	folio_alloc_noprof(gfp, order)
> +static inline struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order,
> +		struct vm_area_struct *vma, unsigned long addr)
> +{
> +	return folio_alloc_noprof(gfp, order);
> +}
>  #endif
>
>  #define alloc_pages(...)			alloc_hooks(alloc_pages_noprof(__VA_ARGS__))
> --
> 2.39.5
>

Cheers, Lorenzo