Re: [PATCH] once: Don't use a work queue to reset sleepable static key

From: Reinette Chatre

Date: Thu Jan 08 2026 - 19:34:14 EST


Hi Tony,

On 1/8/26 3:27 PM, Tony Luck wrote:
> Pointless overhead to use a work queue to reset the static key
> for a DO_ONCE_SLEEPABLE() invocation.
>
> Reported-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
> Signed-off-by: Tony Luck <tony.luck@xxxxxxxxx>
> ---
> lib/once.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/lib/once.c b/lib/once.c
> index 2c306f0e891e..d83bdde78ced 100644
> --- a/lib/once.c
> +++ b/lib/once.c
> @@ -93,6 +93,7 @@ void __do_once_sleepable_done(bool *done, struct static_key_true *once_key,
> {
> *done = true;
> mutex_unlock(&once_mutex);
> - once_disable_jump(once_key, mod);
> + BUG_ON(!static_key_enabled(once_key));
> + static_branch_disable(once_key);

Can this be simplified more by disabling once_key with once_mutex held to eliminate the need for the
done boolean? Unless static_branch_disable() is considered to be so slow that it should also be
avoided in sleepable context, deferring to a mutex protected boolean until it completes ...
If "done" boolean is removed this may need an additional check of once_key within
__do_once_sleepable_start() just in case a second caller was blocked on once_mutex.

Reinette