linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qian Cai <cai@lca.pw>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Will Deacon <will@kernel.org>, Elver Marco <elver@google.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>
Subject: Re: [PATCH -next v2] locking/osq_lock: annotate a data race in osq_lock
Date: Sat, 9 May 2020 09:01:53 -0400	[thread overview]
Message-ID: <9FBC2A17-2821-49F7-9A0F-5E41116BBC70@lca.pw> (raw)
In-Reply-To: <20200509043308.GL2869@paulmck-ThinkPad-P72>



> On May 9, 2020, at 12:33 AM, Paul E. McKenney <paulmck@kernel.org> wrote:
> 
> On Fri, May 08, 2020 at 04:59:05PM -0400, Qian Cai wrote:
>> 
>> 
>>> On Feb 11, 2020, at 8:54 AM, Qian Cai <cai@lca.pw> wrote:
>>> 
>>> prev->next could be accessed concurrently as noticed by KCSAN,
>>> 
>>> write (marked) to 0xffff9d3370dbbe40 of 8 bytes by task 3294 on cpu 107:
>>> osq_lock+0x25f/0x350
>>> osq_wait_next at kernel/locking/osq_lock.c:79
>>> (inlined by) osq_lock at kernel/locking/osq_lock.c:185
>>> rwsem_optimistic_spin
>>> <snip>
>>> 
>>> read to 0xffff9d3370dbbe40 of 8 bytes by task 3398 on cpu 100:
>>> osq_lock+0x196/0x350
>>> osq_lock at kernel/locking/osq_lock.c:157
>>> rwsem_optimistic_spin
>>> <snip>
>>> 
>>> Since the write only stores NULL to prev->next and the read tests if
>>> prev->next equals to this_cpu_ptr(&osq_node). Even if the value is
>>> shattered, the code is still working correctly. Thus, mark it as an
>>> intentional data race using the data_race() macro.
>>> 
>>> Signed-off-by: Qian Cai <cai@lca.pw>
>> 
>> Hmm, this patch has been dropped from linux-next from some reasons.
>> 
>> Paul, can you pick this up along with KCSAN fixes?
>> 
>> https://lore.kernel.org/lkml/1581429255-12542-1-git-send-email-cai@lca.pw/
> 
> I have queued it on -rcu, but it is too late for v5.8 via the -rcu tree,
> so this is v5.9 at the earliest.  Plus I would need an ack from one of
> the locking folks.

Peter, Will, can you give an ACK? This v2 should incorporate all the feedback from Peter,

https://lore.kernel.org/lkml/20200211124753.GP14914@hirez.programming.kicks-ass.net/

V5.9 is fine. All I care about is it is always in linux-next (so the testing bots won’t trigger this over and over again) and to be in mainline at some point in the future.

> 
> 							Thanx, Paul
> 
>>> ---
>>> 
>>> v2: insert some code comments.
>>> 
>>> kernel/locking/osq_lock.c | 6 +++++-
>>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>> 
>>> diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c
>>> index 1f7734949ac8..f733bcd99e8a 100644
>>> --- a/kernel/locking/osq_lock.c
>>> +++ b/kernel/locking/osq_lock.c
>>> @@ -154,7 +154,11 @@ bool osq_lock(struct optimistic_spin_queue *lock)
>>> 	 */
>>> 
>>> 	for (;;) {
>>> -		if (prev->next == node &&
>>> +		/*
>>> +		 * cpu_relax() below implies a compiler barrier which would
>>> +		 * prevent this comparison being optimized away.
>>> +		 */
>>> +		if (data_race(prev->next == node) &&
>>> 		    cmpxchg(&prev->next, node, NULL) == node)
>>> 			break;
>>> 
>>> -- 
>>> 1.8.3.1


  reply	other threads:[~2020-05-09 13:01 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11 13:54 [PATCH -next v2] locking/osq_lock: annotate a data race in osq_lock Qian Cai
2020-05-08 20:59 ` Qian Cai
2020-05-09  4:33   ` Paul E. McKenney
2020-05-09 13:01     ` Qian Cai [this message]
2020-05-09 16:12       ` Paul E. McKenney
2020-05-09 16:53         ` Qian Cai
2020-05-09 21:36           ` Paul E. McKenney
2020-05-11 15:58             ` Will Deacon
2020-05-11 16:43               ` Paul E. McKenney
2020-05-11 16:52                 ` Will Deacon
2020-05-11 17:29                   ` Paul E. McKenney
2020-05-11 17:34                     ` Will Deacon
2020-05-11 18:07                       ` Paul E. McKenney
2020-05-11 16:44               ` Qian Cai
2020-05-11 16:54                 ` Will Deacon
2020-05-11 17:10                   ` Qian Cai

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=9FBC2A17-2821-49F7-9A0F-5E41116BBC70@lca.pw \
    --to=cai@lca.pw \
    --cc=elver@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --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;
as well as URLs for NNTP newsgroup(s).