From: "Paul E. McKenney" <paulmck@kernel.org>
To: Anna-Maria Behnsen <anna-maria@linutronix.de>,
Frederic Weisbecker <frederic@kernel.org>,
Thomas Gleixner <tglx@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
linux-aio@kvack.org, linux-fsdevel@vger.kernel.org,
io-uring@vger.kernel.org, netdev@vger.kernel.org,
kernel-team@meta.com, "Paul E. McKenney" <paulmck@kernel.org>
Subject: [PATCH 12/12] hrtimer: Apply READ_ONCE() to lockless base->running loads
Date: Fri, 18 Sep 2026 17:14:28 -0700 [thread overview]
Message-ID: <20260919001428.3133388-12-paulmck@kernel.org> (raw)
In-Reply-To: <5dca353c-6b3f-4d01-8808-bef2c0dd7af7@paulmck-laptop>
Updates to base->running are protected by the hrtimer base lock, but some
loads are lockless. Therefore, prevent compiler mischief by applying
READ_ONCE() to the lockless loads.
KCSAN located this issue.
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Anna-Maria Behnsen <anna-maria@linutronix.de>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Thomas Gleixner <tglx@kernel.org>
---
kernel/time/hrtimer.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 91ac2b517637..b3b4776c17a1 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -1997,7 +1997,7 @@ bool hrtimer_active(const struct hrtimer *timer)
base = READ_ONCE(timer->base);
seq = raw_read_seqcount_begin(&base->seq);
- if (timer->is_queued || base->running == timer)
+ if (timer->is_queued || READ_ONCE(base->running) == timer)
return true;
} while (read_seqcount_retry(&base->seq, seq) || base != READ_ONCE(timer->base));
@@ -2034,7 +2034,7 @@ static void __run_hrtimer(struct hrtimer_cpu_base *cpu_base, struct hrtimer_cloc
lockdep_assert_held(&cpu_base->lock);
debug_hrtimer_deactivate(timer);
- base->running = timer;
+ WRITE_ONCE(base->running, timer);
/*
* Separate the ->running assignment from the ->is_queued assignment.
@@ -2093,7 +2093,7 @@ static void __run_hrtimer(struct hrtimer_cpu_base *cpu_base, struct hrtimer_cloc
raw_write_seqcount_barrier(&base->seq);
WARN_ON_ONCE(base->running != timer);
- base->running = NULL;
+ WRITE_ONCE(base->running, NULL);
}
static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now,
--
2.40.1
prev parent reply other threads:[~2026-09-19 0:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 0:13 [PATCH v2] Fix data races on hrtimer_sleeper ->task field Paul E. McKenney
2026-09-19 0:14 ` [PATCH 01/12] hrtimer: Mark data-racy accesses to " Paul E. McKenney
2026-09-19 0:14 ` [PATCH 02/12] aio: Use accessor for " Paul E. McKenney
2026-09-19 0:14 ` [PATCH 03/12] wait: " Paul E. McKenney
2026-09-19 0:14 ` [PATCH 04/12] io-uring/rw: " Paul E. McKenney
2026-09-19 0:14 ` [PATCH 05/12] futex: Use accessor for hrtimer_sleeper ->task field in waitwake.c Paul E. McKenney
2026-09-19 0:14 ` [PATCH 06/12] timers: Use accessor for hrtimer_sleeper ->task field in sleep_timeout.c Paul E. McKenney
2026-09-19 0:14 ` [PATCH 07/12] net: pktgen: Use accessor for hrtimer_sleeper ->task field Paul E. McKenney
2026-09-19 0:14 ` [PATCH 08/12] rtmutex: " Paul E. McKenney
2026-09-19 0:14 ` [PATCH 09/12] futex: Use accessor for hrtimer_sleeper ->task field in requeue Paul E. McKenney
2026-09-19 0:14 ` [PATCH 10/12] hrtimer: Update hrtimer_resolution only if value changes Paul E. McKenney
2026-09-19 0:14 ` [PATCH 11/12] hrtimer: Mark the hrtimer_sleeper structure's ->task field __private Paul E. McKenney
2026-09-19 0:14 ` Paul E. McKenney [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260919001428.3133388-12-paulmck@kernel.org \
--to=paulmck@kernel.org \
--cc=anna-maria@linutronix.de \
--cc=frederic@kernel.org \
--cc=io-uring@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-aio@kvack.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.