From: Waiman Long <longman@redhat.com>
To: Hernan Ponce de Leon <hernan.poncedeleon@huaweicloud.com>,
paulmck@kernel.org
Cc: Arjan van de Ven <arjan@linux.intel.com>,
peterz@infradead.org, mingo@redhat.com, will@kernel.org,
boqun.feng@gmail.com, akpm@osdl.org, tglx@linutronix.de,
joel@joelfernandes.org, stern@rowland.harvard.edu,
diogo.behrens@huawei.com, jonas.oberhauser@huawei.com,
linux-kernel@vger.kernel.org,
Hernan Ponce de Leon <hernanl.leon@huawei.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] Fix data race in mark_rt_mutex_waiters
Date: Tue, 24 Jan 2023 10:42:24 -0500 [thread overview]
Message-ID: <d1e28124-b7a7-ae19-87ec-b1dcd3701b61@redhat.com> (raw)
In-Reply-To: <f17dcce0-d510-a112-3127-984e8e73f480@huaweicloud.com>
On 1/24/23 09:57, Hernan Ponce de Leon wrote:
>> In the case, the value read is passed into cmpxchg_relaxed(), which
>> checks the value against memory. In this case, as Arjan noted, the only
>> compiler-and-silicon difference between data_race() and READ_ONCE()
>> is that use of data_race() might allow the compiler to do things like
>> tear the load, thus forcing the occasional spurious cmpxchg_relaxed()
>> failure. In contrast, LKMM (by design) throws up its hands when it sees
>> a data race. Something about not being eager to track the
>> idiosyncrasies
>> of many compiler versions.
>>
>> My approach in my own code is to use *_ONCE() unless it causes a visible
>> performance regression or if it confuses KCSAN. An example of the
>> latter
>> can be debug code, in which case use of data_race() avoids suppressing
>> KCSAN warnings (and also false positives, depending).
>
> I understand that *_ONCE() might avoid some compiler optimization and
> reduce performance in the general case. However, if I understand your
> first paragraph correctly, in this particular case data_race() could
> allow the CAS to fail more often, resulting in more spinning
> iterations and degraded performance. Am I right?
>
>>
>> Except that your other email seems to also be arguing that additional
>> ordering is required. So is https://lkml.org/lkml/2023/1/20/702 really
>> sufficient just by itself, or is additional ordering required?
>
> I do not claim that we need to mark the read to add the ordering that
> is needed for correctness (mutual exclusion). What I claim in this
> patch is that there is a data race, and since it can affect ordering
> constrains in subtle ways, I consider it harmful and thus I want to
> fix it.
>
> What I explain in the other email is that if we fix the data race,
> either the fence or the acquire store might be relaxed (because
> marking the read gives us some extra ordering guarantees). If the race
> is not fixed, both the fence and the acquire are needed according to
> LKMM. The situation is different wrt hardware models. In that case the
> tool cannot find any violation even if we don't fix the race and we
> relax the store / remove the fence.
I would suggest to do it as suggested by PeterZ. Instead of set_bit(),
however, it is probably better to use atomic_long_or() like
atomic_long_or_relaxed(RT_MUTEX_HAS_WAITERS, (atomic_long_t *)&lock->owner)
The mutex code stores the lock owner as atomic_long_t. So it is natural
to treat &lock->owner as atomic_long_t here too.
Cheers,
Longman
next prev parent reply other threads:[~2023-01-24 15:46 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-20 13:55 Hernan Ponce de Leon
2023-01-20 14:58 ` Arjan van de Ven
2023-01-20 15:54 ` Paul E. McKenney
2023-01-22 15:24 ` Hernan Ponce de Leon
2023-01-23 16:40 ` Paul E. McKenney
2023-01-23 17:34 ` Alan Stern
2023-01-23 17:48 ` Paul E. McKenney
2023-01-23 20:02 ` Jonas Oberhauser
2023-01-24 14:57 ` Hernan Ponce de Leon
2023-01-24 15:42 ` Waiman Long [this message]
2023-01-24 15:52 ` Peter Zijlstra
2023-01-24 16:04 ` Waiman Long
2023-01-26 9:42 ` Hernan Ponce de Leon
2023-01-26 12:20 ` Peter Zijlstra
2023-01-26 14:20 ` Peter Zijlstra
2023-01-26 21:07 ` Hernan Ponce de Leon
2023-01-26 22:10 ` David Laight
2023-01-27 1:46 ` Waiman Long
2023-03-01 16:32 ` lock_torture results for different patches: Antonio Paolillo
2023-03-06 7:58 ` Hernan Ponce de Leon
2023-03-10 17:11 ` Paul E. McKenney
2023-01-24 16:12 ` [PATCH] Fix data race in mark_rt_mutex_waiters Paul E. McKenney
2023-01-20 16:23 ` Peter Zijlstra
2023-01-20 16:58 ` David Laight
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=d1e28124-b7a7-ae19-87ec-b1dcd3701b61@redhat.com \
--to=longman@redhat.com \
--cc=akpm@osdl.org \
--cc=arjan@linux.intel.com \
--cc=boqun.feng@gmail.com \
--cc=diogo.behrens@huawei.com \
--cc=hernan.poncedeleon@huaweicloud.com \
--cc=hernanl.leon@huawei.com \
--cc=joel@joelfernandes.org \
--cc=jonas.oberhauser@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=tglx@linutronix.de \
--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
all inboxes | Powered by JetHome®