Re: [patch V3 01/18] posix-timers: Ensure that timer initialization is fully visible

From: Frederic Weisbecker
Date: Sat Mar 08 2025 - 16:39:33 EST


Le Sat, Mar 08, 2025 at 05:48:10PM +0100, Thomas Gleixner a écrit :
> Frederic pointed out that the memory operations to initialize the timer are
> not guaranteed to be visible, when __lock_timer() observes timer::it_signal
> valid under timer::it_lock:
>
> T0 T1
> --------- -----------
> do_timer_create()
> // A
> new_timer->.... = ....
> spin_lock(current->sighand)
> // B
> WRITE_ONCE(new_timer->it_signal, current->signal)
> spin_unlock(current->sighand)
> sys_timer_*()
> t = __lock_timer()
> spin_lock(&timr->it_lock)
> // observes B
> if (timr->it_signal == current->signal)
> return timr;
> if (!t)
> return;
> // Is not guaranteed to observe A
>
> Protect the write of timer::it_signal, which makes the timer valid, with
> timer::it_lock as well. This guarantees that T1 must observe the
> initialization A completely, when it observes the valid signal pointer
> under timer::it_lock. sighand::siglock must still be taken to protect the
> signal::posix_timers list.
>
> Reported-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
> Suggested-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>

Reviewed-by: Frederic Weisbecker <frederic@xxxxxxxxxx>