Re: [PATCH 1/6] posix-cpu-timers: Fix rearm racing against process tick

From: Peter Zijlstra
Date: Fri Jun 11 2021 - 07:49:19 EST


On Wed, Jun 09, 2021 at 01:54:00PM +0200, Frederic Weisbecker wrote:
> On Fri, Jun 04, 2021 at 01:31:54PM +0200, Frederic Weisbecker wrote:
> > Since the process wide cputime counter is started locklessly from
> > posix_cpu_timer_rearm(), it can be concurrently stopped by operations
> > on other timers from the same thread group, such as in the following
> > unlucky scenario:
> >
> > CPU 0 CPU 1
> > ----- -----
> > timer_settime(TIMER B)
> > posix_cpu_timer_rearm(TIMER A)
> > cpu_clock_sample_group()
> > (pct->timers_active already true)
> >
> > handle_posix_cpu_timers()
> > check_process_timers()
> > stop_process_timers()
> > pct->timers_active = false
> > arm_timer(TIMER A)
> >
> > tick -> run_posix_cpu_timers()
> > // sees !pct->timers_active, ignore
> > // our TIMER A
> >
> > Fix this with simply locking process wide cputime counting start and
> > timer arm in the same block.
> >
> > Signed-off-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
> > Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
> > Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> > Cc: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> > Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> > Cc: Eric W. Biederman <ebiederm@xxxxxxxxxxxx>
>
> Fixes: 60f2ceaa8111 ("posix-cpu-timers: Remove unnecessary locking around cpu_clock_sample_group")
> Cc: stable@xxxxxxxxxxxxxxx

Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>


Problem seems to be calling cpu_clock_sample_group(.start = true)
without sighand locked. Do we want a lockdep assertion for that?