From: Andrew Morton <akpm@linux-foundation.org>
To: Vineet Gupta <vineet.gupta@linux.dev>
Cc: dennis@kernel.org, tj@kernel.org, cl@gentwo.org,
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
Subject: Re: [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations
Date: Wed, 2 Dec 2026 11:03:36 -0800 [thread overview]
Message-ID: <20261202110336.89af512bf2a336c18e11556c@linux-foundation.org> (raw)
In-Reply-To: <20261117220824.609017-1-vineet.gupta@linux.dev>
On Tue, 17 Nov 2026 14:08:24 -0800 Vineet Gupta <vineet.gupta@linux.dev> 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().
>
> ...
>
Sorry, I've been hiding from this patch because I don't understand the
BTF stuff at all :( Would it be more appropriate for a BPF person to
handle this?
The patch does address some real problems so I can queue this for some
-next exposure, would prefer not to be the one to upstream it!
otoh, Chris had a good look at the previous version so that and a few
weeks of -next exposure is enough.
next prev parent reply other threads:[~2026-12-02 19:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 22:08 Vineet Gupta
2026-11-24 18:35 ` Vineet Gupta
2026-12-02 16:35 ` Vineet Gupta
2026-12-02 19:03 ` Andrew Morton [this message]
2026-12-02 19:48 ` Alexei Starovoitov
2026-12-02 20:04 ` Vineet Gupta
2026-12-03 1:35 ` Alexei Starovoitov
2026-12-03 1:29 ` Chris Down
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202110336.89af512bf2a336c18e11556c@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=acme@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chris@chrisdown.name \
--cc=cl@gentwo.org \
--cc=daniel@iogearbox.net \
--cc=dennis@kernel.org \
--cc=eddyz87@gmail.com \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=llvm@lists.linux.dev \
--cc=martin.lau@linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=tj@kernel.org \
--cc=vineet.gupta@linux.dev \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®