From: Waiman Long <longman@redhat.com>
To: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
"Peter Zijlstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>, "Will Deacon" <will@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] locking/mutex: remove redundant argument from __mutex_lock_common()
Date: Wed, 30 Aug 2023 19:54:13 -0400 [thread overview]
Message-ID: <cdb0df68-ed29-18d2-22af-12253a4ec659@redhat.com> (raw)
In-Reply-To: <76a1d64e683ee9a9f507114dfbc2d5121da8c3f3.1693433504.git.mirq-linux@rere.qmqm.pl>
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.
> Since now __ww_mutex_add_waiter() is called only with ww_mutex != NULL,
> remove the branch there.
>
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---
> kernel/locking/mutex.c | 16 ++++++----------
> kernel/locking/ww_mutex.h | 5 -----
> 2 files changed, 6 insertions(+), 15 deletions(-)
>
> diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
> index d973fe6041bf..2f0e318233f5 100644
> --- a/kernel/locking/mutex.c
> +++ b/kernel/locking/mutex.c
> @@ -568,15 +568,12 @@ EXPORT_SYMBOL(ww_mutex_unlock);
> static __always_inline int __sched
> __mutex_lock_common(struct mutex *lock, unsigned int state, unsigned int subclass,
> struct lockdep_map *nest_lock, unsigned long ip,
> - struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx)
> + struct ww_acquire_ctx *ww_ctx)
> {
> struct mutex_waiter waiter;
> struct ww_mutex *ww;
> int ret;
>
> - if (!use_ww_ctx)
> - ww_ctx = NULL;
> -
That code is probably not needed given the current usage. Perhaps, you
can change it to "WARN_ON_ONCE(ww_ctx && !use_ww_ctx);"
> might_sleep();
>
> MUTEX_WARN_ON(lock->magic != lock);
> @@ -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.
Cheers,
Longman
next prev parent reply other threads:[~2023-08-31 0:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-30 22:12 Michał Mirosław
2023-08-30 23:54 ` Waiman Long [this message]
2023-09-02 17:06 ` Michał Mirosław
2023-09-02 19:40 ` Waiman Long
2023-09-02 20:06 ` Waiman Long
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=cdb0df68-ed29-18d2-22af-12253a4ec659@redhat.com \
--to=longman@redhat.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mirq-linux@rere.qmqm.pl \
--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
all inboxes | Powered by JetHome®