Re: [PATCH] rust: sync: add wait_interruptible_freezable
From: Peter Zijlstra
Date: Mon Feb 03 2025 - 08:39:58 EST
On Mon, Feb 03, 2025 at 12:56:05PM +0100, Alice Ryhl wrote:
> On Mon, Feb 3, 2025 at 12:54 PM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> >
> > On Thu, Jan 30, 2025 at 11:30:44AM +0000, Alice Ryhl wrote:
> > > Binder allows you to freeze a process where some of its threads are
> > > blocked on the Binder driver. To make this work, we need to pass
> > > TASK_FREEZABLE when going to sleep in the appropriate places. Thus, add
> > > a new method wait_interruptible_freezable for the condition variable so
> > > that sleeps where this is supported can be marked as such.
> >
> > The constraint on freezable is that you must not hold locks. There is a
> > lockdep check for this in the code, but it would probably make sense to
> > teach Rust about this constraint as well, hmm?
>
> Unfortunately, I don't think there's any way to enforce this at
> compile time, but I'm definitely happy to add this in the
> documentation.
Ah, ISTR people talking about teaching Rust about the whole raw_spinlock
vs spinlock vs mutex nesting order and figured if it can do that, then
this should be doable too.
But perhaps that never quite happened.
Yes, documentation would be good. Just in case it isn't obviuos,
freezing a task that holds a lock can trivially deadlock vs another task
that needs that lock to complete before it too can hit freezable.