* Re: [PATCH] panic: suppress gnu_printf warning
[not found] <20240107091641.579849-1-bhe@redhat.com>
@ 2024-01-07 18:21 ` Andrew Morton
2024-01-08 1:56 ` Baoquan He
2024-01-09 13:25 ` Manuel López-Ibáñez
0 siblings, 2 replies; 3+ messages in thread
From: Andrew Morton @ 2024-01-07 18:21 UTC (permalink / raw)
To: Baoquan He; +Cc: linux-kernel, pmladek, gcc
On Sun, 7 Jan 2024 17:16:41 +0800 Baoquan He <bhe@redhat.com> wrote:
> with GCC 13.2.1 and W=1, there's compiling warning like this:
>
> kernel/panic.c: In function ‘__warn’:
> kernel/panic.c:676:17: warning: function ‘__warn’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
> 676 | vprintk(args->fmt, args->args);
> | ^~~~~~~
>
> The normal __printf(x,y) adding can't fix it. So add workaround which
> disables -Wsuggest-attribute=format to mute it.
>
> ...
>
> --- a/kernel/panic.c
> +++ b/kernel/panic.c
> @@ -666,8 +666,13 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
> pr_warn("WARNING: CPU: %d PID: %d at %pS\n",
> raw_smp_processor_id(), current->pid, caller);
>
> +#pragma GCC diagnostic push
> +#ifndef __clang__
> +#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
> +#endif
> if (args)
> vprintk(args->fmt, args->args);
> +#pragma GCC diagnostic pop
>
> print_modules();
__warn() clearly isn't such a candidate. I'm suspecting that gcc's
implementation of this warning is pretty crude. Is it a new thing in
gcc-13.2?
A bit of context for gcc@gcc.gnu.org:
struct warn_args {
const char *fmt;
va_list args;
};
...
void __warn(const char *file, int line, void *caller, unsigned taint,
struct pt_regs *regs, struct warn_args *args)
{
disable_trace_on_warning();
if (file)
pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n",
raw_smp_processor_id(), current->pid, file, line,
caller);
else
pr_warn("WARNING: CPU: %d PID: %d at %pS\n",
raw_smp_processor_id(), current->pid, caller);
if (args)
vprintk(args->fmt, args->args);
print_modules();
if (regs)
show_regs(regs);
check_panic_on_warn("kernel");
if (!regs)
dump_stack();
print_irqtrace_events(current);
print_oops_end_marker();
trace_error_report_end(ERROR_DETECTOR_WARN, (unsigned long)caller);
/* Just a warning, don't kill lockdep. */
add_taint(taint, LOCKDEP_STILL_OK);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] panic: suppress gnu_printf warning
2024-01-07 18:21 ` [PATCH] panic: suppress gnu_printf warning Andrew Morton
@ 2024-01-08 1:56 ` Baoquan He
2024-01-09 13:25 ` Manuel López-Ibáñez
1 sibling, 0 replies; 3+ messages in thread
From: Baoquan He @ 2024-01-08 1:56 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, pmladek, gcc
On 01/07/24 at 10:21am, Andrew Morton wrote:
> On Sun, 7 Jan 2024 17:16:41 +0800 Baoquan He <bhe@redhat.com> wrote:
>
> > with GCC 13.2.1 and W=1, there's compiling warning like this:
> >
> > kernel/panic.c: In function ‘__warn’:
> > kernel/panic.c:676:17: warning: function ‘__warn’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
> > 676 | vprintk(args->fmt, args->args);
> > | ^~~~~~~
> >
> > The normal __printf(x,y) adding can't fix it. So add workaround which
> > disables -Wsuggest-attribute=format to mute it.
> >
> > ...
> >
> > --- a/kernel/panic.c
> > +++ b/kernel/panic.c
> > @@ -666,8 +666,13 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
> > pr_warn("WARNING: CPU: %d PID: %d at %pS\n",
> > raw_smp_processor_id(), current->pid, caller);
> >
> > +#pragma GCC diagnostic push
> > +#ifndef __clang__
> > +#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
> > +#endif
> > if (args)
> > vprintk(args->fmt, args->args);
> > +#pragma GCC diagnostic pop
> >
> > print_modules();
>
> __warn() clearly isn't such a candidate. I'm suspecting that gcc's
> implementation of this warning is pretty crude. Is it a new thing in
> gcc-13.2?
Yeah, this isn't like other warnings in kernel. The compiler seems too
smart by look into the parameter 'args' of 'struct warn_args*'.
>
> A bit of context for gcc@gcc.gnu.org:
>
> struct warn_args {
> const char *fmt;
> va_list args;
> };
>
> ...
>
> void __warn(const char *file, int line, void *caller, unsigned taint,
> struct pt_regs *regs, struct warn_args *args)
> {
> disable_trace_on_warning();
>
> if (file)
> pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n",
> raw_smp_processor_id(), current->pid, file, line,
> caller);
> else
> pr_warn("WARNING: CPU: %d PID: %d at %pS\n",
> raw_smp_processor_id(), current->pid, caller);
>
> if (args)
> vprintk(args->fmt, args->args);
>
> print_modules();
>
> if (regs)
> show_regs(regs);
>
> check_panic_on_warn("kernel");
>
> if (!regs)
> dump_stack();
>
> print_irqtrace_events(current);
>
> print_oops_end_marker();
> trace_error_report_end(ERROR_DETECTOR_WARN, (unsigned long)caller);
>
> /* Just a warning, don't kill lockdep. */
> add_taint(taint, LOCKDEP_STILL_OK);
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] panic: suppress gnu_printf warning
2024-01-07 18:21 ` [PATCH] panic: suppress gnu_printf warning Andrew Morton
2024-01-08 1:56 ` Baoquan He
@ 2024-01-09 13:25 ` Manuel López-Ibáñez
1 sibling, 0 replies; 3+ messages in thread
From: Manuel López-Ibáñez @ 2024-01-09 13:25 UTC (permalink / raw)
To: gcc; +Cc: Andrew Morton, Baoquan He
On 07/01/2024 19:21, Andrew Morton wrote:
> On Sun, 7 Jan 2024 17:16:41 +0800 Baoquan He <bhe@redhat.com> wrote:
>
>> with GCC 13.2.1 and W=1, there's compiling warning like this:
>>
>> kernel/panic.c: In function ?__warn?:
>> kernel/panic.c:676:17: warning: function ?__warn? might be a candidate for ?gnu_printf? format attribute [-Wsuggest-attribute=format]
>> 676 | vprintk(args->fmt, args->args);
>> | ^~~~~~~
>>
>> The normal __printf(x,y) adding can't fix it. So add workaround which
>> disables -Wsuggest-attribute=format to mute it.
>>
>> ...
>>
>> --- a/kernel/panic.c
>> +++ b/kernel/panic.c
>> @@ -666,8 +666,13 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
>> pr_warn("WARNING: CPU: %d PID: %d at %pS\n",
>> raw_smp_processor_id(), current->pid, caller);
>>
>> +#pragma GCC diagnostic push
>> +#ifndef __clang__
>> +#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
>> +#endif
>> if (args)
>> vprintk(args->fmt, args->args);
>> +#pragma GCC diagnostic pop
>>
>> print_modules();
> __warn() clearly isn't such a candidate. I'm suspecting that gcc's
> implementation of this warning is pretty crude. Is it a new thing in
> gcc-13.2?
I suspect the warning is about vprintk(), which does seem a printf-like
function but something (early inlining?) may be messing up the context and GCC
warns about __warn(). This may be bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=28492
If vprintk() already has the format attribute, then the messed up function name
may be confusing GCC into warning again about it.
Best wishes,
Manuel.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-09 13:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20240107091641.579849-1-bhe@redhat.com>
2024-01-07 18:21 ` [PATCH] panic: suppress gnu_printf warning Andrew Morton
2024-01-08 1:56 ` Baoquan He
2024-01-09 13:25 ` Manuel López-Ibáñez
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 read-only IMAP folder(s) and NNTP newsgroup(s).