diff mbox series

[v9,46/96] mm: Add flush_dcache_folio

Message ID 20210505150628.111735-47-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Memory folios | expand

Commit Message

Matthew Wilcox May 5, 2021, 3:05 p.m. UTC
This is a default implementation which calls flush_dcache_page() on
each page in the folio.  If architectures can do better, they should
implement their own version of it.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 Documentation/core-api/cachetlb.rst |  6 ++++++
 include/asm-generic/cacheflush.h    | 14 ++++++++++++++
 2 files changed, 20 insertions(+)

Comments

kernel test robot May 5, 2021, 11:35 p.m. UTC | #1
Hi "Matthew,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on next-20210505]
[cannot apply to hnaz-linux-mm/master xfs-linux/for-next tip/perf/core shaggy/jfs-next block/for-next linus/master asm-generic/master v5.12 v5.12-rc8 v5.12-rc7 v5.12]
[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]

url:    https://github.com/0day-ci/linux/commits/Matthew-Wilcox-Oracle/Memory-folios/20210506-014108
base:    29955e0289b3255c5f609a7564a0f0bb4ae35c7a
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/2104ef87cf0390e2def04a508c79a664b4a4fcc4
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Matthew-Wilcox-Oracle/Memory-folios/20210506-014108
        git checkout 2104ef87cf0390e2def04a508c79a664b4a4fcc4
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross W=1 ARCH=ia64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from arch/ia64/include/asm/cacheflush.h:31,
                    from arch/ia64/include/asm/pgtable.h:153,
                    from include/linux/pgtable.h:6,
                    from arch/ia64/include/asm/uaccess.h:40,
                    from include/linux/uaccess.h:11,
                    from include/linux/sched/task.h:11,
                    from include/linux/sched/signal.h:9,
                    from arch/ia64/kernel/asm-offsets.c:10:
   include/asm-generic/cacheflush.h: In function 'flush_dcache_folio':
>> include/asm-generic/cacheflush.h:61:19: error: implicit declaration of function 'folio_nr_pages'; did you mean 'folio_page'? [-Werror=implicit-function-declaration]
      61 |  unsigned int n = folio_nr_pages(folio);
         |                   ^~~~~~~~~~~~~~
         |                   folio_page
   In file included from arch/ia64/include/asm/pgtable.h:153,
                    from include/linux/pgtable.h:6,
                    from arch/ia64/include/asm/uaccess.h:40,
                    from include/linux/uaccess.h:11,
                    from include/linux/sched/task.h:11,
                    from include/linux/sched/signal.h:9,
                    from arch/ia64/kernel/asm-offsets.c:10:
>> include/asm-generic/cacheflush.h:65:21: error: implicit declaration of function 'nth_page' [-Werror=implicit-function-declaration]
      65 |   flush_dcache_page(nth_page(&folio->page, n));
         |                     ^~~~~~~~
   arch/ia64/include/asm/cacheflush.h:18:25: note: in definition of macro 'flush_dcache_page'
      18 |  clear_bit(PG_arch_1, &(page)->flags); \
         |                         ^~~~
>> arch/ia64/include/asm/cacheflush.h:18:30: error: invalid type argument of '->' (have 'int')
      18 |  clear_bit(PG_arch_1, &(page)->flags); \
         |                              ^~
   include/asm-generic/cacheflush.h:65:3: note: in expansion of macro 'flush_dcache_page'
      65 |   flush_dcache_page(nth_page(&folio->page, n));
         |   ^~~~~~~~~~~~~~~~~
   arch/ia64/kernel/asm-offsets.c: At top level:
   arch/ia64/kernel/asm-offsets.c:23:6: warning: no previous prototype for 'foo' [-Wmissing-prototypes]
      23 | void foo(void)
         |      ^~~
   cc1: some warnings being treated as errors
--
   In file included from arch/ia64/include/asm/cacheflush.h:31,
                    from arch/ia64/include/asm/pgtable.h:153,
                    from include/linux/pgtable.h:6,
                    from arch/ia64/include/asm/uaccess.h:40,
                    from include/linux/uaccess.h:11,
                    from include/linux/sched/task.h:11,
                    from include/linux/sched/signal.h:9,
                    from arch/ia64/kernel/asm-offsets.c:10:
   include/asm-generic/cacheflush.h: In function 'flush_dcache_folio':
>> include/asm-generic/cacheflush.h:61:19: error: implicit declaration of function 'folio_nr_pages'; did you mean 'folio_page'? [-Werror=implicit-function-declaration]
      61 |  unsigned int n = folio_nr_pages(folio);
         |                   ^~~~~~~~~~~~~~
         |                   folio_page
   In file included from arch/ia64/include/asm/pgtable.h:153,
                    from include/linux/pgtable.h:6,
                    from arch/ia64/include/asm/uaccess.h:40,
                    from include/linux/uaccess.h:11,
                    from include/linux/sched/task.h:11,
                    from include/linux/sched/signal.h:9,
                    from arch/ia64/kernel/asm-offsets.c:10:
>> include/asm-generic/cacheflush.h:65:21: error: implicit declaration of function 'nth_page' [-Werror=implicit-function-declaration]
      65 |   flush_dcache_page(nth_page(&folio->page, n));
         |                     ^~~~~~~~
   arch/ia64/include/asm/cacheflush.h:18:25: note: in definition of macro 'flush_dcache_page'
      18 |  clear_bit(PG_arch_1, &(page)->flags); \
         |                         ^~~~
>> arch/ia64/include/asm/cacheflush.h:18:30: error: invalid type argument of '->' (have 'int')
      18 |  clear_bit(PG_arch_1, &(page)->flags); \
         |                              ^~
   include/asm-generic/cacheflush.h:65:3: note: in expansion of macro 'flush_dcache_page'
      65 |   flush_dcache_page(nth_page(&folio->page, n));
         |   ^~~~~~~~~~~~~~~~~
   arch/ia64/kernel/asm-offsets.c: At top level:
   arch/ia64/kernel/asm-offsets.c:23:6: warning: no previous prototype for 'foo' [-Wmissing-prototypes]
      23 | void foo(void)
         |      ^~~
   cc1: some warnings being treated as errors
   make[2]: *** [scripts/Makefile.build:118: arch/ia64/kernel/asm-offsets.s] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [Makefile:1313: prepare0] Error 2
   make[1]: Target 'modules_prepare' not remade because of errors.
   make: *** [Makefile:222: __sub-make] Error 2
   make: Target 'modules_prepare' not remade because of errors.
--
   error: no override and no default toolchain set
   init/Kconfig:70:warning: 'RUSTC_VERSION': number is invalid
   In file included from arch/ia64/include/asm/cacheflush.h:31,
                    from arch/ia64/include/asm/pgtable.h:153,
                    from include/linux/pgtable.h:6,
                    from arch/ia64/include/asm/uaccess.h:40,
                    from include/linux/uaccess.h:11,
                    from include/linux/sched/task.h:11,
                    from include/linux/sched/signal.h:9,
                    from arch/ia64/kernel/asm-offsets.c:10:
   include/asm-generic/cacheflush.h: In function 'flush_dcache_folio':
>> include/asm-generic/cacheflush.h:61:19: error: implicit declaration of function 'folio_nr_pages'; did you mean 'folio_page'? [-Werror=implicit-function-declaration]
      61 |  unsigned int n = folio_nr_pages(folio);
         |                   ^~~~~~~~~~~~~~
         |                   folio_page
   In file included from arch/ia64/include/asm/pgtable.h:153,
                    from include/linux/pgtable.h:6,
                    from arch/ia64/include/asm/uaccess.h:40,
                    from include/linux/uaccess.h:11,
                    from include/linux/sched/task.h:11,
                    from include/linux/sched/signal.h:9,
                    from arch/ia64/kernel/asm-offsets.c:10:
>> include/asm-generic/cacheflush.h:65:21: error: implicit declaration of function 'nth_page' [-Werror=implicit-function-declaration]
      65 |   flush_dcache_page(nth_page(&folio->page, n));
         |                     ^~~~~~~~
   arch/ia64/include/asm/cacheflush.h:18:25: note: in definition of macro 'flush_dcache_page'
      18 |  clear_bit(PG_arch_1, &(page)->flags); \
         |                         ^~~~
>> arch/ia64/include/asm/cacheflush.h:18:30: error: invalid type argument of '->' (have 'int')
      18 |  clear_bit(PG_arch_1, &(page)->flags); \
         |                              ^~
   include/asm-generic/cacheflush.h:65:3: note: in expansion of macro 'flush_dcache_page'
      65 |   flush_dcache_page(nth_page(&folio->page, n));
         |   ^~~~~~~~~~~~~~~~~
   arch/ia64/kernel/asm-offsets.c: At top level:
   arch/ia64/kernel/asm-offsets.c:23:6: warning: no previous prototype for 'foo' [-Wmissing-prototypes]
      23 | void foo(void)
         |      ^~~
   cc1: some warnings being treated as errors
   make[2]: *** [scripts/Makefile.build:118: arch/ia64/kernel/asm-offsets.s] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [Makefile:1313: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:222: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.


vim +61 include/asm-generic/cacheflush.h

    57	
    58	#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO
    59	static inline void flush_dcache_folio(struct folio *folio)
    60	{
  > 61		unsigned int n = folio_nr_pages(folio);
    62	
    63		do {
    64			n--;
  > 65			flush_dcache_page(nth_page(&folio->page, n));
    66		} while (n);
    67	}
    68	#endif
    69	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Matthew Wilcox May 6, 2021, 2:33 a.m. UTC | #2
On Thu, May 06, 2021 at 07:35:16AM +0800, kernel test robot wrote:
>    In file included from arch/ia64/include/asm/cacheflush.h:31,
>                     from arch/ia64/include/asm/pgtable.h:153,
>                     from include/linux/pgtable.h:6,
>                     from arch/ia64/include/asm/uaccess.h:40,
>                     from include/linux/uaccess.h:11,
>                     from include/linux/sched/task.h:11,
>                     from include/linux/sched/signal.h:9,
>                     from arch/ia64/kernel/asm-offsets.c:10:
>    include/asm-generic/cacheflush.h: In function 'flush_dcache_folio':
> >> include/asm-generic/cacheflush.h:61:19: error: implicit declaration of function 'folio_nr_pages'; did you mean 'folio_page'? [-Werror=implicit-function-declaration]

Ugh, I can't be bothered to untangle the ia64 header file mess.
I'll just move the function out of line.
diff mbox series

Patch

diff --git a/Documentation/core-api/cachetlb.rst b/Documentation/core-api/cachetlb.rst
index fe4290e26729..29682f69a915 100644
--- a/Documentation/core-api/cachetlb.rst
+++ b/Documentation/core-api/cachetlb.rst
@@ -325,6 +325,12 @@  maps this page at its virtual address.
 			dirty.  Again, see sparc64 for examples of how
 			to deal with this.
 
+  ``void flush_dcache_folio(struct folio *folio)``
+	This function is called under the same circumstances as
+	flush_dcache_page().  It allows the architecture to
+	optimise for flushing the entire folio of pages instead
+	of flushing one page at a time.
+
   ``void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
   unsigned long user_vaddr, void *dst, void *src, int len)``
   ``void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
diff --git a/include/asm-generic/cacheflush.h b/include/asm-generic/cacheflush.h
index 4a674db4e1fa..0155357b840f 100644
--- a/include/asm-generic/cacheflush.h
+++ b/include/asm-generic/cacheflush.h
@@ -49,9 +49,23 @@  static inline void flush_cache_page(struct vm_area_struct *vma,
 static inline void flush_dcache_page(struct page *page)
 {
 }
+
+static inline void flush_dcache_folio(struct folio *folio) { }
 #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO
 #endif
 
+#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO
+static inline void flush_dcache_folio(struct folio *folio)
+{
+	unsigned int n = folio_nr_pages(folio);
+
+	do {
+		n--;
+		flush_dcache_page(nth_page(&folio->page, n));
+	} while (n);
+}
+#endif
 
 #ifndef flush_dcache_mmap_lock
 static inline void flush_dcache_mmap_lock(struct address_space *mapping)