Subject: linux-next: build failure after merge of the mm tree

From: Stephen Rothwell <[email-masked]>
Date: Wed, 25 Jan 2023 14:05:00 +1100

Hi all,

After merging the mm tree, today's linux-next build (x86_64 allnoconfig)
failed like this:

In file included from arch/x86/include/asm/page.h:85,
                 from arch/x86/include/asm/thread_info.h:12,
                 from include/linux/thread_info.h:60,
                 from arch/x86/include/asm/preempt.h:9,
                 from include/linux/preempt.h:78,
                 from include/linux/spinlock.h:56,
                 from include/linux/mmzone.h:8,
                 from include/linux/gfp.h:7,
                 from include/linux/slab.h:15,
                 from include/linux/crypto.h:20,
                 from arch/x86/kernel/asm-offsets.c:9:
include/linux/mm.h: In function 'folio_estimated_mapcount':
include/asm-generic/memory_model.h:35:21: error: implicit declaration of function 'page_to_section'; did you mean 'present_section'? [-Werror=implicit-function-declaration]
   35 |         int __sec = page_to_section(__pg);                      \
      |                     ^~~~~~~~~~~~~~~
include/asm-generic/memory_model.h:40:32: note: in definition of macro '__pfn_to_page'
   40 | ({      unsigned long __pfn = (pfn);                    \
      |                                ^~~
include/asm-generic/memory_model.h:52:21: note: in expansion of macro '__page_to_pfn'
   52 | #define page_to_pfn __page_to_pfn
      |                     ^~~~~~~~~~~~~
include/linux/mm.h:216:38: note: in expansion of macro 'page_to_pfn'
  216 | #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
      |                                      ^~~~~~~~~~~
include/linux/page-flags.h:286:33: note: in expansion of macro 'nth_page'
  286 | #define folio_page(folio, n)    nth_page(&(folio)->page, n)
      |                                 ^~~~~~~~
include/linux/mm.h:918:30: note: in expansion of macro 'folio_page'
  918 |         return page_mapcount(folio_page(folio, 0));
      |                              ^~~~~~~~~~
In file included from include/linux/memcontrol.h:20,
                 from include/linux/swap.h:9,
                 from include/linux/suspend.h:5,
                 from arch/x86/kernel/asm-offsets.c:14:
include/linux/mm.h: At top level:
include/linux/mm.h:1626:29: error: conflicting types for 'page_to_section'; have 'long unsigned int(const struct page *)'
 1626 | static inline unsigned long page_to_section(const struct page *page)
      |                             ^~~~~~~~~~~~~~~
include/asm-generic/memory_model.h:35:21: note: previous implicit declaration of 'page_to_section' with type 'int()'
   35 |         int __sec = page_to_section(__pg);                      \
      |                     ^~~~~~~~~~~~~~~
include/asm-generic/memory_model.h:40:32: note: in definition of macro '__pfn_to_page'
   40 | ({      unsigned long __pfn = (pfn);                    \
      |                                ^~~
include/asm-generic/memory_model.h:52:21: note: in expansion of macro '__page_to_pfn'
   52 | #define page_to_pfn __page_to_pfn
      |                     ^~~~~~~~~~~~~
include/linux/mm.h:216:38: note: in expansion of macro 'page_to_pfn'
  216 | #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
      |                                      ^~~~~~~~~~~
include/linux/page-flags.h:286:33: note: in expansion of macro 'nth_page'
  286 | #define folio_page(folio, n)    nth_page(&(folio)->page, n)
      |                                 ^~~~~~~~
include/linux/mm.h:918:30: note: in expansion of macro 'folio_page'
  918 |         return page_mapcount(folio_page(folio, 0));
      |                              ^~~~~~~~~~
cc1: some warnings being treated as errors

Caused by commit

  59c975083d37 ("mm: add folio_estimated_mapcount()")

I applied the following fix patch (hack):

From: Stephen Rothwell <[email-masked]>
Date: Wed, 25 Jan 2023 13:42:20 +1100
Subject: [PATCH] fix up for "mm: add folio_estimated_mapcount()"

Signed-off-by: Stephen Rothwell <[email-masked]>
---
 include/linux/mm.h | 5 -----
 mm/mempolicy.c     | 7 +++++++
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index b7d6e290df99..78c766859fb7 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -913,11 +913,6 @@ static inline int page_mapcount(struct page *page)
 	return mapcount;
 }
 
-static inline int folio_estimated_mapcount(struct folio *folio)
-{
-	return page_mapcount(folio_page(folio, 0));
-}
-
 int folio_total_mapcount(struct folio *folio);
 
 /**
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 03220ba94074..c81db10612eb 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -558,6 +558,13 @@ static int queue_folios_pte_range(pmd_t *pmd, unsigned long addr,
 	return addr != end ? -EIO : 0;
 }
 
+#if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_MIGRATION)
+static inline int folio_estimated_mapcount(struct folio *folio)
+{
+	return page_mapcount(folio_page(folio, 0));
+}
+#endif
+
 static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask,
 			       unsigned long addr, unsigned long end,
 			       struct mm_walk *walk)
-- 
2.35.1

-- 
Cheers,
Stephen Rothwell