Skip to contentSkip to conversation

linux-next: build warning after merge of the mm-unstable tree

DISCUSSION Stephen Rothwell 3 participants 3 messages Sep 4, 2025

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

Hi all,

After merging the mm-unstable tree, today's linux-next build (arm multi_v7_defconfig) produced this warning:

In file included from include/linux/highmem.h:14,
from include/linux/bvec.h:10,
from include/linux/blk_types.h:10,
from include/linux/writeback.h:13,
from include/linux/memcontrol.h:23,
from include/linux/swap.h:9,
from include/linux/suspend.h:5,
from arch/arm/mach-highbank/pm.c:9:
include/linux/highmem-internal.h: In function 'kmap_local_folio':
include/linux/highmem-internal.h:86:46: warning: passing argument 1 of 'folio_page' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
86 | const struct page *page = folio_page(folio, offset / PAGE_SIZE);
| ^~~~~
In file included from include/linux/mmzone.h:23,
from include/linux/swap.h:7:
include/linux/page-flags.h:319:53: note: expected 'struct folio *' but argument is of type 'const struct folio *'
319 | static inline struct page *folio_page(struct folio *folio, unsigned long n)

      |                                       ~~~~~~~~~~~~~~^~~~~

And 5.5MB more :-(

Introduced by commit

598ad57d4b46 ("mm: constify highmem related functions for improved const-correctness")

I have reverted that commit for today.

Signature · 2 lines
Cheers,
Stephen Rothwell
maintainer
#1 lore raw
Quoted 19 lines · On Thu, 4 Sep 2025 12:14:38 +1000 Stephen Rothwell <[email protected]> wrote:

After merging the mm-unstable tree, today's linux-next build (arm multi_v7_defconfig) produced this warning:

In file included from include/linux/highmem.h:14,
from include/linux/bvec.h:10,
from include/linux/blk_types.h:10,
from include/linux/writeback.h:13,
from include/linux/memcontrol.h:23,
from include/linux/swap.h:9,
from include/linux/suspend.h:5,
from arch/arm/mach-highbank/pm.c:9:
include/linux/highmem-internal.h: In function 'kmap_local_folio':
include/linux/highmem-internal.h:86:46: warning: passing argument 1 of 'folio_page' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
86 | const struct page *page = folio_page(folio, offset / PAGE_SIZE);
| ^~~~~
In file included from include/linux/mmzone.h:23,
from include/linux/swap.h:7:
include/linux/page-flags.h:319:53: note: expected 'struct folio *' but argument is of type 'const struct folio *'
319 | static inline struct page *folio_page(struct folio *folio, unsigned long n)

Yeah, thanks, folio_page() is a problem. I'll do the below nasty for now, but nasty.

include/linux/page-flags.h renamed from include/linux/page-flags.h~mm-constify-highmem-related-functions-for-improved-const-correctness-fix +2 -2
@@ -316,9 +316,9 @@ static __always_inline unsigned long _co
  * check that the page number lies within @folio; the caller is presumed
  * to have a reference to the page.
  */
-static inline struct page *folio_page(struct folio *folio, unsigned long n)
+static inline struct page *folio_page(const struct folio *folio, unsigned long n)
 {
-	return &folio->page + n;
+	return (struct page *)(&folio->page + n);
 }
 
 static __always_inline int PageTail(const struct page *page)

_

#2 lore raw
Quoted 5 lines · Andrew Morton
Quoted 3 lines · On Thu, 4 Sep 2025 12:14:38 +1000 Stephen Rothwell <[email protected]> wrote:

After merging the mm-unstable tree, today's linux-next build (arm multi_v7_defconfig) produced this warning:

Quoted 17 lines
Quoted 10 lines

In file included from include/linux/highmem.h:14,
from include/linux/bvec.h:10,
from include/linux/blk_types.h:10,
from include/linux/writeback.h:13,
from include/linux/memcontrol.h:23,
from include/linux/swap.h:9,
from include/linux/suspend.h:5,
from arch/arm/mach-highbank/pm.c:9:
include/linux/highmem-internal.h: In function 'kmap_local_folio':
include/linux/highmem-internal.h:86:46: warning: passing argument 1 of 'folio_page' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]

Quoted 6 lines
    86 |         const struct page *page = folio_page(folio, offset / PAGE_SIZE);
       |                                              ^~~~~

In file included from include/linux/mmzone.h:23,
from include/linux/swap.h:7:
include/linux/page-flags.h:319:53: note: expected 'struct folio *' but argument is of type 'const struct folio *'
319 | static inline struct page *folio_page(struct folio *folio, unsigned long n)

Hm, why did we not detect that in mm-new?

Quoted 18 lines

Yeah, thanks, folio_page() is a problem. I'll do the below nasty for now, but nasty.

include/linux/page-flags.h renamed from include/linux/page-flags.h~mm-constify-highmem-related-functions-for-improved-const-correctness-fix +2 -2
@@ -316,9 +316,9 @@ static __always_inline unsigned long _co
   * check that the page number lies within @folio; the caller is presumed
   * to have a reference to the page.
   */
-static inline struct page *folio_page(struct folio *folio, unsigned long n)
+static inline struct page *folio_page(const struct folio *folio, unsigned long n)
  {
-	return &folio->page + n;
+	return (struct page *)(&folio->page + n);
  }
 
  static __always_inline int PageTail(const struct page *page)
Quoted 1 line

_

I think the problem appears when nth_page() removal is paired with const-correctness.

Not a fan of going back to a plain macro either. Likely we can handle it similar to page_folio() and perform the cast cleanly:

include/linux/page-flags.h +9 -4
index faf17ca211b4f..dc67fe08e77c8 100644
@@ -307,6 +307,12 @@ static __always_inline unsigned long _compound_head(const struct page *page)
        const struct page *:    (const struct folio *)_compound_head(p), \
        struct page *:          (struct folio *)_compound_head(p)))
 
+static inline const struct page *_folio_page(const struct folio *folio,
+               unsigned long n)
+{
+       return &folio->page + n;
+}
+
 /**
  * folio_page - Return a page from a folio.
  * @folio: The folio.
@@ -316,10 +322,9 @@ static __always_inline unsigned long _compound_head(const struct page *page)
  * check that the page number lies within @folio; the caller is presumed
  * to have a reference to the page.
  */
-static inline struct page *folio_page(struct folio *folio, unsigned long n)
-{
-       return &folio->page + n;
-}
+#define folio_page(f, p)       (_Generic((f),                          \
+       const struct folio *:   (const struct page *)_folio_page(f, p), \
+       struct folio *:         (struct page *)_folio_page(f, p)))
 
 static __always_inline int PageTail(const struct page *page)
 {
Signature · 3 lines
Cheers

David / dhildenb