sched: add wait_var_event_state()

All wait_var_event() sleep in a fixed task state. For coredumps we need
a variant that takes the state from the caller the way
wait_event_state() does. This allows us to continue sleeping with
TASK_FREEZABLE. That's certainly also a useful addition for other places.

Link: https://patch.msgid.link/20260910-work-coredump-unlock-self-v4-11-a5c1800dc930@kernel.org
Reviewed-by: NeilBrown <neil@brown.name>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2026-09-10 17:48:09 +02:00
parent c2fe52e23c
commit 5d075bd77f
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2

View File

@ -432,6 +432,32 @@ do { \
__ret; \
})
/**
* wait_var_event_state - wait for a variable to be updated and notified
* @var: the address of variable being waited on
* @condition: the condition to wait for
* @state: the task state to sleep in, %TASK_UNINTERRUPTIBLE etc.
*
* Wait for a @condition to be true, only re-checking when a wake up is
* received for the given @var (an arbitrary kernel address which need
* not be directly related to the given condition, but usually is).
*
* Returns 0 if the condition became true, or %-ERESTARTSYS if a signal
* arrived which @state allows to interrupt.
*
* The condition should normally use smp_load_acquire() or a similarly
* ordered access to ensure that any changes to memory made before the
* condition became true will be visible after the wait completes.
*/
#define wait_var_event_state(var, condition, state) \
({ \
int __ret = 0; \
might_sleep(); \
if (!(condition)) \
__ret = ___wait_var_event(var, condition, (state), 0, 0, schedule()); \
__ret; \
})
/**
* wait_var_event_any_lock - wait for a variable to be updated under a lock
* @var: the address of the variable being waited on