[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_8B422629CF388976D1303D2C5B0720089305@qq.com>
Date: Sun, 25 Feb 2024 11:12:50 +0800
From: linke li <lilinke99@...com>
To:
Cc: lilinke99@...com,
Frederic Weisbecker <frederic@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...nel.org>,
linux-kernel@...r.kernel.org
Subject: [PATCH] tick: use READ_ONCE() to read jiffies in concurrent environment
In function tick_sched_do_timer(), jiffies is read using READ_ONCE()
in line 224, while read directly in line 217
217 if (ts->last_tick_jiffies != jiffies) {
218 ts->stalled_jiffies = 0;
219 ts->last_tick_jiffies = READ_ONCE(jiffies);
220 } else {
221 if (++ts->stalled_jiffies == MAX_STALLED_JIFFIES) {
222 tick_do_update_jiffies64(now);
223 ts->stalled_jiffies = 0;
224 ts->last_tick_jiffies = READ_ONCE(jiffies);
225 }
226 }
There is patch similar to this. commit c1c0ce31b242 ("r8169: fix the KCSAN reported data-race in rtl_tx() while reading tp->cur_tx")
This patch find two read of same variable while one is protected, another
is not. And READ_ONCE() is added to protect.
Signed-off-by: linke li <lilinke99@...com>
---
kernel/time/tick-sched.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 01fb50c1b17e..aa684511c25a 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -214,7 +214,7 @@ static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now)
* If the jiffies update stalled for too long (timekeeper in stop_machine()
* or VMEXIT'ed for several msecs), force an update.
*/
- if (ts->last_tick_jiffies != jiffies) {
+ if (ts->last_tick_jiffies != READ_ONCE(jiffies)) {
ts->stalled_jiffies = 0;
ts->last_tick_jiffies = READ_ONCE(jiffies);
} else {
--
2.39.3 (Apple Git-145)
Powered by blists - more mailing lists