Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/percpu: conditionally define _shared_alloc_tag via CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU

Recently discovered this entry while checking kallsyms on ARM64:
ffff800083e509c0 D _shared_alloc_tag

If ARCH_NEEDS_WEAK_PER_CPU is not defined(it is only defined for s390 and
alpha architectures), there's no need to statically define the percpu
variable _shared_alloc_tag.

Therefore, we need to implement isolation for this purpose.

When building the core kernel code for s390 or alpha architectures,
ARCH_NEEDS_WEAK_PER_CPU remains undefined (as it is gated by #if
defined(MODULE)). However, when building modules for these architectures,
the macro is explicitly defined.

Therefore, we remove all instances of ARCH_NEEDS_WEAK_PER_CPU from the
code and introduced CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU to replace the
relevant logic. We can now conditionally define the perpcu variable
_shared_alloc_tag based on CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU. This
allows architectures (such as s390/alpha) that require weak definitions
for percpu variables in modules to include the definition, while others
can omit it via compile-time exclusion.

Link: https://lkml.kernel.org/r/20250618015809.1235761-1-hao.ge@linux.dev
Signed-off-by: Hao Ge <gehao@kylinos.cn>
Suggested-by: Suren Baghdasaryan <surenb@google.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com> [s390]
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Chistoph Lameter <cl@linux.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Hao Ge and committed by
Andrew Morton
59b5ed40 cf34cfbf

+22 -12
+1
arch/alpha/Kconfig
··· 7 7 select ARCH_HAS_DMA_OPS if PCI 8 8 select ARCH_MIGHT_HAVE_PC_PARPORT 9 9 select ARCH_MIGHT_HAVE_PC_SERIO 10 + select ARCH_MODULE_NEEDS_WEAK_PER_CPU if SMP 10 11 select ARCH_NO_PREEMPT 11 12 select ARCH_NO_SG_CHAIN 12 13 select ARCH_USE_CMPXCHG_LOCKREF
+2 -3
arch/alpha/include/asm/percpu.h
··· 9 9 * way above 4G. 10 10 * 11 11 * Always use weak definitions for percpu variables in modules. 12 + * Therefore, we have enabled CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU 13 + * in the Kconfig. 12 14 */ 13 - #if defined(MODULE) && defined(CONFIG_SMP) 14 - #define ARCH_NEEDS_WEAK_PER_CPU 15 - #endif 16 15 17 16 #include <asm-generic/percpu.h> 18 17
+1
arch/s390/Kconfig
··· 132 132 select ARCH_INLINE_WRITE_UNLOCK_IRQ 133 133 select ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE 134 134 select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE 135 + select ARCH_MODULE_NEEDS_WEAK_PER_CPU 135 136 select ARCH_STACKWALK 136 137 select ARCH_SUPPORTS_ATOMIC_RMW 137 138 select ARCH_SUPPORTS_DEBUG_PAGEALLOC
+2 -3
arch/s390/include/asm/percpu.h
··· 16 16 * For 64 bit module code, the module may be more than 4G above the 17 17 * per cpu area, use weak definitions to force the compiler to 18 18 * generate external references. 19 + * Therefore, we have enabled CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU 20 + * in the Kconfig. 19 21 */ 20 - #if defined(MODULE) 21 - #define ARCH_NEEDS_WEAK_PER_CPU 22 - #endif 23 22 24 23 /* 25 24 * We use a compare-and-swap loop since that uses less cpu cycles than
+3 -3
include/linux/alloc_tag.h
··· 88 88 return container_of(ct, struct alloc_tag, ct); 89 89 } 90 90 91 - #ifdef ARCH_NEEDS_WEAK_PER_CPU 91 + #if defined(CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU) && defined(MODULE) 92 92 /* 93 93 * When percpu variables are required to be defined as weak, static percpu 94 94 * variables can't be used inside a function (see comments for DECLARE_PER_CPU_SECTION). ··· 102 102 .ct = CODE_TAG_INIT, \ 103 103 .counters = &_shared_alloc_tag }; 104 104 105 - #else /* ARCH_NEEDS_WEAK_PER_CPU */ 105 + #else /* CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU && MODULE */ 106 106 107 107 #ifdef MODULE 108 108 ··· 123 123 124 124 #endif /* MODULE */ 125 125 126 - #endif /* ARCH_NEEDS_WEAK_PER_CPU */ 126 + #endif /* CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU && MODULE */ 127 127 128 128 DECLARE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT, 129 129 mem_alloc_profiling_key);
+4 -3
include/linux/percpu-defs.h
··· 63 63 * 1. The symbol must be globally unique, even the static ones. 64 64 * 2. Static percpu variables cannot be defined inside a function. 65 65 * 66 - * Archs which need weak percpu definitions should define 67 - * ARCH_NEEDS_WEAK_PER_CPU in asm/percpu.h when necessary. 66 + * Archs which need weak percpu definitions should set 67 + * CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU when necessary. 68 68 * 69 69 * To ensure that the generic code observes the above two 70 70 * restrictions, if CONFIG_DEBUG_FORCE_WEAK_PER_CPU is set weak 71 71 * definition is used for all cases. 72 72 */ 73 - #if defined(ARCH_NEEDS_WEAK_PER_CPU) || defined(CONFIG_DEBUG_FORCE_WEAK_PER_CPU) 73 + #if (defined(CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU) && defined(MODULE)) || \ 74 + defined(CONFIG_DEBUG_FORCE_WEAK_PER_CPU) 74 75 /* 75 76 * __pcpu_scope_* dummy variable is used to enforce scope. It 76 77 * receives the static modifier when it's used in front of
+2
lib/alloc_tag.c
··· 25 25 26 26 static struct codetag_type *alloc_tag_cttype; 27 27 28 + #ifdef CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU 28 29 DEFINE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag); 29 30 EXPORT_SYMBOL(_shared_alloc_tag); 31 + #endif 30 32 31 33 DEFINE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT, 32 34 mem_alloc_profiling_key);
+7
mm/Kconfig
··· 934 934 depends on ARCH_SUPPORTS_HUGE_PFNMAP && HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD 935 935 936 936 # 937 + # Architectures that always use weak definitions for percpu 938 + # variables in modules should set this. 939 + # 940 + config ARCH_MODULE_NEEDS_WEAK_PER_CPU 941 + bool 942 + 943 + # 937 944 # UP and nommu archs use km based percpu allocator 938 945 # 939 946 config NEED_PER_CPU_KM