]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sched_ext: Fix scx_kick_pseqs corruption on concurrent scheduler loads
authorAndrea Righi <arighi@nvidia.com>
Mon, 13 Oct 2025 20:36:34 +0000 (22:36 +0200)
committerTejun Heo <tj@kernel.org>
Tue, 14 Oct 2025 20:29:17 +0000 (10:29 -1000)
If we load a BPF scheduler while another scheduler is already running,
alloc_kick_pseqs() would be called again, overwriting the previously
allocated arrays.

Fix by moving the alloc_kick_pseqs() call after the scx_enable_state()
check, ensuring that the arrays are only allocated when a scheduler can
actually be loaded.

Fixes: 14c1da3895a11 ("sched_ext: Allocate scx_kick_cpus_pnt_seqs lazily using kvzalloc()")
Signed-off-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/sched/ext.c

index c645d47124e72aa40762fc8c38791ff1454b03c5..12c9c3595692649f2d6e2566e2d6895e4f214d21 100644 (file)
@@ -4577,15 +4577,15 @@ static int scx_enable(struct sched_ext_ops *ops, struct bpf_link *link)
 
        mutex_lock(&scx_enable_mutex);
 
-       ret = alloc_kick_pseqs();
-       if (ret)
-               goto err_unlock;
-
        if (scx_enable_state() != SCX_DISABLED) {
                ret = -EBUSY;
-               goto err_free_pseqs;
+               goto err_unlock;
        }
 
+       ret = alloc_kick_pseqs();
+       if (ret)
+               goto err_unlock;
+
        sch = scx_alloc_and_add_sched(ops);
        if (IS_ERR(sch)) {
                ret = PTR_ERR(sch);