diff mbox series

[2/6] mm: Constify page_address_in_vma()

Message ID 20240723153503.1669586-3-willy@infradead.org (mailing list archive)
State New
Headers show
Series page->index removals in mm | expand

Commit Message

Matthew Wilcox July 23, 2024, 3:34 p.m. UTC
If we also mark the struct folio argument to folio_anon_vma(),
we can make page_address_in_vma() take a const struct page pointer.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/rmap.h | 2 +-
 mm/internal.h        | 2 +-
 mm/rmap.c            | 5 +++--
 mm/util.c            | 2 +-
 4 files changed, 6 insertions(+), 5 deletions(-)

Comments

kernel test robot July 24, 2024, 5:54 a.m. UTC | #1
Hi Matthew,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master next-20240723]
[cannot apply to tip/x86/mm dennis-percpu/for-next v6.10]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthew-Wilcox-Oracle/bootmem-Stop-using-page-index/20240723-233932
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20240723153503.1669586-3-willy%40infradead.org
patch subject: [PATCH 2/6] mm: Constify page_address_in_vma()
config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20240724/202407241351.QvA9uyqf-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240724/202407241351.QvA9uyqf-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202407241351.QvA9uyqf-lkp@intel.com/

All errors (new ones prefixed by >>):

>> mm/rmap.c:796:40: error: passing 'const struct folio *' to parameter of type 'struct folio *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
     796 |         pgoff = folio->index + folio_page_idx(folio, page);
         |                                               ^~~~~
   include/linux/mm.h:216:62: note: expanded from macro 'folio_page_idx'
     216 | #define folio_page_idx(folio, p)        (page_to_pfn(p) - folio_pfn(folio))
         |                                                                     ^~~~~
   include/linux/mm.h:1877:53: note: passing argument to parameter 'folio' here
    1877 | static inline unsigned long folio_pfn(struct folio *folio)
         |                                                     ^
   1 error generated.


vim +796 mm/rmap.c

72b252aed506b8 Mel Gorman              2015-09-04  769  
^1da177e4c3f41 Linus Torvalds          2005-04-16  770  /*
bf89c8c8673223 Huang Shijie            2009-10-01  771   * At what user virtual address is page expected in vma?
ab941e0fff3947 Naoya Horiguchi         2010-05-11  772   * Caller should check the page is actually part of the vma.
^1da177e4c3f41 Linus Torvalds          2005-04-16  773   */
eb7052fd71d991 Matthew Wilcox (Oracle  2024-07-23  774) unsigned long page_address_in_vma(const struct page *page,
eb7052fd71d991 Matthew Wilcox (Oracle  2024-07-23  775) 		struct vm_area_struct *vma)
^1da177e4c3f41 Linus Torvalds          2005-04-16  776  {
eb7052fd71d991 Matthew Wilcox (Oracle  2024-07-23  777) 	const struct folio *folio = page_folio(page);
412ad5fbe9285f Matthew Wilcox (Oracle  2024-03-28  778) 	pgoff_t pgoff;
412ad5fbe9285f Matthew Wilcox (Oracle  2024-03-28  779) 
e05b34539d008a Matthew Wilcox (Oracle  2022-01-29  780) 	if (folio_test_anon(folio)) {
e05b34539d008a Matthew Wilcox (Oracle  2022-01-29  781) 		struct anon_vma *page__anon_vma = folio_anon_vma(folio);
4829b906cc063c Hugh Dickins            2010-10-02  782  		/*
4829b906cc063c Hugh Dickins            2010-10-02  783  		 * Note: swapoff's unuse_vma() is more efficient with this
4829b906cc063c Hugh Dickins            2010-10-02  784  		 * check, and needs it to match anon_vma when KSM is active.
4829b906cc063c Hugh Dickins            2010-10-02  785  		 */
4829b906cc063c Hugh Dickins            2010-10-02  786  		if (!vma->anon_vma || !page__anon_vma ||
4829b906cc063c Hugh Dickins            2010-10-02  787  		    vma->anon_vma->root != page__anon_vma->root)
21d0d443cdc165 Andrea Arcangeli        2010-08-09  788  			return -EFAULT;
31657170deaf1d Jue Wang                2021-06-15  789  	} else if (!vma->vm_file) {
^1da177e4c3f41 Linus Torvalds          2005-04-16  790  		return -EFAULT;
e05b34539d008a Matthew Wilcox (Oracle  2022-01-29  791) 	} else if (vma->vm_file->f_mapping != folio->mapping) {
^1da177e4c3f41 Linus Torvalds          2005-04-16  792  		return -EFAULT;
31657170deaf1d Jue Wang                2021-06-15  793  	}
494334e43c16d6 Hugh Dickins            2021-06-15  794  
412ad5fbe9285f Matthew Wilcox (Oracle  2024-03-28  795) 	/* The !page__anon_vma above handles KSM folios */
412ad5fbe9285f Matthew Wilcox (Oracle  2024-03-28 @796) 	pgoff = folio->index + folio_page_idx(folio, page);
e0abfbb6714244 Matthew Wilcox (Oracle  2024-03-28  797) 	return vma_address(vma, pgoff, 1);
^1da177e4c3f41 Linus Torvalds          2005-04-16  798  }
^1da177e4c3f41 Linus Torvalds          2005-04-16  799
kernel test robot July 24, 2024, 7:24 a.m. UTC | #2
Hi Matthew,

kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on linus/master next-20240724]
[cannot apply to tip/x86/mm dennis-percpu/for-next v6.10]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthew-Wilcox-Oracle/bootmem-Stop-using-page-index/20240723-233932
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20240723153503.1669586-3-willy%40infradead.org
patch subject: [PATCH 2/6] mm: Constify page_address_in_vma()
config: sh-migor_defconfig (https://download.01.org/0day-ci/archive/20240724/202407241541.GgplaeTD-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240724/202407241541.GgplaeTD-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202407241541.GgplaeTD-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from mm/rmap.c:56:
   mm/rmap.c: In function 'page_address_in_vma':
>> mm/rmap.c:796:47: warning: passing argument 1 of 'folio_pfn' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     796 |         pgoff = folio->index + folio_page_idx(folio, page);
         |                                               ^~~~~
   include/linux/mm.h:216:69: note: in definition of macro 'folio_page_idx'
     216 | #define folio_page_idx(folio, p)        (page_to_pfn(p) - folio_pfn(folio))
         |                                                                     ^~~~~
   include/linux/mm.h:1877:53: note: expected 'struct folio *' but argument is of type 'const struct folio *'
    1877 | static inline unsigned long folio_pfn(struct folio *folio)
         |                                       ~~~~~~~~~~~~~~^~~~~


vim +796 mm/rmap.c

72b252aed506b8 Mel Gorman              2015-09-04  769  
^1da177e4c3f41 Linus Torvalds          2005-04-16  770  /*
bf89c8c8673223 Huang Shijie            2009-10-01  771   * At what user virtual address is page expected in vma?
ab941e0fff3947 Naoya Horiguchi         2010-05-11  772   * Caller should check the page is actually part of the vma.
^1da177e4c3f41 Linus Torvalds          2005-04-16  773   */
eb7052fd71d991 Matthew Wilcox (Oracle  2024-07-23  774) unsigned long page_address_in_vma(const struct page *page,
eb7052fd71d991 Matthew Wilcox (Oracle  2024-07-23  775) 		struct vm_area_struct *vma)
^1da177e4c3f41 Linus Torvalds          2005-04-16  776  {
eb7052fd71d991 Matthew Wilcox (Oracle  2024-07-23  777) 	const struct folio *folio = page_folio(page);
412ad5fbe9285f Matthew Wilcox (Oracle  2024-03-28  778) 	pgoff_t pgoff;
412ad5fbe9285f Matthew Wilcox (Oracle  2024-03-28  779) 
e05b34539d008a Matthew Wilcox (Oracle  2022-01-29  780) 	if (folio_test_anon(folio)) {
e05b34539d008a Matthew Wilcox (Oracle  2022-01-29  781) 		struct anon_vma *page__anon_vma = folio_anon_vma(folio);
4829b906cc063c Hugh Dickins            2010-10-02  782  		/*
4829b906cc063c Hugh Dickins            2010-10-02  783  		 * Note: swapoff's unuse_vma() is more efficient with this
4829b906cc063c Hugh Dickins            2010-10-02  784  		 * check, and needs it to match anon_vma when KSM is active.
4829b906cc063c Hugh Dickins            2010-10-02  785  		 */
4829b906cc063c Hugh Dickins            2010-10-02  786  		if (!vma->anon_vma || !page__anon_vma ||
4829b906cc063c Hugh Dickins            2010-10-02  787  		    vma->anon_vma->root != page__anon_vma->root)
21d0d443cdc165 Andrea Arcangeli        2010-08-09  788  			return -EFAULT;
31657170deaf1d Jue Wang                2021-06-15  789  	} else if (!vma->vm_file) {
^1da177e4c3f41 Linus Torvalds          2005-04-16  790  		return -EFAULT;
e05b34539d008a Matthew Wilcox (Oracle  2022-01-29  791) 	} else if (vma->vm_file->f_mapping != folio->mapping) {
^1da177e4c3f41 Linus Torvalds          2005-04-16  792  		return -EFAULT;
31657170deaf1d Jue Wang                2021-06-15  793  	}
494334e43c16d6 Hugh Dickins            2021-06-15  794  
412ad5fbe9285f Matthew Wilcox (Oracle  2024-03-28  795) 	/* The !page__anon_vma above handles KSM folios */
412ad5fbe9285f Matthew Wilcox (Oracle  2024-03-28 @796) 	pgoff = folio->index + folio_page_idx(folio, page);
e0abfbb6714244 Matthew Wilcox (Oracle  2024-03-28  797) 	return vma_address(vma, pgoff, 1);
^1da177e4c3f41 Linus Torvalds          2005-04-16  798  }
^1da177e4c3f41 Linus Torvalds          2005-04-16  799
diff mbox series

Patch

diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index 0978c64f49d8..d1fca5b76039 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -732,7 +732,7 @@  bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw);
 /*
  * Used by swapoff to help locate where page is expected in vma.
  */
-unsigned long page_address_in_vma(struct page *, struct vm_area_struct *);
+unsigned long page_address_in_vma(const struct page *, struct vm_area_struct *);
 
 /*
  * Cleans the PTEs of shared mappings.
diff --git a/mm/internal.h b/mm/internal.h
index b4d86436565b..e511708b2be0 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -810,7 +810,7 @@  static inline bool is_data_mapping(vm_flags_t flags)
 }
 
 /* mm/util.c */
-struct anon_vma *folio_anon_vma(struct folio *folio);
+struct anon_vma *folio_anon_vma(const struct folio *folio);
 
 #ifdef CONFIG_MMU
 void unmap_mapping_folio(struct folio *folio);
diff --git a/mm/rmap.c b/mm/rmap.c
index 8616308610b9..886bf67ba382 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -771,9 +771,10 @@  static bool should_defer_flush(struct mm_struct *mm, enum ttu_flags flags)
  * At what user virtual address is page expected in vma?
  * Caller should check the page is actually part of the vma.
  */
-unsigned long page_address_in_vma(struct page *page, struct vm_area_struct *vma)
+unsigned long page_address_in_vma(const struct page *page,
+		struct vm_area_struct *vma)
 {
-	struct folio *folio = page_folio(page);
+	const struct folio *folio = page_folio(page);
 	pgoff_t pgoff;
 
 	if (folio_test_anon(folio)) {
diff --git a/mm/util.c b/mm/util.c
index bc488f0121a7..8afe3b90d650 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -780,7 +780,7 @@  void *vcalloc_noprof(size_t n, size_t size)
 }
 EXPORT_SYMBOL(vcalloc_noprof);
 
-struct anon_vma *folio_anon_vma(struct folio *folio)
+struct anon_vma *folio_anon_vma(const struct folio *folio)
 {
 	unsigned long mapping = (unsigned long)folio->mapping;