* [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations
@ 2026-11-17 22:08 Vineet Gupta
2026-11-24 18:35 ` Vineet Gupta
2026-12-02 19:03 ` Andrew Morton
0 siblings, 2 replies; 10+ messages in thread
From: Vineet Gupta @ 2026-11-17 22:08 UTC (permalink / raw)
To: dennis, tj, cl
Cc: chris, linux-mm, linux-kernel, bpf, ast, andrii, daniel, acme,
yonghong.song, eddyz87, martin.lau, nathan, ndesaulniers, morbo,
justinstitt, llvm, Vineet Gupta
__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 <vineet.gupta@linux.dev>
Reviewed-by: Chris Down <chris@chrisdown.name>
Tested-by: Chris Down <chris@chrisdown.name>
---
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 \
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations
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
1 sibling, 1 reply; 10+ messages in thread
From: Vineet Gupta @ 2026-11-24 18:35 UTC (permalink / raw)
To: dennis, tj, cl
Cc: chris, linux-mm, linux-kernel, bpf, ast, andrii, daniel, acme,
yonghong.song, eddyz87, martin.lau, nathan, ndesaulniers, morbo,
justinstitt, llvm
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 <vineet.gupta@linux.dev>
> Reviewed-by: Chris Down <chris@chrisdown.name>
> Tested-by: Chris Down <chris@chrisdown.name>
If this patch is OK can someone pick this up please. I'm not sure what
subsys?
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 \
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations
2026-11-24 18:35 ` Vineet Gupta
@ 2026-12-02 16:35 ` Vineet Gupta
0 siblings, 0 replies; 10+ messages in thread
From: Vineet Gupta @ 2026-12-02 16:35 UTC (permalink / raw)
To: dennis, tj, cl
Cc: chris, linux-mm, linux-kernel, bpf, ast, andrii, daniel, acme,
yonghong.song, eddyz87, martin.lau, nathan, ndesaulniers, morbo,
justinstitt, llvm, Andrew Morton
+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 <vineet.gupta@linux.dev>
>> Reviewed-by: Chris Down <chris@chrisdown.name>
>> Tested-by: Chris Down <chris@chrisdown.name>
> 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 \
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations
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 19:03 ` Andrew Morton
2026-12-02 19:48 ` Alexei Starovoitov
2026-12-03 1:29 ` Chris Down
1 sibling, 2 replies; 10+ messages in thread
From: Andrew Morton @ 2026-12-02 19:03 UTC (permalink / raw)
To: Vineet Gupta
Cc: dennis, tj, cl, chris, linux-mm, linux-kernel, bpf, ast, andrii,
daniel, acme, yonghong.song, eddyz87, martin.lau, nathan,
ndesaulniers, morbo, justinstitt, llvm
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.
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations
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:29 ` Chris Down
1 sibling, 1 reply; 10+ messages in thread
From: Alexei Starovoitov @ 2026-12-02 19:48 UTC (permalink / raw)
To: Andrew Morton, Vineet Gupta
Cc: dennis, tj, cl, chris, linux-mm, linux-kernel, bpf, andrii,
daniel, acme, yonghong.song, eddyz87, martin.lau, nathan,
ndesaulniers, morbo, justinstitt, llvm
On Wed, Dec 02, 2026 at 11:03 AM Andrew Morton <akpm@linux-foundation.org> wrote:
> On Tue, 17 Nov 2026 14:08:24 -0800 Vineet Gupta <vineet.gupta@linux.dev> wrote:
>
>> 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.
It's a prep for GCC support.
> 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 BPF side is fine.
It's really GCC behavior. clang does fine as-is.
It's arguable whether it's a gcc bug or correct behavior.
I feel the latter.
> otoh, Chris had a good look at the previous version so that and a few
> weeks of -next exposure is enough.
I think it better fits in Nick's build tree, since it's about GCC
and less about bpf/btf.
But if folks are fine I can take it into bpf-next.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations
2026-12-02 19:48 ` Alexei Starovoitov
@ 2026-12-02 20:04 ` Vineet Gupta
2026-12-03 1:35 ` Alexei Starovoitov
0 siblings, 1 reply; 10+ messages in thread
From: Vineet Gupta @ 2026-12-02 20:04 UTC (permalink / raw)
To: Alexei Starovoitov, Andrew Morton
Cc: dennis, tj, cl, chris, linux-mm, linux-kernel, bpf, andrii,
daniel, acme, yonghong.song, eddyz87, martin.lau, nathan,
ndesaulniers, morbo, justinstitt, llvm
Hi,
Some comments below, mostly for Alexei; Andrew you can ignore ;-)
On 12/2/26 11:48 AM, Alexei Starovoitov wrote:
> On Wed, Dec 02, 2026 at 11:03 AM Andrew Morton <akpm@linux-foundation.org> wrote:
>> On Tue, 17 Nov 2026 14:08:24 -0800 Vineet Gupta <vineet.gupta@linux.dev> wrote:
>>
>>> 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.
> It's a prep for GCC support.
>
>> 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 BPF side is fine.
> It's really GCC behavior. clang does fine as-is.
Because clang ignores the construct GCC warns about.
> It's arguable whether it's a gcc bug or correct behavior.
> I feel the latter.
A GCC bug was opened PR/128480 [1] to silent the warning but was
rejected won't fix, for the right reasons.
The issue is btf_type_tag being applied to a variant of an aggregate.
struct mce { int status; };
extern __attribute__((btf_type_tag("percpu")))
__typeof__(struct mce) injectm;
$ gcc -c t.c
t.c:3:15: warning: ignoring attributes applied to 'struct mce'
after definition [-Wattributes]
That warning is legit: In dwarf, every variant of an aggregate shares
one DIE, so a btf_type_tag on such a variant has nowhere to live and is
dropped. clang just does it silently, gcc complains.
Thx,
-Vineet
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128480
>> otoh, Chris had a good look at the previous version so that and a few
>> weeks of -next exposure is enough.
> I think it better fits in Nick's build tree, since it's about GCC
> and less about bpf/btf.
> But if folks are fine I can take it into bpf-next.
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations
2026-12-02 20:04 ` Vineet Gupta
@ 2026-12-03 1:35 ` Alexei Starovoitov
2026-12-04 0:00 ` Vineet Gupta
0 siblings, 1 reply; 10+ messages in thread
From: Alexei Starovoitov @ 2026-12-03 1:35 UTC (permalink / raw)
To: Vineet Gupta, Andrew Morton
Cc: dennis, tj, cl, chris, linux-mm, linux-kernel, bpf, andrii,
daniel, acme, yonghong.song, eddyz87, martin.lau, nathan,
ndesaulniers, morbo, justinstitt, llvm
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.
if not should we push/pop -Wno-attributes around that one construct?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations
2026-12-03 1:35 ` Alexei Starovoitov
@ 2026-12-04 0:00 ` Vineet Gupta
2026-12-04 21:07 ` Alexei Starovoitov
0 siblings, 1 reply; 10+ messages in thread
From: Vineet Gupta @ 2026-12-04 0:00 UTC (permalink / raw)
To: Alexei Starovoitov, Andrew Morton
Cc: dennis, tj, cl, chris, linux-mm, linux-kernel, bpf, andrii,
daniel, acme, yonghong.song, eddyz87, martin.lau, nathan,
ndesaulniers, morbo, justinstitt, llvm
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
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations
2026-12-04 0:00 ` Vineet Gupta
@ 2026-12-04 21:07 ` Alexei Starovoitov
0 siblings, 0 replies; 10+ messages in thread
From: Alexei Starovoitov @ 2026-12-04 21:07 UTC (permalink / raw)
To: Vineet Gupta, Andrew Morton
Cc: dennis, tj, cl, chris, linux-mm, linux-kernel, bpf, andrii,
daniel, acme, yonghong.song, eddyz87, martin.lau, nathan,
ndesaulniers, morbo, justinstitt, llvm
On Thu, Dec 03, 2026 at 04:00 PM Vineet Gupta <vineet.gupta@linux.dev> wrote:
> 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;
I see.
Pls explain that bit in commit log.
> 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.
fair. No pragmas then.
Pls respin as [PATCH bpf-next v3] and cc build folks.
pw-bot: cr
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] percpu: do not put btf_type_tag on per-cpu variable declarations
2026-12-02 19:03 ` Andrew Morton
2026-12-02 19:48 ` Alexei Starovoitov
@ 2026-12-03 1:29 ` Chris Down
1 sibling, 0 replies; 10+ messages in thread
From: Chris Down @ 2026-12-03 1:29 UTC (permalink / raw)
To: Andrew Morton
Cc: Vineet Gupta, dennis, tj, cl, linux-mm, linux-kernel, bpf, ast,
andrii, daniel, acme, yonghong.song, eddyz87, martin.lau, nathan,
ndesaulniers, morbo, justinstitt, llvm
Hi Andrew,
Andrew Morton writes:
>otoh, Chris had a good look at the previous version so that and a few
>weeks of -next exposure is enough.
Just to confirm for everyone on the thread, as far as I can tell v2 is
identical to v1's first patch, so my trailers are still valid. But if I
missed something please feel free to let me know.
Thanks!
Chris
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-12-04 21:07 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-12-04 21:07 ` Alexei Starovoitov
2026-12-03 1:29 ` Chris Down
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox