mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: David Laight <David.Laight@ACULAB.COM>,
	'Hernan Ponce de Leon' <hernan.poncedeleon@huaweicloud.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: "paulmck@kernel.org" <paulmck@kernel.org>,
	Arjan van de Ven <arjan@linux.intel.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"will@kernel.org" <will@kernel.org>,
	"boqun.feng@gmail.com" <boqun.feng@gmail.com>,
	"akpm@osdl.org" <akpm@osdl.org>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"joel@joelfernandes.org" <joel@joelfernandes.org>,
	"stern@rowland.harvard.edu" <stern@rowland.harvard.edu>,
	"diogo.behrens@huawei.com" <diogo.behrens@huawei.com>,
	"jonas.oberhauser@huawei.com" <jonas.oberhauser@huawei.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Hernan Ponce de Leon <hernanl.leon@huawei.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	Jonas Oberhauser <jonas.oberhauser@huaweicloud.com>
Subject: Re: [PATCH] Fix data race in mark_rt_mutex_waiters
Date: Thu, 26 Jan 2023 20:46:45 -0500	[thread overview]
Message-ID: <4122ef0d-1508-8ce2-df80-874565a612ce@redhat.com> (raw)
In-Reply-To: <004045af7a2b4abaa5f4d9840371da60@AcuMS.aculab.com>


On 1/26/23 17:10, David Laight wrote:
> From: Hernan Ponce de Leon
>> Sent: 26 January 2023 21:07
> ...
>>    static __always_inline void rt_mutex_clear_owner(struct rt_mutex_base
>> *lock)
>> @@ -232,12 +232,7 @@ static __always_inline bool
>> rt_mutex_cmpxchg_release(struct rt_mutex_base *lock,
>>     */
>>    static __always_inline void mark_rt_mutex_waiters(struct rt_mutex_base
>> *lock)
>>    {
>> -	unsigned long owner, *p = (unsigned long *) &lock->owner;
>> -
>> -	do {
>> -		owner = *p;
>> -	} while (cmpxchg_relaxed(p, owner,
>> -				 owner | RT_MUTEX_HAS_WAITERS) != owner);
>> +	atomic_long_or(RT_MUTEX_HAS_WAITERS, (atomic_long_t *)&lock->owner);
> These *(int_type *)&foo accesses (quite often just plain wrong)
> made me look up the definitions.
>
> All one big accident waiting to happen...
> RT_MUTEX_HAS_WAITERS is defined in a different header to the structure.
> The explanatory comment is in a 3rd file.
>
> It would all be safer if lock->owner were atomic_long_t with a comment
> that it was the waiting task_struct | RT_MUTEX_HAS_WAITERS.
>
> Given the actual definition is rt_mutex_base_is_locked() even correct?

It is arguable if it should be considered locked if a waiter is waiting 
but the lock is at an unlock state at the moment. Mutex has a narrower 
definition of locked while others have a broader one.

Cheers,
Longman


  reply	other threads:[~2023-01-27  1:47 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
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 [this message]
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=4122ef0d-1508-8ce2-df80-874565a612ce@redhat.com \
    --to=longman@redhat.com \
    --cc=David.Laight@ACULAB.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=jonas.oberhauser@huaweicloud.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®