linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [akpm-mm:mm-unstable 313/322] include/linux/huge_mm.h:274:16: error: fields must have a constant size: 'variable length array in structure' extension will never be supported
@ 2024-04-06  9:30 kernel test robot
  2024-04-06 22:40 ` Barry Song
  0 siblings, 1 reply; 4+ messages in thread
From: kernel test robot @ 2024-04-06  9:30 UTC (permalink / raw)
  To: Barry Song
  Cc: llvm, oe-kbuild-all, Andrew Morton, Linux Memory Management List

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-unstable
head:   f43b3aae94511d62174c3b29239da0dd22d0eeb3
commit: d4358ee0a075e232114dfec0cd162860cfa2771b [313/322] mm: add per-order mTHP anon_alloc and anon_alloc_fallback counters
config: powerpc-allyesconfig (https://download.01.org/0day-ci/archive/20240406/202404061754.n8jmZ6s3-lkp@intel.com/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 546dc2245ffc4cccd0b05b58b7a5955e355a3b27)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240406/202404061754.n8jmZ6s3-lkp@intel.com/reproduce)

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

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

   In file included from arch/powerpc/kernel/asm-offsets.c:19:
   In file included from include/linux/mman.h:5:
   In file included from include/linux/mm.h:1115:
>> include/linux/huge_mm.h:274:22: warning: variable length array used [-Wvla]
     274 |         unsigned long stats[PMD_ORDER + 1][__MTHP_STAT_COUNT];
         |                             ^~~~~~~~~~~~~
   include/linux/pgtable.h:8:20: note: expanded from macro 'PMD_ORDER'
       8 | #define PMD_ORDER       (PMD_SHIFT - PAGE_SHIFT)
         |                          ^
   arch/powerpc/include/asm/book3s/64/pgtable.h:207:33: note: expanded from macro 'PMD_SHIFT'
     207 | #define PMD_SHIFT       (PAGE_SHIFT + PTE_INDEX_SIZE)
         |                                       ^
   arch/powerpc/include/asm/book3s/64/pgtable.h:156:25: note: expanded from macro 'PTE_INDEX_SIZE'
     156 | #define PTE_INDEX_SIZE  __pte_index_size
         |                         ^
   In file included from arch/powerpc/kernel/asm-offsets.c:19:
   In file included from include/linux/mman.h:5:
   In file included from include/linux/mm.h:1115:
>> include/linux/huge_mm.h:274:16: error: fields must have a constant size: 'variable length array in structure' extension will never be supported
     274 |         unsigned long stats[PMD_ORDER + 1][__MTHP_STAT_COUNT];
         |                       ^
>> include/linux/huge_mm.h:283:2: error: indirection requires pointer operand ('void' invalid)
     283 |         this_cpu_inc(mthp_stats.stats[order][item]);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:501:28: note: expanded from macro 'this_cpu_inc'
     501 | #define this_cpu_inc(pcp)               this_cpu_add(pcp, 1)
         |                                         ^~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:491:33: note: expanded from macro 'this_cpu_add'
     491 | #define this_cpu_add(pcp, val)          __pcpu_size_call(this_cpu_add_, pcp, val)
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:365:11: note: expanded from macro '__pcpu_size_call'
     365 |                 case 1: stem##1(variable, __VA_ARGS__);break;           \
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/asm-generic/percpu.h:401:34: note: expanded from macro 'this_cpu_add_1'
     401 | #define this_cpu_add_1(pcp, val)        this_cpu_generic_to_op(pcp, val, +=)
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/percpu.h:156:2: note: expanded from macro 'this_cpu_generic_to_op'
     156 |         raw_cpu_generic_to_op(pcp, val, op);                            \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/percpu.h:72:2: note: expanded from macro 'raw_cpu_generic_to_op'
      72 |         *raw_cpu_ptr(&(pcp)) op val;                                    \
         |         ^~~~~~~~~~~~~~~~~~~~
   In file included from arch/powerpc/kernel/asm-offsets.c:19:
   In file included from include/linux/mman.h:5:
   In file included from include/linux/mm.h:1115:
>> include/linux/huge_mm.h:283:2: error: indirection requires pointer operand ('void' invalid)
     283 |         this_cpu_inc(mthp_stats.stats[order][item]);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:501:28: note: expanded from macro 'this_cpu_inc'
     501 | #define this_cpu_inc(pcp)               this_cpu_add(pcp, 1)
         |                                         ^~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:491:33: note: expanded from macro 'this_cpu_add'
     491 | #define this_cpu_add(pcp, val)          __pcpu_size_call(this_cpu_add_, pcp, val)
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:366:11: note: expanded from macro '__pcpu_size_call'
     366 |                 case 2: stem##2(variable, __VA_ARGS__);break;           \
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/asm-generic/percpu.h:404:34: note: expanded from macro 'this_cpu_add_2'
     404 | #define this_cpu_add_2(pcp, val)        this_cpu_generic_to_op(pcp, val, +=)
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/percpu.h:156:2: note: expanded from macro 'this_cpu_generic_to_op'
     156 |         raw_cpu_generic_to_op(pcp, val, op);                            \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/percpu.h:72:2: note: expanded from macro 'raw_cpu_generic_to_op'
      72 |         *raw_cpu_ptr(&(pcp)) op val;                                    \
         |         ^~~~~~~~~~~~~~~~~~~~
   In file included from arch/powerpc/kernel/asm-offsets.c:19:
   In file included from include/linux/mman.h:5:
   In file included from include/linux/mm.h:1115:
>> include/linux/huge_mm.h:283:2: error: indirection requires pointer operand ('void' invalid)
     283 |         this_cpu_inc(mthp_stats.stats[order][item]);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:501:28: note: expanded from macro 'this_cpu_inc'
     501 | #define this_cpu_inc(pcp)               this_cpu_add(pcp, 1)
         |                                         ^~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:491:33: note: expanded from macro 'this_cpu_add'
     491 | #define this_cpu_add(pcp, val)          __pcpu_size_call(this_cpu_add_, pcp, val)
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:367:11: note: expanded from macro '__pcpu_size_call'
     367 |                 case 4: stem##4(variable, __VA_ARGS__);break;           \
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/asm-generic/percpu.h:407:34: note: expanded from macro 'this_cpu_add_4'
     407 | #define this_cpu_add_4(pcp, val)        this_cpu_generic_to_op(pcp, val, +=)
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/percpu.h:156:2: note: expanded from macro 'this_cpu_generic_to_op'
     156 |         raw_cpu_generic_to_op(pcp, val, op);                            \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/percpu.h:72:2: note: expanded from macro 'raw_cpu_generic_to_op'
      72 |         *raw_cpu_ptr(&(pcp)) op val;                                    \
         |         ^~~~~~~~~~~~~~~~~~~~
   In file included from arch/powerpc/kernel/asm-offsets.c:19:
   In file included from include/linux/mman.h:5:
   In file included from include/linux/mm.h:1115:
>> include/linux/huge_mm.h:283:2: error: indirection requires pointer operand ('void' invalid)
     283 |         this_cpu_inc(mthp_stats.stats[order][item]);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:501:28: note: expanded from macro 'this_cpu_inc'
     501 | #define this_cpu_inc(pcp)               this_cpu_add(pcp, 1)
         |                                         ^~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:491:33: note: expanded from macro 'this_cpu_add'
     491 | #define this_cpu_add(pcp, val)          __pcpu_size_call(this_cpu_add_, pcp, val)
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/percpu-defs.h:368:11: note: expanded from macro '__pcpu_size_call'
     368 |                 case 8: stem##8(variable, __VA_ARGS__);break;           \
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/asm-generic/percpu.h:410:34: note: expanded from macro 'this_cpu_add_8'
     410 | #define this_cpu_add_8(pcp, val)        this_cpu_generic_to_op(pcp, val, +=)
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/percpu.h:156:2: note: expanded from macro 'this_cpu_generic_to_op'
     156 |         raw_cpu_generic_to_op(pcp, val, op);                            \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/percpu.h:72:2: note: expanded from macro 'raw_cpu_generic_to_op'
      72 |         *raw_cpu_ptr(&(pcp)) op val;                                    \
         |         ^~~~~~~~~~~~~~~~~~~~
   In file included from arch/powerpc/kernel/asm-offsets.c:19:
   In file included from include/linux/mman.h:5:
   In file included from include/linux/mm.h:2237:
   include/linux/vmstat.h:500:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     500 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     501 |                            item];
         |                            ~~~~
   include/linux/vmstat.h:507:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     507 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     508 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   include/linux/vmstat.h:514:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     514 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   include/linux/vmstat.h:519:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     519 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     520 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   include/linux/vmstat.h:528:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     528 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     529 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   In file included from arch/powerpc/kernel/asm-offsets.c:19:
   include/linux/mman.h:157:9: warning: division by zero is undefined [-Wdivision-by-zero]
     157 |                _calc_vm_trans(flags, MAP_LOCKED,     VM_LOCKED    ) |
         |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/mman.h:136:21: note: expanded from macro '_calc_vm_trans'
     136 |    : ((x) & (bit1)) / ((bit1) / (bit2))))
         |                     ^ ~~~~~~~~~~~~~~~~~
   include/linux/mman.h:158:9: warning: division by zero is undefined [-Wdivision-by-zero]
     158 |                _calc_vm_trans(flags, MAP_SYNC,       VM_SYNC      ) |
         |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/mman.h:136:21: note: expanded from macro '_calc_vm_trans'
     136 |    : ((x) & (bit1)) / ((bit1) / (bit2))))
         |                     ^ ~~~~~~~~~~~~~~~~~
   include/linux/mman.h:159:9: warning: division by zero is undefined [-Wdivision-by-zero]
     159 |                _calc_vm_trans(flags, MAP_STACK,      VM_NOHUGEPAGE) |
         |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/mman.h:136:21: note: expanded from macro '_calc_vm_trans'
     136 |    : ((x) & (bit1)) / ((bit1) / (bit2))))
         |                     ^ ~~~~~~~~~~~~~~~~~
   9 warnings and 5 errors generated.
   make[3]: *** [scripts/Makefile.build:117: arch/powerpc/kernel/asm-offsets.s] Error 1
   make[3]: Target 'prepare' not remade because of errors.
   make[2]: *** [Makefile:1197: prepare0] Error 2
   make[2]: Target 'prepare' not remade because of errors.
   make[1]: *** [Makefile:240: __sub-make] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:240: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.


vim +274 include/linux/huge_mm.h

   272	
   273	struct mthp_stat {
 > 274		unsigned long stats[PMD_ORDER + 1][__MTHP_STAT_COUNT];
   275	};
   276	
   277	DECLARE_PER_CPU(struct mthp_stat, mthp_stats);
   278	
   279	static inline void count_mthp_stat(int order, enum mthp_stat_item item)
   280	{
   281		if (unlikely(order > PMD_ORDER))
   282			return;
 > 283		this_cpu_inc(mthp_stats.stats[order][item]);
   284	}
   285	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


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

* [akpm-mm:mm-unstable 313/322] include/linux/huge_mm.h:274:16: error: fields must have a constant size: 'variable length array in structure' extension will never be supported
  2024-04-06  9:30 [akpm-mm:mm-unstable 313/322] include/linux/huge_mm.h:274:16: error: fields must have a constant size: 'variable length array in structure' extension will never be supported kernel test robot
@ 2024-04-06 22:40 ` Barry Song
  2024-04-07  4:22   ` Barry Song
  0 siblings, 1 reply; 4+ messages in thread
From: Barry Song @ 2024-04-06 22:40 UTC (permalink / raw)
  To: lkp; +Cc: akpm, linux-mm, llvm, oe-kbuild-all, v-songbaohua

> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-unstable
> head:   f43b3aae94511d62174c3b29239da0dd22d0eeb3
> commit: d4358ee0a075e232114dfec0cd162860cfa2771b [313/322] mm: add per-order mTHP anon_alloc and anon_alloc_fallback counters
> config: powerpc-allyesconfig (https://download.01.org/0day-ci/archive/20240406/202404061754.n8jmZ6s3-lkp@intel.com/config)
> compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 546dc2245ffc4cccd0b05b58b7a5955e355a3b27)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240406/202404061754.n8jmZ6s3-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202404061754.n8jmZ6s3-lkp@intel.com/
> 
> All error/warnings (new ones prefixed by >>):
> 
>    In file included from arch/powerpc/kernel/asm-offsets.c:19:
>    In file included from include/linux/mman.h:5:
>    In file included from include/linux/mm.h:1115:
>>> include/linux/huge_mm.h:274:22: warning: variable length array used [-Wvla]
>      274 |         unsigned long stats[PMD_ORDER + 1][__MTHP_STAT_COUNT];
>          |                             ^~~~~~~~~~~~~

This is amazing. powerpc's PMD_ORDER isn't const. I will
move to alloc_percpu instead of using a static array.

Thanks
Barry



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

* Re: [akpm-mm:mm-unstable 313/322] include/linux/huge_mm.h:274:16: error: fields must have a constant size: 'variable length array in structure' extension will never be supported
  2024-04-06 22:40 ` Barry Song
@ 2024-04-07  4:22   ` Barry Song
  2024-04-07  7:39     ` Yujie Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Barry Song @ 2024-04-07  4:22 UTC (permalink / raw)
  To: 21cnbao, lkp; +Cc: akpm, linux-mm, llvm, oe-kbuild-all, v-songbaohua

>> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-unstable
>> head:   f43b3aae94511d62174c3b29239da0dd22d0eeb3
>> commit: d4358ee0a075e232114dfec0cd162860cfa2771b [313/322] mm: add per-order mTHP anon_alloc and anon_alloc_fallback counters
>> config: powerpc-allyesconfig (https://download.01.org/0day-ci/archive/20240406/202404061754.n8jmZ6s3-lkp@intel.com/config)
>> compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 546dc2245ffc4cccd0b05b58b7a5955e355a3b27)
>> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240406/202404061754.n8jmZ6s3-lkp@intel.com/reproduce)
>> 
>> If you fix the issue in a separate patch/commit (i.e. not just a new version of
>> the same patch/commit), kindly add following tags
>> | Reported-by: kernel test robot <lkp@intel.com>
>> | Closes: https://lore.kernel.org/oe-kbuild-all/202404061754.n8jmZ6s3-lkp@intel.com/
>> 
>> All error/warnings (new ones prefixed by >>):
>> 
>>    In file included from arch/powerpc/kernel/asm-offsets.c:19:
>>    In file included from include/linux/mman.h:5:
>>    In file included from include/linux/mm.h:1115:
>>>> include/linux/huge_mm.h:274:22: warning: variable length array used [-Wvla]
>>      274 |         unsigned long stats[PMD_ORDER + 1][__MTHP_STAT_COUNT];
>          |                             ^~~~~~~~~~~~~
> 
> This is amazing. powerpc's PMD_ORDER isn't const. I will
> move to alloc_percpu instead of using a static array.

As replied in another thread, can you please test the below patch?
this is v2 combining the fix and the fix of the fix.

From 6f8604a51ff3333be467e2a681a1f1e8a5d41c48 Mon Sep 17 00:00:00 2001
From: Barry Song <v-songbaohua@oppo.com>
Date: Sun, 7 Apr 2024 12:23:35 +1200
Subject: [PATCH v2] mm: fix powerpc build issue

On powerpc, PMD_ORDER is not a constant variable. We should transition
to using alloc_percpu instead of a static percpu array.

Signed-off-by: Barry Song <v-songbaohua@oppo.com>
---
 include/linux/huge_mm.h |  9 ++++-----
 mm/huge_memory.c        | 12 ++++++++++--
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index c5d33017a4dd..0717063dc5e7 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -271,16 +271,15 @@ enum mthp_stat_item {
 };
 
 struct mthp_stat {
-	unsigned long stats[PMD_ORDER + 1][__MTHP_STAT_COUNT];
+	unsigned long stats[0][__MTHP_STAT_COUNT];
 };
 
-DECLARE_PER_CPU(struct mthp_stat, mthp_stats);
+extern struct mthp_stat __percpu *mthp_stats;
 
 static inline void count_mthp_stat(int order, enum mthp_stat_item item)
 {
-	if (unlikely(order > PMD_ORDER))
-		return;
-	this_cpu_inc(mthp_stats.stats[order][item]);
+	if (likely(order <= PMD_ORDER))
+		raw_cpu_ptr(mthp_stats)->stats[order][item]++;
 }
 
 #define transparent_hugepage_use_zero_page()				\
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 5b875f0fc923..7a72760dc1ce 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -526,7 +526,7 @@ static const struct kobj_type thpsize_ktype = {
 	.sysfs_ops = &kobj_sysfs_ops,
 };
 
-DEFINE_PER_CPU(struct mthp_stat, mthp_stats) = {{{0}}};
+struct mthp_stat __percpu *mthp_stats;
 
 static unsigned long sum_mthp_stat(int order, enum mthp_stat_item item)
 {
@@ -534,7 +534,7 @@ static unsigned long sum_mthp_stat(int order, enum mthp_stat_item item)
 	int cpu;
 
 	for_each_online_cpu(cpu) {
-		struct mthp_stat *this = &per_cpu(mthp_stats, cpu);
+		struct mthp_stat *this = per_cpu_ptr(mthp_stats, cpu);
 
 		sum += this->stats[order][item];
 	}
@@ -636,6 +636,13 @@ static int __init hugepage_init_sysfs(struct kobject **hugepage_kobj)
 		goto remove_hp_group;
 	}
 
+	mthp_stats = __alloc_percpu((PMD_ORDER + 1) * sizeof(mthp_stats->stats[0]),
+			sizeof(unsigned long));
+	if (!mthp_stats) {
+		err = -ENOMEM;
+		goto remove_hp_group;
+	}
+
 	orders = THP_ORDERS_ALL_ANON;
 	order = highest_order(orders);
 	while (orders) {
@@ -673,6 +680,7 @@ static void __init hugepage_exit_sysfs(struct kobject *hugepage_kobj)
 	sysfs_remove_group(hugepage_kobj, &khugepaged_attr_group);
 	sysfs_remove_group(hugepage_kobj, &hugepage_attr_group);
 	kobject_put(hugepage_kobj);
+	free_percpu(mthp_stats);
 }
 #else
 static inline int hugepage_init_sysfs(struct kobject **hugepage_kobj)
-- 
2.34.1




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

* Re: [akpm-mm:mm-unstable 313/322] include/linux/huge_mm.h:274:16: error: fields must have a constant size: 'variable length array in structure' extension will never be supported
  2024-04-07  4:22   ` Barry Song
@ 2024-04-07  7:39     ` Yujie Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Yujie Liu @ 2024-04-07  7:39 UTC (permalink / raw)
  To: Barry Song; +Cc: lkp, akpm, linux-mm, llvm, oe-kbuild-all, v-songbaohua

Hi Barry,

On Sun, Apr 07, 2024 at 04:22:47PM +1200, Barry Song wrote:
> >> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-unstable
> >> head:   f43b3aae94511d62174c3b29239da0dd22d0eeb3
> >> commit: d4358ee0a075e232114dfec0cd162860cfa2771b [313/322] mm: add per-order mTHP anon_alloc and anon_alloc_fallback counters
> >> config: powerpc-allyesconfig (https://download.01.org/0day-ci/archive/20240406/202404061754.n8jmZ6s3-lkp@intel.com/config)
> >> compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 546dc2245ffc4cccd0b05b58b7a5955e355a3b27)
> >> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240406/202404061754.n8jmZ6s3-lkp@intel.com/reproduce)
> >> 
> >> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> >> the same patch/commit), kindly add following tags
> >> | Reported-by: kernel test robot <lkp@intel.com>
> >> | Closes: https://lore.kernel.org/oe-kbuild-all/202404061754.n8jmZ6s3-lkp@intel.com/
> >> 
> >> All error/warnings (new ones prefixed by >>):
> >> 
> >>    In file included from arch/powerpc/kernel/asm-offsets.c:19:
> >>    In file included from include/linux/mman.h:5:
> >>    In file included from include/linux/mm.h:1115:
> >>>> include/linux/huge_mm.h:274:22: warning: variable length array used [-Wvla]
> >>      274 |         unsigned long stats[PMD_ORDER + 1][__MTHP_STAT_COUNT];
> >          |                             ^~~~~~~~~~~~~
> > 
> > This is amazing. powerpc's PMD_ORDER isn't const. I will
> > move to alloc_percpu instead of using a static array.
> 
> As replied in another thread, can you please test the below patch?
> this is v2 combining the fix and the fix of the fix.

This v2 patch fixes the errors/warnings reported in both this thread
and thread [1].

[1] https://lore.kernel.org/all/202404061627.ungVloow-lkp@intel.com/

Tested-by: Yujie Liu <yujie.liu@intel.com>
 
> From 6f8604a51ff3333be467e2a681a1f1e8a5d41c48 Mon Sep 17 00:00:00 2001
> From: Barry Song <v-songbaohua@oppo.com>
> Date: Sun, 7 Apr 2024 12:23:35 +1200
> Subject: [PATCH v2] mm: fix powerpc build issue
> 
> On powerpc, PMD_ORDER is not a constant variable. We should transition
> to using alloc_percpu instead of a static percpu array.
> 
> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
> ---
>  include/linux/huge_mm.h |  9 ++++-----
>  mm/huge_memory.c        | 12 ++++++++++--
>  2 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
> index c5d33017a4dd..0717063dc5e7 100644
> --- a/include/linux/huge_mm.h
> +++ b/include/linux/huge_mm.h
> @@ -271,16 +271,15 @@ enum mthp_stat_item {
>  };
>  
>  struct mthp_stat {
> -	unsigned long stats[PMD_ORDER + 1][__MTHP_STAT_COUNT];
> +	unsigned long stats[0][__MTHP_STAT_COUNT];
>  };
>  
> -DECLARE_PER_CPU(struct mthp_stat, mthp_stats);
> +extern struct mthp_stat __percpu *mthp_stats;
>  
>  static inline void count_mthp_stat(int order, enum mthp_stat_item item)
>  {
> -	if (unlikely(order > PMD_ORDER))
> -		return;
> -	this_cpu_inc(mthp_stats.stats[order][item]);
> +	if (likely(order <= PMD_ORDER))
> +		raw_cpu_ptr(mthp_stats)->stats[order][item]++;
>  }
>  
>  #define transparent_hugepage_use_zero_page()				\
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 5b875f0fc923..7a72760dc1ce 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -526,7 +526,7 @@ static const struct kobj_type thpsize_ktype = {
>  	.sysfs_ops = &kobj_sysfs_ops,
>  };
>  
> -DEFINE_PER_CPU(struct mthp_stat, mthp_stats) = {{{0}}};
> +struct mthp_stat __percpu *mthp_stats;
>  
>  static unsigned long sum_mthp_stat(int order, enum mthp_stat_item item)
>  {
> @@ -534,7 +534,7 @@ static unsigned long sum_mthp_stat(int order, enum mthp_stat_item item)
>  	int cpu;
>  
>  	for_each_online_cpu(cpu) {
> -		struct mthp_stat *this = &per_cpu(mthp_stats, cpu);
> +		struct mthp_stat *this = per_cpu_ptr(mthp_stats, cpu);
>  
>  		sum += this->stats[order][item];
>  	}
> @@ -636,6 +636,13 @@ static int __init hugepage_init_sysfs(struct kobject **hugepage_kobj)
>  		goto remove_hp_group;
>  	}
>  
> +	mthp_stats = __alloc_percpu((PMD_ORDER + 1) * sizeof(mthp_stats->stats[0]),
> +			sizeof(unsigned long));
> +	if (!mthp_stats) {
> +		err = -ENOMEM;
> +		goto remove_hp_group;
> +	}
> +
>  	orders = THP_ORDERS_ALL_ANON;
>  	order = highest_order(orders);
>  	while (orders) {
> @@ -673,6 +680,7 @@ static void __init hugepage_exit_sysfs(struct kobject *hugepage_kobj)
>  	sysfs_remove_group(hugepage_kobj, &khugepaged_attr_group);
>  	sysfs_remove_group(hugepage_kobj, &hugepage_attr_group);
>  	kobject_put(hugepage_kobj);
> +	free_percpu(mthp_stats);
>  }
>  #else
>  static inline int hugepage_init_sysfs(struct kobject **hugepage_kobj)
> -- 
> 2.34.1
> 
> 
> 


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

end of thread, other threads:[~2024-04-07  7:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-06  9:30 [akpm-mm:mm-unstable 313/322] include/linux/huge_mm.h:274:16: error: fields must have a constant size: 'variable length array in structure' extension will never be supported kernel test robot
2024-04-06 22:40 ` Barry Song
2024-04-07  4:22   ` Barry Song
2024-04-07  7:39     ` Yujie Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox