From: Peter Zijlstra <peterz@infradead.org>
To: Waiman Long <longman@redhat.com>
Cc: "Hillf Danton" <hdanton@sina.com>, 马振华 <mazhenhua@xiaomi.com>,
mingo <mingo@redhat.com>, will <will@kernel.org>,
"boqun.feng" <boqun.feng@gmail.com>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [BUG]locking/rwsem: only clean RWSEM_FLAG_HANDOFF when already set
Date: Wed, 10 Nov 2021 22:38:54 +0100 [thread overview]
Message-ID: <20211110213854.GE174703@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <02e118c0-2116-b806-2b48-b9c91dc847dd@redhat.com>
On Sun, Nov 07, 2021 at 02:52:36PM -0500, Waiman Long wrote:
> >
> > I did have a tentative patch to address this issue which is somewhat
> > similar to your approach. However, I would like to further investigate
> > the exact mechanics of the race condition to make sure that I won't miss
> > a latent bug somewhere else in the rwsem code.
>
> I still couldn't figure how this race condition can happen. However, I do
> discover that it is possible to leave rwsem with no waiter but handoff bit
> set if we kill or interrupt all the waiters in the wait queue. I have just
> sent out a patch to address that concern, but it should be able to handle
> this race condition as well if it really happens.
The comment above RWSEM_WRITER_LOCKED seems wrong/out-dated in that
there's a 4th place that modifies the HANDOFF bit namely
rwsem_down_read_slowpath() in the out_nolock: case.
Now the thing I'm most worried about is that rwsem_down_write_slowpath()
modifies the HANDOFF bit depending on wstate, and wstate itself it not
determined under the same ->wait_lock section, so there could be a race
there.
Another thing is that once wstate==HANDOFF, we rely on spin_on_owner()
to return OWNER_NULL such that it goes to trylock_again, however if it
returns anything else then we're at signal_pending_state() and the
observed race can happen.
Now, spin_on_owner() *can* in fact return something else, consider
need_resched() being set for instance.
Combined I think the observed race is valid.
Now before we go make things more complicated, I think we should see if
we can make things simpler. Also I think perhaps the HANDOFF name here
is a misnomer.
I agree that using _andnot() will fix this issue; I also agree with
folding it with the existing _andnot() already there. But let me stare a
little more at this code, something isn't making sense...
next prev parent reply other threads:[~2021-11-10 21:39 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4fafad133b074f279dbab1aa3642e23f@xiaomi.com>
2021-11-07 3:25 ` [BUG]locking/rwsem: only clean RWSEM_FLAG_HANDOFF when already set Waiman Long
2021-11-07 3:28 ` Waiman Long
[not found] ` <20211107090131.1535-1-hdanton@sina.com>
2021-11-07 15:24 ` Waiman Long
2021-11-07 19:52 ` Waiman Long
2021-11-10 21:38 ` Peter Zijlstra [this message]
2021-11-11 2:42 ` Maria Yu
2021-11-11 15:08 ` Peter Zijlstra
2021-11-11 19:14 ` Waiman Long
2021-11-11 19:20 ` Peter Zijlstra
2021-11-11 19:36 ` Waiman Long
2021-11-11 19:52 ` Waiman Long
2021-11-11 20:26 ` Peter Zijlstra
2021-11-11 21:01 ` Waiman Long
2021-11-11 21:25 ` Waiman Long
2021-11-11 21:53 ` Peter Zijlstra
2021-11-11 21:55 ` Waiman Long
2021-11-11 22:00 ` Waiman Long
2021-11-11 21:38 ` Peter Zijlstra
2021-11-11 21:46 ` Waiman Long
2021-11-11 20:35 ` Peter Zijlstra
2021-11-11 20:39 ` Peter Zijlstra
2021-11-11 20:45 ` Waiman Long
2021-11-11 21:27 ` Peter Zijlstra
2021-11-11 21:54 ` Waiman Long
2021-11-11 20:50 ` Peter Zijlstra
2021-11-11 21:09 ` Waiman Long
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=20211110213854.GE174703@worktop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=boqun.feng@gmail.com \
--cc=hdanton@sina.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mazhenhua@xiaomi.com \
--cc=mingo@redhat.com \
--cc=will@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.