* [PATCH] sched_ext: Use READ_ONCE() for lock-free reads of module param variables
@ 2026-03-05 4:06 zhidao su
0 siblings, 0 replies; 3+ messages in thread
From: zhidao su @ 2026-03-05 4:06 UTC (permalink / raw)
To: linux-kernel, sched-ext; +Cc: tj, void, arighi, changwoo, zhidao su
bypass_lb_cpu() reads scx_bypass_lb_intv_us and scx_slice_bypass_us
without holding any lock, in timer callback context where module
parameter writes via sysfs can happen concurrently:
min_delta_us = scx_bypass_lb_intv_us / SCX_BYPASS_LB_MIN_DELTA_DIV;
^^^^^^^^^^^^^^^^^^^^
plain read -- KCSAN data race
if (delta < DIV_ROUND_UP(min_delta_us, scx_slice_bypass_us))
^^^^^^^^^^^^^^^^^
plain read -- KCSAN data race
scx_bypass_lb_intv_us already uses READ_ONCE() in scx_bypass_lb_timerfn()
and scx_bypass() for its other lock-free read sites, leaving bypass_lb_cpu()
inconsistent. scx_slice_bypass_us has the same lock-free access pattern in
the same function.
Fix both plain reads by using READ_ONCE() to complete the concurrent
access annotation and make the code KCSAN-clean:
min_delta_us = READ_ONCE(scx_bypass_lb_intv_us) / SCX_BYPASS_LB_MIN_DELTA_DIV;
if (delta < DIV_ROUND_UP(min_delta_us, READ_ONCE(scx_slice_bypass_us)))
Signed-off-by: zhidao su <suzhidao@xiaomi.com>
---
kernel/sched/ext.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 1c3170846c84..9a1471ad5ae7 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -4004,8 +4004,8 @@ static u32 bypass_lb_cpu(struct scx_sched *sch, struct rq *rq,
* consider offloading iff the total queued duration is over the
* threshold.
*/
- min_delta_us = scx_bypass_lb_intv_us / SCX_BYPASS_LB_MIN_DELTA_DIV;
- if (delta < DIV_ROUND_UP(min_delta_us, scx_slice_bypass_us))
+ min_delta_us = READ_ONCE(scx_bypass_lb_intv_us) / SCX_BYPASS_LB_MIN_DELTA_DIV;
+ if (delta < DIV_ROUND_UP(min_delta_us, READ_ONCE(scx_slice_bypass_us)))
return 0;
raw_spin_rq_lock_irq(rq);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] sched_ext: Use READ_ONCE() for lock-free reads of module param variables
@ 2026-03-05 6:18 zhidao su
2026-03-05 16:20 ` Tejun Heo
0 siblings, 1 reply; 3+ messages in thread
From: zhidao su @ 2026-03-05 6:18 UTC (permalink / raw)
To: sched-ext
Cc: linux-kernel, tj, void, arighi, changwoo, peterz, mingo,
zhidao su
bypass_lb_cpu() reads scx_bypass_lb_intv_us and scx_slice_bypass_us
without holding any lock, in timer callback context where module
parameter writes via sysfs can happen concurrently:
min_delta_us = scx_bypass_lb_intv_us / SCX_BYPASS_LB_MIN_DELTA_DIV;
^^^^^^^^^^^^^^^^^^^^
plain read -- KCSAN data race
if (delta < DIV_ROUND_UP(min_delta_us, scx_slice_bypass_us))
^^^^^^^^^^^^^^^^^
plain read -- KCSAN data race
scx_bypass_lb_intv_us already uses READ_ONCE() in scx_bypass_lb_timerfn()
and scx_bypass() for its other lock-free read sites, leaving
bypass_lb_cpu() inconsistent. scx_slice_bypass_us has the same
lock-free access pattern in the same function.
Fix both plain reads by using READ_ONCE() to complete the concurrent
access annotation and make the code KCSAN-clean.
Signed-off-by: zhidao su <suzhidao@xiaomi.com>
---
kernel/sched/ext.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 1c3170846c84..9a1471ad5ae7 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -4004,8 +4004,8 @@ static u32 bypass_lb_cpu(struct scx_sched *sch, struct rq *rq,
* consider offloading iff the total queued duration is over the
* threshold.
*/
- min_delta_us = scx_bypass_lb_intv_us / SCX_BYPASS_LB_MIN_DELTA_DIV;
- if (delta < DIV_ROUND_UP(min_delta_us, scx_slice_bypass_us))
+ min_delta_us = READ_ONCE(scx_bypass_lb_intv_us) / SCX_BYPASS_LB_MIN_DELTA_DIV;
+ if (delta < DIV_ROUND_UP(min_delta_us, READ_ONCE(scx_slice_bypass_us)))
return 0;
raw_spin_rq_lock_irq(rq);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] sched_ext: Use READ_ONCE() for lock-free reads of module param variables
2026-03-05 6:18 [PATCH] sched_ext: Use READ_ONCE() for lock-free reads of module param variables zhidao su
@ 2026-03-05 16:20 ` Tejun Heo
0 siblings, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2026-03-05 16:20 UTC (permalink / raw)
To: zhidao su; +Cc: sched-ext, linux-kernel, void, arighi, changwoo, peterz, mingo
Applied to sched_ext/for-7.0-fixes.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-05 16:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05 6:18 [PATCH] sched_ext: Use READ_ONCE() for lock-free reads of module param variables zhidao su
2026-03-05 16:20 ` Tejun Heo
-- strict thread matches above, loose matches on Subject: below --
2026-03-05 4:06 zhidao su
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox