Skip to contentSkip to conversation

mm: change vma_alloc_folio_noprof() macro to inline function

PATCH Applied Arnd Bergmann 4 participants 4 messages Feb 16

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: change vma_alloc_folio_noprof() macro to inline function

From: Arnd Bergmann <[email protected]>

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.

---
 include/linux/gfp.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
include/linux/gfp.h +5 -2
index 6ecf6dda93e0..23240208a91f 100644
@@ -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__))
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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=]

Quoted 8 lines
  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.

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:

Quoted 23 lines
---
 include/linux/gfp.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
include/linux/gfp.h +5 -3
index 6ecf6dda93e0..23240208a91f 100644
@@ -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__))
--
Quoted 2 lines

2.39.5

Cheers, Lorenzo

reviewer Acked-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 3 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

In a few rare configurations with extra warnings eanbled, the new

s/eanbled/enabled

Quoted 8 lines

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.

Quoted 29 lines

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.

---
 include/linux/gfp.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
include/linux/gfp.h +5 -2
index 6ecf6dda93e0..23240208a91f 100644
@@ -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__))
Signature · 1 line
2.39.5

The changes look good to me.

--
Best Regards,
Yan, Zi

reviewer Reviewed-by
#3 lore raw
Quoted 49 lines · Zi Yan
Quoted 3 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

In a few rare configurations with extra warnings eanbled, the new

s/eanbled/enabled

Quoted 8 lines

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.

Quoted 26 lines

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.

---
 include/linux/gfp.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
include/linux/gfp.h +5 -2
index 6ecf6dda93e0..23240208a91f 100644
@@ -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
 
Quoted 7 lines
Quoted 3 lines
include/linux/gfp.h +0 -1
 #define alloc_pages(...)                     alloc_hooks(alloc_pages_noprof(__VA_ARGS__))
--

2.39.5

The changes look good to me.

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

Quoted 4 lines

--
Best Regards,
Yan, Zi