]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
watchdog/softlockup: fix sample ring index wrap in need_counting_irqs()
authorShengming Hu <hu.shengming@zte.com.cn>
Mon, 19 Jan 2026 13:59:05 +0000 (21:59 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 8 Feb 2026 08:13:34 +0000 (00:13 -0800)
cpustat_tail indexes cpustat_util[], which is a NUM_SAMPLE_PERIODS-sized
ring buffer. need_counting_irqs() currently wraps the index using
NUM_HARDIRQ_REPORT, which only happens to match NUM_SAMPLE_PERIODS.

Use NUM_SAMPLE_PERIODS for the wrap to keep the ring math correct even if
the NUM_HARDIRQ_REPORT or  NUM_SAMPLE_PERIODS changes.

Link: https://lkml.kernel.org/r/tencent_7068189CB6D6689EB353F3D17BF5A5311A07@qq.com
Fixes: e9a9292e2368 ("watchdog/softlockup: Report the most frequent interrupts")
Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Zhang Run <zhang.run@zte.com.cn>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/watchdog.c

index b4d5fbdb933a2f9b56de72e64799cf774e8f23c8..7d675781bc917d709aa3fb499629eeac86934f55 100644 (file)
@@ -550,7 +550,7 @@ static bool need_counting_irqs(void)
        u8 util;
        int tail = __this_cpu_read(cpustat_tail);
 
-       tail = (tail + NUM_HARDIRQ_REPORT - 1) % NUM_HARDIRQ_REPORT;
+       tail = (tail + NUM_SAMPLE_PERIODS - 1) % NUM_SAMPLE_PERIODS;
        util = __this_cpu_read(cpustat_util[tail][STATS_HARDIRQ]);
        return util > HARDIRQ_PERCENT_THRESH;
 }