ring-buffer: Ensure proper resetting of atomic variables in ring_buffer_reset_online_cpus
authorTze-nan Wu <Tze-nan.Wu@mediatek.com>
Wed, 26 Apr 2023 06:20:23 +0000 (14:20 +0800)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Wed, 26 Apr 2023 13:08:53 +0000 (09:08 -0400)
commit7c339fb4d8577792378136c15fde773cfb863cb8
treeec62c8837d1eb448143877c16a092e277e22812d
parentfa359d068574d29e7d2f0fdd0ebe4c6a12b5cfb9
ring-buffer: Ensure proper resetting of atomic variables in ring_buffer_reset_online_cpus

In ring_buffer_reset_online_cpus, the buffer_size_kb write operation
may permanently fail if the cpu_online_mask changes between two
for_each_online_buffer_cpu loops. The number of increases and decreases
on both cpu_buffer->resize_disabled and cpu_buffer->record_disabled may be
inconsistent, causing some CPUs to have non-zero values for these atomic
variables after the function returns.

This issue can be reproduced by "echo 0 > trace" while hotplugging cpu.
After reproducing success, we can find out buffer_size_kb will not be
functional anymore.

To prevent leaving 'resize_disabled' and 'record_disabled' non-zero after
ring_buffer_reset_online_cpus returns, we ensure that each atomic variable
has been set up before atomic_sub() to it.

Link: https://lore.kernel.org/linux-trace-kernel/20230426062027.17451-1-Tze-nan.Wu@mediatek.com
Cc: stable@vger.kernel.org
Cc: <mhiramat@kernel.org>
Cc: npiggin@gmail.com
Fixes: b23d7a5f4a07 ("ring-buffer: speed up buffer resets by avoiding synchronize_rcu for each CPU")
Reviewed-by: Cheng-Jui Wang <cheng-jui.wang@mediatek.com>
Signed-off-by: Tze-nan Wu <Tze-nan.Wu@mediatek.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/ring_buffer.c