From: Matthew Wilcox <willy@infradead.org>
To: Kees Cook <keescook@chromium.org>
Cc: 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>,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 00/19] Enable -Wshadow=local for kernel/sched
Date: Wed, 2 Mar 2022 18:43:57 +0000 [thread overview]
Message-ID: <Yh+67VF0/OFSp15y@casper.infradead.org> (raw)
In-Reply-To: <202203021030.EEEF58C2@keescook>
On Wed, Mar 02, 2022 at 10:32:23AM -0800, Kees Cook wrote:
> On Wed, Mar 02, 2022 at 04:34:32AM +0000, Matthew Wilcox (Oracle) wrote:
> > I thought I'd choose one of the more core parts of the kernel to
> > demonstrate the value of -Wshadow. It found two places where there are
> > shadowed variables that are at least confusing. For all I know they're
> > buggy and my resolution of these warnings is wrong.
> >
> > The first 12 patches just untangle the unclean uses of __ret in wait.h
> > & friends. Then 4 patches to fix problems in headers that are noticed
> > by kernel/sched. Two patches fix the two places in kernel/sched/
> > with shadowed variables and the final patch adds -Wshadow=local to
> > the Makefile.
>
> You are my hero. I was pulling my hair out trying to figure out how
> to deal with this a few months ago, and the use of UNIQUE_ID was the
> key. Yay!
>
> > I'm quite certain this patch series isn't going in as-is. But maybe
> > it'll inspire some patches that can go in.
>
> I think it's pretty darn close. One thing that can be done to test the
> results for the first 12 patches is to do a binary comparison -- these
> changes _should_ have no impact on the final machine code. (It'll
> totally change the debug sections, etc, but the machine code should be
> the same.)
Peter pointed out that I got confused about which __ret was being
referred to:
<peterz> +#define __wait_event_freezable_timeout(wq_head, condition, timeout, __ret) \
<peterz> + ___wait_event(wq_head, ___wait_cond_timeout(condition, __ret), \
<peterz> + TASK_INTERRUPTIBLE, 0, timeout, \
<peterz> + __ret = freezable_schedule_timeout(__ret), UNIQUE_ID)
<peterz> so now that internal variable is UNIQUE_ID, whatever that is
<peterz> but the condition argument was supposed to look at that
<peterz> but you explicitly pulled that out
ie "__ret = freezable_schedule_timeout(__ret)" is supposed to refer to
the inner __ret, not the outer __ret. Which was the opposite of what
I thought was supposed to happen.
We can fix this, of course. Something like ...
#define ___wait_event_freezable_timeout(wq_head, condition, timeout, ret) \
___wait_event(wq_head, ___wait_cond_timeout(condition, ret), \
TASK_INTERRUPTIBLE, 0, timeout, \
ret = freezable_schedule_timeout(ret), ret)
#define __wait_event_freezable_timeout(wq_head, condition, timeout) \
___wait_event_freezable_timeout(wq_head, condition, timeout, UNIQUE_ID)
... and now all the 'ret' refer to the thing that they look like they're
referring to.
next prev parent reply other threads:[~2022-03-02 18:44 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-02 4:34 [PATCH 00/19] Enable -Wshadow=local for kernel/sched 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 [this message]
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
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=Yh+67VF0/OFSp15y@casper.infradead.org \
--to=willy@infradead.org \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=keescook@chromium.org \
--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 \
/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