On Tue, Jan 06, 2026 at 10:21PM +0900, Tetsuo Handa wrote:
> On 2025/12/20 0:39, Marco Elver wrote:
> > Introduce basic compatibility with cleanup.h infrastructure.
> 
> Can Compiler-Based Context- and Locking-Analysis work with conditional guards
> (unlock only if lock succeeded) ?
> 
> I consider that replacing mutex_lock() with mutex_lock_killable() helps 
> reducing
> frequency of hung tasks under heavy load where many processes are preempted 
> waiting
> for the same mutex to become available (e.g.
> https://syzkaller.appspot.com/bug?extid=8f41dccfb6c03cc36fd6 ).
> 
> But e.g. commit f49573f2f53e ("tty: use lock guard()s in tty_io") already 
> replaced
> plain mutex_lock()/mutex_unlock() with plain guard(mutex). If I propose a 
> patch for
> replacing mutex_lock() with mutex_lock_killable(), can I use conditional 
> guards?
> (Would be yes if Compiler-Based Context- and Locking-Analysis can work, would 
> be no
>  if Compiler-Based Context- and Locking-Analysis cannot work) ?

It works for cond guards, so yes. But, only if support for
mutex_lock_killable() is added. At the moment mutex.h only has:

        ...
        DEFINE_LOCK_GUARD_1(mutex, struct mutex, mutex_lock(_T->lock), 
mutex_unlock(_T->lock))
        DEFINE_LOCK_GUARD_1_COND(mutex, _try, mutex_trylock(_T->lock))
        DEFINE_LOCK_GUARD_1_COND(mutex, _intr, 
mutex_lock_interruptible(_T->lock), _RET == 0)

        DECLARE_LOCK_GUARD_1_ATTRS(mutex,       __acquires(_T), 
__releases(*(struct mutex **)_T))
        #define class_mutex_constructor(_T) WITH_LOCK_GUARD_1_ATTRS(mutex, _T)
        DECLARE_LOCK_GUARD_1_ATTRS(mutex_try,   __acquires(_T), 
__releases(*(struct mutex **)_T))
        #define class_mutex_try_constructor(_T) 
WITH_LOCK_GUARD_1_ATTRS(mutex_try, _T)
        DECLARE_LOCK_GUARD_1_ATTRS(mutex_intr,  __acquires(_T), 
__releases(*(struct mutex **)_T))
        #define class_mutex_intr_constructor(_T) 
WITH_LOCK_GUARD_1_ATTRS(mutex_intr, _T)
        ...

And we also have a test in lib/test_context-analysis.c checking it
actually works:

        ...
        scoped_cond_guard(mutex_try, return, &d->mtx) {
                d->counter++;
        }
        scoped_cond_guard(mutex_intr, return, &d->mtx) {
                d->counter++;
        }
        ...

What's missing is a variant for mutex_lock_killable(), but that should
be similar to the mutex_lock_interruptible() variant.

Reply via email to