timers/nohz: Protect idle/iowait sleep time under seqcount
authorFrederic Weisbecker <frederic@kernel.org>
Wed, 22 Feb 2023 14:46:44 +0000 (15:46 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Tue, 18 Apr 2023 14:35:12 +0000 (16:35 +0200)
commit620a30fa0bd14878891b22bf2261e6ed4587c2b4
tree9d193dac68bacb68e34c573819d7c570c96dbc6b
parent07b65a800b6d5b6afbd6a91487b47038eac97c21
timers/nohz: Protect idle/iowait sleep time under seqcount

Reading idle/IO sleep time (eg: from /proc/stat) can race with idle exit
updates because the state machine handling the stats is not atomic and
requires a coherent read batch.

As a result reading the sleep time may report irrelevant or backward
values.

Fix this with protecting the simple state machine within a seqcount.
This is expected to be cheap enough not to add measurable performance
impact on the idle path.

Note this only fixes reader VS writer condition partitially. A race
remains that involves remote updates of the CPU iowait task counter. It
can hardly be fixed.

Reported-by: Yu Liao <liaoyu15@huawei.com>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230222144649.624380-4-frederic@kernel.org
kernel/time/tick-sched.c
kernel/time/tick-sched.h