Re: [PATCH v3 11/19] unwind: Add deferred user space unwinding API

From: Peter Zijlstra
Date: Tue Oct 29 2024 - 09:49:39 EST


On Mon, Oct 28, 2024 at 02:47:38PM -0700, Josh Poimboeuf wrote:

> +static void unwind_user_task_work(struct callback_head *head)
> +{
...
> + guard(rwsem_read)(&callbacks_rwsem);
> +
> + for_each_set_bit(i, &pending, UNWIND_MAX_CALLBACKS) {
> + if (callbacks[i])
> + callbacks[i]->func(&trace, cookie, privs[i]);
> + }

I'm fairly sure people will come with pitchforks for that read-lock
there. They scale like shit on big systems. Please use SRCU or somesuch.

> +}
> +
> +int unwind_user_register(struct unwind_callback *callback, unwind_callback_t func)
> +{
> + scoped_guard(rwsem_write, &callbacks_rwsem) {
> + for (int i = 0; i < UNWIND_MAX_CALLBACKS; i++) {
> + if (!callbacks[i]) {
> + callback->func = func;
> + callback->idx = i;
> + callbacks[i] = callback;
> + return 0;
> + }
> + }
> + }
> +
> + callback->func = NULL;
> + callback->idx = -1;
> + return -ENOSPC;
> +}
> +
> +int unwind_user_unregister(struct unwind_callback *callback)
> +{
> + if (callback->idx < 0)
> + return -EINVAL;
> +
> + scoped_guard(rwsem_write, &callbacks_rwsem)
> + callbacks[callback->idx] = NULL;
> +
> + callback->func = NULL;
> + callback->idx = -1;
> +
> + return 0;
> +}