Re: [PATCH] tick/sched: fix data races at tick_do_timer_cpu

From: Peter Zijlstra
Date: Wed Mar 04 2020 - 04:56:56 EST


On Wed, Mar 04, 2020 at 10:39:41AM +0100, Thomas Gleixner wrote:
> Qian,
>
> Qian Cai <cai@xxxxxx> writes:
> > tick_do_timer_cpu could be accessed concurrently where both plain writes
> > and plain reads are not protected by a lock. Thus, it could result in
> > data races. Fix them by adding pairs of READ|WRITE_ONCE(). The data
> > races were reported by KCSAN,
>
> They are reported, but are they actually a real problem?
>
> This completely lacks analysis why these 8 places need the
> READ/WRITE_ONCE() treatment at all and if so why the other 14 places
> accessing tick_do_timer_cpu are safe without it.
>
> I definitely appreciate the work done with KCSAN, but just making the
> tool shut up does not cut it.

Worse:

+ if (cpu != READ_ONCE(tick_do_timer_cpu) &&
+ (READ_ONCE(tick_do_timer_cpu) != TICK_DO_TIMER_NONE ||

Doing that read twice is just utterly stupid. And the patch is full of
that :/

Please stop this non-thinking 'fix' generation!