From: Bart Van Assche <bvanassche@acm.org>
To: Peter Zijlstra <peterz@infradead.org>,
"Puchert, Aaron" <aaron.puchert@sap.com>
Cc: Marco Elver <elver@google.com>,
Aaron Ballman <aaron@aaronballman.com>,
"linux-toolchains@vger.kernel.org"
<linux-toolchains@vger.kernel.org>,
"llvm@lists.linux.dev" <llvm@lists.linux.dev>,
"Paul E. McKenney" <paulmck@kernel.org>,
Boqun Feng <boqun.feng@gmail.com>
Subject: Re: Thread Safety Analysis and the Linux kernel
Date: Thu, 6 Mar 2025 08:18:37 -0800 [thread overview]
Message-ID: <c5e6c203-aa4e-4208-9783-83146c9d49e9@acm.org> (raw)
In-Reply-To: <20250306094752.GC16878@noisy.programming.kicks-ass.net>
On 3/6/25 1:47 AM, Peter Zijlstra wrote:
> That no longer works for the case of:
>
> DEFINE_GUARD_COND(mutex, _try, mutex_trylock(_T))
>
> which expands to have a constructor like:
>
> static inline struct mutex * class_mutex_try_constructor(struct mutex *_T)
> {
> struct mutex * t = ({ void *_t = _T; if (_T && !(mutex_trylock(_T))) _t = NULL; _t; });
> return t;
> }
Hi Peter,
Would it be acceptable to introduce variants of the conditional locking
functions that return the mutex pointer instead of a boolean to indicate
whether or not locking succeeded? Would that be sufficient to change the
type of 't' above from 'struct mutex *' into 'struct mutex *const'? Two
examples of what such functions could look like:
struct mutex *mutex_trylock_ptr(struct mutex *mutex)
__cond_acquires(nonnull, mutex)
{
return mutex_trylock(mutex) ? mutex : NULL;
}
struct mutex *mutex_lock_interruptible_ptr(struct mutex *mutex, int *res)
__cond_acquires(nonnull, mutex)
{
int ret = mutex_lock_interruptible(mutex);
if (res)
*res = ret;
return ret == 0 ? mutex : NULL;
}
Thanks,
Bart.
next prev parent reply other threads:[~2025-03-06 16:18 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-05 11:47 Thread Safety Analysis and the Linux kernel Marco Elver
2025-03-05 23:54 ` Puchert, Aaron
2025-03-06 9:47 ` Peter Zijlstra
2025-03-06 16:18 ` Bart Van Assche [this message]
2025-03-07 8:07 ` Peter Zijlstra
2025-03-07 21:50 ` Puchert, Aaron
2025-03-07 21:46 ` Puchert, Aaron
2025-03-06 10:08 ` Peter Zijlstra
2025-03-06 22:18 ` Puchert, Aaron
2025-03-07 7:59 ` Peter Zijlstra
2025-03-07 14:13 ` Peter Zijlstra
2025-03-06 10:37 ` Peter Zijlstra
2025-03-06 23:14 ` Puchert, Aaron
2025-03-07 8:52 ` Peter Zijlstra
2025-03-07 12:52 ` Peter Zijlstra
2025-03-07 14:22 ` Greg Kroah-Hartman
2025-03-07 14:35 ` Peter Zijlstra
2025-03-08 6:06 ` Greg Kroah-Hartman
2025-03-07 23:03 ` Puchert, Aaron
2025-03-06 17:11 ` Paul E. McKenney
2025-03-06 23:24 ` Puchert, Aaron
2025-03-06 23:44 ` Paul E. McKenney
2025-03-07 17:59 ` Puchert, Aaron
2025-03-07 18:24 ` Paul E. McKenney
2025-03-07 12:00 ` Marco Elver
2025-05-05 13:44 ` Marco Elver
2025-06-05 12:44 ` Marco Elver
2025-09-18 10:37 ` Marco Elver
2025-09-18 11:10 ` Peter Zijlstra
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=c5e6c203-aa4e-4208-9783-83146c9d49e9@acm.org \
--to=bvanassche@acm.org \
--cc=aaron.puchert@sap.com \
--cc=aaron@aaronballman.com \
--cc=boqun.feng@gmail.com \
--cc=elver@google.com \
--cc=linux-toolchains@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.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