From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDFD1C71157 for ; Mon, 16 Jun 2025 02:30:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 732EC6B0093; Sun, 15 Jun 2025 22:30:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70AEB6B0095; Sun, 15 Jun 2025 22:30:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 620E46B0096; Sun, 15 Jun 2025 22:30:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4EEFE6B0093 for ; Sun, 15 Jun 2025 22:30:20 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 111A6142424 for ; Mon, 16 Jun 2025 02:30:20 +0000 (UTC) X-FDA: 83559684600.27.2F986F5 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) by imf11.hostedemail.com (Postfix) with ESMTP id 63AE540005 for ; Mon, 16 Jun 2025 02:30:18 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=G1nsNB40; spf=pass (imf11.hostedemail.com: domain of hao.ge@linux.dev designates 95.215.58.183 as permitted sender) smtp.mailfrom=hao.ge@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750041018; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TwaFPyIkk+e4dx1cWe+AhOCnypnekR9FeQe3heGaETY=; b=IguhJz1UKWfkAFeCyfNLwIBw9p1SdEdql9I8cyjv4ciB7aJ5zVQoEqheWmp/Jhq5uIGhnu pCH/prypEYEWz/sM+AbaibAmrShYnTEMCRiCW+IO/yhFnGUOGX5sdOnchPdtfdyDQDbm7E PPJbUQ3vEzGDJNcCmTHrb8raRr+WcCA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=G1nsNB40; spf=pass (imf11.hostedemail.com: domain of hao.ge@linux.dev designates 95.215.58.183 as permitted sender) smtp.mailfrom=hao.ge@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750041018; a=rsa-sha256; cv=none; b=MTrPnh3ltUxg4Fr0sHr8UWWny7bvh6E/p8eoCf6+67pO5YLrttd/bnat4Jc6p13h/90BYK oBDf0I2E5DGMsrg+JATG20nZe94clTQeNlCGivX+6luZdvTcMSA2nV7RDg7DWCSb4//PGc 5tbR06ydybhaWQ+5QAUOwsDXFs+NE5k= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1750041016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TwaFPyIkk+e4dx1cWe+AhOCnypnekR9FeQe3heGaETY=; b=G1nsNB403+jLLhmsMsa83nMOPV15GspnvXLjv/x1jEbGPHiXpQ5aonlDOWgJ5wOgolDj3X odcqhWwE/bLnF71FVMAxtsVuVQovfQsMd1PcpRs27GGlEETJacLNTFJ+Bv/MVsE/rWsCE+ 9ugUOwqUkn5vVH5RM727QiSIbuyyD44= From: Hao Ge To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Suren Baghdasaryan , Mike Rapoport , Richard Henderson , Matt Turner , Dennis Zhou , Tejun Heo , Christoph Lameter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Kent Overstreet Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-s390@vger.kernel.org, Hao Ge , Hao Ge Subject: [PATCH v3 1/2] mm: Optimize the ARCH_NEEDS_WEAK_PER_CPU logic for s390/alpha architectures Date: Mon, 16 Jun 2025 10:29:17 +0800 Message-Id: <57e110be6d8387e403b4ef1f3b10714c36afbb51.1750040317.git.gehao@kylinos.cn> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 63AE540005 X-Stat-Signature: cajmi4m6spxhpwxx5rbukarwydbshmew X-Rspam-User: X-HE-Tag: 1750041018-15943 X-HE-Meta: U2FsdGVkX1/qIwqQiUVtv7Ka6gmLqj6+aGatZoDiFQrtkTgV+9FYNdVsNkOeb5ezOcuSxmt4dB0W1J6Ygn21PDMiZ8j+XDM09OlYR1lCer9KjfPO0T46LqUfinqSKj5Ncrhbq/ahsxTx5SIb2Jouna4/OJPTnfR1M8wqhDVlJ9iNKDBENfrbLdhE+/aGOEgrfAjzPupMNbXrnwBFIge823KrvoyJ5xedUwXJw8XCXvjjDExnMlwZuXFoyUovs9zZdL8XbE0sxABVoLu+gVeUCU6cTH8iMuZ7+IUT5CjW4yKyR0ZqfryPLpuZRdD3k1HJiY7wna8eIxxFLifrRpijxlU1U4uUyndmwlsWwJALTVcaJ/ekpbnPfNsor6SADnJmt3TpAqAxwrTJBT2n7q3D9+EINgR5b6eo034s4Tyzl+2ErsrAvcG5R5d1+RghzzSHbe6gb4+NI7Bg6+XpxVxU6SEL6SVld5aBhoFR4ewt+SEuh87Rq9j74Up03ZQVyuNwlLlpDqFesAaPbp3fyLoqJRpwlVuCspXmCZd+DzA1YOUDN8f8b3dNg+4JLXxKwOFoW8cPfnvrhZhs8Oy9JKXD4jmlaPOlwUduPqllUHb5OIsDpU0v6a0PcpCw8R9TY9x29H1WuDuB9a9m4YvTc/JsTL58081MXnIZb2TyG13NTxE4KvNIC66FY/iefelPiV19JTimry90uluhoy/kxEbHN6oU11KpK6pj3BGXE9hCUQQO7TaJjbrXekuiWRpr7529ERBMSA83mY2a48YbtykRxzvVQHLNI6JIZcW+Yk91D0/XOCb1FAT1EvbHoLvpvBZFK/lXRD7+ovkq9sKV7/QNxnoMrBfEXgMot+af1J17Ck36TJUTFB2f0TR4vffxzZV9vg8wtAt4szqXjpPLkBWm67tyLUGlYnEFD4E6ffoI+uUQ6oW9INigPxSHFueD//cdkteQParC5NMyMTxI1gD pXDV59Ks FhzVA+7zQx32JYEsHMcIoOBpikML6nxh7f83/U37R1eahwm2Gue8NqBsxjeCv4YPJSmQEoxSwiLnSQss2p1jiRauNI7vF8VHDPKUXc1XpytsbBQQ/HZW51yMAVOoQFEW8hJtECRz8xkjjaNkpT0p/poS5jOGp8JTzsv0SArP9X1WyMOjUcJGyXUQX3Wn8RAM5PLYjQ7P22aWCZTbVnhDgAjGbaXXZ+iN2IFcF+x476SP3WtIUm30Ed19BWw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Hao Ge 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 need to make ARCH_NEEDS_WEAK_PER_CPU a Kconfig option. And replace all instances of ARCH_NEEDS_WEAK_PER_CPU in the kernel code with MODULE_NEEDS_WEAK_PER_CPU,MODULE_NEEDS_WEAK_PER_CPU might be a more accurate description,because it was only needed for modules. Then,when defining the percpu variable _shared_alloc_tag,wrap it with the CONFIG_ARCH_NEEDS_WEAK_PER_CPU condition. Therefore, this patch does the following things: Add the ARCH_NEEDS_WEAK_PER_CPU option to the mm Kconfig file and enable it for the s390 and alpha architectures. And replace all instances of ARCH_NEEDS_WEAK_PER_CPU in the kernel code with MODULE_NEEDS_WEAK_PER_CPU. Suggested-by: Suren Baghdasaryan Signed-off-by: Hao Ge --- arch/alpha/Kconfig | 1 + arch/alpha/include/asm/percpu.h | 2 +- arch/s390/Kconfig | 1 + arch/s390/include/asm/percpu.h | 2 +- include/linux/alloc_tag.h | 6 +++--- include/linux/percpu-defs.h | 4 ++-- mm/Kconfig | 4 ++++ 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig index 109a4cddcd13..ce9bc842e384 100644 --- a/arch/alpha/Kconfig +++ b/arch/alpha/Kconfig @@ -7,6 +7,7 @@ config ALPHA select ARCH_HAS_DMA_OPS if PCI select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO + select ARCH_NEEDS_WEAK_PER_CPU select ARCH_NO_PREEMPT select ARCH_NO_SG_CHAIN select ARCH_USE_CMPXCHG_LOCKREF diff --git a/arch/alpha/include/asm/percpu.h b/arch/alpha/include/asm/percpu.h index 6923249f2d49..b164d3720e9e 100644 --- a/arch/alpha/include/asm/percpu.h +++ b/arch/alpha/include/asm/percpu.h @@ -11,7 +11,7 @@ * Always use weak definitions for percpu variables in modules. */ #if defined(MODULE) && defined(CONFIG_SMP) -#define ARCH_NEEDS_WEAK_PER_CPU +#define MODULE_NEEDS_WEAK_PER_CPU #endif #include diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index 0c16dc443e2f..716031d22346 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -132,6 +132,7 @@ config S390 select ARCH_INLINE_WRITE_UNLOCK_IRQ select ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE + select ARCH_NEEDS_WEAK_PER_CPU select ARCH_STACKWALK select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_DEBUG_PAGEALLOC diff --git a/arch/s390/include/asm/percpu.h b/arch/s390/include/asm/percpu.h index 84f6b8357b45..0afc7ce9c26f 100644 --- a/arch/s390/include/asm/percpu.h +++ b/arch/s390/include/asm/percpu.h @@ -18,7 +18,7 @@ * generate external references. */ #if defined(MODULE) -#define ARCH_NEEDS_WEAK_PER_CPU +#define MODULE_NEEDS_WEAK_PER_CPU #endif /* diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 8f7931eb7d16..f349cca0ebed 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -88,7 +88,7 @@ static inline struct alloc_tag *ct_to_alloc_tag(struct codetag *ct) return container_of(ct, struct alloc_tag, ct); } -#ifdef ARCH_NEEDS_WEAK_PER_CPU +#ifdef MODULE_NEEDS_WEAK_PER_CPU /* * When percpu variables are required to be defined as weak, static percpu * variables can't be used inside a function (see comments for DECLARE_PER_CPU_SECTION). @@ -102,7 +102,7 @@ DECLARE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag); .ct = CODE_TAG_INIT, \ .counters = &_shared_alloc_tag }; -#else /* ARCH_NEEDS_WEAK_PER_CPU */ +#else /* MODULE_NEEDS_WEAK_PER_CPU */ #ifdef MODULE @@ -123,7 +123,7 @@ DECLARE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag); #endif /* MODULE */ -#endif /* ARCH_NEEDS_WEAK_PER_CPU */ +#endif /* MODULE_NEEDS_WEAK_PER_CPU */ DECLARE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT, mem_alloc_profiling_key); diff --git a/include/linux/percpu-defs.h b/include/linux/percpu-defs.h index 0aeb0e276a3e..b4ecfc3a7b2b 100644 --- a/include/linux/percpu-defs.h +++ b/include/linux/percpu-defs.h @@ -64,13 +64,13 @@ * 2. Static percpu variables cannot be defined inside a function. * * Archs which need weak percpu definitions should define - * ARCH_NEEDS_WEAK_PER_CPU in asm/percpu.h when necessary. + * MODULE_NEEDS_WEAK_PER_CPU in asm/percpu.h when necessary. * * To ensure that the generic code observes the above two * restrictions, if CONFIG_DEBUG_FORCE_WEAK_PER_CPU is set weak * definition is used for all cases. */ -#if defined(ARCH_NEEDS_WEAK_PER_CPU) || defined(CONFIG_DEBUG_FORCE_WEAK_PER_CPU) +#if defined(MODULE_NEEDS_WEAK_PER_CPU) || defined(CONFIG_DEBUG_FORCE_WEAK_PER_CPU) /* * __pcpu_scope_* dummy variable is used to enforce scope. It * receives the static modifier when it's used in front of diff --git a/mm/Kconfig b/mm/Kconfig index e113f713b493..2f55cc95cfcb 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -929,6 +929,10 @@ config ARCH_SUPPORTS_PUD_PFNMAP def_bool y depends on ARCH_SUPPORTS_HUGE_PFNMAP && HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD +# s390 and alpha should be enabled,see comments for DECLARE_PER_CPU_SECTION +config ARCH_NEEDS_WEAK_PER_CPU + bool + # # UP and nommu archs use km based percpu allocator # -- 2.25.1