Re: [patch V5 16/26] signal: Replace resched_timer logic

From: Frederic Weisbecker
Date: Tue Oct 29 2024 - 13:56:21 EST


Le Tue, Oct 29, 2024 at 05:55:38PM +0100, Thomas Gleixner a écrit :
> On Tue, Oct 29 2024 at 17:34, Frederic Weisbecker wrote:
>
> > Le Tue, Oct 29, 2024 at 05:22:17PM +0100, Thomas Gleixner a écrit :
> >> On Tue, Oct 29 2024 at 16:56, Frederic Weisbecker wrote:
> >> >> @@ -568,10 +568,10 @@ static void collect_signal(int sig, stru
> >> >> list_del_init(&first->list);
> >> >> copy_siginfo(info, &first->info);
> >> >>
> >> >> - *resched_timer = (first->flags & SIGQUEUE_PREALLOC) &&
> >> >> - (info->si_code == SI_TIMER);
> >> >> -
> >> >> - __sigqueue_free(first);
> >> >> + if (unlikely((first->flags & SIGQUEUE_PREALLOC) && (info->si_code == SI_TIMER)))
> >> >> + *timer_sigq = first;
> >> >> + else
> >> >> + __sigqueue_free(first);
> >> >
> >> > So this isn't calling __sigqueue_free() unconditionally anymore. What if
> >> > the timer has been freed already, what is going to free the sigqueue?
> >>
> >> __sigqueue_free() does not free timers marked with SIGQUEUE_PREALLOC.
> >>
> >> sigqueue_free() takes care of that, which is invoked from
> >> posixtimer_free_timer(). It clears SIGQUEUE_PREALLOC and if it is queued
> >> it lets it pending and delivery will free it.
> >
> > But the delivery freeing used to be done with the __sigqueue_free()
> > above, which doesn't happen anymore, right?
>
> It still happens because SIGQUEUE_PREALLOC is cleared in sigqueue_free()
>
> __sigqueue_free() has
> if (q->flags & PREALLOC)
> return;
>
> So the old code called __sigqueue_free() unconditionally which just
> returned. But now we have a condition to that effect already, so why
> call into __sigqueue_free() for nothing?

1) Signal is queued
2) Timer is deleted, sigqueue() clears SIGQUEUE_PREALLOC but doesn't go
further because the sigqueue is queued
3) Signal is collected and delivered but it's not calling __sigqueue_free()
so the sigqueue is not released.

This is "fixed" on the subsequent patch which uses embedded sigqueue and
rcuref but this patch alone breaks.

Or am I missing something that prevents it?

Thanks.