Skip to content

Commit e14fd98

Browse files
leitaohtejun
authored andcommitted
sched/ext: Prevent update_locked_rq() calls with NULL rq
Avoid invoking update_locked_rq() when the runqueue (rq) pointer is NULL in the SCX_CALL_OP and SCX_CALL_OP_RET macros. Previously, calling update_locked_rq(NULL) with preemption enabled could trigger the following warning: BUG: using __this_cpu_write() in preemptible [00000000] This happens because __this_cpu_write() is unsafe to use in preemptible context. rq is NULL when an ops invoked from an unlocked context. In such cases, we don't need to store any rq, since the value should already be NULL (unlocked). Ensure that update_locked_rq() is only called when rq is non-NULL, preventing calling __this_cpu_write() on preemptible context. Suggested-by: Peter Zijlstra <[email protected]> Fixes: 18853ba ("sched_ext: Track currently locked rq") Signed-off-by: Breno Leitao <[email protected]> Acked-by: Andrea Righi <[email protected]> Signed-off-by: Tejun Heo <[email protected]> Cc: [email protected] # v6.15
1 parent 7980ad7 commit e14fd98

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

kernel/sched/ext.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,30 +1272,34 @@ static inline struct rq *scx_locked_rq(void)
12721272

12731273
#define SCX_CALL_OP(sch, mask, op, rq, args...) \
12741274
do { \
1275-
update_locked_rq(rq); \
1275+
if (rq) \
1276+
update_locked_rq(rq); \
12761277
if (mask) { \
12771278
scx_kf_allow(mask); \
12781279
(sch)->ops.op(args); \
12791280
scx_kf_disallow(mask); \
12801281
} else { \
12811282
(sch)->ops.op(args); \
12821283
} \
1283-
update_locked_rq(NULL); \
1284+
if (rq) \
1285+
update_locked_rq(NULL); \
12841286
} while (0)
12851287

12861288
#define SCX_CALL_OP_RET(sch, mask, op, rq, args...) \
12871289
({ \
12881290
__typeof__((sch)->ops.op(args)) __ret; \
12891291
\
1290-
update_locked_rq(rq); \
1292+
if (rq) \
1293+
update_locked_rq(rq); \
12911294
if (mask) { \
12921295
scx_kf_allow(mask); \
12931296
__ret = (sch)->ops.op(args); \
12941297
scx_kf_disallow(mask); \
12951298
} else { \
12961299
__ret = (sch)->ops.op(args); \
12971300
} \
1298-
update_locked_rq(NULL); \
1301+
if (rq) \
1302+
update_locked_rq(NULL); \
12991303
__ret; \
13001304
})
13011305

0 commit comments

Comments
 (0)