[v4,2/3] mm, page_owner: Add page_owner_stacks file to print out only stacks and their counte

Message ID 20230421101415.5734-3-osalvador@suse.de
State New
Headers
Series page_owner: print stacks and their counter |

Commit Message

Oscar Salvador April 21, 2023, 10:14 a.m. UTC
  We might be only interested in knowing about stacks <-> count
relationship, so instead of having to fiddle with page_owner
output and screen through pfns, let us add a new file called
'page_owner_stacks' that does just that.
By cating such file, we will get all the stacktraces followed by
its counter, so we can have a more global view.

Signed-off-by: Oscar Salvador <osalvador@suse.de
---
 include/linux/stackdepot.h |  6 ++++
 lib/stackdepot.c           | 73 ++++++++++++++++++++++++++++++++++++++
 mm/page_owner.c            | 28 +++++++++++++++
 3 files changed, 107 insertions(+)
  

Comments

kernel test robot April 21, 2023, 1:25 p.m. UTC | #1
Hi Oscar,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.3-rc7]
[cannot apply to akpm-mm/mm-everything next-20230420]
[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/Oscar-Salvador/lib-stackdepot-Add-a-refcount-field-in-stack_record/20230421-181709
patch link:    https://lore.kernel.org/r/20230421101415.5734-3-osalvador%40suse.de
patch subject: [PATCH v4 2/3] mm, page_owner: Add page_owner_stacks file to print out only stacks and their counte
config: ia64-allyesconfig (https://download.01.org/0day-ci/archive/20230421/202304212153.jLLmROz6-lkp@intel.com/config)
compiler: ia64-linux-gcc (GCC) 12.1.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/intel-lab-lkp/linux/commit/6c6dfc43015e1939f433f4371d33418ab4d03411
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Oscar-Salvador/lib-stackdepot-Add-a-refcount-field-in-stack_record/20230421-181709
        git checkout 6c6dfc43015e1939f433f4371d33418ab4d03411
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 SHELL=/bin/bash M=lib/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304212153.jLLmROz6-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/linux/page_ext.h:7,
                    from include/linux/mm.h:22,
                    from include/linux/mman.h:5,
                    from lib/test_user_copy.c:13:
>> include/linux/stackdepot.h:120:26: warning: 'struct seq_file' declared inside parameter list will not be visible outside of this definition or declaration
     120 | void *stack_start(struct seq_file *m, loff_t *ppos);
         |                          ^~~~~~~~
   include/linux/stackdepot.h:121:25: warning: 'struct seq_file' declared inside parameter list will not be visible outside of this definition or declaration
     121 | void *stack_next(struct seq_file *m, void *v, loff_t *ppos);
         |                         ^~~~~~~~
   include/linux/stackdepot.h:122:24: warning: 'struct seq_file' declared inside parameter list will not be visible outside of this definition or declaration
     122 | int stack_print(struct seq_file *m, void *v);
         |                        ^~~~~~~~


vim +120 include/linux/stackdepot.h

    99	
   100	/**
   101	 * stack_depot_save - Save a stack trace to stack depot
   102	 *
   103	 * @entries:		Pointer to the stack trace
   104	 * @nr_entries:		Number of frames in the stack
   105	 * @alloc_flags:	Allocation GFP flags
   106	 *
   107	 * Context: Contexts where allocations via alloc_pages() are allowed.
   108	 *          See __stack_depot_save() for more details.
   109	 *
   110	 * Return: Handle of the stack trace stored in depot, 0 on failure
   111	 */
   112	depot_stack_handle_t stack_depot_save(unsigned long *entries,
   113					      unsigned int nr_entries, gfp_t gfp_flags);
   114	depot_stack_handle_t stack_depot_save_action(unsigned long *entries,
   115						     unsigned int nr_entries,
   116						     gfp_t gfp_flags,
   117						     bool counter);
   118	
   119	#ifdef CONFIG_PAGE_OWNER
 > 120	void *stack_start(struct seq_file *m, loff_t *ppos);
   121	void *stack_next(struct seq_file *m, void *v, loff_t *ppos);
   122	int stack_print(struct seq_file *m, void *v);
   123	#endif
   124
  
kernel test robot April 22, 2023, 12:11 a.m. UTC | #2
Hi Oscar,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.3-rc7]
[cannot apply to akpm-mm/mm-everything next-20230421]
[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/Oscar-Salvador/lib-stackdepot-Add-a-refcount-field-in-stack_record/20230421-181709
base:   linus/master
patch link:    https://lore.kernel.org/r/20230421101415.5734-3-osalvador%40suse.de
patch subject: [PATCH v4 2/3] mm, page_owner: Add page_owner_stacks file to print out only stacks and their counte
config: powerpc-randconfig-r026-20230421 (https://download.01.org/0day-ci/archive/20230422/202304220715.syaqgRUa-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 437b7602e4a998220871de78afcb020b9c14a661)
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
        # install powerpc cross compiling tool for clang build
        # apt-get install binutils-powerpc-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/6c6dfc43015e1939f433f4371d33418ab4d03411
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Oscar-Salvador/lib-stackdepot-Add-a-refcount-field-in-stack_record/20230421-181709
        git checkout 6c6dfc43015e1939f433f4371d33418ab4d03411
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash arch/powerpc/kernel/ kernel/dma/ lib/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304220715.syaqgRUa-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

   In file included from lib/show_mem.c:8:
   In file included from include/linux/mm.h:22:
   In file included from include/linux/page_ext.h:7:
>> include/linux/stackdepot.h:120:26: warning: declaration of 'struct seq_file' will not be visible outside of this function [-Wvisibility]
   void *stack_start(struct seq_file *m, loff_t *ppos);
                            ^
   include/linux/stackdepot.h:121:25: warning: declaration of 'struct seq_file' will not be visible outside of this function [-Wvisibility]
   void *stack_next(struct seq_file *m, void *v, loff_t *ppos);
                           ^
   include/linux/stackdepot.h:122:24: warning: declaration of 'struct seq_file' will not be visible outside of this function [-Wvisibility]
   int stack_print(struct seq_file *m, void *v);
                          ^
   3 warnings generated.
--
   In file included from lib/scatterlist.c:9:
   In file included from include/linux/scatterlist.h:8:
   In file included from include/linux/mm.h:22:
   In file included from include/linux/page_ext.h:7:
>> include/linux/stackdepot.h:120:26: warning: declaration of 'struct seq_file' will not be visible outside of this function [-Wvisibility]
   void *stack_start(struct seq_file *m, loff_t *ppos);
                            ^
   include/linux/stackdepot.h:121:25: warning: declaration of 'struct seq_file' will not be visible outside of this function [-Wvisibility]
   void *stack_next(struct seq_file *m, void *v, loff_t *ppos);
                           ^
   include/linux/stackdepot.h:122:24: warning: declaration of 'struct seq_file' will not be visible outside of this function [-Wvisibility]
   int stack_print(struct seq_file *m, void *v);
                          ^
   In file included from lib/scatterlist.c:9:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:43:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insb, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:214:1: note: expanded from here
   __do_insb
   ^
   arch/powerpc/include/asm/io.h:577:56: note: expanded from macro '__do_insb'
   #define __do_insb(p, b, n)      readsb((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from lib/scatterlist.c:9:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:45:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insw, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:216:1: note: expanded from here
   __do_insw
   ^
   arch/powerpc/include/asm/io.h:578:56: note: expanded from macro '__do_insw'
   #define __do_insw(p, b, n)      readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from lib/scatterlist.c:9:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:47:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:218:1: note: expanded from here
   __do_insl
   ^
   arch/powerpc/include/asm/io.h:579:56: note: expanded from macro '__do_insl'
   #define __do_insl(p, b, n)      readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from lib/scatterlist.c:9:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:49:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:220:1: note: expanded from here
   __do_outsb
   ^
   arch/powerpc/include/asm/io.h:580:58: note: expanded from macro '__do_outsb'
   #define __do_outsb(p, b, n)     writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from lib/scatterlist.c:9:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:51:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:222:1: note: expanded from here
   __do_outsw
   ^
   arch/powerpc/include/asm/io.h:581:58: note: expanded from macro '__do_outsw'
   #define __do_outsw(p, b, n)     writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from lib/scatterlist.c:9:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:53:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:224:1: note: expanded from here
   __do_outsl
   ^
   arch/powerpc/include/asm/io.h:582:58: note: expanded from macro '__do_outsl'
   #define __do_outsl(p, b, n)     writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   9 warnings generated.
--
   In file included from lib/stackdepot.c:20:
   In file included from include/linux/mm.h:22:
   In file included from include/linux/page_ext.h:7:
>> include/linux/stackdepot.h:120:26: warning: declaration of 'struct seq_file' will not be visible outside of this function [-Wvisibility]
   void *stack_start(struct seq_file *m, loff_t *ppos);
                            ^
   include/linux/stackdepot.h:121:25: warning: declaration of 'struct seq_file' will not be visible outside of this function [-Wvisibility]
   void *stack_next(struct seq_file *m, void *v, loff_t *ppos);
                           ^
   include/linux/stackdepot.h:122:24: warning: declaration of 'struct seq_file' will not be visible outside of this function [-Wvisibility]
   int stack_print(struct seq_file *m, void *v);
                          ^
   In file included from lib/stackdepot.c:29:
   In file included from include/linux/memblock.h:13:
   In file included from arch/powerpc/include/asm/dma.h:22:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:43:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insb, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:217:1: note: expanded from here
   __do_insb
   ^
   arch/powerpc/include/asm/io.h:577:56: note: expanded from macro '__do_insb'
   #define __do_insb(p, b, n)      readsb((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from lib/stackdepot.c:29:
   In file included from include/linux/memblock.h:13:
   In file included from arch/powerpc/include/asm/dma.h:22:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:45:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insw, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:219:1: note: expanded from here
   __do_insw
   ^
   arch/powerpc/include/asm/io.h:578:56: note: expanded from macro '__do_insw'
   #define __do_insw(p, b, n)      readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from lib/stackdepot.c:29:
   In file included from include/linux/memblock.h:13:
   In file included from arch/powerpc/include/asm/dma.h:22:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:47:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:221:1: note: expanded from here
   __do_insl
   ^
   arch/powerpc/include/asm/io.h:579:56: note: expanded from macro '__do_insl'
   #define __do_insl(p, b, n)      readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from lib/stackdepot.c:29:
   In file included from include/linux/memblock.h:13:
   In file included from arch/powerpc/include/asm/dma.h:22:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:49:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:223:1: note: expanded from here
   __do_outsb
   ^
   arch/powerpc/include/asm/io.h:580:58: note: expanded from macro '__do_outsb'
   #define __do_outsb(p, b, n)     writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from lib/stackdepot.c:29:
   In file included from include/linux/memblock.h:13:
   In file included from arch/powerpc/include/asm/dma.h:22:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:51:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:225:1: note: expanded from here
   __do_outsw
   ^
   arch/powerpc/include/asm/io.h:581:58: note: expanded from macro '__do_outsw'
   #define __do_outsw(p, b, n)     writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from lib/stackdepot.c:29:
   In file included from include/linux/memblock.h:13:
   In file included from arch/powerpc/include/asm/dma.h:22:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:53:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:227:1: note: expanded from here
   __do_outsl
   ^
   arch/powerpc/include/asm/io.h:582:58: note: expanded from macro '__do_outsl'
   #define __do_outsl(p, b, n)     writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
>> lib/stackdepot.c:505:7: error: conflicting types for 'stack_start'
   void *stack_start(struct seq_file *m, loff_t *ppos)
         ^
   include/linux/stackdepot.h:120:7: note: previous declaration is here
   void *stack_start(struct seq_file *m, loff_t *ppos);
         ^
>> lib/stackdepot.c:523:7: error: conflicting types for 'stack_next'
   void *stack_next(struct seq_file *m, void *v, loff_t *ppos)
         ^
   include/linux/stackdepot.h:121:7: note: previous declaration is here
   void *stack_next(struct seq_file *m, void *v, loff_t *ppos);
         ^
>> lib/stackdepot.c:552:5: error: conflicting types for 'stack_print'
   int stack_print(struct seq_file *m, void *v)
       ^
   include/linux/stackdepot.h:122:5: note: previous declaration is here
   int stack_print(struct seq_file *m, void *v);
       ^
   9 warnings and 3 errors generated.
--
   In file included from arch/powerpc/kernel/align.c:17:
   In file included from include/linux/mm.h:22:
   In file included from include/linux/page_ext.h:7:
>> include/linux/stackdepot.h:120:26: error: declaration of 'struct seq_file' will not be visible outside of this function [-Werror,-Wvisibility]
   void *stack_start(struct seq_file *m, loff_t *ppos);
                            ^
   include/linux/stackdepot.h:121:25: error: declaration of 'struct seq_file' will not be visible outside of this function [-Werror,-Wvisibility]
   void *stack_next(struct seq_file *m, void *v, loff_t *ppos);
                           ^
   include/linux/stackdepot.h:122:24: error: declaration of 'struct seq_file' will not be visible outside of this function [-Werror,-Wvisibility]
   int stack_print(struct seq_file *m, void *v);
                          ^
   In file included from arch/powerpc/kernel/align.c:22:
   In file included from arch/powerpc/include/asm/emulated_ops.h:10:
   In file included from include/linux/perf_event.h:52:
   In file included from include/linux/ftrace.h:10:
   In file included from include/linux/trace_recursion.h:5:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:43:1: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insb, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:220:1: note: expanded from here
   __do_insb
   ^
   arch/powerpc/include/asm/io.h:577:56: note: expanded from macro '__do_insb'
   #define __do_insb(p, b, n)      readsb((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from arch/powerpc/kernel/align.c:22:
   In file included from arch/powerpc/include/asm/emulated_ops.h:10:
   In file included from include/linux/perf_event.h:52:
   In file included from include/linux/ftrace.h:10:
   In file included from include/linux/trace_recursion.h:5:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:45:1: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insw, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:222:1: note: expanded from here
   __do_insw
   ^
   arch/powerpc/include/asm/io.h:578:56: note: expanded from macro '__do_insw'
   #define __do_insw(p, b, n)      readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from arch/powerpc/kernel/align.c:22:
   In file included from arch/powerpc/include/asm/emulated_ops.h:10:
   In file included from include/linux/perf_event.h:52:
   In file included from include/linux/ftrace.h:10:
   In file included from include/linux/trace_recursion.h:5:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:47:1: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:224:1: note: expanded from here
   __do_insl
   ^
   arch/powerpc/include/asm/io.h:579:56: note: expanded from macro '__do_insl'
   #define __do_insl(p, b, n)      readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from arch/powerpc/kernel/align.c:22:
   In file included from arch/powerpc/include/asm/emulated_ops.h:10:
   In file included from include/linux/perf_event.h:52:
   In file included from include/linux/ftrace.h:10:
   In file included from include/linux/trace_recursion.h:5:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:49:1: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:226:1: note: expanded from here
   __do_outsb
   ^
   arch/powerpc/include/asm/io.h:580:58: note: expanded from macro '__do_outsb'
   #define __do_outsb(p, b, n)     writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^


vim +/stack_start +505 lib/stackdepot.c

   503	
   504	#ifdef CONFIG_PAGE_OWNER
 > 505	void *stack_start(struct seq_file *m, loff_t *ppos)
   506	{
   507		unsigned long *table = m->private;
   508		struct stack_record **stacks, *stack;
   509	
   510		/* First time */
   511		if (*ppos == 0)
   512			*table = 0;
   513	
   514		if (*ppos == -1UL)
   515			return NULL;
   516	
   517		stacks = &stack_table[*table];
   518		stack = (struct stack_record *)stacks;
   519	
   520		return stack;
   521	}
   522	
 > 523	void *stack_next(struct seq_file *m, void *v, loff_t *ppos)
   524	{
   525		unsigned long *table = m->private;
   526		unsigned long nr_table = *table;
   527		struct stack_record *next = NULL, *stack = v, **stacks;
   528		unsigned long stack_table_entries = stack_hash_mask + 1;
   529	
   530		if (!stack) {
   531	new_table:
   532			/* New table */
   533			nr_table++;
   534			if (nr_table >= stack_table_entries)
   535				goto out;
   536			stacks = &stack_table[nr_table];
   537			stack = (struct stack_record *)stacks;
   538			next = stack;
   539		} else {
   540			next = stack->next;
   541		}
   542	
   543		if (!next)
   544			goto new_table;
   545	
   546	out:
   547		*table = nr_table;
   548		*ppos = (nr_table >= stack_table_entries) ? -1UL : *ppos + 1;
   549		return next;
   550	}
   551	
 > 552	int stack_print(struct seq_file *m, void *v)
   553	{
   554		char *buf;
   555		int ret = 0;
   556		struct stack_record *stack =v;
   557	
   558		if (!stack->size || stack->size < 0 ||
   559		    stack->size > PAGE_SIZE || stack->handle.valid != 1 ||
   560		    refcount_read(&stack->count) < 1)
   561			return 0;
   562	
   563		buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
   564		ret += stack_trace_snprint(buf, PAGE_SIZE, stack->entries, stack->size, 0);
   565		scnprintf(buf + ret, PAGE_SIZE - ret, "stack count: %d\n\n",
   566			  refcount_read(&stack->count));
   567		seq_printf(m, buf);
   568		seq_puts(m, "\n\n");
   569		kfree(buf);
   570	
   571	        return 0;
   572	}
   573	#endif
   574
  
kernel test robot April 22, 2023, 11:18 a.m. UTC | #3
Hi Oscar,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.3-rc7]
[cannot apply to akpm-mm/mm-everything next-20230421]
[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/Oscar-Salvador/lib-stackdepot-Add-a-refcount-field-in-stack_record/20230421-181709
base:   linus/master
patch link:    https://lore.kernel.org/r/20230421101415.5734-3-osalvador%40suse.de
patch subject: [PATCH v4 2/3] mm, page_owner: Add page_owner_stacks file to print out only stacks and their counte
config: x86_64-randconfig-m001 (https://download.01.org/0day-ci/archive/20230422/202304221906.CKlcyd2r-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304221906.CKlcyd2r-lkp@intel.com/

smatch warnings:
lib/stackdepot.c:558 stack_print() warn: unsigned 'stack->size' is never less than zero.

vim +558 lib/stackdepot.c

   551	
   552	int stack_print(struct seq_file *m, void *v)
   553	{
   554		char *buf;
   555		int ret = 0;
   556		struct stack_record *stack =v;
   557	
 > 558		if (!stack->size || stack->size < 0 ||
   559		    stack->size > PAGE_SIZE || stack->handle.valid != 1 ||
   560		    refcount_read(&stack->count) < 1)
   561			return 0;
   562	
   563		buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
   564		ret += stack_trace_snprint(buf, PAGE_SIZE, stack->entries, stack->size, 0);
   565		scnprintf(buf + ret, PAGE_SIZE - ret, "stack count: %d\n\n",
   566			  refcount_read(&stack->count));
   567		seq_printf(m, buf);
   568		seq_puts(m, "\n\n");
   569		kfree(buf);
   570	
   571	        return 0;
   572	}
   573	#endif
   574
  

Patch

diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h
index b94d33312839..e1d05d9adcd1 100644
--- a/include/linux/stackdepot.h
+++ b/include/linux/stackdepot.h
@@ -116,6 +116,12 @@  depot_stack_handle_t stack_depot_save_action(unsigned long *entries,
 					     gfp_t gfp_flags,
 					     bool counter);
 
+#ifdef CONFIG_PAGE_OWNER
+void *stack_start(struct seq_file *m, loff_t *ppos);
+void *stack_next(struct seq_file *m, void *v, loff_t *ppos);
+int stack_print(struct seq_file *m, void *v);
+#endif
+
 /**
  * stack_depot_fetch - Fetch a stack trace from stack depot
  *
diff --git a/lib/stackdepot.c b/lib/stackdepot.c
index e99f4ef218ef..d0a4e6ac0bc9 100644
--- a/lib/stackdepot.c
+++ b/lib/stackdepot.c
@@ -28,6 +28,8 @@ 
 #include <linux/types.h>
 #include <linux/memblock.h>
 #include <linux/kasan-enabled.h>
+#include <linux/seq_file.h>
+#include <linux/debugfs.h>
 
 #define DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8)
 
@@ -499,6 +501,77 @@  static struct stack_record *stack_depot_getstack(depot_stack_handle_t handle)
 	return stack;
 }
 
+#ifdef CONFIG_PAGE_OWNER
+void *stack_start(struct seq_file *m, loff_t *ppos)
+{
+	unsigned long *table = m->private;
+	struct stack_record **stacks, *stack;
+
+	/* First time */
+	if (*ppos == 0)
+		*table = 0;
+
+	if (*ppos == -1UL)
+		return NULL;
+
+	stacks = &stack_table[*table];
+	stack = (struct stack_record *)stacks;
+
+	return stack;
+}
+
+void *stack_next(struct seq_file *m, void *v, loff_t *ppos)
+{
+	unsigned long *table = m->private;
+	unsigned long nr_table = *table;
+	struct stack_record *next = NULL, *stack = v, **stacks;
+	unsigned long stack_table_entries = stack_hash_mask + 1;
+
+	if (!stack) {
+new_table:
+		/* New table */
+		nr_table++;
+		if (nr_table >= stack_table_entries)
+			goto out;
+		stacks = &stack_table[nr_table];
+		stack = (struct stack_record *)stacks;
+		next = stack;
+	} else {
+		next = stack->next;
+	}
+
+	if (!next)
+		goto new_table;
+
+out:
+	*table = nr_table;
+	*ppos = (nr_table >= stack_table_entries) ? -1UL : *ppos + 1;
+	return next;
+}
+
+int stack_print(struct seq_file *m, void *v)
+{
+	char *buf;
+	int ret = 0;
+	struct stack_record *stack =v;
+
+	if (!stack->size || stack->size < 0 ||
+	    stack->size > PAGE_SIZE || stack->handle.valid != 1 ||
+	    refcount_read(&stack->count) < 1)
+		return 0;
+
+	buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
+	ret += stack_trace_snprint(buf, PAGE_SIZE, stack->entries, stack->size, 0);
+	scnprintf(buf + ret, PAGE_SIZE - ret, "stack count: %d\n\n",
+		  refcount_read(&stack->count));
+	seq_printf(m, buf);
+	seq_puts(m, "\n\n");
+	kfree(buf);
+
+        return 0;
+}
+#endif
+
 unsigned int stack_depot_fetch(depot_stack_handle_t handle,
 			       unsigned long **entries)
 {
diff --git a/mm/page_owner.c b/mm/page_owner.c
index b6637524e442..b191ad1d41f9 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -718,6 +718,31 @@  static const struct file_operations proc_page_owner_operations = {
 	.llseek		= lseek_page_owner,
 };
 
+static void stack_stop(struct seq_file *m, void *v)
+{
+	return;
+}
+
+static const struct seq_operations page_owner_stack_op = {
+	.start  = stack_start,
+	.next   = stack_next,
+	.stop   = stack_stop,
+	.show   = stack_print
+};
+
+static int page_owner_stack_open(struct inode *inode, struct file *file)
+{
+	return seq_open_private(file, &page_owner_stack_op,
+				sizeof(unsigned long));
+}
+
+const struct file_operations page_owner_stack_operations = {
+	.open           = page_owner_stack_open,
+	.read           = seq_read,
+	.llseek         = seq_lseek,
+	.release        = seq_release,
+};
+
 static int __init pageowner_init(void)
 {
 	if (!static_branch_unlikely(&page_owner_inited)) {
@@ -728,6 +753,9 @@  static int __init pageowner_init(void)
 	debugfs_create_file("page_owner", 0400, NULL, NULL,
 			    &proc_page_owner_operations);
 
+	debugfs_create_file("page_owner_stacks", S_IRUSR, NULL, NULL,
+			     &page_owner_stack_operations);
+
 	return 0;
 }
 late_initcall(pageowner_init)