[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZPNrqZokdzpuyAqR@qmqm.qmqm.pl>
Date: Sat, 2 Sep 2023 19:06:49 +0200
From: Michał Mirosław <mirq-linux@...e.qmqm.pl>
To: Waiman Long <longman@...hat.com>
Cc: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>, Will Deacon <will@...nel.org>,
Boqun Feng <boqun.feng@...il.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] locking/mutex: remove redundant argument from
__mutex_lock_common()
On Wed, Aug 30, 2023 at 07:54:13PM -0400, Waiman Long wrote:
> On 8/30/23 18:12, Michał Mirosław wrote:
> > use_ww_ctx is equivalent to ww_ctx != NULL. The one case where
> > use_ww_ctx was true but ww_ctx == NULL leads to the same
> > __mutex_add_waiter() call via __ww_mutex_add_waiter().
> I think ww_mutex_lock() can be called with a NULL ctx. Your patch will
> effectively change those ww_mutex_lock() to be equivalent to mutex_lock().
> So it is a behavioral change.
Isn't ww_mutex_lock() with ctx = NULL expected to behave like mutex_lock()?
> > Since now __ww_mutex_add_waiter() is called only with ww_mutex != NULL,
> > remove the branch there.
[...]
> > @@ -627,12 +624,11 @@ __mutex_lock_common(struct mutex *lock, unsigned int state, unsigned int subclas
> > debug_mutex_lock_common(lock, &waiter);
> > waiter.task = current;
> > - if (use_ww_ctx)
> > - waiter.ww_ctx = ww_ctx;
> > + waiter.ww_ctx = ww_ctx;
> This one is fine.
> > lock_contended(&lock->dep_map, ip);
> > - if (!use_ww_ctx) {
> > + if (!ww_ctx) {
> That change will break ww_mutex.
I see that there is the rt_mutex version that stubs out
__ww_mutex_add_waiter(), but its ww_mutex_lock() doesn't use
__mutex_lock_common() at all. With the RT version out of the picture, we
can see that __ww_mutex_add_waiter(), when passed ww_ctx == NULL, just
forwards the work to __ww_waiter_add() with the same arguments
and returns 0 -- making the path exactly as the !use_ww_ctx branch.
Note: There is a lot of templating-via-preprocessor code here and I
might have missed something. I'll appreciate hints here as maybe it
could be made simpler or better understood.
Best Regards
Michał Mirosław
Powered by blists - more mailing lists