linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] bpf: Disable -Wsuggest-attribute=format
@ 2025-12-10 13:12 Andy Shevchenko
  2025-12-15 17:36 ` Andrii Nakryiko
  2025-12-16  0:11 ` Ihor Solodrai
  0 siblings, 2 replies; 8+ messages in thread
From: Andy Shevchenko @ 2025-12-10 13:12 UTC (permalink / raw)
  To: Alexei Starovoitov, Steven Rostedt, bpf, linux-kernel,
	linux-trace-kernel
  Cc: Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
	Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Masami Hiramatsu, Mathieu Desnoyers, Andy Shevchenko,
	kernel test robot

The printing functions in BPF code are using printf() type of format,
and compiler is not happy about them as is:

kernel/bpf/helpers.c:1069:9: error: function ‘____bpf_snprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
 1069 |         err = bstr_printf(str, str_size, fmt, data.bin_args);
      |         ^~~

kernel/bpf/stream.c:241:9: error: function ‘bpf_stream_vprintk_impl’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
  241 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt__str, data.bin_args);
      |         ^~~

kernel/trace/bpf_trace.c:377:9: error: function ‘____bpf_trace_printk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
  377 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
      |         ^~~

kernel/trace/bpf_trace.c:433:9: error: function ‘____bpf_trace_vprintk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
  433 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
      |         ^~~

kernel/trace/bpf_trace.c:475:9: error: function ‘____bpf_seq_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
  475 |         seq_bprintf(m, fmt, data.bin_args);
      |         ^~~~~~~~~~~

Fix the compilation errors by disabling that warning since the code is
generated and warning is not so useful in this case — it can't check
the parameters for now.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202512061425.x0qTt9ww-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202512061640.9hKTnB8p-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202512081321.2h9ThWTg-lkp@intel.com/
Fixes: 5ab154f1463a ("bpf: Introduce BPF standard streams")
Fixes: 10aceb629e19 ("bpf: Add bpf_trace_vprintk helper")
Fixes: 7b15523a989b ("bpf: Add a bpf_snprintf helper")
Fixes: 492e639f0c22 ("bpf: Add bpf_seq_printf and bpf_seq_write helpers")
Fixes: f3694e001238 ("bpf: add BPF_CALL_x macros for declaring helpers")
Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 kernel/bpf/Makefile   | 11 +++++++++--
 kernel/trace/Makefile |  6 ++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile
index 232cbc97434d..cf7e8a972f98 100644
--- a/kernel/bpf/Makefile
+++ b/kernel/bpf/Makefile
@@ -6,7 +6,14 @@ cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse
 endif
 CFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy)
 
-obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o log.o token.o liveness.o
+obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o tnum.o log.o token.o liveness.o
+
+obj-$(CONFIG_BPF_SYSCALL) += helpers.o stream.o
+# The ____bpf_snprintf() uses the format string that triggers a compiler warning.
+CFLAGS_helpers.o += -Wno-suggest-attribute=format
+# The bpf_stream_vprintk_impl() uses the format string that triggers a compiler warning.
+CFLAGS_stream.o += -Wno-suggest-attribute=format
+
 obj-$(CONFIG_BPF_SYSCALL) += bpf_iter.o map_iter.o task_iter.o prog_iter.o link_iter.o
 obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o bloom_filter.o
 obj-$(CONFIG_BPF_SYSCALL) += local_storage.o queue_stack_maps.o ringbuf.o bpf_insn_array.o
@@ -14,7 +21,7 @@ obj-$(CONFIG_BPF_SYSCALL) += bpf_local_storage.o bpf_task_storage.o
 obj-${CONFIG_BPF_LSM}	  += bpf_inode_storage.o
 obj-$(CONFIG_BPF_SYSCALL) += disasm.o mprog.o
 obj-$(CONFIG_BPF_JIT) += trampoline.o
-obj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o stream.o
+obj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o
 ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)
 obj-$(CONFIG_BPF_SYSCALL) += arena.o range_tree.o
 endif
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index fc5dcc888e13..1673b395c14c 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -104,7 +104,13 @@ obj-$(CONFIG_TRACE_EVENT_INJECT) += trace_events_inject.o
 obj-$(CONFIG_SYNTH_EVENTS) += trace_events_synth.o
 obj-$(CONFIG_HIST_TRIGGERS) += trace_events_hist.o
 obj-$(CONFIG_USER_EVENTS) += trace_events_user.o
+
 obj-$(CONFIG_BPF_EVENTS) += bpf_trace.o
+# The BPF printing functions use the format string that triggers a compiler warning.
+# Since the code is generated and warning is not so useful in this case (it can't
+# check the parameters for now) disable the warning.
+CFLAGS_bpf_trace.o += -Wno-suggest-attribute=format
+
 obj-$(CONFIG_KPROBE_EVENTS) += trace_kprobe.o
 obj-$(CONFIG_TRACEPOINTS) += error_report-traces.o
 obj-$(CONFIG_TRACEPOINTS) += power-traces.o
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] bpf: Disable -Wsuggest-attribute=format
  2025-12-10 13:12 [PATCH v1 1/1] bpf: Disable -Wsuggest-attribute=format Andy Shevchenko
@ 2025-12-15 17:36 ` Andrii Nakryiko
  2025-12-15 18:13   ` Alexei Starovoitov
  2025-12-16  0:11 ` Ihor Solodrai
  1 sibling, 1 reply; 8+ messages in thread
From: Andrii Nakryiko @ 2025-12-15 17:36 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Alexei Starovoitov, Steven Rostedt, bpf, linux-kernel,
	linux-trace-kernel, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Masami Hiramatsu, Mathieu Desnoyers, kernel test robot

On Wed, Dec 10, 2025 at 5:12 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> The printing functions in BPF code are using printf() type of format,
> and compiler is not happy about them as is:
>
> kernel/bpf/helpers.c:1069:9: error: function ‘____bpf_snprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>  1069 |         err = bstr_printf(str, str_size, fmt, data.bin_args);
>       |         ^~~
>
> kernel/bpf/stream.c:241:9: error: function ‘bpf_stream_vprintk_impl’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>   241 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt__str, data.bin_args);
>       |         ^~~
>
> kernel/trace/bpf_trace.c:377:9: error: function ‘____bpf_trace_printk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>   377 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
>       |         ^~~
>
> kernel/trace/bpf_trace.c:433:9: error: function ‘____bpf_trace_vprintk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>   433 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
>       |         ^~~
>
> kernel/trace/bpf_trace.c:475:9: error: function ‘____bpf_seq_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>   475 |         seq_bprintf(m, fmt, data.bin_args);
>       |         ^~~~~~~~~~~
>

I just want to point out that the compiler suggestion is wrong here
and these functions do not follow printf semantics. Yes, they have
printf format string argument, but arguments themselves are passed
using a special convention that the compiler won't know how to verify
properly. So now, these are not candidates for gnu_printf, and it
would be nice to have some way to shut up GCC for individual function
instead of blanket -Wno-suggest-attribute for the entire file.

Similarly, I see you marked bstr_printf() with __printf() earlier.
That also seems wrong, so you might want to fix that mistake as well,
while at it.

Maybe the pragma push/pop approach would be a bit better and more
explicit in the code?

> Fix the compilation errors by disabling that warning since the code is
> generated and warning is not so useful in this case — it can't check
> the parameters for now.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202512061425.x0qTt9ww-lkp@intel.com/
> Closes: https://lore.kernel.org/oe-kbuild-all/202512061640.9hKTnB8p-lkp@intel.com/
> Closes: https://lore.kernel.org/oe-kbuild-all/202512081321.2h9ThWTg-lkp@intel.com/
> Fixes: 5ab154f1463a ("bpf: Introduce BPF standard streams")
> Fixes: 10aceb629e19 ("bpf: Add bpf_trace_vprintk helper")
> Fixes: 7b15523a989b ("bpf: Add a bpf_snprintf helper")
> Fixes: 492e639f0c22 ("bpf: Add bpf_seq_printf and bpf_seq_write helpers")
> Fixes: f3694e001238 ("bpf: add BPF_CALL_x macros for declaring helpers")
> Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  kernel/bpf/Makefile   | 11 +++++++++--
>  kernel/trace/Makefile |  6 ++++++
>  2 files changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile
> index 232cbc97434d..cf7e8a972f98 100644
> --- a/kernel/bpf/Makefile
> +++ b/kernel/bpf/Makefile
> @@ -6,7 +6,14 @@ cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse
>  endif
>  CFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy)
>
> -obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o log.o token.o liveness.o
> +obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o tnum.o log.o token.o liveness.o
> +
> +obj-$(CONFIG_BPF_SYSCALL) += helpers.o stream.o
> +# The ____bpf_snprintf() uses the format string that triggers a compiler warning.
> +CFLAGS_helpers.o += -Wno-suggest-attribute=format
> +# The bpf_stream_vprintk_impl() uses the format string that triggers a compiler warning.
> +CFLAGS_stream.o += -Wno-suggest-attribute=format
> +
>  obj-$(CONFIG_BPF_SYSCALL) += bpf_iter.o map_iter.o task_iter.o prog_iter.o link_iter.o
>  obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o bloom_filter.o
>  obj-$(CONFIG_BPF_SYSCALL) += local_storage.o queue_stack_maps.o ringbuf.o bpf_insn_array.o
> @@ -14,7 +21,7 @@ obj-$(CONFIG_BPF_SYSCALL) += bpf_local_storage.o bpf_task_storage.o
>  obj-${CONFIG_BPF_LSM}    += bpf_inode_storage.o
>  obj-$(CONFIG_BPF_SYSCALL) += disasm.o mprog.o
>  obj-$(CONFIG_BPF_JIT) += trampoline.o
> -obj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o stream.o
> +obj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o
>  ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)
>  obj-$(CONFIG_BPF_SYSCALL) += arena.o range_tree.o
>  endif
> diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
> index fc5dcc888e13..1673b395c14c 100644
> --- a/kernel/trace/Makefile
> +++ b/kernel/trace/Makefile
> @@ -104,7 +104,13 @@ obj-$(CONFIG_TRACE_EVENT_INJECT) += trace_events_inject.o
>  obj-$(CONFIG_SYNTH_EVENTS) += trace_events_synth.o
>  obj-$(CONFIG_HIST_TRIGGERS) += trace_events_hist.o
>  obj-$(CONFIG_USER_EVENTS) += trace_events_user.o
> +
>  obj-$(CONFIG_BPF_EVENTS) += bpf_trace.o
> +# The BPF printing functions use the format string that triggers a compiler warning.
> +# Since the code is generated and warning is not so useful in this case (it can't
> +# check the parameters for now) disable the warning.
> +CFLAGS_bpf_trace.o += -Wno-suggest-attribute=format
> +
>  obj-$(CONFIG_KPROBE_EVENTS) += trace_kprobe.o
>  obj-$(CONFIG_TRACEPOINTS) += error_report-traces.o
>  obj-$(CONFIG_TRACEPOINTS) += power-traces.o
> --
> 2.50.1
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] bpf: Disable -Wsuggest-attribute=format
  2025-12-15 17:36 ` Andrii Nakryiko
@ 2025-12-15 18:13   ` Alexei Starovoitov
  2025-12-15 18:23     ` Andrii Nakryiko
  0 siblings, 1 reply; 8+ messages in thread
From: Alexei Starovoitov @ 2025-12-15 18:13 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Andy Shevchenko, Alexei Starovoitov, Steven Rostedt, bpf, LKML,
	linux-trace-kernel, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Masami Hiramatsu, Mathieu Desnoyers, kernel test robot

On Mon, Dec 15, 2025 at 9:36 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Dec 10, 2025 at 5:12 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > The printing functions in BPF code are using printf() type of format,
> > and compiler is not happy about them as is:
> >
> > kernel/bpf/helpers.c:1069:9: error: function ‘____bpf_snprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> >  1069 |         err = bstr_printf(str, str_size, fmt, data.bin_args);
> >       |         ^~~
> >
> > kernel/bpf/stream.c:241:9: error: function ‘bpf_stream_vprintk_impl’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> >   241 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt__str, data.bin_args);
> >       |         ^~~
> >
> > kernel/trace/bpf_trace.c:377:9: error: function ‘____bpf_trace_printk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> >   377 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
> >       |         ^~~
> >
> > kernel/trace/bpf_trace.c:433:9: error: function ‘____bpf_trace_vprintk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> >   433 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
> >       |         ^~~
> >
> > kernel/trace/bpf_trace.c:475:9: error: function ‘____bpf_seq_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> >   475 |         seq_bprintf(m, fmt, data.bin_args);
> >       |         ^~~~~~~~~~~
> >
>
> I just want to point out that the compiler suggestion is wrong here
> and these functions do not follow printf semantics. Yes, they have
> printf format string argument, but arguments themselves are passed
> using a special convention that the compiler won't know how to verify
> properly. So now, these are not candidates for gnu_printf, and it
> would be nice to have some way to shut up GCC for individual function
> instead of blanket -Wno-suggest-attribute for the entire file.
>
> Similarly, I see you marked bstr_printf() with __printf() earlier.
> That also seems wrong, so you might want to fix that mistake as well,
> while at it.
>
> Maybe the pragma push/pop approach would be a bit better and more
> explicit in the code?

I suggested using makefile and file level disable to avoid polluting
the code. Even when attr-print applies it doesn't help definitions.
The attribute is only useful in declaration and in our case it's not
going to be in vmlinux.h or in bpf_helpers.h
So having it right or wrong in .c is misleading.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] bpf: Disable -Wsuggest-attribute=format
  2025-12-15 18:13   ` Alexei Starovoitov
@ 2025-12-15 18:23     ` Andrii Nakryiko
  2025-12-15 18:40       ` Alexei Starovoitov
  0 siblings, 1 reply; 8+ messages in thread
From: Andrii Nakryiko @ 2025-12-15 18:23 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Andy Shevchenko, Alexei Starovoitov, Steven Rostedt, bpf, LKML,
	linux-trace-kernel, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Masami Hiramatsu, Mathieu Desnoyers, kernel test robot

On Mon, Dec 15, 2025 at 10:13 AM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Mon, Dec 15, 2025 at 9:36 AM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
> >
> > On Wed, Dec 10, 2025 at 5:12 AM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > The printing functions in BPF code are using printf() type of format,
> > > and compiler is not happy about them as is:
> > >
> > > kernel/bpf/helpers.c:1069:9: error: function ‘____bpf_snprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> > >  1069 |         err = bstr_printf(str, str_size, fmt, data.bin_args);
> > >       |         ^~~
> > >
> > > kernel/bpf/stream.c:241:9: error: function ‘bpf_stream_vprintk_impl’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> > >   241 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt__str, data.bin_args);
> > >       |         ^~~
> > >
> > > kernel/trace/bpf_trace.c:377:9: error: function ‘____bpf_trace_printk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> > >   377 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
> > >       |         ^~~
> > >
> > > kernel/trace/bpf_trace.c:433:9: error: function ‘____bpf_trace_vprintk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> > >   433 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
> > >       |         ^~~
> > >
> > > kernel/trace/bpf_trace.c:475:9: error: function ‘____bpf_seq_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> > >   475 |         seq_bprintf(m, fmt, data.bin_args);
> > >       |         ^~~~~~~~~~~
> > >
> >
> > I just want to point out that the compiler suggestion is wrong here
> > and these functions do not follow printf semantics. Yes, they have
> > printf format string argument, but arguments themselves are passed
> > using a special convention that the compiler won't know how to verify
> > properly. So now, these are not candidates for gnu_printf, and it
> > would be nice to have some way to shut up GCC for individual function
> > instead of blanket -Wno-suggest-attribute for the entire file.
> >
> > Similarly, I see you marked bstr_printf() with __printf() earlier.
> > That also seems wrong, so you might want to fix that mistake as well,
> > while at it.
> >
> > Maybe the pragma push/pop approach would be a bit better and more
> > explicit in the code?
>
> I suggested using makefile and file level disable to avoid polluting
> the code. Even when attr-print applies it doesn't help definitions.
> The attribute is only useful in declaration and in our case it's not
> going to be in vmlinux.h or in bpf_helpers.h
> So having it right or wrong in .c is misleading.

Makefile is fine, even if it's a big hammer, I don't mind or care.

But I think instead of Makefile changes we should fix the root cause
here. And that seems to be just wrong __printf annotations for
seq_bprintf and bstr_printf. They are not printf-like, they should not
be marked as such, and then the compiler won't be wrongly suggesting
bpf_stream_vprintk_impl (and others that make use of either
bstr_printf or seq_bprintf) to be marked with __printf.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] bpf: Disable -Wsuggest-attribute=format
  2025-12-15 18:23     ` Andrii Nakryiko
@ 2025-12-15 18:40       ` Alexei Starovoitov
  2025-12-15 22:18         ` Steven Rostedt
  0 siblings, 1 reply; 8+ messages in thread
From: Alexei Starovoitov @ 2025-12-15 18:40 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Andy Shevchenko, Alexei Starovoitov, Steven Rostedt, bpf, LKML,
	linux-trace-kernel, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Masami Hiramatsu, Mathieu Desnoyers, kernel test robot

On Mon, Dec 15, 2025 at 10:23 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Mon, Dec 15, 2025 at 10:13 AM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
> >
> > On Mon, Dec 15, 2025 at 9:36 AM Andrii Nakryiko
> > <andrii.nakryiko@gmail.com> wrote:
> > >
> > > On Wed, Dec 10, 2025 at 5:12 AM Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com> wrote:
> > > >
> > > > The printing functions in BPF code are using printf() type of format,
> > > > and compiler is not happy about them as is:
> > > >
> > > > kernel/bpf/helpers.c:1069:9: error: function ‘____bpf_snprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> > > >  1069 |         err = bstr_printf(str, str_size, fmt, data.bin_args);
> > > >       |         ^~~
> > > >
> > > > kernel/bpf/stream.c:241:9: error: function ‘bpf_stream_vprintk_impl’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> > > >   241 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt__str, data.bin_args);
> > > >       |         ^~~
> > > >
> > > > kernel/trace/bpf_trace.c:377:9: error: function ‘____bpf_trace_printk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> > > >   377 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
> > > >       |         ^~~
> > > >
> > > > kernel/trace/bpf_trace.c:433:9: error: function ‘____bpf_trace_vprintk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> > > >   433 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
> > > >       |         ^~~
> > > >
> > > > kernel/trace/bpf_trace.c:475:9: error: function ‘____bpf_seq_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> > > >   475 |         seq_bprintf(m, fmt, data.bin_args);
> > > >       |         ^~~~~~~~~~~
> > > >
> > >
> > > I just want to point out that the compiler suggestion is wrong here
> > > and these functions do not follow printf semantics. Yes, they have
> > > printf format string argument, but arguments themselves are passed
> > > using a special convention that the compiler won't know how to verify
> > > properly. So now, these are not candidates for gnu_printf, and it
> > > would be nice to have some way to shut up GCC for individual function
> > > instead of blanket -Wno-suggest-attribute for the entire file.
> > >
> > > Similarly, I see you marked bstr_printf() with __printf() earlier.
> > > That also seems wrong, so you might want to fix that mistake as well,
> > > while at it.
> > >
> > > Maybe the pragma push/pop approach would be a bit better and more
> > > explicit in the code?
> >
> > I suggested using makefile and file level disable to avoid polluting
> > the code. Even when attr-print applies it doesn't help definitions.
> > The attribute is only useful in declaration and in our case it's not
> > going to be in vmlinux.h or in bpf_helpers.h
> > So having it right or wrong in .c is misleading.
>
> Makefile is fine, even if it's a big hammer, I don't mind or care.

I rewrote the patch, commit log and pushed:
https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=ba34388912b5326aac591508c953a0be67a15d5a

> But I think instead of Makefile changes we should fix the root cause
> here. And that seems to be just wrong __printf annotations for
> seq_bprintf and bstr_printf. They are not printf-like, they should not
> be marked as such, and then the compiler won't be wrongly suggesting
> bpf_stream_vprintk_impl (and others that make use of either
> bstr_printf or seq_bprintf) to be marked with __printf.

yeah. commit 7bf819aa992f ("vsnprintf: Mark binary printing functions
with __printf() attribute")
should be reverted,
but that somebody else problem and the revert would need to silence
that incorrect warning in lib/vsprintf.c too.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] bpf: Disable -Wsuggest-attribute=format
  2025-12-15 18:40       ` Alexei Starovoitov
@ 2025-12-15 22:18         ` Steven Rostedt
  0 siblings, 0 replies; 8+ messages in thread
From: Steven Rostedt @ 2025-12-15 22:18 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Andrii Nakryiko, Andy Shevchenko, Alexei Starovoitov, bpf, LKML,
	linux-trace-kernel, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Masami Hiramatsu, Mathieu Desnoyers, kernel test robot

On Mon, 15 Dec 2025 10:40:16 -0800
Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:

> > But I think instead of Makefile changes we should fix the root cause
> > here. And that seems to be just wrong __printf annotations for
> > seq_bprintf and bstr_printf. They are not printf-like, they should not
> > be marked as such, and then the compiler won't be wrongly suggesting
> > bpf_stream_vprintk_impl (and others that make use of either
> > bstr_printf or seq_bprintf) to be marked with __printf.  
> 
> yeah. commit 7bf819aa992f ("vsnprintf: Mark binary printing functions
> with __printf() attribute")
> should be reverted,
> but that somebody else problem and the revert would need to silence
> that incorrect warning in lib/vsprintf.c too.

From what I understand, the __printf(X, 0) simply quiets the warning, which
is why those two are:

__printf(3, 0) int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
__printf(3, 0) int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf);

Hence, it's not a big deal to have that. Actually, it does document that
the printf format is different than a normal printf, and that the arguments
are not the same as a normal printf.

I complained about this at first too (and never gave an acked-by), but
because it does quiet a warning, I also didn't nack it.

-- Steve

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] bpf: Disable -Wsuggest-attribute=format
  2025-12-10 13:12 [PATCH v1 1/1] bpf: Disable -Wsuggest-attribute=format Andy Shevchenko
  2025-12-15 17:36 ` Andrii Nakryiko
@ 2025-12-16  0:11 ` Ihor Solodrai
  2025-12-16  0:53   ` Ihor Solodrai
  1 sibling, 1 reply; 8+ messages in thread
From: Ihor Solodrai @ 2025-12-16  0:11 UTC (permalink / raw)
  To: Andy Shevchenko, Alexei Starovoitov, Steven Rostedt, bpf,
	linux-kernel, linux-trace-kernel, Andrii Nakryiko
  Cc: Daniel Borkmann, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Masami Hiramatsu, Mathieu Desnoyers,
	kernel test robot

On 12/10/25 5:12 AM, Andy Shevchenko wrote:
> The printing functions in BPF code are using printf() type of format,
> and compiler is not happy about them as is:
> 
> kernel/bpf/helpers.c:1069:9: error: function ‘____bpf_snprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>  1069 |         err = bstr_printf(str, str_size, fmt, data.bin_args);
>       |         ^~~
> 
> kernel/bpf/stream.c:241:9: error: function ‘bpf_stream_vprintk_impl’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>   241 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt__str, data.bin_args);
>       |         ^~~
> 
> kernel/trace/bpf_trace.c:377:9: error: function ‘____bpf_trace_printk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>   377 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
>       |         ^~~
> 
> kernel/trace/bpf_trace.c:433:9: error: function ‘____bpf_trace_vprintk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>   433 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
>       |         ^~~
> 
> kernel/trace/bpf_trace.c:475:9: error: function ‘____bpf_seq_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>   475 |         seq_bprintf(m, fmt, data.bin_args);
>       |         ^~~~~~~~~~~
> 
> Fix the compilation errors by disabling that warning since the code is
> generated and warning is not so useful in this case — it can't check
> the parameters for now.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202512061425.x0qTt9ww-lkp@intel.com/
> Closes: https://lore.kernel.org/oe-kbuild-all/202512061640.9hKTnB8p-lkp@intel.com/
> Closes: https://lore.kernel.org/oe-kbuild-all/202512081321.2h9ThWTg-lkp@intel.com/
> Fixes: 5ab154f1463a ("bpf: Introduce BPF standard streams")
> Fixes: 10aceb629e19 ("bpf: Add bpf_trace_vprintk helper")
> Fixes: 7b15523a989b ("bpf: Add a bpf_snprintf helper")
> Fixes: 492e639f0c22 ("bpf: Add bpf_seq_printf and bpf_seq_write helpers")
> Fixes: f3694e001238 ("bpf: add BPF_CALL_x macros for declaring helpers")
> Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  kernel/bpf/Makefile   | 11 +++++++++--
>  kernel/trace/Makefile |  6 ++++++
>  2 files changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile
> index 232cbc97434d..cf7e8a972f98 100644
> --- a/kernel/bpf/Makefile
> +++ b/kernel/bpf/Makefile
> @@ -6,7 +6,14 @@ cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse
>  endif
>  CFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy)
>  
> -obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o log.o token.o liveness.o
> +obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o tnum.o log.o token.o liveness.o
> +
> +obj-$(CONFIG_BPF_SYSCALL) += helpers.o stream.o
> +# The ____bpf_snprintf() uses the format string that triggers a compiler warning.
> +CFLAGS_helpers.o += -Wno-suggest-attribute=format
> +# The bpf_stream_vprintk_impl() uses the format string that triggers a compiler warning.
> +CFLAGS_stream.o += -Wno-suggest-attribute=format

Hi Andy,

This flag does not exist in clang:

$ LLVM=1 make -j$(nproc) 
  [...]
$ LLVM=1 make
  CALL    scripts/checksyscalls.sh
  DESCEND objtool
  INSTALL libsubcmd_headers
  DESCEND bpf/resolve_btfids
  INSTALL libsubcmd_headers
  CC      kernel/trace/bpf_trace.o
error: unknown warning option '-Wno-suggest-attribute=format'; did you mean '-Wno-property-attribute-mismatch'? [-Werror,-Wunknown-warning-option]
make[4]: *** [scripts/Makefile.build:287: kernel/trace/bpf_trace.o] Error 1
make[3]: *** [scripts/Makefile.build:556: kernel/trace] Error 2
make[2]: *** [scripts/Makefile.build:556: kernel] Error 2
make[1]: *** [/home/isolodrai/kernels/bpf-next/Makefile:2030: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2

We should probably conditionalize the flag addition in the makefile.

Or better yet, address the root cause as suggested in the thread.

BPF CI is red on bpf branch at the moment:
https://github.com/kernel-patches/bpf/actions/runs/20243520506/job/58144348281

> +
>  obj-$(CONFIG_BPF_SYSCALL) += bpf_iter.o map_iter.o task_iter.o prog_iter.o link_iter.o
>  obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o bloom_filter.o
>  obj-$(CONFIG_BPF_SYSCALL) += local_storage.o queue_stack_maps.o ringbuf.o bpf_insn_array.o
> @@ -14,7 +21,7 @@ obj-$(CONFIG_BPF_SYSCALL) += bpf_local_storage.o bpf_task_storage.o
>  obj-${CONFIG_BPF_LSM}	  += bpf_inode_storage.o
>  obj-$(CONFIG_BPF_SYSCALL) += disasm.o mprog.o
>  obj-$(CONFIG_BPF_JIT) += trampoline.o
> -obj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o stream.o
> +obj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o
>  ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)
>  obj-$(CONFIG_BPF_SYSCALL) += arena.o range_tree.o
>  endif
> diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
> index fc5dcc888e13..1673b395c14c 100644
> --- a/kernel/trace/Makefile
> +++ b/kernel/trace/Makefile
> @@ -104,7 +104,13 @@ obj-$(CONFIG_TRACE_EVENT_INJECT) += trace_events_inject.o
>  obj-$(CONFIG_SYNTH_EVENTS) += trace_events_synth.o
>  obj-$(CONFIG_HIST_TRIGGERS) += trace_events_hist.o
>  obj-$(CONFIG_USER_EVENTS) += trace_events_user.o
> +
>  obj-$(CONFIG_BPF_EVENTS) += bpf_trace.o
> +# The BPF printing functions use the format string that triggers a compiler warning.
> +# Since the code is generated and warning is not so useful in this case (it can't
> +# check the parameters for now) disable the warning.
> +CFLAGS_bpf_trace.o += -Wno-suggest-attribute=format
> +
>  obj-$(CONFIG_KPROBE_EVENTS) += trace_kprobe.o
>  obj-$(CONFIG_TRACEPOINTS) += error_report-traces.o
>  obj-$(CONFIG_TRACEPOINTS) += power-traces.o


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] bpf: Disable -Wsuggest-attribute=format
  2025-12-16  0:11 ` Ihor Solodrai
@ 2025-12-16  0:53   ` Ihor Solodrai
  0 siblings, 0 replies; 8+ messages in thread
From: Ihor Solodrai @ 2025-12-16  0:53 UTC (permalink / raw)
  To: Andy Shevchenko, Alexei Starovoitov, Steven Rostedt, bpf,
	linux-kernel, linux-trace-kernel, Andrii Nakryiko
  Cc: Daniel Borkmann, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Masami Hiramatsu, Mathieu Desnoyers,
	kernel test robot

On 12/15/25 4:11 PM, Ihor Solodrai wrote:
> On 12/10/25 5:12 AM, Andy Shevchenko wrote:
>> [...]
>> -obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o log.o token.o liveness.o
>> +obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o tnum.o log.o token.o liveness.o
>> +
>> +obj-$(CONFIG_BPF_SYSCALL) += helpers.o stream.o
>> +# The ____bpf_snprintf() uses the format string that triggers a compiler warning.
>> +CFLAGS_helpers.o += -Wno-suggest-attribute=format
>> +# The bpf_stream_vprintk_impl() uses the format string that triggers a compiler warning.
>> +CFLAGS_stream.o += -Wno-suggest-attribute=format
> 
> Hi Andy,
> 
> This flag does not exist in clang:
> 
> $ LLVM=1 make -j$(nproc) 
>   [...]
> $ LLVM=1 make
>   CALL    scripts/checksyscalls.sh
>   DESCEND objtool
>   INSTALL libsubcmd_headers
>   DESCEND bpf/resolve_btfids
>   INSTALL libsubcmd_headers
>   CC      kernel/trace/bpf_trace.o
> error: unknown warning option '-Wno-suggest-attribute=format'; did you mean '-Wno-property-attribute-mismatch'? [-Werror,-Wunknown-warning-option]
> make[4]: *** [scripts/Makefile.build:287: kernel/trace/bpf_trace.o] Error 1
> make[3]: *** [scripts/Makefile.build:556: kernel/trace] Error 2
> make[2]: *** [scripts/Makefile.build:556: kernel] Error 2
> make[1]: *** [/home/isolodrai/kernels/bpf-next/Makefile:2030: .] Error 2
> make: *** [Makefile:248: __sub-make] Error 2
> 
> We should probably conditionalize the flag addition in the makefile.

Just confirmed that the patch below fixes LLVM=1 build:

From 842b31ff3384df65bb6f13763464daa03ba4f025 Mon Sep 17 00:00:00 2001
From: Ihor Solodrai <isolodrai@meta.com>
Date: Mon, 15 Dec 2025 16:45:19 -0800
Subject: [PATCH] bpf: Ensure CC is set to GCC for
 -Wno-suggest-attribute=format

LLVM=1 kernel build got broken because clang does not have
-Wno-suggest-attribute=format option.

Check for CONFIG_CC_IS_GCC before setting this option.

Fixes: ba34388912b5 ("bpf: Disable false positive -Wsuggest-attribute=format warning")
Closes: https://lore.kernel.org/bpf/20251210131234.3185985-1-andriy.shevchenko@linux.intel.com/
Signed-off-by: Ihor Solodrai <isolodrai@meta.com>
---
 kernel/bpf/Makefile   | 2 ++
 kernel/trace/Makefile | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile
index d7bcdb1fd35a..7a33c701e5fb 100644
--- a/kernel/bpf/Makefile
+++ b/kernel/bpf/Makefile
@@ -17,8 +17,10 @@ obj-$(CONFIG_BPF_JIT) += trampoline.o
 obj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o stream.o
 # Disable incorrect warning. bpf printf-like helpers cannot use
 # gnu_printf attribute.
+ifeq ($(CONFIG_CC_IS_GCC),y)
 CFLAGS_helpers.o += -Wno-suggest-attribute=format
 CFLAGS_stream.o += -Wno-suggest-attribute=format
+endif
 ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)
 obj-$(CONFIG_BPF_SYSCALL) += arena.o range_tree.o
 endif
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index 5869c1f1af89..06705d6fed2c 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -90,7 +90,9 @@ obj-$(CONFIG_USER_EVENTS) += trace_events_user.o
 obj-$(CONFIG_BPF_EVENTS) += bpf_trace.o
 # Disable incorrect warning. bpf printf-like helpers cannot use
 # gnu_printf attribute.
+ifeq ($(CONFIG_CC_IS_GCC),y)
 CFLAGS_bpf_trace.o += -Wno-suggest-attribute=format
+endif
 obj-$(CONFIG_KPROBE_EVENTS) += trace_kprobe.o
 obj-$(CONFIG_TRACEPOINTS) += error_report-traces.o
 obj-$(CONFIG_TRACEPOINTS) += power-traces.o
-- 
2.47.3

> 
> Or better yet, address the root cause as suggested in the thread.
> 
> BPF CI is red on bpf branch at the moment:
> https://github.com/kernel-patches/bpf/actions/runs/20243520506/job/58144348281
> 
>>
>>  [...]
> 


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-12-16  0:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-10 13:12 [PATCH v1 1/1] bpf: Disable -Wsuggest-attribute=format Andy Shevchenko
2025-12-15 17:36 ` Andrii Nakryiko
2025-12-15 18:13   ` Alexei Starovoitov
2025-12-15 18:23     ` Andrii Nakryiko
2025-12-15 18:40       ` Alexei Starovoitov
2025-12-15 22:18         ` Steven Rostedt
2025-12-16  0:11 ` Ihor Solodrai
2025-12-16  0:53   ` Ihor Solodrai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).