From: Peter Zijlstra <peterz@infradead.org>
To: "Aiqun(Maria) Yu" <quic_aiquny@quicinc.com>
Cc: Waiman Long <longman@redhat.com>, Ingo Molnar <mingo@redhat.com>,
Will Deacon <will@kernel.org>,
linux-kernel@vger.kernel.org, Davidlohr Bueso <dave@stgolabs.net>,
mazhenhua <mazhenhua@xiaomi.com>, Hillf Danton <hdanton@sina.com>
Subject: Re: [PATCH v5] locking/rwsem: Make handoff bit handling more consistent
Date: Tue, 16 Nov 2021 10:14:20 +0100 [thread overview]
Message-ID: <20211116091420.GA174703@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <32b433a1-31f9-14ba-e8f6-87b69c2c4ac9@quicinc.com>
On Tue, Nov 16, 2021 at 10:52:42AM +0800, Aiqun(Maria) Yu wrote:
> On 11/16/2021 9:29 AM, Waiman Long wrote:
> > There are some inconsistency in the way that the handoff bit is being
> > handled in readers and writers.
> >
> > Firstly, when a queue head writer set the handoff bit, it will clear it
> > when the writer is being killed or interrupted on its way out without
> > acquiring the lock. That is not the case for a queue head reader. The
> > handoff bit will simply be inherited by the next waiter.
> >
> > Secondly, in the out_nolock path of rwsem_down_read_slowpath(), both
> > the waiter and handoff bits are cleared if the wait queue becomes empty.
> > For rwsem_down_write_slowpath(), however, the handoff bit is not checked
> > and cleared if the wait queue is empty. This can potentially make the
> > handoff bit set with empty wait queue.
> >
> > To make the handoff bit handling more consistent and robust, extract
> > out handoff bit clearing code into the new rwsem_del_waiter() helper
> > function. The common function will only use atomic_long_andnot() to
> > clear bits when the wait queue is empty to avoid possible race condition.
> we do have race condition needed to be fixed with this change.
Indeed, let me edit the changelog to reflect that. Also, I think, it
needs a Reported-by:.
> > If the first waiter with handoff bit set is killed or interrupted to
> > exit the slowpath without acquiring the lock, the next waiter will
> > inherit the handoff bit.
> >
> > While at it, simplify the trylock for loop in rwsem_down_write_slowpath()
> > to make it easier to read.
> >
> > Fixes: 4f23dbc1e657 ("locking/rwsem: Implement lock handoff to prevent lock starvation")
> > Suggested-by: Peter Zijlstra <peterz@infradead.org>
> > Signed-off-by: Waiman Long <longman@redhat.com>
next prev parent reply other threads:[~2021-11-16 9:14 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-16 1:29 [PATCH v5] locking/rwsem: Make handoff bit handling more consistent Waiman Long
2021-11-16 2:52 ` Aiqun(Maria) Yu
2021-11-16 9:14 ` Peter Zijlstra [this message]
2021-11-16 9:24 ` Peter Zijlstra
2021-11-16 14:52 ` Waiman Long
2021-11-17 13:36 ` Peter Zijlstra
2021-11-23 8:53 ` [tip: locking/urgent] " tip-bot2 for Waiman Long
2022-02-14 15:47 ` Re:[PATCH v5] " chenguanyou
2022-02-14 16:01 ` [PATCH " Greg KH
2022-04-11 18:26 ` john.p.donnelly
2022-04-11 18:40 ` Waiman Long
2022-04-11 21:03 ` john.p.donnelly
2022-04-11 21:07 ` Waiman Long
2022-04-12 16:28 ` john.p.donnelly
2022-04-12 17:04 ` Waiman Long
2022-04-14 10:48 ` Greg KH
2022-04-14 15:18 ` Waiman Long
2022-04-14 15:42 ` Greg KH
2022-04-14 15:44 ` Waiman Long
2022-04-20 13:55 ` john.p.donnelly
2022-04-26 20:21 ` Waiman Long
2022-04-26 21:22 ` john.p.donnelly
2022-02-14 16:22 ` chenguanyou
2022-02-15 7:41 ` [PATCH " Greg KH
2022-02-16 16:30 ` Waiman Long
2022-02-17 15:41 ` chenguanyou
2022-03-14 8:07 ` [PATCH " Greg KH
2022-03-22 2:49 ` chenguanyou
2022-03-24 12:51 ` [PATCH " Greg KH
2022-07-19 0:27 ` Doug Anderson
[not found] ` <20220719104104.1634-1-hdanton@sina.com>
2022-07-19 15:30 ` Doug Anderson
[not found] ` <20220722115510.2101-1-hdanton@sina.com>
2022-07-22 14:02 ` Doug Anderson
[not found] ` <20220723001713.2156-1-hdanton@sina.com>
2022-08-05 17:14 ` Doug Anderson
2022-08-05 19:02 ` Waiman Long
2022-08-05 19:16 ` Doug Anderson
2022-08-30 16:18 ` Doug Anderson
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=20211116091420.GA174703@worktop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=dave@stgolabs.net \
--cc=hdanton@sina.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mazhenhua@xiaomi.com \
--cc=mingo@redhat.com \
--cc=quic_aiquny@quicinc.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox