]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sched/ext: Prevent update_locked_rq() calls with NULL rq
authorBreno Leitao <leitao@debian.org>
Wed, 16 Jul 2025 17:38:48 +0000 (10:38 -0700)
committerTejun Heo <tj@kernel.org>
Thu, 17 Jul 2025 01:02:12 +0000 (15:02 -1000)
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 <peterz@infradead.org>
Fixes: 18853ba782bef ("sched_ext: Track currently locked rq")
Signed-off-by: Breno Leitao <leitao@debian.org>
Acked-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: stable@vger.kernel.org # v6.15
kernel/sched/ext.c

index b498d867ba210a94128db5bfb17583ac44eb884a..7dd5cbcb7a069deea2789a1bad78d5f21770a6d9 100644 (file)
@@ -1272,7 +1272,8 @@ static inline struct rq *scx_locked_rq(void)
 
 #define SCX_CALL_OP(sch, mask, op, rq, args...)                                        \
 do {                                                                           \
-       update_locked_rq(rq);                                                   \
+       if (rq)                                                                 \
+               update_locked_rq(rq);                                           \
        if (mask) {                                                             \
                scx_kf_allow(mask);                                             \
                (sch)->ops.op(args);                                            \
@@ -1280,14 +1281,16 @@ do {                                                                            \
        } else {                                                                \
                (sch)->ops.op(args);                                            \
        }                                                                       \
-       update_locked_rq(NULL);                                                 \
+       if (rq)                                                                 \
+               update_locked_rq(NULL);                                         \
 } while (0)
 
 #define SCX_CALL_OP_RET(sch, mask, op, rq, args...)                            \
 ({                                                                             \
        __typeof__((sch)->ops.op(args)) __ret;                                  \
                                                                                \
-       update_locked_rq(rq);                                                   \
+       if (rq)                                                                 \
+               update_locked_rq(rq);                                           \
        if (mask) {                                                             \
                scx_kf_allow(mask);                                             \
                __ret = (sch)->ops.op(args);                                    \
@@ -1295,7 +1298,8 @@ do {                                                                              \
        } else {                                                                \
                __ret = (sch)->ops.op(args);                                    \
        }                                                                       \
-       update_locked_rq(NULL);                                                 \
+       if (rq)                                                                 \
+               update_locked_rq(NULL);                                         \
        __ret;                                                                  \
 })