lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250730132457.20a13d71@nimda.home>
Date: Wed, 30 Jul 2025 13:24:57 +0300
From: Onur Özkan <work@...rozkan.dev>
To: "Benno Lossin" <lossin@...nel.org>
Cc: <linux-kernel@...r.kernel.org>, <rust-for-linux@...r.kernel.org>,
 <ojeda@...nel.org>, <alex.gaynor@...il.com>, <boqun.feng@...il.com>,
 <gary@...yguo.net>, <a.hindborg@...nel.org>, <aliceryhl@...gle.com>,
 <tmgross@...ch.edu>, <dakr@...nel.org>, <peterz@...radead.org>,
 <mingo@...hat.com>, <will@...nel.org>, <longman@...hat.com>,
 <felipe_life@...e.com>, <daniel@...lak.dev>, <bjorn3_gh@...tonmail.com>,
 "Lyude" <thatslyude@...il.com>
Subject: Re: [PATCH v5 0/3] rust: add `ww_mutex` support

On Tue, 29 Jul 2025 19:15:12 +0200
"Benno Lossin" <lossin@...nel.org> wrote:

> > - The second note is about how EDEADLK is handled. On the C side, it
> > looks like some code paths may not release all the previously locked
> > mutexes or have a special/custom logic when locking returns EDEADLK
> > (see [3]). So, handling EDEADLK automatically (pointed
> > in [1]) can be quite useful for most cases, but that could also be a
> > limitation in certain scenarios.
> >
> >  I was thinking we could provide an alternative version of each
> > `lock*` function that accepts a closure which is called on the
> > EDEADLK error. This way, we can support both auto-release locks and
> > custom logic for handling EDEADLK scenarios.
> >
> >  Something like this (just a dummy code for demonstration):
> >
> >     ctx.lock_and_handle_edeadlk(|active_locks| {
> >         // user-defined handling here
> >     });
> 
> But this function wouldn't be locking any additional locks, right?
> 
> I think the closure makes sense to give as a way to allow custom code.
> But we definitely should try to get the common use-cases closure-free
> (except of course they run completely custom code to their specific
> use-case).
> 
> We can also try to invent a custom return type that is used instead of
> `Result`. So for example:
> 
>     let a: WwMutex<'_, A>;
>     let b: WwMutex<'_, B>;
>     let ctx: WwAcquireCtx<'_>;
> 
>     ctx.enter()             // EnteredContext<'_, ()>
>         .lock(a)            // LockAttempt<'_, A, ()>
>         .or_err(a)?         // EnteredContext<'_, (A,)>
>         .lock(b)            // LockAttempt<'_, B, (A,)>
>         .or_lock_slow(a, b) // Result<EnteredContext<'_, (A, B,)>>
>         ?.finish()          // (WwMutexGuard<'_, A>, WwMutexGuard<'_,
> B>)
> 
> But no idea if this is actually useful...

That wouldn't work if the user wants to lock `a` and `b` in separate
calls, right? If user wants to lock `a` right away and lock `b` later
under certain conditions (still in the same context as `a`), then to
automatically release `a`, we have to keep the locked mutexes in some
dynamic list inside `EnteredContext` so we can access all the locked
mutexes when we want to unlock them on EDEADLK.

> 
> 
> What I think would be a good way forward would be to convert some
> existing C uses of `WwMutex` to the intended Rust API and see how it
> looks. Best to cover several different kinds of uses.

Good idea. I will try find sometime to do that during next week.


Regards,
Onur

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ