From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F9DE606A329 for ; Wed, 2 Dec 2026 16:35:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=tKYz6EYl Received: by kanga.kvack.org (Postfix) id F3EDB6B05E9; Wed, 2 Dec 2026 11:35:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F165D6B05F3; Wed, 2 Dec 2026 11:35:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E52F66B05F5; Wed, 2 Dec 2026 11:35:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B4D536B05E9 for ; Wed, 2 Dec 2026 11:35:47 -0500 (EST) Received: from smtpin21.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2DD391203AC for ; Wed, 2 Dec 2026 16:35:47 +0000 (UTC) X-FDA: 85499594334.21.4D7A22E Received: from mta0.migadu.com (out-166.mta0.migadu.com [91.218.175.166]) by imf22.hostedemail.com (Postfix) with ESMTP id D36ABC000B for ; Wed, 2 Dec 2026 16:35:44 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tKYz6EYl; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of vineet.gupta@linux.dev designates 91.218.175.166 as permitted sender) smtp.mailfrom=vineet.gupta@linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796229345; b=gFi38mKPtHC10a029HJJKWVu1Pxjx2qmLi81DCB0Nr29+Jejj4yyIidGFOG+Exag7yGeHP ygQMPJ+6WDbIEhP63PPuQ/4y0ix9vHxrJLeXDmh46z36eYTP6YFyHUf6U8EPWBFDmAqsus Vd9521cUgsAid61G38hxT7dSPMeQeSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796229345; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jUMTct8rYxsWeolLHqERjpNwpmM/qvkXhnWuFRtyxV0=; b=2sjcwGDDZafXEuDne0gWUQ95NZJmR4bFwL9IftXwhS/ltAaDcAnaw1FOFH2X1QbFd/hx5v X5SFb3OZVquouj2cc/CSDZ3gdGNzrbnXphL3TWhYJjY//1j/pj5NZyb3OGCtWVbYe+iG+U 57a1Jec5wFcL8tBIo1cd1PkoQh4OxEo= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tKYz6EYl; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of vineet.gupta@linux.dev designates 91.218.175.166 as permitted sender) smtp.mailfrom=vineet.gupta@linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=szGse/sNpqb8672sM/4dI+4W7/Ei0CMBgwyB43m90g4=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796229343; v=1; x=1796834143; b=tKYz6EYll1ZC8ZG9Nyru6xMRwHL8vGLU6nQ+s+gHJ4Xel3z8/OBeDsbBehvLWQDks4rN9/u/ EMw46VHfh8F8GxmykMy59kNJexiJuqtPuKg2nYfcdOqLmDLIWcg5WB5JbyOvcivSrAlZN9S3lLb 4LXhXP0RChgAmpcMq00eri2k= X-Envelope-To: linux-mm@kvack.org Received: by smtp.migadu.com with ESMTPS id f7e198698e8716f9; Wed, 02 Dec 2026 16:35:41 +0000 X-Mizu-Trace-ID: f7e198698e8716f9 X-Migadu-Flow: FLOW_OUT Message-ID: <68496180-7b1e-482a-bcbb-3e926e6d2152@linux.dev> Date: Wed, 2 Dec 2026 09:35:35 -0700 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations From: Vineet Gupta To: dennis@kernel.org, tj@kernel.org, cl@gentwo.org Cc: chris@chrisdown.name, linux-mm@kvack.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, acme@kernel.org, yonghong.song@linux.dev, eddyz87@gmail.com, martin.lau@linux.dev, nathan@kernel.org, ndesaulniers@google.com, morbo@google.com, justinstitt@google.com, llvm@lists.linux.dev, Andrew Morton References: <20261117220824.609017-1-vineet.gupta@linux.dev> <59a0bc6a-61d2-462c-92c5-445d29298d85@linux.dev> Content-Language: en-US In-Reply-To: <59a0bc6a-61d2-462c-92c5-445d29298d85@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D36ABC000B X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Stat-Signature: bo4ftg3yx6om36w5h7iaf4x9gb7dm434 X-HE-Tag: 1796229344-793139 X-HE-Meta: U2FsdGVkX19gkAAl0npfxrVmZv5HAjof2yBMQWC57WvGT8X0CJoScSWb1xJJCVoaGWrfB7ZkNk6XZQBvMZ/1NhXrBPnHJiZtSenNeJl0Z7h+drvTB74CVI8qqgSlzRG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77ivvripvErq+T/nUChmByKCzQZgz6OkC9+SjWwD43sZFZQvA+AW2TNtFEs9mEl0pnQEXoOqveCXnNZIJtc+gsY052MV+130NwNs/1GOMhOxAa1FffoR+xovoLsGccalQSzmH91KcF4DAKlZnH2Mfylg1IlKmIFk2e83up9/wS6S2keAssBwvixiG1E1mCTTfaV8Gwx4JoWEjK1bPntDB98mffiX+RHyOwCFFSKcXh+7HOLHFT3k1QR8FQFm30L0ajawE2XgOzUFJO+Fg4hyMoGTYtCS9FA3euvS/90wfNWlIsrG5aOp0ZscGH7RlFwqA5FLai9tLhY+nqWt8G5clFMKIUIUctQoamipWxusSNKHr/oYj0cUNNntJcIQ4xzcyRuIOXYSu95pupfujuMHwS976/LVo/HHPBgXXSwZ1RFw== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 +CC Andrew On 11/24/26 10:35 AM, Vineet Gupta wrote: > On 11/17/26 2:08 PM, Vineet Gupta wrote: >> __percpu carries BTF_TYPE_TAG(percpu), which records that a pointer >> points to per-cpu memory. __PCPU_ATTRS() applies __percpu to the per-cpu >> variable itself, so DECLARE_PER_CPU() and DEFINE_PER_CPU() put the tag in >> declaration specifier position on the variable's own type. >> >> arch/x86/include/asm/processor.h has >> >> DECLARE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info); >> >> which an x86 defconfig preprocesses to >> >> extern __seg_gs __attribute__((btf_type_tag("percpu"))) >> __attribute__((section(".data..percpu" "..read_mostly"))) >> __typeof__(struct cpuinfo_x86) cpu_info; >> >> and GCC warns: >> >> processor.h:232:36: warning: ignoring attributes applied to >> 'struct cpuinfo_x86' after definition [-Wattributes] >> >> which -Werror turns into a build failure. >> >> The compiler is right to object to a type tag on the aggregate, and the >> issue is fundamental: every variant of an aggregate shares one DIE, so >> there is nowhere to put it. clang drops it silently and GCC warns. >> >> The tag is meant to record that a pointer points to per-cpu memory, and >> cpu_info is not a pointer. >> >> And this gets worse: for a pointer-typed per-cpu variable GCC attaches >> the tag to the pointee, so >> >> static DEFINE_PER_CPU(struct bpf_hrtimer *, hrtimer_running); >> >> comes out as PTR -> TYPE_TAG 'percpu' -> struct bpf_hrtimer. The truth >> is the other way round: hrtimer_running lives in per-cpu memory and >> points at ordinary memory, while that record says it is an ordinary >> pointer to per-cpu memory. clang emits no tag there at all. >> >> Add __percpu_var, which skips the btf tag (__percpu under sparse) and >> use it in __PCPU_ATTRS(). The cpu_info declaration above becomes >> >> extern __seg_gs >> __attribute__((section(".data..percpu" "..read_mostly"))) >> __typeof__(struct cpuinfo_x86) cpu_info; >> >> The pointer spelling, T __percpu *p, is unchanged and keeps its tag. >> >> Before this patch the tag also qualified the variable's type, so &var >> had type "T __percpu *", and a pointer does have a DIE of its own: >> pahole emitted PTR -> TYPE_TAG 'percpu' -> T for each one. >> this_cpu_ptr(&var) is that shape, and that is where the records came >> from. >> >> Those are the records an x86 defconfig built with clang loses: 280 BTF >> types, 140 TYPE_TAG and the 140 pointers carrying them, with .BTF >> shrinking by 3360 bytes. They are the derived pointers -- clang never >> recorded the declarations themselves. None of them were reachable: a >> record points at a type only if something is declared with it, and >> nothing is declared with these. The 803 places that do declare a >> "T __percpu *" keep theirs -- the 110 tagged pointers that something >> references are the same before and after. .text is byte-identical. >> >> Signed-off-by: Vineet Gupta >> Reviewed-by: Chris Down >> Tested-by: Chris Down > If this patch is OK can someone pick this up please. I'm not sure what > subsys? Hi Andrew, Looking it the git log of the percpu header, can this be routed via mm tree. Thx, -Vineet >> --- >> Changes in v2: >> - Dropped the "message is confusing" sentence: GCC's "after definition" >> refers to the definition of struct cpuinfo_x86, not to the declaration >> of cpu_info, so the message is accurate (Chris Down). >> - Dropped 2/2, "local_lock: do not put btf_type_tag on the lock guard >> type". Only the tag on the typedef generates a warning, and that >> needs a GCC fix [1] anyway. The pointer usage "T __percpu *" is fine >> (Chris Down). >> - Rebased onto v7.4-rc2. >> >> RFC: https://lore.kernel.org/r/20261110012235.1024461-1-vineet.gupta@linux.dev/ >> >> [1] https://inbox.sourceware.org/gcc-patches/20261112191815.884167-1-vineet.gupta@linux.dev/ >> >> include/linux/compiler_types.h | 8 ++++++++ >> include/linux/percpu-defs.h | 2 +- >> 2 files changed, 9 insertions(+), 1 deletion(-) >> >> diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h >> index c5921f139007..b250d6870324 100644 >> --- a/include/linux/compiler_types.h >> +++ b/include/linux/compiler_types.h >> @@ -50,6 +50,7 @@ >> # define __user __attribute__((noderef, address_space(__user))) >> # define __iomem __attribute__((noderef, address_space(__iomem))) >> # define __percpu __attribute__((noderef, address_space(__percpu))) >> +# define __percpu_var __percpu >> # define __rcu __attribute__((noderef, address_space(__rcu))) >> static inline void __chk_user_ptr(const volatile void __user *ptr) { } >> static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } >> @@ -68,7 +69,14 @@ static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } >> # define __user BTF_TYPE_TAG(user) >> # endif >> # define __iomem >> +/* >> + * btf_type_tag records "points to per-cpu memory", so it belongs on the >> + * pointer spelling only. Declaring the per-cpu variable itself puts the tag >> + * in declaration specifier position, where clang drops it and GCC attaches it >> + * to the wrong type, so __percpu_var leaves it out. >> + */ >> # define __percpu __percpu_qual BTF_TYPE_TAG(percpu) >> +# define __percpu_var __percpu_qual >> # define __rcu BTF_TYPE_TAG(rcu) >> >> # define __chk_user_ptr(x) (void)0 >> diff --git a/include/linux/percpu-defs.h b/include/linux/percpu-defs.h >> index dbe3267a0a13..f53fc430aaad 100644 >> --- a/include/linux/percpu-defs.h >> +++ b/include/linux/percpu-defs.h >> @@ -45,7 +45,7 @@ >> * that section. >> */ >> #define __PCPU_ATTRS(sec) \ >> - __percpu __attribute__((section(PER_CPU_BASE_SECTION sec))) \ >> + __percpu_var __attribute__((section(PER_CPU_BASE_SECTION sec))) \ >> PER_CPU_ATTRIBUTES >> >> #define __PCPU_DUMMY_ATTRS \