The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Vineet Gupta <vineet.gupta@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>
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,
	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: Thu, 3 Dec 2026 17:00:17 -0700	[thread overview]
Message-ID: <c9a5f5ba-fa01-4dbb-a60c-f93abc5da909@linux.dev> (raw)
In-Reply-To: <DNAPMU4HJ0JT.2GRZYJ1G9KU29@gmail.com>



On 12/2/26 6:35 PM, Alexei Starovoitov wrote:
> On Wed, Dec 02, 2026 at 12:04 PM Vineet Gupta <vineet.gupta@linux.dev> wrote:
>>> It's really GCC behavior. clang does fine as-is.
>> Because clang ignores the construct GCC warns about.
> For the variable, yes.
> But clang keeps the tag in the type of &var.
> this_cpu_ptr(&var) gives PTR -> TYPE_TAG 'percpu' -> T.
> So this commit will remove 140 such valid tags?
> Doesn't seem fair to clang.
> I'm probably missing something.

TL;DR: those tags are worthless: nothing can reach them.

No variable, struct member or function parameter has that type, so no 
BTF record points at them.
The verifier would not use them anyway. It finds a per-cpu variable 
through the .data..percpu DATASEC, not through a tag, and it reads the 
percpu tag only on attach function arguments and struct members.

They come from typecasts: the accessor macros cast to the type of &var 
in __verify_pcpu_ptr():

     const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL;

clang records the type of each explicit cast in DWARF (GCC does not), 
and pahole turns it into BTF with nothing pointing at it.

A simplified example:

     #define __tag __attribute__((btf_type_tag("percpu")))
     struct S { int a; };
     extern __tag __typeof__(struct S) v;    /* before: tag on the 
declaration */
     extern __typeof__(struct S) w;        /* after: no tag */
     int f(void)
     {
         return (__typeof__((&v) + 0))0 != 0;    /* cast only */
     }
     int g(void)
     {
         return (__typeof__((&w) + 0))0 != 0;
     }

     $ clang -g -O2 -c t.c -o t.o && pahole -J t.o && bpftool btf dump 
file t.o format raw
     [1] TYPE_TAG 'percpu' type_id=3
     [2] PTR '(anon)' type_id=1
     [3] STRUCT 'S' size=4 vlen=1
         'a' type_id=4 bits_offset=0
     [4] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
     [5] PTR '(anon)' type_id=3
     [6] FUNC_PROTO '(anon)' ret_type_id=4 vlen=0
     [7] FUNC 'f' type_id=6 linkage=static
     [8] FUNC 'g' type_id=6 linkage=static

[2] -> [1] is the cast in f(), and nothing refers to [2]. With this 
patch the kernel looks like g(): its cast is the plain [5], which the 
kernel needs anyway.

> if not should we push/pop -Wno-attributes around that one construct?

This might be moot given above. Still it would be hard since there is no 
one place to put it.
The pragmas cannot go inside DECLARE_PER_CPU()/DEFINE_PER_CPU(), because 
the caller writes "static" before them and "= init;" after them, so the 
pop lands in the middle of the declaration, and GCC rejects that:

     error: expected '=', ',', ';', 'asm' or '__attribute__' before 
'#pragma'

So it would have to wrap each per-cpu declaration of a struct or union 
type, about 650 of them, at which point we might as well do 
-Wno-attributes for the whole kernel.

Thx,
-Vineet

  reply	other threads:[~2026-12-04  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 22:08 [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations Vineet Gupta
2026-11-24 18:35 ` Vineet Gupta
2026-12-02 16:35   ` Vineet Gupta
2026-12-02 19:03 ` Andrew Morton
2026-12-02 19:48   ` Alexei Starovoitov
2026-12-02 20:04     ` Vineet Gupta
2026-12-03  1:35       ` Alexei Starovoitov
2026-12-04  0:00         ` Vineet Gupta [this message]
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=c9a5f5ba-fa01-4dbb-a60c-f93abc5da909@linux.dev \
    --to=vineet.gupta@linux.dev \
    --cc=acme@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@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=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