From: Kees Cook <keescook@chromium.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 00/19] Enable -Wshadow=local for kernel/sched
Date: Fri, 19 Apr 2024 15:06:39 -0700 [thread overview]
Message-ID: <202404191458.17308A48D4@keescook> (raw)
In-Reply-To: <Zh8dTOZ_YxeGhp-L@casper.infradead.org>
On Wed, Apr 17, 2024 at 01:52:28AM +0100, Matthew Wilcox wrote:
> On Tue, Apr 16, 2024 at 05:29:02PM -0700, Linus Torvalds wrote:
> > On Tue, 16 Apr 2024 at 14:15, Kees Cook <keescook@chromium.org> wrote:
> > >
> > > I was looking at -Wshadow=local again, and remembered this series. It
> > > sounded like things were close, but a tweak was needed. What would be
> > > next to get this working?
> >
> > So what is the solution to
> >
> > #define MAX(a,b) ({ \
> > typeof(a) __a = (a); \
> > typeof(b) __b = (b); \
> > __a > __b ? __a : __b; \
> > })
>
> #define __MAX(a, __a, b, __b) ({ \
> typeof(a) __a = (a); \
> typeof(b) __b = (b); \
> __a > __b ? __a : __b; \
> })
>
> #define MAX(a, b) __MAX(a, UNIQUE_ID(a), b, UNIQUE_ID(b))
Yup, this is what we've had for a long time now. See
include/linux/minmax.h
> At least, I think that was the plan. This was two years ago and I've
> mostly forgotten.
>
> > int test(int a, int b, int c)
> > {
> > return MAX(a, MAX(b,c));
> > }
> >
> > where -Wshadow=all causes insane warnings that are bogus garbage?
> >
> > Honestly, Willy's patch-series is a hack to avoid this kind of very
> > natural nested macro pattern.
> >
> > But it's a horrible hack, and it does it by making the code actively worse.
> >
> > Here's the deal: if we can't handle somethng like the above without
> > warning, -Wshadow isn't getting enabled.
> >
> > Because we don't write worse code because of bad warnings.
> >
> > IOW, what is the sane way to just say "this variable can shadow the
> > use site, and it's fine"?
> >
> > Without that kind of out, I don't think -Wshadow=local is workable.
This isn't a hill I want to die on, but it's just another case where
we've fought bugs more than once that would have stood out immediately
if we had -Wshadow=local enabled, but there is basically only 1 user. In
my bug-fighting calculus, it makes sense to deal with fixing the 1 user
so we can gain the coverage everywhere else.
But there are much worse bug sources, so if Willy's series isn't
workable, I'll drop this again for now. :)
-Kees
--
Kees Cook
prev parent reply other threads:[~2024-04-19 22:06 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-02 4:34 Matthew Wilcox (Oracle)
2022-03-02 4:34 ` [PATCH 01/19] wait: Parameterize the return variable to ___wait_event() Matthew Wilcox (Oracle)
2022-03-02 4:34 ` [PATCH 02/19] swait: Parameterize the return variable to __swait_event_timeout() Matthew Wilcox (Oracle)
2022-03-02 4:34 ` [PATCH 03/19] swait: Parameterize the return variable to __swait_event_interruptible_timeout() Matthew Wilcox (Oracle)
2022-03-02 4:34 ` [PATCH 04/19] swait: Parameterize the return variable to __swait_event_idle_timeout() Matthew Wilcox (Oracle)
2022-03-02 4:34 ` [PATCH 05/19] wait: Parameterize the return variable to __wait_event_timeout() Matthew Wilcox (Oracle)
2022-03-02 4:34 ` [PATCH 06/19] wait: Parameterize the return variable to __wait_event_freezable_timeout() Matthew Wilcox (Oracle)
2022-03-02 4:34 ` [PATCH 07/19] wait: Parameterize the return variable to __wait_event_interruptible_timeout() Matthew Wilcox (Oracle)
2022-03-02 4:34 ` [PATCH 08/19] wait: Parameterize the return variable to __wait_event_idle_timeout() Matthew Wilcox (Oracle)
2022-03-02 4:34 ` [PATCH 09/19] wait: Parameterize the return variable to __wait_event_idle_exclusive_timeout() Matthew Wilcox (Oracle)
2022-03-02 4:34 ` [PATCH 10/19] wait: Parameterize the return variable to __wait_event_killable_timeout() Matthew Wilcox (Oracle)
2022-03-02 4:34 ` [PATCH 11/19] wait: Parameterize the return variable to __wait_event_lock_irq_timeout() Matthew Wilcox (Oracle)
2022-03-02 4:34 ` [PATCH 12/19] wait_bit: Parameterize the return variable to __wait_var_event_timeout() Matthew Wilcox (Oracle)
2022-03-02 18:32 ` [PATCH 00/19] Enable -Wshadow=local for kernel/sched Kees Cook
2022-03-02 18:43 ` Matthew Wilcox
2022-03-02 19:18 ` Peter Zijlstra
2024-04-16 21:15 ` Kees Cook
2024-04-17 0:29 ` Linus Torvalds
2024-04-17 0:50 ` Linus Torvalds
2024-04-17 0:52 ` Matthew Wilcox
2024-04-17 11:23 ` Ingo Molnar
2024-04-19 22:06 ` Kees Cook [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202404191458.17308A48D4@keescook \
--to=keescook@chromium.org \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=torvalds@linux-foundation.org \
--cc=vincent.guittot@linaro.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome