linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2
@ 2022-03-29 15:37 Muchun Song
  0 siblings, 0 replies; 9+ messages in thread
From: Muchun Song @ 2022-03-29 15:37 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Jonathan Corbet, Mike Kravetz, Andrew Morton, Luis R. Rodriguez,
	Kees Cook, Iurii Zaikin, Oscar Salvador, David Hildenbrand,
	open list:DOCUMENTATION, Linux Kernel Mailing List,
	Linux Memory Management List, Xiongchun duan, Muchun Song

On Fri, Mar 25, 2022 at 1:11 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Wed, Mar 23, 2022 at 9:57 PM Muchun Song <songmuchun@bytedance.com> wrote:
> >
> > If the size of "struct page" is not the power of two and this
> > feature is enabled, then the vmemmap pages of HugeTLB will be
> > corrupted after remapping (panic is about to happen in theory).
> > But this only exists when !CONFIG_MEMCG && !CONFIG_SLUB on
> > x86_64.  However, it is not a conventional configuration nowadays.
> > So it is not a real word issue, just the result of a code review.
> > But we have to prevent anyone from configuring that combined
> > configuration.  In order to avoid many checks like "is_power_of_2
> > (sizeof(struct page))" through mm/hugetlb_vmemmap.c.  Introduce
> > STRUCT_PAGE_SIZE_IS_POWER_OF_2 to detect if the size of struct
> > page is power of 2 and make this feature depends on this new
> > config.  Then we could prevent anyone do any unexpected
> > configuration.
> >
> > Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> > Suggested-by: Luis Chamberlain <mcgrof@kernel.org>
> > ---
> >  Kbuild                           | 14 ++++++++++++++
> >  fs/Kconfig                       |  1 +
> >  include/linux/mm_types.h         |  2 ++
> >  mm/Kconfig                       |  3 +++
> >  mm/hugetlb_vmemmap.c             |  6 ------
> >  mm/struct_page_size.c            | 19 +++++++++++++++++++
> >  scripts/check_struct_page_po2.sh |  9 +++++++++
> >  7 files changed, 48 insertions(+), 6 deletions(-)
> >  create mode 100644 mm/struct_page_size.c
> >  create mode 100755 scripts/check_struct_page_po2.sh
> >
> > diff --git a/Kbuild b/Kbuild
> > index fa441b98c9f6..21415c3b2728 100644
> > --- a/Kbuild
> > +++ b/Kbuild
> > @@ -37,6 +37,20 @@ $(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE
> >         $(call filechk,offsets,__ASM_OFFSETS_H__)
> >
> >  #####
> > +# Generate struct_page_size.h.
> > +
> > +struct_page_size-file := include/generated/struct_page_size.h
> > +
> > +always-y := $(struct_page_size-file)
> > +targets := mm/struct_page_size.s
> > +
> > +mm/struct_page_size.s: $(timeconst-file) $(bounds-file)
> > +
> > +$(struct_page_size-file): mm/struct_page_size.s FORCE
> > +       $(call filechk,offsets,__LINUX_STRUCT_PAGE_SIZE_H__)
> > +       $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
>
>
> No, please do not do this.
> It is terrible to feed back this to Kconfig again.

OK. I'll remove syncconfig.

>
> If you know this happens on !CONFIG_MEMCG && !CONFIG_SLUB on x86_64,
> why don't you add this dependency directly?

It is not enough since the size of the struct page also depends on
LAST_CPUPID_NOT_IN_PAGE_FLAGS && CONFIG_SLAB.
We cannot know the result of LAST_CPUPID_NOT_IN_PAGE_FLAGS in
Kconfig.

>
>
> If you want to avoid the run-time check,
> why don't you use  BUILD_BUG_ON() ?
>

Now I have another solution to avoid the run-time check.
We could use macro STRUCT_PAGE_SIZE_IS_POWER_OF_2
to do that like the following.

#ifdef STRUCT_PAGE_SIZE_IS_POWER_OF_2
/* code */
#endif

Thanks.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2
  2022-03-24 10:40           ` Chen, Rong A
@ 2022-03-24 10:47             ` Muchun Song
  0 siblings, 0 replies; 9+ messages in thread
From: Muchun Song @ 2022-03-24 10:47 UTC (permalink / raw)
  To: Chen, Rong A
  Cc: Andrew Morton, kernel test robot, Jonathan Corbet, Mike Kravetz,
	Luis Chamberlain, Kees Cook, Iurii Zaikin, Oscar Salvador,
	David Hildenbrand, kbuild-all, Linux Doc Mailing List, LKML,
	Linux Memory Management List, Xiongchun duan, Muchun Song

On Thu, Mar 24, 2022 at 6:40 PM Chen, Rong A <rong.a.chen@intel.com> wrote:
>
>
>
> On 3/24/2022 6:20 PM, Muchun Song wrote:
> > On Thu, Mar 24, 2022 at 5:40 PM Chen, Rong A <rong.a.chen@intel.com> wrote:
> >>
> >>
> >>
> >> On 3/24/2022 6:13 AM, Andrew Morton wrote:
> >>> On Thu, 24 Mar 2022 06:06:41 +0800 kernel test robot <lkp@intel.com> wrote:
> >>>
> >>>> Hi Muchun,
> >>>>
> >>>> Thank you for the patch! Yet something to improve:
> >>>>
> >>>> [auto build test ERROR on hnaz-mm/master]
> >>>> [also build test ERROR on linus/master next-20220323]
> >>>> [cannot apply to mcgrof/sysctl-next v5.17]
> >>>> [If your patch is applied to the wrong git tree, kindly drop us a note.
> >>>> And when submitting patch, we suggest to use '--base' as documented in
> >>>> https://git-scm.com/docs/git-format-patch]
> >>>>
> >>>> url:    https://github.com/0day-ci/linux/commits/Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
> >>>> base:   https://github.com/hnaz/linux-mm master
> >>>> config: arc-randconfig-r043-20220323 (https://download.01.org/0day-ci/archive/20220324/202203240546.MHJzsBaO-lkp@intel.com/config)
> >>>> compiler: arc-elf-gcc (GCC) 11.2.0
> >>>> reproduce (this is a W=1 build):
> >>>>           wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >>>>           chmod +x ~/bin/make.cross
> >>>>           # https://github.com/0day-ci/linux/commit/64211be650af117819368a26d7b86c33df5deea4
> >>>>           git remote add linux-review https://github.com/0day-ci/linux
> >>>>           git fetch --no-tags linux-review Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
> >>>>           git checkout 64211be650af117819368a26d7b86c33df5deea4
> >>>>           # save the config file to linux build tree
> >>>>           mkdir build_dir
> >>>>           COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc prepare
> >>>>
> >>>> If you fix the issue, kindly add following tag as appropriate
> >>>> Reported-by: kernel test robot <lkp@intel.com>
> >>>>
> >>>> All errors (new ones prefixed by >>):
> >>>>
> >>>>>> cc1: fatal error: cannot open 'kernel/bounds.s' for writing: No such file or directory
> >>>
> >>> It would take a lot of talent for Munchun to have caused this!
> >>>
> >>> Methinks you just ran out of disk space?
> >>
> >> Hi Andrew,
> >>
> >> Thanks for the reply, I tried to apply this patch to the head of
> >> mainline and I still can reproduce the error in my local machine:
> >>
> >> $ wget -q -O -
> >> https://lore.kernel.org/lkml/20220323125523.79254-2-songmuchun@bytedance.com/raw
> >> | git apply -v
> >> $ mkdir build_dir && wget
> >> https://download.01.org/0day-ci/archive/20220324/202203240546.MHJzsBaO-lkp@intel.com/config
> >> -O build_dir/.config
> >> $ COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross
> >> O=build_dir ARCH=arc olddefconfig prepare
> >> make --keep-going CONFIG_OF_ALL_DTBS=y CONFIG_DTC=y
> >> CROSS_COMPILE=/home/nfs/0day/gcc-11.2.0-nolibc/arc-elf/bin/arc-elf-
> >> --jobs=72 O=build_dir ARCH=arc olddefconfig prepare
> >> ...
> >> cc1: fatal error: cannot open 'kernel/bounds.s' for writing: No such
> >> file or directory
> >> compilation terminated.
> >> make[3]: *** [../scripts/Makefile.build:121: kernel/bounds.s] Error 1
> >> make[3]: Target '__build' not remade because of errors.
> >> make[2]: *** [../Makefile:1191: prepare0] Error 2
> >> make[2]: Target 'prepare' not remade because of errors.
> >>
> >
> > Would you help me to test the following patch?  Thanks.
>
> I have confirmed the patch can fix the issue.
>

Thanks Chen.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2
  2022-03-24 10:20         ` Muchun Song
@ 2022-03-24 10:40           ` Chen, Rong A
  2022-03-24 10:47             ` Muchun Song
  0 siblings, 1 reply; 9+ messages in thread
From: Chen, Rong A @ 2022-03-24 10:40 UTC (permalink / raw)
  To: Muchun Song
  Cc: Andrew Morton, kernel test robot, Jonathan Corbet, Mike Kravetz,
	Luis Chamberlain, Kees Cook, Iurii Zaikin, Oscar Salvador,
	David Hildenbrand, kbuild-all, Linux Doc Mailing List, LKML,
	Linux Memory Management List, Xiongchun duan, Muchun Song



On 3/24/2022 6:20 PM, Muchun Song wrote:
> On Thu, Mar 24, 2022 at 5:40 PM Chen, Rong A <rong.a.chen@intel.com> wrote:
>>
>>
>>
>> On 3/24/2022 6:13 AM, Andrew Morton wrote:
>>> On Thu, 24 Mar 2022 06:06:41 +0800 kernel test robot <lkp@intel.com> wrote:
>>>
>>>> Hi Muchun,
>>>>
>>>> Thank you for the patch! Yet something to improve:
>>>>
>>>> [auto build test ERROR on hnaz-mm/master]
>>>> [also build test ERROR on linus/master next-20220323]
>>>> [cannot apply to mcgrof/sysctl-next v5.17]
>>>> [If your patch is applied to the wrong git tree, kindly drop us a note.
>>>> And when submitting patch, we suggest to use '--base' as documented in
>>>> https://git-scm.com/docs/git-format-patch]
>>>>
>>>> url:    https://github.com/0day-ci/linux/commits/Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
>>>> base:   https://github.com/hnaz/linux-mm master
>>>> config: arc-randconfig-r043-20220323 (https://download.01.org/0day-ci/archive/20220324/202203240546.MHJzsBaO-lkp@intel.com/config)
>>>> compiler: arc-elf-gcc (GCC) 11.2.0
>>>> reproduce (this is a W=1 build):
>>>>           wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>>>>           chmod +x ~/bin/make.cross
>>>>           # https://github.com/0day-ci/linux/commit/64211be650af117819368a26d7b86c33df5deea4
>>>>           git remote add linux-review https://github.com/0day-ci/linux
>>>>           git fetch --no-tags linux-review Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
>>>>           git checkout 64211be650af117819368a26d7b86c33df5deea4
>>>>           # save the config file to linux build tree
>>>>           mkdir build_dir
>>>>           COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc prepare
>>>>
>>>> If you fix the issue, kindly add following tag as appropriate
>>>> Reported-by: kernel test robot <lkp@intel.com>
>>>>
>>>> All errors (new ones prefixed by >>):
>>>>
>>>>>> cc1: fatal error: cannot open 'kernel/bounds.s' for writing: No such file or directory
>>>
>>> It would take a lot of talent for Munchun to have caused this!
>>>
>>> Methinks you just ran out of disk space?
>>
>> Hi Andrew,
>>
>> Thanks for the reply, I tried to apply this patch to the head of
>> mainline and I still can reproduce the error in my local machine:
>>
>> $ wget -q -O -
>> https://lore.kernel.org/lkml/20220323125523.79254-2-songmuchun@bytedance.com/raw
>> | git apply -v
>> $ mkdir build_dir && wget
>> https://download.01.org/0day-ci/archive/20220324/202203240546.MHJzsBaO-lkp@intel.com/config
>> -O build_dir/.config
>> $ COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross
>> O=build_dir ARCH=arc olddefconfig prepare
>> make --keep-going CONFIG_OF_ALL_DTBS=y CONFIG_DTC=y
>> CROSS_COMPILE=/home/nfs/0day/gcc-11.2.0-nolibc/arc-elf/bin/arc-elf-
>> --jobs=72 O=build_dir ARCH=arc olddefconfig prepare
>> ...
>> cc1: fatal error: cannot open 'kernel/bounds.s' for writing: No such
>> file or directory
>> compilation terminated.
>> make[3]: *** [../scripts/Makefile.build:121: kernel/bounds.s] Error 1
>> make[3]: Target '__build' not remade because of errors.
>> make[2]: *** [../Makefile:1191: prepare0] Error 2
>> make[2]: Target 'prepare' not remade because of errors.
>>
> 
> Would you help me to test the following patch?  Thanks.

I have confirmed the patch can fix the issue.

Best Regards,
Rong Chen

> 
> diff --git a/Kbuild b/Kbuild
> index 21415c3b2728..a8477c011b1d 100644
> --- a/Kbuild
> +++ b/Kbuild
> @@ -42,7 +42,7 @@ $(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE
>   struct_page_size-file := include/generated/struct_page_size.h
> 
>   always-y := $(struct_page_size-file)
> -targets := mm/struct_page_size.s
> +targets += mm/struct_page_size.s
> 
>   mm/struct_page_size.s: $(timeconst-file) $(bounds-file)
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2
  2022-03-24  9:40       ` [kbuild-all] " Chen, Rong A
  2022-03-24 10:05         ` Muchun Song
@ 2022-03-24 10:20         ` Muchun Song
  2022-03-24 10:40           ` Chen, Rong A
  1 sibling, 1 reply; 9+ messages in thread
From: Muchun Song @ 2022-03-24 10:20 UTC (permalink / raw)
  To: Chen, Rong A
  Cc: Andrew Morton, kernel test robot, Jonathan Corbet, Mike Kravetz,
	Luis Chamberlain, Kees Cook, Iurii Zaikin, Oscar Salvador,
	David Hildenbrand, kbuild-all, Linux Doc Mailing List, LKML,
	Linux Memory Management List, Xiongchun duan, Muchun Song

On Thu, Mar 24, 2022 at 5:40 PM Chen, Rong A <rong.a.chen@intel.com> wrote:
>
>
>
> On 3/24/2022 6:13 AM, Andrew Morton wrote:
> > On Thu, 24 Mar 2022 06:06:41 +0800 kernel test robot <lkp@intel.com> wrote:
> >
> >> Hi Muchun,
> >>
> >> Thank you for the patch! Yet something to improve:
> >>
> >> [auto build test ERROR on hnaz-mm/master]
> >> [also build test ERROR on linus/master next-20220323]
> >> [cannot apply to mcgrof/sysctl-next v5.17]
> >> [If your patch is applied to the wrong git tree, kindly drop us a note.
> >> And when submitting patch, we suggest to use '--base' as documented in
> >> https://git-scm.com/docs/git-format-patch]
> >>
> >> url:    https://github.com/0day-ci/linux/commits/Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
> >> base:   https://github.com/hnaz/linux-mm master
> >> config: arc-randconfig-r043-20220323 (https://download.01.org/0day-ci/archive/20220324/202203240546.MHJzsBaO-lkp@intel.com/config)
> >> compiler: arc-elf-gcc (GCC) 11.2.0
> >> reproduce (this is a W=1 build):
> >>          wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >>          chmod +x ~/bin/make.cross
> >>          # https://github.com/0day-ci/linux/commit/64211be650af117819368a26d7b86c33df5deea4
> >>          git remote add linux-review https://github.com/0day-ci/linux
> >>          git fetch --no-tags linux-review Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
> >>          git checkout 64211be650af117819368a26d7b86c33df5deea4
> >>          # save the config file to linux build tree
> >>          mkdir build_dir
> >>          COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc prepare
> >>
> >> If you fix the issue, kindly add following tag as appropriate
> >> Reported-by: kernel test robot <lkp@intel.com>
> >>
> >> All errors (new ones prefixed by >>):
> >>
> >>>> cc1: fatal error: cannot open 'kernel/bounds.s' for writing: No such file or directory
> >
> > It would take a lot of talent for Munchun to have caused this!
> >
> > Methinks you just ran out of disk space?
>
> Hi Andrew,
>
> Thanks for the reply, I tried to apply this patch to the head of
> mainline and I still can reproduce the error in my local machine:
>
> $ wget -q -O -
> https://lore.kernel.org/lkml/20220323125523.79254-2-songmuchun@bytedance.com/raw
> | git apply -v
> $ mkdir build_dir && wget
> https://download.01.org/0day-ci/archive/20220324/202203240546.MHJzsBaO-lkp@intel.com/config
> -O build_dir/.config
> $ COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross
> O=build_dir ARCH=arc olddefconfig prepare
> make --keep-going CONFIG_OF_ALL_DTBS=y CONFIG_DTC=y
> CROSS_COMPILE=/home/nfs/0day/gcc-11.2.0-nolibc/arc-elf/bin/arc-elf-
> --jobs=72 O=build_dir ARCH=arc olddefconfig prepare
> ...
> cc1: fatal error: cannot open 'kernel/bounds.s' for writing: No such
> file or directory
> compilation terminated.
> make[3]: *** [../scripts/Makefile.build:121: kernel/bounds.s] Error 1
> make[3]: Target '__build' not remade because of errors.
> make[2]: *** [../Makefile:1191: prepare0] Error 2
> make[2]: Target 'prepare' not remade because of errors.
>

Would you help me to test the following patch?  Thanks.

diff --git a/Kbuild b/Kbuild
index 21415c3b2728..a8477c011b1d 100644
--- a/Kbuild
+++ b/Kbuild
@@ -42,7 +42,7 @@ $(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE
 struct_page_size-file := include/generated/struct_page_size.h

 always-y := $(struct_page_size-file)
-targets := mm/struct_page_size.s
+targets += mm/struct_page_size.s

 mm/struct_page_size.s: $(timeconst-file) $(bounds-file)


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2
  2022-03-24  9:40       ` [kbuild-all] " Chen, Rong A
@ 2022-03-24 10:05         ` Muchun Song
  2022-03-24 10:20         ` Muchun Song
  1 sibling, 0 replies; 9+ messages in thread
From: Muchun Song @ 2022-03-24 10:05 UTC (permalink / raw)
  To: Chen, Rong A
  Cc: Andrew Morton, kernel test robot, Jonathan Corbet, Mike Kravetz,
	Luis Chamberlain, Kees Cook, Iurii Zaikin, Oscar Salvador,
	David Hildenbrand, kbuild-all, Linux Doc Mailing List, LKML,
	Linux Memory Management List, Xiongchun duan, Muchun Song

On Thu, Mar 24, 2022 at 5:40 PM Chen, Rong A <rong.a.chen@intel.com> wrote:
>
>
>
> On 3/24/2022 6:13 AM, Andrew Morton wrote:
> > On Thu, 24 Mar 2022 06:06:41 +0800 kernel test robot <lkp@intel.com> wrote:
> >
> >> Hi Muchun,
> >>
> >> Thank you for the patch! Yet something to improve:
> >>
> >> [auto build test ERROR on hnaz-mm/master]
> >> [also build test ERROR on linus/master next-20220323]
> >> [cannot apply to mcgrof/sysctl-next v5.17]
> >> [If your patch is applied to the wrong git tree, kindly drop us a note.
> >> And when submitting patch, we suggest to use '--base' as documented in
> >> https://git-scm.com/docs/git-format-patch]
> >>
> >> url:    https://github.com/0day-ci/linux/commits/Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
> >> base:   https://github.com/hnaz/linux-mm master
> >> config: arc-randconfig-r043-20220323 (https://download.01.org/0day-ci/archive/20220324/202203240546.MHJzsBaO-lkp@intel.com/config)
> >> compiler: arc-elf-gcc (GCC) 11.2.0
> >> reproduce (this is a W=1 build):
> >>          wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >>          chmod +x ~/bin/make.cross
> >>          # https://github.com/0day-ci/linux/commit/64211be650af117819368a26d7b86c33df5deea4
> >>          git remote add linux-review https://github.com/0day-ci/linux
> >>          git fetch --no-tags linux-review Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
> >>          git checkout 64211be650af117819368a26d7b86c33df5deea4
> >>          # save the config file to linux build tree
> >>          mkdir build_dir
> >>          COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc prepare
> >>
> >> If you fix the issue, kindly add following tag as appropriate
> >> Reported-by: kernel test robot <lkp@intel.com>
> >>
> >> All errors (new ones prefixed by >>):
> >>
> >>>> cc1: fatal error: cannot open 'kernel/bounds.s' for writing: No such file or directory
> >
> > It would take a lot of talent for Munchun to have caused this!
> >
> > Methinks you just ran out of disk space?
>
> Hi Andrew,
>
> Thanks for the reply, I tried to apply this patch to the head of
> mainline and I still can reproduce the error in my local machine:
>
> $ wget -q -O -
> https://lore.kernel.org/lkml/20220323125523.79254-2-songmuchun@bytedance.com/raw
> | git apply -v
> $ mkdir build_dir && wget
> https://download.01.org/0day-ci/archive/20220324/202203240546.MHJzsBaO-lkp@intel.com/config
> -O build_dir/.config
> $ COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross
> O=build_dir ARCH=arc olddefconfig prepare
> make --keep-going CONFIG_OF_ALL_DTBS=y CONFIG_DTC=y
> CROSS_COMPILE=/home/nfs/0day/gcc-11.2.0-nolibc/arc-elf/bin/arc-elf-
> --jobs=72 O=build_dir ARCH=arc olddefconfig prepare
> ...
> cc1: fatal error: cannot open 'kernel/bounds.s' for writing: No such
> file or directory
> compilation terminated.
> make[3]: *** [../scripts/Makefile.build:121: kernel/bounds.s] Error 1
> make[3]: Target '__build' not remade because of errors.
> make[2]: *** [../Makefile:1191: prepare0] Error 2
> make[2]: Target 'prepare' not remade because of errors.
>

I'll look at this, thanks for your report.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2
  2022-03-23 12:55 ` [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2 Muchun Song
  2022-03-23 22:06   ` kernel test robot
@ 2022-03-24  1:11   ` kernel test robot
  1 sibling, 0 replies; 9+ messages in thread
From: kernel test robot @ 2022-03-24  1:11 UTC (permalink / raw)
  To: Muchun Song, corbet, mike.kravetz, akpm, mcgrof, keescook,
	yzaikin, osalvador, david
  Cc: kbuild-all, linux-doc, linux-kernel, linux-mm, duanxiongchun,
	smuchun, Muchun Song

Hi Muchun,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on hnaz-mm/master]
[also build test ERROR on linus/master next-20220323]
[cannot apply to mcgrof/sysctl-next v5.17]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
base:   https://github.com/hnaz/linux-mm master
config: i386-randconfig-m021 (https://download.01.org/0day-ci/archive/20220324/202203240912.6ZaeXSiH-lkp@intel.com/config)
compiler: gcc-9 (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/64211be650af117819368a26d7b86c33df5deea4
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
        git checkout 64211be650af117819368a26d7b86c33df5deea4
        # save the config file to linux build tree
        mkdir build_dir
        make W=1 O=build_dir ARCH=i386 prepare

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

All errors (new ones prefixed by >>):

>> cc1: fatal error: can't open 'kernel/bounds.s' for writing: No such file or directory
   compilation terminated.
   make[2]: *** [scripts/Makefile.build:127: kernel/bounds.s] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [Makefile:1261: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:226: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2
  2022-03-23 22:06   ` kernel test robot
@ 2022-03-23 22:13     ` Andrew Morton
  2022-03-24  9:40       ` [kbuild-all] " Chen, Rong A
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Morton @ 2022-03-23 22:13 UTC (permalink / raw)
  To: kernel test robot
  Cc: Muchun Song, corbet, mike.kravetz, mcgrof, keescook, yzaikin,
	osalvador, david, kbuild-all, linux-doc, linux-kernel, linux-mm,
	duanxiongchun, smuchun

On Thu, 24 Mar 2022 06:06:41 +0800 kernel test robot <lkp@intel.com> wrote:

> Hi Muchun,
> 
> Thank you for the patch! Yet something to improve:
> 
> [auto build test ERROR on hnaz-mm/master]
> [also build test ERROR on linus/master next-20220323]
> [cannot apply to mcgrof/sysctl-next v5.17]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
> 
> url:    https://github.com/0day-ci/linux/commits/Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
> base:   https://github.com/hnaz/linux-mm master
> config: arc-randconfig-r043-20220323 (https://download.01.org/0day-ci/archive/20220324/202203240546.MHJzsBaO-lkp@intel.com/config)
> compiler: arc-elf-gcc (GCC) 11.2.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/0day-ci/linux/commit/64211be650af117819368a26d7b86c33df5deea4
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
>         git checkout 64211be650af117819368a26d7b86c33df5deea4
>         # save the config file to linux build tree
>         mkdir build_dir
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc prepare
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All errors (new ones prefixed by >>):
> 
> >> cc1: fatal error: cannot open 'kernel/bounds.s' for writing: No such file or directory

It would take a lot of talent for Munchun to have caused this!

Methinks you just ran out of disk space?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2
  2022-03-23 12:55 ` [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2 Muchun Song
@ 2022-03-23 22:06   ` kernel test robot
  2022-03-23 22:13     ` Andrew Morton
  2022-03-24  1:11   ` kernel test robot
  1 sibling, 1 reply; 9+ messages in thread
From: kernel test robot @ 2022-03-23 22:06 UTC (permalink / raw)
  To: Muchun Song, corbet, mike.kravetz, akpm, mcgrof, keescook,
	yzaikin, osalvador, david
  Cc: kbuild-all, linux-doc, linux-kernel, linux-mm, duanxiongchun,
	smuchun, Muchun Song

Hi Muchun,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on hnaz-mm/master]
[also build test ERROR on linus/master next-20220323]
[cannot apply to mcgrof/sysctl-next v5.17]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
base:   https://github.com/hnaz/linux-mm master
config: arc-randconfig-r043-20220323 (https://download.01.org/0day-ci/archive/20220324/202203240546.MHJzsBaO-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/64211be650af117819368a26d7b86c33df5deea4
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Muchun-Song/add-hugetlb_free_vmemmap-sysctl/20220323-205902
        git checkout 64211be650af117819368a26d7b86c33df5deea4
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc prepare

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

All errors (new ones prefixed by >>):

>> cc1: fatal error: cannot open 'kernel/bounds.s' for writing: No such file or directory
   compilation terminated.
   make[2]: *** [scripts/Makefile.build:127: kernel/bounds.s] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [Makefile:1261: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:226: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2
  2022-03-23 12:55 [PATCH v5 0/4] add hugetlb_free_vmemmap sysctl Muchun Song
@ 2022-03-23 12:55 ` Muchun Song
  2022-03-23 22:06   ` kernel test robot
  2022-03-24  1:11   ` kernel test robot
  0 siblings, 2 replies; 9+ messages in thread
From: Muchun Song @ 2022-03-23 12:55 UTC (permalink / raw)
  To: corbet, mike.kravetz, akpm, mcgrof, keescook, yzaikin, osalvador, david
  Cc: linux-doc, linux-kernel, linux-mm, duanxiongchun, smuchun, Muchun Song

If the size of "struct page" is not the power of two and this
feature is enabled, then the vmemmap pages of HugeTLB will be
corrupted after remapping (panic is about to happen in theory).
But this only exists when !CONFIG_MEMCG && !CONFIG_SLUB on
x86_64.  However, it is not a conventional configuration nowadays.
So it is not a real word issue, just the result of a code review.
But we have to prevent anyone from configuring that combined
configuration.  In order to avoid many checks like "is_power_of_2
(sizeof(struct page))" through mm/hugetlb_vmemmap.c.  Introduce
STRUCT_PAGE_SIZE_IS_POWER_OF_2 to detect if the size of struct
page is power of 2 and make this feature depends on this new
config.  Then we could prevent anyone do any unexpected
configuration.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Suggested-by: Luis Chamberlain <mcgrof@kernel.org>
---
 Kbuild                           | 14 ++++++++++++++
 fs/Kconfig                       |  1 +
 include/linux/mm_types.h         |  2 ++
 mm/Kconfig                       |  3 +++
 mm/hugetlb_vmemmap.c             |  6 ------
 mm/struct_page_size.c            | 19 +++++++++++++++++++
 scripts/check_struct_page_po2.sh |  9 +++++++++
 7 files changed, 48 insertions(+), 6 deletions(-)
 create mode 100644 mm/struct_page_size.c
 create mode 100755 scripts/check_struct_page_po2.sh

diff --git a/Kbuild b/Kbuild
index fa441b98c9f6..21415c3b2728 100644
--- a/Kbuild
+++ b/Kbuild
@@ -37,6 +37,20 @@ $(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE
 	$(call filechk,offsets,__ASM_OFFSETS_H__)
 
 #####
+# Generate struct_page_size.h.
+
+struct_page_size-file := include/generated/struct_page_size.h
+
+always-y := $(struct_page_size-file)
+targets := mm/struct_page_size.s
+
+mm/struct_page_size.s: $(timeconst-file) $(bounds-file)
+
+$(struct_page_size-file): mm/struct_page_size.s FORCE
+	$(call filechk,offsets,__LINUX_STRUCT_PAGE_SIZE_H__)
+	$(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
+
+#####
 # Check for missing system calls
 
 always-y += missing-syscalls
diff --git a/fs/Kconfig b/fs/Kconfig
index 7f2455e8e18a..856d2e9f5aef 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -249,6 +249,7 @@ config HUGETLB_PAGE_FREE_VMEMMAP
 	def_bool HUGETLB_PAGE
 	depends on X86_64
 	depends on SPARSEMEM_VMEMMAP
+	depends on STRUCT_PAGE_SIZE_IS_POWER_OF_2
 
 config HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON
 	bool "Default freeing vmemmap pages of HugeTLB to on"
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 8834e38c06a4..5fbff44a4310 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -223,6 +223,7 @@ struct page {
 #endif
 } _struct_page_alignment;
 
+#ifndef __GENERATING_STRUCT_PAGE_SIZE_IS_POWER_OF_2_H
 /**
  * struct folio - Represents a contiguous set of bytes.
  * @flags: Identical to the page flags.
@@ -844,5 +845,6 @@ enum fault_flag {
 	FAULT_FLAG_INSTRUCTION =	1 << 8,
 	FAULT_FLAG_INTERRUPTIBLE =	1 << 9,
 };
+#endif /* !__GENERATING_STRUCT_PAGE_SIZE_IS_POWER_OF_2_H */
 
 #endif /* _LINUX_MM_TYPES_H */
diff --git a/mm/Kconfig b/mm/Kconfig
index 034d87953600..9314bd34f49e 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -2,6 +2,9 @@
 
 menu "Memory Management options"
 
+config STRUCT_PAGE_SIZE_IS_POWER_OF_2
+	def_bool $(success,test "$(shell, $(srctree)/scripts/check_struct_page_po2.sh)" = 1)
+
 config SELECT_MEMORY_MODEL
 	def_bool y
 	depends on ARCH_SELECT_MEMORY_MODEL
diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index 791626983c2e..33ecb77c2b2a 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -194,12 +194,6 @@ EXPORT_SYMBOL(hugetlb_free_vmemmap_enabled_key);
 
 static int __init early_hugetlb_free_vmemmap_param(char *buf)
 {
-	/* We cannot optimize if a "struct page" crosses page boundaries. */
-	if (!is_power_of_2(sizeof(struct page))) {
-		pr_warn("cannot free vmemmap pages because \"struct page\" crosses page boundaries\n");
-		return 0;
-	}
-
 	if (!buf)
 		return -EINVAL;
 
diff --git a/mm/struct_page_size.c b/mm/struct_page_size.c
new file mode 100644
index 000000000000..5749609aa1b3
--- /dev/null
+++ b/mm/struct_page_size.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Generate definitions needed by the preprocessor.
+ * This code generates raw asm output which is post-processed
+ * to extract and format the required data.
+ */
+
+#define __GENERATING_STRUCT_PAGE_SIZE_IS_POWER_OF_2_H
+/* Include headers that define the enum constants of interest */
+#include <linux/mm_types.h>
+#include <linux/kbuild.h>
+#include <linux/log2.h>
+
+int main(void)
+{
+	DEFINE(STRUCT_PAGE_SIZE_IS_POWER_OF_2, is_power_of_2(sizeof(struct page)));
+
+	return 0;
+}
diff --git a/scripts/check_struct_page_po2.sh b/scripts/check_struct_page_po2.sh
new file mode 100755
index 000000000000..1764ef9a4f1d
--- /dev/null
+++ b/scripts/check_struct_page_po2.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Check if the size of "struct page" is power of 2
+
+file="include/generated/struct_page_size.h"
+if [ -f "$file" ]; then
+	grep STRUCT_PAGE_SIZE_IS_POWER_OF_2 "$file" | cut -d' ' -f3
+fi
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-03-29 15:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-29 15:37 [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2 Muchun Song
  -- strict thread matches above, loose matches on Subject: below --
2022-03-23 12:55 [PATCH v5 0/4] add hugetlb_free_vmemmap sysctl Muchun Song
2022-03-23 12:55 ` [PATCH v5 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2 Muchun Song
2022-03-23 22:06   ` kernel test robot
2022-03-23 22:13     ` Andrew Morton
2022-03-24  9:40       ` [kbuild-all] " Chen, Rong A
2022-03-24 10:05         ` Muchun Song
2022-03-24 10:20         ` Muchun Song
2022-03-24 10:40           ` Chen, Rong A
2022-03-24 10:47             ` Muchun Song
2022-03-24  1:11   ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).