Re: [patch V2 8/8] posix-timers: Handle exit in do_exit() completely

From: Thomas Gleixner

Date: Mon Sep 07 2026 - 08:31:00 EST


On Sun, Sep 06 2026 at 18:40, Oleg Nesterov wrote:

> I am still trying to understand this patch, one question for now.
>
> On 09/05, Thomas Gleixner wrote:
>>
>> +void posix_cpu_timers_exit_task(void)
>> {
>> - cleanup_timers(&tsk->posix_cputimers);
>> + posix_cpu_timers_exit_work();
>> +
>> + guard(spinlock_irq)(&current->sighand->siglock);
>> + cleanup_timers(&current->posix_cputimers);
>> }
>
> So it calls posix_cpu_timers_exit_work()
>
>> +static inline void posix_cpu_timers_exit_work(void)
>> +{
>> + /*
>> + * current->flags has PF_EXITING set so this can be done lockless and
>> + * with interrupts enabled as PF_EXITING prevents the interrupt from
>> + * scheduling the work.
>> + */
>> + if (current->posix_cputimers_work.scheduled)
>> + task_work_cancel(current, &current->posix_cputimers_work.work);
>
> ... which does not clear ->scheduled
>
>> void posixtimer_exec(void)
>> {
>> - scoped_guard(spinlock_irq, &current->sighand->siglock)
>> - posix_cpu_timers_exit(current);
>> -
>> + posix_cpu_timers_exit_task();
>
> ... and this looks obviously wrong for posixtimer_exec() ?

Yes.

Thanks,

tglx
---
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -1270,6 +1270,9 @@ static void posix_cpu_timers_work(struct callback_head *work)

static inline void posix_cpu_timers_exit_work(void)
{
+ /* Canceling the work is only valid for exit() but not for exec() */
+ if (!(current->flags & PF_EXITING))
+ return;
/*
* current->flags has PF_EXITING set so this can be done lockless and
* with interrupts enabled as PF_EXITING prevents the interrupt from