diff mbox series

[-next,1/8] mm: memory_hotplug: add pfn_to_online_folio()

Message ID 20221213092735.187924-2-wangkefeng.wang@huawei.com (mailing list archive)
State New
Headers show
Series mm: converted page idle and damon to use folios | expand

Commit Message

Kefeng Wang Dec. 13, 2022, 9:27 a.m. UTC
Introduce a wrapper function pfn_to_online_folio(), which calls
pfn_to_online_page() and returns the folio of the page found,
or null if no page.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 include/linux/memory_hotplug.h | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

kernel test robot Dec. 13, 2022, 11:13 a.m. UTC | #1
Hi Kefeng,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.1]
[cannot apply to akpm-mm/mm-everything next-20221213]
[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/Kefeng-Wang/mm-converted-page-idle-and-damon-to-use-folios/20221213-171230
patch link:    https://lore.kernel.org/r/20221213092735.187924-2-wangkefeng.wang%40huawei.com
patch subject: [PATCH -next 1/8] mm: memory_hotplug: add pfn_to_online_folio()
config: alpha-allyesconfig
compiler: alpha-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/6549c7ce5345695320d1dadef2aceff6e76d34f4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Kefeng-Wang/mm-converted-page-idle-and-damon-to-use-folios/20221213-171230
        git checkout 6549c7ce5345695320d1dadef2aceff6e76d34f4
        # 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=alpha prepare

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

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

   In file included from include/linux/mmzone.h:1245,
                    from include/linux/gfp.h:7,
                    from include/linux/percpu_counter.h:16,
                    from include/linux/sched/user.h:7,
                    from include/linux/cred.h:17,
                    from include/linux/sched/signal.h:10,
                    from include/linux/ptrace.h:7,
                    from arch/alpha/kernel/asm-offsets.c:11:
   include/linux/memory_hotplug.h: In function 'pfn_to_online_folio':
>> include/linux/memory_hotplug.h:230:13: error: implicit declaration of function 'pfn_valid'; did you mean 'gid_valid'? [-Werror=implicit-function-declaration]
     230 |         if (pfn_valid(pfn))                     \
         |             ^~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   In file included from arch/alpha/include/asm/page.h:94,
                    from include/linux/shm.h:6,
                    from include/linux/sched.h:16,
                    from arch/alpha/kernel/asm-offsets.c:10:
>> include/asm-generic/memory_model.h:41:37: error: implicit declaration of function '__pfn_to_section' [-Werror=implicit-function-declaration]
      41 |         struct mem_section *__sec = __pfn_to_section(__pfn);    \
         |                                     ^~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
>> include/asm-generic/memory_model.h:41:37: warning: initialization of 'struct mem_section *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
      41 |         struct mem_section *__sec = __pfn_to_section(__pfn);    \
         |                                     ^~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:41:37: note: (near initialization for 'page')
      41 |         struct mem_section *__sec = __pfn_to_section(__pfn);    \
         |                                     ^~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
>> include/asm-generic/memory_model.h:42:9: error: implicit declaration of function '__section_mem_map_addr' [-Werror=implicit-function-declaration]
      42 |         __section_mem_map_addr(__sec) + __pfn;          \
         |         ^~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
>> include/linux/memory_hotplug.h:231:25: warning: assignment to 'struct page *' from 'long unsigned int' makes pointer from integer without a cast [-Wint-conversion]
     231 |                 ___page = pfn_to_page(pfn);     \
         |                         ^
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   include/linux/mmzone.h: At top level:
>> include/linux/mmzone.h:1740:28: error: conflicting types for '__section_mem_map_addr'; have 'struct page *(struct mem_section *)'
    1740 | static inline struct page *__section_mem_map_addr(struct mem_section *section)
         |                            ^~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:42:9: note: previous implicit declaration of '__section_mem_map_addr' with type 'int()'
      42 |         __section_mem_map_addr(__sec) + __pfn;          \
         |         ^~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
>> include/linux/mmzone.h:1801:35: error: conflicting types for '__pfn_to_section'; have 'struct mem_section *(long unsigned int)'
    1801 | static inline struct mem_section *__pfn_to_section(unsigned long pfn)
         |                                   ^~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:41:37: note: previous implicit declaration of '__pfn_to_section' with type 'int()'
      41 |         struct mem_section *__sec = __pfn_to_section(__pfn);    \
         |                                     ^~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
>> include/linux/mmzone.h:1839:19: error: static declaration of 'pfn_valid' follows non-static declaration
    1839 | static inline int pfn_valid(unsigned long pfn)
         |                   ^~~~~~~~~
   include/linux/memory_hotplug.h:230:13: note: previous implicit declaration of 'pfn_valid' with type 'int()'
     230 |         if (pfn_valid(pfn))                     \
         |             ^~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   arch/alpha/kernel/asm-offsets.c:15:6: warning: no previous prototype for 'foo' [-Wmissing-prototypes]
      15 | void foo(void)
         |      ^~~
   cc1: some warnings being treated as errors
   make[2]: *** [scripts/Makefile.build:118: arch/alpha/kernel/asm-offsets.s] Error 1
   make[2]: Target 'prepare' not remade because of errors.
   make[1]: *** [Makefile:1272: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:231: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.


vim +230 include/linux/memory_hotplug.h

b4a0215e11dcfe Kefeng Wang  2022-08-27  225  
208d54e5513c0c Dave Hansen  2005-10-29  226  #else /* ! CONFIG_MEMORY_HOTPLUG */
2d070eab2e8270 Michal Hocko 2017-07-06  227  #define pfn_to_online_page(pfn)			\
2d070eab2e8270 Michal Hocko 2017-07-06  228  ({						\
2d070eab2e8270 Michal Hocko 2017-07-06  229  	struct page *___page = NULL;		\
2d070eab2e8270 Michal Hocko 2017-07-06 @230  	if (pfn_valid(pfn))			\
2d070eab2e8270 Michal Hocko 2017-07-06 @231  		___page = pfn_to_page(pfn);	\
2d070eab2e8270 Michal Hocko 2017-07-06  232  	___page;				\
2d070eab2e8270 Michal Hocko 2017-07-06  233   })
2d070eab2e8270 Michal Hocko 2017-07-06  234
kernel test robot Dec. 13, 2022, 11:23 a.m. UTC | #2
Hi Kefeng,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.1]
[cannot apply to akpm-mm/mm-everything next-20221213]
[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/Kefeng-Wang/mm-converted-page-idle-and-damon-to-use-folios/20221213-171230
patch link:    https://lore.kernel.org/r/20221213092735.187924-2-wangkefeng.wang%40huawei.com
patch subject: [PATCH -next 1/8] mm: memory_hotplug: add pfn_to_online_folio()
config: m68k-allyesconfig
compiler: m68k-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/6549c7ce5345695320d1dadef2aceff6e76d34f4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Kefeng-Wang/mm-converted-page-idle-and-damon-to-use-folios/20221213-171230
        git checkout 6549c7ce5345695320d1dadef2aceff6e76d34f4
        # 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=m68k prepare

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

All errors (new ones prefixed by >>):

   In file included from arch/m68k/include/asm/page.h:60,
                    from arch/m68k/include/asm/thread_info.h:6,
                    from include/linux/thread_info.h:60,
                    from include/asm-generic/preempt.h:5,
                    from ./arch/m68k/include/generated/asm/preempt.h:1,
                    from include/linux/preempt.h:78,
                    from arch/m68k/include/asm/irqflags.h:6,
                    from include/linux/irqflags.h:16,
                    from arch/m68k/include/asm/atomic.h:6,
                    from include/linux/atomic.h:7,
                    from include/linux/rcupdate.h:25,
                    from include/linux/rculist.h:11,
                    from include/linux/pid.h:5,
                    from include/linux/sched.h:14,
                    from arch/m68k/kernel/asm-offsets.c:15:
   include/linux/memory_hotplug.h: In function 'pfn_to_online_folio':
>> arch/m68k/include/asm/page_mm.h:139:115: error: 'high_memory' undeclared (first use in this function)
     139 | #define virt_addr_valid(kaddr)  ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
         |                                                                                                                   ^~~~~~~~~~~
   arch/m68k/include/asm/page_mm.h:140:33: note: in expansion of macro 'virt_addr_valid'
     140 | #define pfn_valid(pfn)          virt_addr_valid(pfn_to_virt(pfn))
         |                                 ^~~~~~~~~~~~~~~
   include/linux/memory_hotplug.h:230:13: note: in expansion of macro 'pfn_valid'
     230 |         if (pfn_valid(pfn))                     \
         |             ^~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   arch/m68k/include/asm/page_mm.h:139:115: note: each undeclared identifier is reported only once for each function it appears in
     139 | #define virt_addr_valid(kaddr)  ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
         |                                                                                                                   ^~~~~~~~~~~
   arch/m68k/include/asm/page_mm.h:140:33: note: in expansion of macro 'virt_addr_valid'
     140 | #define pfn_valid(pfn)          virt_addr_valid(pfn_to_virt(pfn))
         |                                 ^~~~~~~~~~~~~~~
   include/linux/memory_hotplug.h:230:13: note: in expansion of macro 'pfn_valid'
     230 |         if (pfn_valid(pfn))                     \
         |             ^~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   make[2]: *** [scripts/Makefile.build:118: arch/m68k/kernel/asm-offsets.s] Error 1
   make[2]: Target 'prepare' not remade because of errors.
   make[1]: *** [Makefile:1272: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:231: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.


vim +/high_memory +139 arch/m68k/include/asm/page_mm.h

^1da177e4c3f41 include/asm-m68k/page.h         Linus Torvalds     2005-04-16  138  
a65a802aadba07 arch/m68k/include/asm/page_mm.h Geert Uytterhoeven 2021-03-05 @139  #define virt_addr_valid(kaddr)	((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
^1da177e4c3f41 include/asm-m68k/page.h         Linus Torvalds     2005-04-16  140  #define pfn_valid(pfn)		virt_addr_valid(pfn_to_virt(pfn))
^1da177e4c3f41 include/asm-m68k/page.h         Linus Torvalds     2005-04-16  141
Kefeng Wang Dec. 13, 2022, 11:36 a.m. UTC | #3
On 2022/12/13 19:13, kernel test robot wrote:
> Hi Kefeng,
>
> Thank you for the patch! Yet something to improve:
>
> [auto build test ERROR on linus/master]
> [also build test ERROR on v6.1]
> [cannot apply to akpm-mm/mm-everything next-20221213]
> [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/Kefeng-Wang/mm-converted-page-idle-and-damon-to-use-folios/20221213-171230
> patch link:    https://lore.kernel.org/r/20221213092735.187924-2-wangkefeng.wang%40huawei.com
> patch subject: [PATCH -next 1/8] mm: memory_hotplug: add pfn_to_online_folio()
> config: alpha-allyesconfig
> compiler: alpha-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/6549c7ce5345695320d1dadef2aceff6e76d34f4
>          git remote add linux-review https://github.com/intel-lab-lkp/linux
>          git fetch --no-tags linux-review Kefeng-Wang/mm-converted-page-idle-and-damon-to-use-folios/20221213-171230
>          git checkout 6549c7ce5345695320d1dadef2aceff6e76d34f4
>          # 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=alpha prepare
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <lkp@intel.com>
>
> All error/warnings (new ones prefixed by >>):
>
>     In file included from include/linux/mmzone.h:1245,
>                      from include/linux/gfp.h:7,
>                      from include/linux/percpu_counter.h:16,
>                      from include/linux/sched/user.h:7,
>                      from include/linux/cred.h:17,
>                      from include/linux/sched/signal.h:10,
>                      from include/linux/ptrace.h:7,
>                      from arch/alpha/kernel/asm-offsets.c:11:
>     include/linux/memory_hotplug.h: In function 'pfn_to_online_folio':
>>> include/linux/memory_hotplug.h:230:13: error: implicit declaration of function 'pfn_valid'; did you mean 'gid_valid'? [-Werror=implicit-function-declaration]
>       230 |         if (pfn_valid(pfn))                     \
>           |             ^~~~~~~~~
>     include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
>       270 |         struct page *page = pfn_to_online_page(pfn);
>           |                             ^~~~~~~~~~~~~~~~~~
>     In file included from arch/alpha/include/asm/page.h:94,
>                      from include/linux/shm.h:6,
>                      from include/linux/sched.h:16,
>                      from arch/alpha/kernel/asm-offsets.c:10:
>>> include/asm-generic/memory_model.h:41:37: error: implicit declaration of function '__pfn_to_section' [-Werror=implicit-function-declaration]
>        41 |         struct mem_section *__sec = __pfn_to_section(__pfn);    \
>           |                                     ^~~~~~~~~~~~~~~~
>     include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
>        53 | #define pfn_to_page __pfn_to_page
>           |                     ^~~~~~~~~~~~~
>     include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
>       231 |                 ___page = pfn_to_page(pfn);     \
>           |                           ^~~~~~~~~~~
>     include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
>       270 |         struct page *page = pfn_to_online_page(pfn);
>           |                             ^~~~~~~~~~~~~~~~~~
>>> include/asm-generic/memory_model.h:41:37: warning: initialization of 'struct mem_section *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
>        41 |         struct mem_section *__sec = __pfn_to_section(__pfn);    \
>           |                                     ^~~~~~~~~~~~~~~~
>     include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
>        53 | #define pfn_to_page __pfn_to_page
>           |                     ^~~~~~~~~~~~~
>     include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
>       231 |                 ___page = pfn_to_page(pfn);     \
>           |                           ^~~~~~~~~~~
>     include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
>       270 |         struct page *page = pfn_to_online_page(pfn);
>           |                             ^~~~~~~~~~~~~~~~~~
>     include/asm-generic/memory_model.h:41:37: note: (near initialization for 'page')
>        41 |         struct mem_section *__sec = __pfn_to_section(__pfn);    \
>           |                                     ^~~~~~~~~~~~~~~~
>     include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
>        53 | #define pfn_to_page __pfn_to_page
>           |                     ^~~~~~~~~~~~~
>     include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
>       231 |                 ___page = pfn_to_page(pfn);     \
>           |                           ^~~~~~~~~~~
>     include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
>       270 |         struct page *page = pfn_to_online_page(pfn);
>           |                             ^~~~~~~~~~~~~~~~~~
>>> include/asm-generic/memory_model.h:42:9: error: implicit declaration of function '__section_mem_map_addr' [-Werror=implicit-function-declaration]
>        42 |         __section_mem_map_addr(__sec) + __pfn;          \
>           |         ^~~~~~~~~~~~~~~~~~~~~~
>     include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
>        53 | #define pfn_to_page __pfn_to_page
>           |                     ^~~~~~~~~~~~~
>     include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
>       231 |                 ___page = pfn_to_page(pfn);     \
>           |                           ^~~~~~~~~~~
>     include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
>       270 |         struct page *page = pfn_to_online_page(pfn);
>           |                             ^~~~~~~~~~~~~~~~~~
>>> include/linux/memory_hotplug.h:231:25: warning: assignment to 'struct page *' from 'long unsigned int' makes pointer from integer without a cast [-Wint-conversion]
>       231 |                 ___page = pfn_to_page(pfn);     \
>           |                         ^
>     include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
>       270 |         struct page *page = pfn_to_online_page(pfn);
>           |                             ^~~~~~~~~~~~~~~~~~
>     include/linux/mmzone.h: At top level:
>>> include/linux/mmzone.h:1740:28: error: conflicting types for '__section_mem_map_addr'; have 'struct page *(struct mem_section *)'
>      1740 | static inline struct page *__section_mem_map_addr(struct mem_section *section)
>           |                            ^~~~~~~~~~~~~~~~~~~~~~
>     include/asm-generic/memory_model.h:42:9: note: previous implicit declaration of '__section_mem_map_addr' with type 'int()'
>        42 |         __section_mem_map_addr(__sec) + __pfn;          \
>           |         ^~~~~~~~~~~~~~~~~~~~~~
>     include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
>        53 | #define pfn_to_page __pfn_to_page
>           |                     ^~~~~~~~~~~~~
>     include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
>       231 |                 ___page = pfn_to_page(pfn);     \
>           |                           ^~~~~~~~~~~
>     include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
>       270 |         struct page *page = pfn_to_online_page(pfn);
>           |                             ^~~~~~~~~~~~~~~~~~
>>> include/linux/mmzone.h:1801:35: error: conflicting types for '__pfn_to_section'; have 'struct mem_section *(long unsigned int)'
>      1801 | static inline struct mem_section *__pfn_to_section(unsigned long pfn)
>           |                                   ^~~~~~~~~~~~~~~~
>     include/asm-generic/memory_model.h:41:37: note: previous implicit declaration of '__pfn_to_section' with type 'int()'
>        41 |         struct mem_section *__sec = __pfn_to_section(__pfn);    \
>           |                                     ^~~~~~~~~~~~~~~~
>     include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
>        53 | #define pfn_to_page __pfn_to_page
>           |                     ^~~~~~~~~~~~~
>     include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
>       231 |                 ___page = pfn_to_page(pfn);     \
>           |                           ^~~~~~~~~~~
>     include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
>       270 |         struct page *page = pfn_to_online_page(pfn);
>           |                             ^~~~~~~~~~~~~~~~~~
>>> include/linux/mmzone.h:1839:19: error: static declaration of 'pfn_valid' follows non-static declaration
>      1839 | static inline int pfn_valid(unsigned long pfn)
>           |                   ^~~~~~~~~
>     include/linux/memory_hotplug.h:230:13: note: previous implicit declaration of 'pfn_valid' with type 'int()'
>       230 |         if (pfn_valid(pfn))                     \
>           |             ^~~~~~~~~
>     include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
>       270 |         struct page *page = pfn_to_online_page(pfn);
>           |                             ^~~~~~~~~~~~~~~~~~
>     arch/alpha/kernel/asm-offsets.c:15:6: warning: no previous prototype for 'foo' [-Wmissing-prototypes]
>        15 | void foo(void)
>           |      ^~~
>     cc1: some warnings being treated as errors
>     make[2]: *** [scripts/Makefile.build:118: arch/alpha/kernel/asm-offsets.s] Error 1
>     make[2]: Target 'prepare' not remade because of errors.
>     make[1]: *** [Makefile:1272: prepare0] Error 2
>     make[1]: Target 'prepare' not remade because of errors.
>     make: *** [Makefile:231: __sub-make] Error 2
>     make: Target 'prepare' not remade because of errors.
>
>
> vim +230 include/linux/memory_hotplug.h
Thanks, it seems that we need use macro definition instead of inline 
function, will update in the next version.
>
> b4a0215e11dcfe Kefeng Wang  2022-08-27  225
> 208d54e5513c0c Dave Hansen  2005-10-29  226  #else /* ! CONFIG_MEMORY_HOTPLUG */
> 2d070eab2e8270 Michal Hocko 2017-07-06  227  #define pfn_to_online_page(pfn)			\
> 2d070eab2e8270 Michal Hocko 2017-07-06  228  ({						\
> 2d070eab2e8270 Michal Hocko 2017-07-06  229  	struct page *___page = NULL;		\
> 2d070eab2e8270 Michal Hocko 2017-07-06 @230  	if (pfn_valid(pfn))			\
> 2d070eab2e8270 Michal Hocko 2017-07-06 @231  		___page = pfn_to_page(pfn);	\
> 2d070eab2e8270 Michal Hocko 2017-07-06  232  	___page;				\
> 2d070eab2e8270 Michal Hocko 2017-07-06  233   })
> 2d070eab2e8270 Michal Hocko 2017-07-06  234
>
David Hildenbrand Dec. 13, 2022, 11:40 a.m. UTC | #4
On 13.12.22 10:27, Kefeng Wang wrote:
> Introduce a wrapper function pfn_to_online_folio(), which calls
> pfn_to_online_page() and returns the folio of the page found,
> or null if no page.
> 
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>   include/linux/memory_hotplug.h | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
> index 9fcbf5706595..e841e4fb52a7 100644
> --- a/include/linux/memory_hotplug.h
> +++ b/include/linux/memory_hotplug.h
> @@ -265,6 +265,13 @@ static inline void pgdat_kswapd_unlock(pg_data_t *pgdat) {}
>   static inline void pgdat_kswapd_lock_init(pg_data_t *pgdat) {}
>   #endif /* ! CONFIG_MEMORY_HOTPLUG */
>   
> +static inline struct folio *pfn_to_online_folio(unsigned long pfn)
> +{
> +	struct page *page = pfn_to_online_page(pfn);
> +
> +	return page ? page_folio(page) : NULL;
> +}

Who guarantees that page_folio() is safe and stable at that point?

IIRC, that's very tricky. We could have the page concurrently getting 
freed and the folio dissolved.
kernel test robot Dec. 13, 2022, 12:03 p.m. UTC | #5
Hi Kefeng,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.1]
[cannot apply to akpm-mm/mm-everything next-20221213]
[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/Kefeng-Wang/mm-converted-page-idle-and-damon-to-use-folios/20221213-171230
patch link:    https://lore.kernel.org/r/20221213092735.187924-2-wangkefeng.wang%40huawei.com
patch subject: [PATCH -next 1/8] mm: memory_hotplug: add pfn_to_online_folio()
config: sparc-allyesconfig
compiler: sparc64-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/6549c7ce5345695320d1dadef2aceff6e76d34f4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Kefeng-Wang/mm-converted-page-idle-and-damon-to-use-folios/20221213-171230
        git checkout 6549c7ce5345695320d1dadef2aceff6e76d34f4
        # 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=sparc SHELL=/bin/bash drivers/media/usb/cx231xx/

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

All warnings (new ones prefixed by >>):

   In file included from include/linux/mmzone.h:1245,
                    from include/linux/gfp.h:7,
                    from include/linux/xarray.h:15,
                    from include/linux/radix-tree.h:21,
                    from include/linux/idr.h:15,
                    from include/linux/kernfs.h:12,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/of.h:17,
                    from include/linux/irqdomain.h:36,
                    from include/linux/acpi.h:13,
                    from include/linux/i2c.h:13,
                    from drivers/media/usb/cx231xx/cx231xx.h:16,
                    from drivers/media/usb/cx231xx/cx231xx-audio.c:9:
   include/linux/memory_hotplug.h: In function 'pfn_to_online_folio':
   include/linux/memory_hotplug.h:230:13: error: implicit declaration of function 'pfn_valid' [-Werror=implicit-function-declaration]
     230 |         if (pfn_valid(pfn))                     \
         |             ^~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   In file included from arch/sparc/include/asm/page_64.h:130,
                    from arch/sparc/include/asm/page.h:8,
                    from arch/sparc/include/asm/thread_info_64.h:27,
                    from arch/sparc/include/asm/thread_info.h:5,
                    from include/linux/thread_info.h:60,
                    from arch/sparc/include/asm/current.h:15,
                    from include/linux/mutex.h:14,
                    from include/linux/kernfs.h:11:
   include/asm-generic/memory_model.h:25:34: error: 'vmemmap' undeclared (first use in this function); did you mean 'mem_map'?
      25 | #define __pfn_to_page(pfn)      (vmemmap + (pfn))
         |                                  ^~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:25:34: note: each undeclared identifier is reported only once for each function it appears in
      25 | #define __pfn_to_page(pfn)      (vmemmap + (pfn))
         |                                  ^~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   include/linux/mmzone.h: At top level:
   include/linux/mmzone.h:1839:19: error: static declaration of 'pfn_valid' follows non-static declaration
    1839 | static inline int pfn_valid(unsigned long pfn)
         |                   ^~~~~~~~~
   include/linux/memory_hotplug.h:230:13: note: previous implicit declaration of 'pfn_valid' with type 'int()'
     230 |         if (pfn_valid(pfn))                     \
         |             ^~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   drivers/media/usb/cx231xx/cx231xx-audio.c: In function 'cx231xx_audio_init':
>> drivers/media/usb/cx231xx/cx231xx-audio.c:564:20: warning: variable 'devnr' set but not used [-Wunused-but-set-variable]
     564 |         static int devnr;
         |                    ^~~~~
   drivers/media/usb/cx231xx/cx231xx-audio.c: At top level:
   drivers/media/usb/cx231xx/cx231xx-audio.c:29:12: warning: 'index' defined but not used [-Wunused-variable]
      29 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
         |            ^~~~~
   cc1: some warnings being treated as errors


vim +/devnr +564 drivers/media/usb/cx231xx/cx231xx-audio.c

e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  558  
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  559  static int cx231xx_audio_init(struct cx231xx *dev)
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  560  {
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  561  	struct cx231xx_audio *adev = &dev->adev;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  562  	struct snd_pcm *pcm;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  563  	struct snd_card *card;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03 @564  	static int devnr;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  565  	int err;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  566  	struct usb_interface *uif;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  567  	int i, isoc_pipe = 0;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  568  
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  569  	if (dev->has_alsa_audio != 1) {
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  570  		/* This device does not support the extension (in this case
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  571  		   the device is expecting the snd-usb-audio module or
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  572  		   doesn't have analog audio support at all) */
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  573  		return 0;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  574  	}
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  575  
336fea922936c1 drivers/media/usb/cx231xx/cx231xx-audio.c   Mauro Carvalho Chehab 2014-11-03  576  	dev_dbg(dev->dev,
b7085c08647598 drivers/media/usb/cx231xx/cx231xx-audio.c   Mauro Carvalho Chehab 2014-11-02  577  		"probing for cx231xx non standard usbaudio\n");
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  578  
336fea922936c1 drivers/media/usb/cx231xx/cx231xx-audio.c   Mauro Carvalho Chehab 2014-11-03  579  	err = snd_card_new(dev->dev, index[devnr], "Cx231xx Audio",
e735688875208f drivers/media/usb/cx231xx/cx231xx-audio.c   Takashi Iwai          2014-01-29  580  			   THIS_MODULE, 0, &card);
a938b8c5be8fe5 drivers/media/video/cx231xx/cx231xx-audio.c Mauro Carvalho Chehab 2009-04-06  581  	if (err < 0)
a938b8c5be8fe5 drivers/media/video/cx231xx/cx231xx-audio.c Mauro Carvalho Chehab 2009-04-06  582  		return err;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  583  
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  584  	spin_lock_init(&adev->slock);
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  585  	err = snd_pcm_new(card, "Cx231xx Audio", 0, 0, 1, &pcm);
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  586  	if (err < 0)
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  587  		goto err_free_card;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  588  
84b5dbf39ed2f5 drivers/media/video/cx231xx/cx231xx-audio.c Mauro Carvalho Chehab 2009-03-03  589  	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
84b5dbf39ed2f5 drivers/media/video/cx231xx/cx231xx-audio.c Mauro Carvalho Chehab 2009-03-03  590  			&snd_cx231xx_pcm_capture);
355b9a0c585669 drivers/media/usb/cx231xx/cx231xx-audio.c   Takashi Iwai          2019-12-10  591  	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  592  	pcm->info_flags = 0;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  593  	pcm->private_data = dev;
cc1e6315e83db0 drivers/media/usb/cx231xx/cx231xx-audio.c   Mauro Carvalho Chehab 2018-09-10  594  	strscpy(pcm->name, "Conexant cx231xx Capture", sizeof(pcm->name));
cc1e6315e83db0 drivers/media/usb/cx231xx/cx231xx-audio.c   Mauro Carvalho Chehab 2018-09-10  595  	strscpy(card->driver, "Cx231xx-Audio", sizeof(card->driver));
cc1e6315e83db0 drivers/media/usb/cx231xx/cx231xx-audio.c   Mauro Carvalho Chehab 2018-09-10  596  	strscpy(card->shortname, "Cx231xx Audio", sizeof(card->shortname));
cc1e6315e83db0 drivers/media/usb/cx231xx/cx231xx-audio.c   Mauro Carvalho Chehab 2018-09-10  597  	strscpy(card->longname, "Conexant cx231xx Audio", sizeof(card->longname));
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  598  
61b04cb24a129f drivers/media/video/cx231xx/cx231xx-audio.c Mauro Carvalho Chehab 2010-09-27  599  	INIT_WORK(&dev->wq_trigger, audio_trigger);
61b04cb24a129f drivers/media/video/cx231xx/cx231xx-audio.c Mauro Carvalho Chehab 2010-09-27  600  
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  601  	err = snd_card_register(card);
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  602  	if (err < 0)
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  603  		goto err_free_card;
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  604  
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  605  	adev->sndcard = card;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  606  	adev->udev = dev->udev;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  607  
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  608  	/* compute alternate max packet sizes for Audio */
84b5dbf39ed2f5 drivers/media/video/cx231xx/cx231xx-audio.c Mauro Carvalho Chehab 2009-03-03  609  	uif =
84b5dbf39ed2f5 drivers/media/video/cx231xx/cx231xx-audio.c Mauro Carvalho Chehab 2009-03-03  610  	    dev->udev->actconfig->interface[dev->current_pcb_config.
84b5dbf39ed2f5 drivers/media/video/cx231xx/cx231xx-audio.c Mauro Carvalho Chehab 2009-03-03  611  					    hs_config_info[0].interface_info.
84b5dbf39ed2f5 drivers/media/video/cx231xx/cx231xx-audio.c Mauro Carvalho Chehab 2009-03-03  612  					    audio_index + 1];
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  613  
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  614  	if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1) {
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  615  		err = -ENODEV;
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  616  		goto err_free_card;
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  617  	}
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  618  
84b5dbf39ed2f5 drivers/media/video/cx231xx/cx231xx-audio.c Mauro Carvalho Chehab 2009-03-03  619  	adev->end_point_addr =
69a11a32643bda drivers/media/usb/cx231xx/cx231xx-audio.c   Hans Verkuil          2013-02-07  620  	    uif->altsetting[0].endpoint[isoc_pipe].desc.
69a11a32643bda drivers/media/usb/cx231xx/cx231xx-audio.c   Hans Verkuil          2013-02-07  621  			bEndpointAddress;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  622  
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  623  	adev->num_alt = uif->num_altsetting;
336fea922936c1 drivers/media/usb/cx231xx/cx231xx-audio.c   Mauro Carvalho Chehab 2014-11-03  624  	dev_info(dev->dev,
b7085c08647598 drivers/media/usb/cx231xx/cx231xx-audio.c   Mauro Carvalho Chehab 2014-11-02  625  		"audio EndPoint Addr 0x%x, Alternate settings: %i\n",
84b5dbf39ed2f5 drivers/media/video/cx231xx/cx231xx-audio.c Mauro Carvalho Chehab 2009-03-03  626  		adev->end_point_addr, adev->num_alt);
6da2ec56059c3c drivers/media/usb/cx231xx/cx231xx-audio.c   Kees Cook             2018-06-12  627  	adev->alt_max_pkt_size = kmalloc_array(32, adev->num_alt, GFP_KERNEL);
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  628  	if (!adev->alt_max_pkt_size) {
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  629  		err = -ENOMEM;
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  630  		goto err_free_card;
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  631  	}
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  632  
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  633  	for (i = 0; i < adev->num_alt; i++) {
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  634  		u16 tmp;
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  635  
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  636  		if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1) {
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  637  			err = -ENODEV;
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  638  			goto err_free_pkt_size;
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  639  		}
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  640  
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  641  		tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  642  				wMaxPacketSize);
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  643  		adev->alt_max_pkt_size[i] =
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  644  		    (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
336fea922936c1 drivers/media/usb/cx231xx/cx231xx-audio.c   Mauro Carvalho Chehab 2014-11-03  645  		dev_dbg(dev->dev,
b7085c08647598 drivers/media/usb/cx231xx/cx231xx-audio.c   Mauro Carvalho Chehab 2014-11-02  646  			"audio alternate setting %i, max size= %i\n", i,
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  647  			adev->alt_max_pkt_size[i]);
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  648  	}
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  649  
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  650  	return 0;
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  651  
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  652  err_free_pkt_size:
65f921647f4c89 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  653  	kfree(adev->alt_max_pkt_size);
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  654  err_free_card:
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  655  	snd_card_free(card);
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  656  
fff1abc4d54e46 drivers/media/usb/cx231xx/cx231xx-audio.c   Johan Hovold          2017-03-13  657  	return err;
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  658  }
e0d3bafd02586c drivers/media/video/cx231xx/cx231xx-audio.c Sri Deevi             2009-03-03  659
Kefeng Wang Dec. 13, 2022, 12:13 p.m. UTC | #6
On 2022/12/13 19:40, David Hildenbrand wrote:
> On 13.12.22 10:27, Kefeng Wang wrote:
>> Introduce a wrapper function pfn_to_online_folio(), which calls
>> pfn_to_online_page() and returns the folio of the page found,
>> or null if no page.
>>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>> ---
>>   include/linux/memory_hotplug.h | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/include/linux/memory_hotplug.h 
>> b/include/linux/memory_hotplug.h
>> index 9fcbf5706595..e841e4fb52a7 100644
>> --- a/include/linux/memory_hotplug.h
>> +++ b/include/linux/memory_hotplug.h
>> @@ -265,6 +265,13 @@ static inline void pgdat_kswapd_unlock(pg_data_t 
>> *pgdat) {}
>>   static inline void pgdat_kswapd_lock_init(pg_data_t *pgdat) {}
>>   #endif /* ! CONFIG_MEMORY_HOTPLUG */
>>   +static inline struct folio *pfn_to_online_folio(unsigned long pfn)
>> +{
>> +    struct page *page = pfn_to_online_page(pfn);
>> +
>> +    return page ? page_folio(page) : NULL;
>> +}
>
> Who guarantees that page_folio() is safe and stable at that point?
>
> IIRC, that's very tricky. We could have the page concurrently getting 
> freed and the folio dissolved.
So the caller should consider this,  lock or get the folio in the caller?
David Hildenbrand Dec. 13, 2022, 2:42 p.m. UTC | #7
On 13.12.22 13:13, Kefeng Wang wrote:
> 
> On 2022/12/13 19:40, David Hildenbrand wrote:
>> On 13.12.22 10:27, Kefeng Wang wrote:
>>> Introduce a wrapper function pfn_to_online_folio(), which calls
>>> pfn_to_online_page() and returns the folio of the page found,
>>> or null if no page.
>>>
>>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>>> ---
>>>    include/linux/memory_hotplug.h | 7 +++++++
>>>    1 file changed, 7 insertions(+)
>>>
>>> diff --git a/include/linux/memory_hotplug.h
>>> b/include/linux/memory_hotplug.h
>>> index 9fcbf5706595..e841e4fb52a7 100644
>>> --- a/include/linux/memory_hotplug.h
>>> +++ b/include/linux/memory_hotplug.h
>>> @@ -265,6 +265,13 @@ static inline void pgdat_kswapd_unlock(pg_data_t
>>> *pgdat) {}
>>>    static inline void pgdat_kswapd_lock_init(pg_data_t *pgdat) {}
>>>    #endif /* ! CONFIG_MEMORY_HOTPLUG */
>>>    +static inline struct folio *pfn_to_online_folio(unsigned long pfn)
>>> +{
>>> +    struct page *page = pfn_to_online_page(pfn);
>>> +
>>> +    return page ? page_folio(page) : NULL;
>>> +}
>>
>> Who guarantees that page_folio() is safe and stable at that point?
>>
>> IIRC, that's very tricky. We could have the page concurrently getting
>> freed and the folio dissolved.
> So the caller should consider this,  lock or get the folio in the caller?
> 

I think the helper pfn_to_online_folio() as is might be wrong approach. 
The caller should convert to a folio after taking precautions that it is 
actually safe to do that (e.g., succeeded grabbing a reference first).
Matthew Wilcox Dec. 13, 2022, 2:47 p.m. UTC | #8
On Tue, Dec 13, 2022 at 08:13:31PM +0800, Kefeng Wang wrote:
> 
> On 2022/12/13 19:40, David Hildenbrand wrote:
> > On 13.12.22 10:27, Kefeng Wang wrote:
> > > Introduce a wrapper function pfn_to_online_folio(), which calls
> > > pfn_to_online_page() and returns the folio of the page found,
> > > or null if no page.
> > > 
> > > Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> > > ---
> > >   include/linux/memory_hotplug.h | 7 +++++++
> > >   1 file changed, 7 insertions(+)
> > > 
> > > diff --git a/include/linux/memory_hotplug.h
> > > b/include/linux/memory_hotplug.h
> > > index 9fcbf5706595..e841e4fb52a7 100644
> > > --- a/include/linux/memory_hotplug.h
> > > +++ b/include/linux/memory_hotplug.h
> > > @@ -265,6 +265,13 @@ static inline void
> > > pgdat_kswapd_unlock(pg_data_t *pgdat) {}
> > >   static inline void pgdat_kswapd_lock_init(pg_data_t *pgdat) {}
> > >   #endif /* ! CONFIG_MEMORY_HOTPLUG */
> > >   +static inline struct folio *pfn_to_online_folio(unsigned long pfn)
> > > +{
> > > +    struct page *page = pfn_to_online_page(pfn);
> > > +
> > > +    return page ? page_folio(page) : NULL;
> > > +}
> > 
> > Who guarantees that page_folio() is safe and stable at that point?
> > 
> > IIRC, that's very tricky. We could have the page concurrently getting
> > freed and the folio dissolved.
> So the caller should consider this,  lock or get the folio in the caller?

The caller only has a pfn; it doesn't have the folio at the time of
the call.  David is right, this function cannot safely exist.
Kefeng Wang Dec. 14, 2022, 1:10 a.m. UTC | #9
On 2022/12/13 22:47, Matthew Wilcox wrote:
> On Tue, Dec 13, 2022 at 08:13:31PM +0800, Kefeng Wang wrote:
>> On 2022/12/13 19:40, David Hildenbrand wrote:
>>> On 13.12.22 10:27, Kefeng Wang wrote:
>>>> Introduce a wrapper function pfn_to_online_folio(), which calls
>>>> pfn_to_online_page() and returns the folio of the page found,
>>>> or null if no page.
>>>>
>>>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>>>> ---
>>>>    include/linux/memory_hotplug.h | 7 +++++++
>>>>    1 file changed, 7 insertions(+)
>>>>
>>>> diff --git a/include/linux/memory_hotplug.h
>>>> b/include/linux/memory_hotplug.h
>>>> index 9fcbf5706595..e841e4fb52a7 100644
>>>> --- a/include/linux/memory_hotplug.h
>>>> +++ b/include/linux/memory_hotplug.h
>>>> @@ -265,6 +265,13 @@ static inline void
>>>> pgdat_kswapd_unlock(pg_data_t *pgdat) {}
>>>>    static inline void pgdat_kswapd_lock_init(pg_data_t *pgdat) {}
>>>>    #endif /* ! CONFIG_MEMORY_HOTPLUG */
>>>>    +static inline struct folio *pfn_to_online_folio(unsigned long pfn)
>>>> +{
>>>> +    struct page *page = pfn_to_online_page(pfn);
>>>> +
>>>> +    return page ? page_folio(page) : NULL;
>>>> +}
>>> Who guarantees that page_folio() is safe and stable at that point?
>>>
>>> IIRC, that's very tricky. We could have the page concurrently getting
>>> freed and the folio dissolved.
>> So the caller should consider this,  lock or get the folio in the caller?
> The caller only has a pfn; it doesn't have the folio at the time of
> the call.  David is right, this function cannot safely exist.
Thanks fro all the advises from David/Matthew/SeongJae,  will rethink 
this converting.
>
kernel test robot Dec. 14, 2022, 4:15 a.m. UTC | #10
Hi Kefeng,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.1]
[cannot apply to akpm-mm/mm-everything next-20221213]
[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/Kefeng-Wang/mm-converted-page-idle-and-damon-to-use-folios/20221213-171230
patch link:    https://lore.kernel.org/r/20221213092735.187924-2-wangkefeng.wang%40huawei.com
patch subject: [PATCH -next 1/8] mm: memory_hotplug: add pfn_to_online_folio()
config: i386-randconfig-a001
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/6549c7ce5345695320d1dadef2aceff6e76d34f4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Kefeng-Wang/mm-converted-page-idle-and-damon-to-use-folios/20221213-171230
        git checkout 6549c7ce5345695320d1dadef2aceff6e76d34f4
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=i386 prepare

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

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

   In file included from include/linux/mmzone.h:1245,
                    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/memory_hotplug.h: In function 'pfn_to_online_folio':
   include/linux/memory_hotplug.h:230:13: error: implicit declaration of function 'pfn_valid' [-Werror=implicit-function-declaration]
     230 |         if (pfn_valid(pfn))                     \
         |             ^~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   In file included from arch/x86/include/asm/page.h:86,
                    from arch/x86/include/asm/thread_info.h:12,
                    from include/linux/thread_info.h:60,
                    from arch/x86/include/asm/preempt.h:7,
                    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/asm-generic/memory_model.h:41:37: error: implicit declaration of function '__pfn_to_section' [-Werror=implicit-function-declaration]
      41 |         struct mem_section *__sec = __pfn_to_section(__pfn);    \
         |                                     ^~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
>> include/asm-generic/memory_model.h:41:37: warning: initialization of 'struct mem_section *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
      41 |         struct mem_section *__sec = __pfn_to_section(__pfn);    \
         |                                     ^~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:41:37: note: (near initialization for 'page')
      41 |         struct mem_section *__sec = __pfn_to_section(__pfn);    \
         |                                     ^~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
>> include/asm-generic/memory_model.h:42:9: error: implicit declaration of function '__section_mem_map_addr' [-Werror=implicit-function-declaration]
      42 |         __section_mem_map_addr(__sec) + __pfn;          \
         |         ^~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   In file included from include/linux/mmzone.h:1245,
                    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/memory_hotplug.h:231:25: warning: assignment to 'struct page *' from 'long unsigned int' makes pointer from integer without a cast [-Wint-conversion]
     231 |                 ___page = pfn_to_page(pfn);     \
         |                         ^
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   In file included 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/mmzone.h: At top level:
>> include/linux/mmzone.h:1740:28: error: conflicting types for '__section_mem_map_addr'; have 'struct page *(struct mem_section *)'
    1740 | static inline struct page *__section_mem_map_addr(struct mem_section *section)
         |                            ^~~~~~~~~~~~~~~~~~~~~~
   In file included from arch/x86/include/asm/page.h:86,
                    from arch/x86/include/asm/thread_info.h:12,
                    from include/linux/thread_info.h:60,
                    from arch/x86/include/asm/preempt.h:7,
                    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/asm-generic/memory_model.h:42:9: note: previous implicit declaration of '__section_mem_map_addr' with type 'int()'
      42 |         __section_mem_map_addr(__sec) + __pfn;          \
         |         ^~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   In file included 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/mmzone.h:1801:35: error: conflicting types for '__pfn_to_section'; have 'struct mem_section *(long unsigned int)'
    1801 | static inline struct mem_section *__pfn_to_section(unsigned long pfn)
         |                                   ^~~~~~~~~~~~~~~~
   In file included from arch/x86/include/asm/page.h:86,
                    from arch/x86/include/asm/thread_info.h:12,
                    from include/linux/thread_info.h:60,
                    from arch/x86/include/asm/preempt.h:7,
                    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/asm-generic/memory_model.h:41:37: note: previous implicit declaration of '__pfn_to_section' with type 'int()'
      41 |         struct mem_section *__sec = __pfn_to_section(__pfn);    \
         |                                     ^~~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:53:21: note: in expansion of macro '__pfn_to_page'
      53 | #define pfn_to_page __pfn_to_page
         |                     ^~~~~~~~~~~~~
   include/linux/memory_hotplug.h:231:27: note: in expansion of macro 'pfn_to_page'
     231 |                 ___page = pfn_to_page(pfn);     \
         |                           ^~~~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   In file included 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/mmzone.h:1839:19: error: static declaration of 'pfn_valid' follows non-static declaration
    1839 | static inline int pfn_valid(unsigned long pfn)
         |                   ^~~~~~~~~
   In file included from include/linux/mmzone.h:1245,
                    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/memory_hotplug.h:230:13: note: previous implicit declaration of 'pfn_valid' with type 'int()'
     230 |         if (pfn_valid(pfn))                     \
         |             ^~~~~~~~~
   include/linux/memory_hotplug.h:270:29: note: in expansion of macro 'pfn_to_online_page'
     270 |         struct page *page = pfn_to_online_page(pfn);
         |                             ^~~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors
   make[2]: *** [scripts/Makefile.build:118: arch/x86/kernel/asm-offsets.s] Error 1
   make[2]: Target 'prepare' not remade because of errors.
   make[1]: *** [Makefile:1272: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:231: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.


vim +231 include/linux/memory_hotplug.h

b4a0215e11dcfe Kefeng Wang  2022-08-27  225  
208d54e5513c0c Dave Hansen  2005-10-29  226  #else /* ! CONFIG_MEMORY_HOTPLUG */
2d070eab2e8270 Michal Hocko 2017-07-06  227  #define pfn_to_online_page(pfn)			\
2d070eab2e8270 Michal Hocko 2017-07-06  228  ({						\
2d070eab2e8270 Michal Hocko 2017-07-06  229  	struct page *___page = NULL;		\
2d070eab2e8270 Michal Hocko 2017-07-06  230  	if (pfn_valid(pfn))			\
2d070eab2e8270 Michal Hocko 2017-07-06 @231  		___page = pfn_to_page(pfn);	\
2d070eab2e8270 Michal Hocko 2017-07-06  232  	___page;				\
2d070eab2e8270 Michal Hocko 2017-07-06  233   })
2d070eab2e8270 Michal Hocko 2017-07-06  234
diff mbox series

Patch

diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index 9fcbf5706595..e841e4fb52a7 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -265,6 +265,13 @@  static inline void pgdat_kswapd_unlock(pg_data_t *pgdat) {}
 static inline void pgdat_kswapd_lock_init(pg_data_t *pgdat) {}
 #endif /* ! CONFIG_MEMORY_HOTPLUG */
 
+static inline struct folio *pfn_to_online_folio(unsigned long pfn)
+{
+	struct page *page = pfn_to_online_page(pfn);
+
+	return page ? page_folio(page) : NULL;
+}
+
 /*
  * Keep this declaration outside CONFIG_MEMORY_HOTPLUG as some
  * platforms might override and use arch_get_mappable_range()