Commit 05e63305 authored by Andrea Righi's avatar Andrea Righi Committed by Tejun Heo
Browse files

sched_ext: Fix scx_kick_pseqs corruption on concurrent scheduler loads



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: 14c1da38 ("sched_ext: Allocate scx_kick_cpus_pnt_seqs lazily using kvzalloc()")
Signed-off-by: default avatarAndrea Righi <arighi@nvidia.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent 14c1da38
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -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);