On Thu, Feb 27, 2025 at 03:06:31PM -0800, Keith Busch wrote:
> From: Sean Christopherson <[email protected]>
>
> A VMM may send a signal to its threads while they've entered KVM_RUN. If
> that thread happens to be trying to make the huge page recovery vhost
> task, then it fails with -ERESTARTNOINTR. We need to retry if that
> happens, so call_once needs to be retryable. Make call_once complete
> only if what it called was successful.
>
> [implemented the kvm user side]
> Signed-off-by: Keith Busch <[email protected]>
...
> diff --git a/include/linux/call_once.h b/include/linux/call_once.h
> index 6261aa0b3fb00..ddcfd91493eaa 100644
> --- a/include/linux/call_once.h
> +++ b/include/linux/call_once.h
> @@ -26,20 +26,26 @@ do {
> \
> __once_init((once), #once, &__key); \
> } while (0)
>
> -static inline void call_once(struct once *once, void (*cb)(struct once *))
> +static inline int call_once(struct once *once, int (*cb)(struct once *))
> {
> + int r;
> +
> /* Pairs with atomic_set_release() below. */
> if (atomic_read_acquire(&once->state) == ONCE_COMPLETED)
> - return;
> + return 0;
>
> guard(mutex)(&once->lock);
> WARN_ON(atomic_read(&once->state) == ONCE_RUNNING);
> if (atomic_read(&once->state) != ONCE_NOT_STARTED)
> - return;
> + return -EINVAL;
Hi Keith,
A minor nit from my side:
As you are changing this line, and it seems like there will be another
revision of this series anyway, please consider updating the indentation to
use tabs.
>
> atomic_set(&once->state, ONCE_RUNNING);
> - cb(once);
> - atomic_set_release(&once->state, ONCE_COMPLETED);
> + r = cb(once);
> + if (r)
> + atomic_set(&once->state, ONCE_NOT_STARTED);
> + else
> + atomic_set_release(&once->state, ONCE_COMPLETED);
> + return r;
> }
>
> #endif /* _LINUX_CALL_ONCE_H */
> --
> 2.43.5
>
>