[PATCH v4 0/1] mm: Restrict _shared_alloc_tag static definition to CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU
From: Hao Ge
Date: Tue Jun 17 2025 - 01:35:08 EST
From: Hao Ge <gehao@xxxxxxxxxx>
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.
However, currently ARCH_NEEDS_WEAK_PER_CPU is a #define and
is enclosed within the #if defined(MODULE) conditional block.
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.
The following version can be regarded as the most original version:
https://lore.kernel.org/all/20250529073537.563107-1-hao.ge@xxxxxxxxx/
But unfortunately, it caused build errors on s390.
Based on Suren's guidance and suggestions,
I've refined it into this patch series.
Many thanks to Suren for his patient instruction.
Verify:
1. On Arm64:
nm vmlinux | grep "_shared_alloc_tag",no output is returned.
2. On S390:
Compile tested.
nm vmlinux | grep "_shared_alloc_tag"
00000000015605b4 r __crc__shared_alloc_tag
0000000001585fef r __kstrtab__shared_alloc_tag
0000000001586897 r __kstrtabns__shared_alloc_tag
00000000014f6548 r __ksymtab__shared_alloc_tag
0000000001a8fa28 D _shared_alloc_tag
nm net/ceph/libceph.ko | grep "_shared"
U _shared_alloc_tag
3. On alpha
Compile tested.
nm vmlinux | grep "_shared_alloc_tag"
fffffc0000b080fa r __kstrtab__shared_alloc_tag
fffffc0000b07ee7 r __kstrtabns__shared_alloc_tag
fffffc0000adee98 r __ksymtab__shared_alloc_tag
fffffc0000b83d38 D _shared_alloc_tag
nm crypto/cryptomgr.ko | grep "_share"
U _shared_alloc_tag
v4:
Merge previous patches into a single patch.
Remove all instances of ARCH_MODULE_NEEDS_WEAK_PER_CPU from v3
and use CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU to
replace the relevant logic.
Replace CONFIG_ARCH_NEEDS_WEAK_PER_CPU with CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU
in v3, as weak percpu support is only required for modules ,making the name more
semantically accurate.
David, Mike, Matthew, Kent, Heiko and Suren have all provided valuable input.
Thanks for this.
v3:
Suren pointed out that patches 1-2 can be merged into a single patch
in version 2. And the commit message for patch 3 can be made more
concise.Make corresponding modifications based on the pointed-out
issues and update the corresponding commit message.
v2:
Heiko pointed out that when defining MODULE_NEEDS_WEAK_PER_CPU,
the CONFIG_ARCH_NEEDS_WEAK_PER_CPU condition in the v1 version
should be removed,as it is always true for s390 and alpha
architectures.And He also pointed out that patches 2-4 need to
be merged into one patch. Modify the code according to the suggestions
and update the corresponding commit message
Hao Ge (1):
mm/percpu: Conditionally define _shared_alloc_tag via
CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU
arch/alpha/Kconfig | 1 +
arch/alpha/include/asm/percpu.h | 5 ++---
arch/s390/Kconfig | 1 +
arch/s390/include/asm/percpu.h | 5 ++---
include/linux/alloc_tag.h | 6 +++---
include/linux/percpu-defs.h | 7 ++++---
lib/alloc_tag.c | 2 ++
mm/Kconfig | 7 +++++++
8 files changed, 22 insertions(+), 12 deletions(-)
--
2.25.1