tracing: remove __printf() attribute on __ftrace_vbprintk()
Subsystems (5)
PATCH 1/1 tracing: remove __printf() attribute on __ftrace_vbprintk()
From: Arnd Bergmann <[email protected]>
The sunrpc change to use trace_printk() for debugging caused a new warning for every instance of dprintk() in some configurations, when -Wformat-security is enabled:
fs/nfs/getroot.c: In function 'nfs_get_root':fs/nfs/getroot.c:90:17: error: format not a string literal and no format arguments [-Werror=format-security]
90 | nfs_errorf(fc, "NFS: Couldn't getattr on root");
I've been slowly chipping away at those warnings over time with the intention of enabling them by default in the future. While I could not figure out why this only happens for this one instance, I see that the __trace_bprintk() function is always called with a local variable as the format string, rather than a literal.
Remove the __printf(2,3) annotation on this function, as this is can only be validated for literals. The format strings still get checked because the underlying literal keeps getting passed into __trace_printk() in the "else" branch, which is not taken but still evaluated for compile-time warnings.
--- include/linux/trace_printk.h | 1 - 1 file changed, 1 deletion(-)
include/linux/trace_printk.h +0 -1
@@ -107,7 +107,6 @@ do { \ __trace_printk(_THIS_IP_, fmt, ##args); \ } while (0) -extern __printf(2, 3)int __trace_bprintk (unsigned long ip,const char *fmt, ...); extern __printf(2, 3)
Signature · 1 line
2.39.5
Quoted 33 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The sunrpc change to use
trace_printk()for debugging caused a new warning for every instance ofdprintk()in some configurations, when -Wformat-security is enabled:
fs/nfs/getroot.c: In function 'nfs_get_root':fs/nfs/getroot.c:90:17: error: format not a string literal and no format arguments [-Werror=format-security]
90 |nfs_errorf(fc, "NFS: Couldn't getattr on root");I've been slowly chipping away at those warnings over time with the intention of enabling them by default in the future. While I could not figure out why this only happens for this one instance, I see that the
__trace_bprintk()function is always called with a local variable as the format string, rather than a literal.Remove the
__printf(2,3)annotation on this function, as this is can only be validated for literals. The format strings still get checked because the underlying literal keeps getting passed into__trace_printk()in the "else" branch, which is not taken but still evaluated for compile-time warnings.Fixes ec7d8e68ef0e ("sunrpc: add a Kconfig option to redirect dfprintk() output to trace buffer")Signed-off-by Arnd Bergmann <[email protected]>--- include/linux/trace_printk.h | 1 - 1 file changed, 1 deletion(-)include/linux/trace_printk.h +0
-0
include/linux/trace_printk.h do { \ · line 112
Quoted 7 lines
include/linux/trace_printk.h +0
-1@@ -107,7 +107,6 @@ do { \ __trace_printk(_THIS_IP_, fmt, ##args); \ } while (0) -extern __printf(2, 3)int __trace_bprintk (unsigned long ip,const char *fmt, ...); extern __printf(2, 3)
Quoted 14 lines · Arnd Bergmann
The sunrpc change to use
trace_printk()for debugging caused a new warning for every instance ofdprintk()in some configurations, when -Wformat-security is enabled:
fs/nfs/getroot.c: In function 'nfs_get_root':fs/nfs/getroot.c:90:17: error: format not a string literal and no format arguments [-Werror=format-security]
90 |nfs_errorf(fc, "NFS: Couldn't getattr on root");I've been slowly chipping away at those warnings over time with the intention of enabling them by default in the future. While I could not figure out why this only happens for this one instance, I see that the
__trace_bprintk()function is always called with a local variable as the format string, rather than a literal.
Quoted 5 lines
Remove the
__printf(2,3)annotation on this function, as this is can only be validated for literals. The format strings still get checked because the underlying literal keeps getting passed into__trace_printk()in the "else" branch, which is not taken but still evaluated for compile-time warnings.
Yeah, it was discussed in the past that binary printf() should not be annotated as we have BPF code that doesn't compile (with the default WERROR=y).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 16 lines · On Mon, 2 Feb 2026 10:58:27 +0100 Arnd Bergmann <[email protected]> wrote:
From: Arnd Bergmann <[email protected]>
The sunrpc change to use
trace_printk()for debugging caused a new warning for every instance ofdprintk()in some configurations, when -Wformat-security is enabled:
fs/nfs/getroot.c: In function 'nfs_get_root':fs/nfs/getroot.c:90:17: error: format not a string literal and no format arguments [-Werror=format-security]
90 |nfs_errorf(fc, "NFS: Couldn't getattr on root");I've been slowly chipping away at those warnings over time with the intention of enabling them by default in the future. While I could not figure out why this only happens for this one instance, I see that the
__trace_bprintk()function is always called with a local variable as the format string, rather than a literal.
Quoted 8 lines
Remove the
__printf(2,3)annotation on this function, as this is can only be validated for literals. The format strings still get checked because the underlying literal keeps getting passed into__trace_printk()in the "else" branch, which is not taken but still evaluated for compile-time warnings.Fixes ec7d8e68ef0e ("sunrpc: add a Kconfig option to redirect dfprintk() output to trace buffer")Signed-off-by Arnd Bergmann <[email protected]>
-- Steve
Quoted 16 lines
--- include/linux/trace_printk.h | 1 - 1 file changed, 1 deletion(-)include/linux/trace_printk.h +0
-1@@ -107,7 +107,6 @@ do { \ __trace_printk(_THIS_IP_, fmt, ##args); \ } while (0) -extern __printf(2, 3)int __trace_bprintk (unsigned long ip,const char *fmt, ...); extern __printf(2, 3)
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Arnd,
kernel test robot noticed the following build warnings:
[auto build test WARNING on next-20260130]
[cannot apply to trace/for-next linus/master v6.19-rc8 v6.19-rc7 v6.19-rc6 v6.19-rc8] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Arnd-Bergmann/tracing-remove-__printf-attribute-on-__ftrace_vbprintk/20260202-180958 base: next-20260130 patch link: https://lore.kernel.org/r/20260202095834.1328352-1-arnd%40kernel.org patch subject: [PATCH] tracing: remove __printf() attribute on __ftrace_vbprintk() config: riscv-allmodconfig (https://download.01.org/0day-ci/archive/20260203/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 9b8addffa70cee5b2acc5454712d9cf78ce45710) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260203/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> kernel/trace/trace_printk.c:212:34: warning: diagnostic behavior may be improved by adding the 'format(printf, 2, 3)' attribute to the declaration of '__trace_bprintk' [-Wmissing-format-attribute]
212 | ret = trace_vbprintk(ip, fmt, ap);
| ^
include/linux/trace_printk.h:110:5: note: '__trace_bprintk' declared here
110 | int __trace_bprintk(unsigned long ip, const char *fmt, ...);
| ^1 warning generated.
vim +212 kernel/trace/trace_printk.c
1ba28e02a18cbd kernel/trace/trace_bprintk.c Lai Jiangshan 2009-03-06 199
48ead02030f849 kernel/trace/trace_printk.c Frederic Weisbecker 2009-03-12 200 int __trace_bprintk(unsigned long ip, const char *fmt, ...)
1427cdf0592368 kernel/trace/trace_bprintk.c Lai Jiangshan 2009-03-06 201 {
769b0441f438c4 kernel/trace/trace_printk.c Frederic Weisbecker 2009-03-06 202 int ret;
769b0441f438c4 kernel/trace/trace_printk.c Frederic Weisbecker 2009-03-06 203 va_list ap;
1427cdf0592368 kernel/trace/trace_bprintk.c Lai Jiangshan 2009-03-06 204
769b0441f438c4 kernel/trace/trace_printk.c Frederic Weisbecker 2009-03-06 205 if (unlikely(!fmt))
769b0441f438c4 kernel/trace/trace_printk.c Frederic Weisbecker 2009-03-06 206 return 0;
769b0441f438c4 kernel/trace/trace_printk.c Frederic Weisbecker 2009-03-06 207
b9f9108cad3998 kernel/trace/trace_printk.c Steven Rostedt (Red Hat 2015-09-29 208) if (!trace_printk_enabled)
769b0441f438c4 kernel/trace/trace_printk.c Frederic Weisbecker 2009-03-06 209 return 0;
769b0441f438c4 kernel/trace/trace_printk.c Frederic Weisbecker 2009-03-06 210
769b0441f438c4 kernel/trace/trace_printk.c Frederic Weisbecker 2009-03-06 211 va_start(ap, fmt);
40ce74f19c2807 kernel/trace/trace_printk.c Steven Rostedt 2009-03-19 @212 ret = trace_vbprintk(ip, fmt, ap);
769b0441f438c4 kernel/trace/trace_printk.c Frederic Weisbecker 2009-03-06 213 va_end(ap);
769b0441f438c4 kernel/trace/trace_printk.c Frederic Weisbecker 2009-03-06 214 return ret;
1427cdf0592368 kernel/trace/trace_bprintk.c Lai Jiangshan 2009-03-06 215 }
48ead02030f849 kernel/trace/trace_printk.c Frederic Weisbecker 2009-03-12 216 EXPORT_SYMBOL_GPL(__trace_bprintk);
1427cdf0592368 kernel/trace/trace_bprintk.c Lai Jiangshan 2009-03-06 217 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 1 line · kernel test robot
kernel test robot noticed the following build warnings:
Yeah, you need to go for the full stack of these calls and mark the bottom one with __diag() to avoid these warnings. That's my understanding and what BPF people required. Chasing this one-by-one would produce unneeded churn.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 1 line · kernel test robot
kernel test robot noticed the following build warnings:
Yeah, you need to go for the full stack of these calls and mark the bottom one with
__diag()to avoid these warnings. That's my understanding and what BPF people required. Chasing this one-by-one would produce unneeded churn.
From what I can tell, I can just move the printf attribute to the __ftrace_vbprintk() definition to make this bit work. I'll send an updated patch:
kernel/trace/trace_printk.c +1 -0
@@ -197,6 +197,7 @@ struct notifier_block module_trace_bprintk_format_nb = { .notifier_call = module_trace_bprintk_format_notify, }; +__printf(2, 3)int __trace_bprintk (unsigned long ip,const char *fmt, ...) {int ret;
There are unrelated warnings for BPF that I managed to shut up the same way, doing
kernel/bpf/helpers.c +1 -0
@@ -1046,6 +1046,7 @@ int bpf_bprintf_prepare(const char *fmt, u32 fmt_size, const u64 *raw_args,return err; } +__printf(3, 0) BPF_CALL_5(bpf_snprintf, char *, str, u32, str_size, char *, fmt, const void *, args, u32, data_len) {
kernel/bpf/stream.c +1 -0
@@ -212,6 +212,7 @@ __bpf_kfunc_start_defs();* Avoid using enum bpf_stream_id so that kfunc users don't have to pull in the * enum in headers. */ +__printf(2, 0) __bpf_kfunc int bpf_stream_vprintk(int stream_id, const char *fmt__str, const void *args,u32 len__sz,struct bpf_prog_aux *aux) {
kernel/trace/bpf_trace.c +3 -0
@@ -359,6 +359,7 @@ static const struct bpf_func_proto bpf_probe_write_user_proto = {#define MAX_TRACE_PRINTK_VARARGS 3#define BPF_TRACE_PRINTK_SIZE 1024 +__printf(1, 0) BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, fmt_size, u64, arg1, u64, arg2, u64, arg3) {
@@ -412,6 +413,7 @@ const struct bpf_func_proto *bpf_get_trace_printk_proto(void)return &bpf_trace_printk_proto; } +__printf(1, 0) BPF_CALL_4(bpf_trace_vprintk, char *, fmt, u32, fmt_size, const void *, args, u32, data_len) {
@@ -455,6 +457,7 @@ const struct bpf_func_proto *bpf_get_trace_vprintk_proto(void)return &bpf_trace_vprintk_proto; } +__printf(2, 0) BPF_CALL_5(bpf_seq_printf, struct seq_file *, m, char *, fmt, u32, fmt_size, const void *, args, u32, data_len) {
Since those functions have no callers, the annotation on the print functions does nothing.
With those added, and a couple of drivers fixed to use the correct printf attributes, the only remaining one I see is in samples/trace_events/trace-events-sample.h:
In file included from /home/arnd/arm-soc/include/trace/define_trace.h:132,
from /home/arnd/arm-soc/samples/trace_events/trace-events-sample.h:640,
from /home/arnd/arm-soc/samples/trace_events/trace-events-sample.c:12:/home/arnd/arm-soc/samples/trace_events/./trace-events-sample.h: In function 'trace_event_get_offsets_foo_bar':/home/arnd/arm-soc/include/trace/stages/stage5_get_offsets.h:33:31: error: function 'trace_event_get_offsets_foo_bar' might be a candidate for 'gnu_printf' format attribute [-Werror=suggest-attribute=format]
33 | { (void)sizeof(struct _test_no_array_##item *); }
| ^~~~~~~~~~~~~~~
/home/arnd/arm-soc/include/trace/trace_events.h:285:9: note: in definition of macro 'DECLARE_EVENT_CLASS'
285 | tstruct; \
| ^~~~~~~
/home/arnd/arm-soc/include/trace/trace_events.h:43:30: note: in expansion of macro 'PARAMS'
43 | PARAMS(tstruct), \
| ^~~~~~
/home/arnd/arm-soc/samples/trace_events/./trace-events-sample.h:291:1: note: in expansion of macro 'TRACE_EVENT'
291 | TRACE_EVENT(foo_bar,
| ^~~~~~~~~~~
/home/arnd/arm-soc/samples/trace_events/./trace-events-sample.h:299:9: note: in expansion of macro 'TP_STRUCT__entry'
299 | TP_STRUCT__entry(
| ^~~~~~~~~~~~~~~~
/home/arnd/arm-soc/samples/trace_events/./trace-events-sample.h:301:17: note: in expansion of macro '__field'
301 | __field( int, bar )
| ^~~~~~~/home/arnd/arm-soc/samples/trace_events/./trace-events-sample.h: In function 'do_trace_event_raw_event_foo_bar':
I don't think this is related, but I also don't see an obvious workaround other than forcing the warning off around that definition.
Arnd
Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · Andy Shevchenko
Quoted 1 line · kernel test robot
kernel test robot noticed the following build warnings:
Quoted 7 lines
Quoted 4 lines
Yeah, you need to go for the full stack of these calls and mark the bottom one with
__diag()to avoid these warnings. That's my understanding and what BPF people required. Chasing this one-by-one would produce unneeded churn.From what I can tell, I can just move the printf attribute to the
__ftrace_vbprintk()definition to make this bit work.
Ah, that's cool!
...
Quoted 2 lines
There are unrelated warnings for BPF that I managed to shut up the same way, doing
BPF rejected such an approach, see lore discussions in the past (patches from me). Here some pointers (but not all of them):
[email protected] [email protected] [email protected] [email protected] [email protected]
Signature · 2 lines
With Best Regards, Andy Shevchenko