From nobody Wed Jun 17 05:13:07 2026 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 215EA1E98EF for ; Thu, 23 Apr 2026 02:58:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776913119; cv=none; b=VtrWULLQ0wTgu+rGY3z5b1o0DMro/IRol79J85v1vUnpbWVdIbRzcvKq26hB9BRpXUV55mPqNQoCVhwcaIiC2+Hjx9LVs8wh+I/Ff/1jCVoL4HZ3wPpzeqhyZmLJDiLdsvO0tA2JIjRVkLdqC03jNqG0vd+EDWiNLQxcULfZsg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776913119; c=relaxed/simple; bh=4vJ1vQBx5aZxCFhVEV9FaApDcxkF9GOzX3LYImBrYFk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Khz8rOkxbrZx2DfY6PV2QwnRJBGfcsud+1jSXE0R+c/oYNTN1Zdf3CSV+9Syn9tfrDTgTORybUWj3mqpAfpUFOJqg7XjFy9kQ4Kay4x+cQxSQD3alusqIVu1wRu0SirKcrbPO3kmu0roYuuMs2nCZ2teGOO+95c8lcnC5VnqiYM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bvQvjYzX; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bvQvjYzX" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-35fbca04006so3174168a91.1 for ; Wed, 22 Apr 2026 19:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776913117; x=1777517917; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=OkkJORPduwPjHLezrsPZnPFlvN7Sd8ZaerZpPHaabyA=; b=bvQvjYzX/yXA53FTbB3+zK3VYpI9+6u1zQOWQ7cLrwuh6Br94eg0qt5fbiYV0ZpYnI efyo39Q34CbQhwHumxVOIkCEu/U7PJ3DUjvRMcENbsNK5js8+wzflDvxjTkejHvJ9WFN rsDMJRGmaDqFahYCBCHSR5YIjDEA77xR0zUQBjKAfSqdQXOzO8A/LkmHVPrb/FnPBrVs K5VcJaAsv6V4txqdD6egriG5DCmDgY01Wkg6YMjiZmF2cq07D+s9EAdEukMg9siyMXbo YoCCLZTcWCxHP09Dxlp29l6q+KxFXMQ+kz6aur0O5q4tdDZBX2bz5FIxehkBoljX3RV3 YpWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776913117; x=1777517917; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OkkJORPduwPjHLezrsPZnPFlvN7Sd8ZaerZpPHaabyA=; b=qJGII+wzA5FQwlVFWdtdo8//i2Rh2a40/8xEAsh+NNw60X8YYKJS+Wk+Bq+B+5oZXX fcPAvA0ZZ0aAi/p9MoSwLbwJUtzF4OvEotS4h4EkfuqTFztt83ec2aE7tHSryfd7MH85 2oJTnO8bnMZvYc90HcLPE2msnvmsRz13606QARv1io5Q5B20af/zfCFa0NkICzf07vHq oEVEqakBYFBe/UUV1iDO0h5WotCBkWk+TmUfW7DccSzIMhI+UKZlNH8MEpbZmT5KJVQi bZ6dGO/Ue7DHUVKy8psXgC0gWeBJLloJ2KygEDzjZLtI9QAS7YWpK1zFXwi7TaO5aWtT 6A/Q== X-Forwarded-Encrypted: i=1; AFNElJ9Rb1gJfK0C7EZ2brPA5GuCuyGXSCc01OYgqpFyBhhhb1g705Y784JMpaIhv6IP3waJJf5Z3qx5CF0guJk=@vger.kernel.org X-Gm-Message-State: AOJu0Yywd0YC/fx1ogWgP06trtMzZ4Oq/LtQKX83K90/r3pp3gucBX2t N+vbTdMtV5Lny1av3T/hsZ3u+y7rX2/P1yaL/nEvWk41KdFugojNm+It X-Gm-Gg: AeBDievMSQVO23HI2lxe9+5nN8WAqFsZWG8crDIkWEt9NFCHdFFDtVN1U7SXx6hQPWp DAefC5Y2ad+kZSRfvNHkwripB1COQ+vDkSPrJGRV7J2jiWiMRMVkd/3/+UKAtpr8TizjKCilTGD FCu3UXImHllETWLilKY6kJ/OaoMGfLmjX/iRblemHk7NS8pffxA0r/GNyR0QLW/lGA3cDzX6UOo tGjusw0seznZa1/EZBxKFf/h1xl6Lx7jzele6A7RwvhCk06e3qG+x3FedMIpFjClEHrDobhdVI8 OdI3Y/6llo8EBig72hfavpvBSbsTlqsEC3acsa3KE8qD8BoUiF/cE5tT63b2WODj5OOm+2Yc4Fj 7/Snw4yLxrkBXzJPIRNp6tUDGaywCoZR5WDhUiCCN1MCx4McX453EAiSZSlAoeq18lvKIl1MnsR AIq6dHG7xGZXnMrWmgKeux0Oe03BhuFpii6JhzmK6TkouLQoyQFSqhgSE2m5xr16Vwt+JZbN/Vc YN+5RrtoMekrA== X-Received: by 2002:a17:903:c11:b0:2b2:5857:6011 with SMTP id d9443c01a7336-2b5f9f8324dmr182709865ad.19.1776913117469; Wed, 22 Apr 2026 19:58:37 -0700 (PDT) Received: from mi-HP-ProDesk-680-G6-PCI-Microtower-PC.mioffice.cn ([43.224.245.226]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c79770587c1sm14153602a12.32.2026.04.22.19.58.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2026 19:58:37 -0700 (PDT) From: zhidao su X-Google-Original-From: zhidao su To: Tejun Heo , Andrea Righi Cc: David Vernet , Changwoo Min , sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, zhidao su Subject: [PATCH] sched_ext: Fix local_dsq_post_enq() to use task's scheduler in sub-sched Date: Thu, 23 Apr 2026 10:58:32 +0800 Message-ID: <20260423025832.2654840-1-suzhidao@xiaomi.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" local_dsq_post_enq() calls call_task_dequeue() with scx_root instead of the scheduler instance actually managing the task. When CONFIG_EXT_SUB_SCHED is enabled, tasks may be managed by a sub-scheduler whose ops.dequeue() callback differs from root's. Using scx_root causes the wrong scheduler's ops.dequeue() to be consulted: sub-sched tasks dispatched to a local DSQ via scx_bpf_dsq_move_to_local() will have SCX_TASK_IN_CUSTODY cleared but the sub-scheduler's ops.dequeue() is never invoked, violating the custody exit semantics. Fix by adding a 'struct scx_sched *sch' parameter to local_dsq_post_enq() and move_local_task_to_local_dsq(), and propagating the correct scheduler from their callers dispatch_enqueue(), move_task_between_dsqs(), and consume_dispatch_q(). This is consistent with dispatch_enqueue()'s non-local path which already passes 'sch' directly to call_task_dequeue() for global/bypass DSQs. Fixes: ebf1ccff79c4 ("sched_ext: Fix ops.dequeue() semantics") Signed-off-by: zhidao su Reviewed-by: Cheng-Yang Chou --- kernel/sched/ext.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 9628c64e5592..6ab743777a54 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -1467,13 +1467,13 @@ static void call_task_dequeue(struct scx_sched *sch= , struct rq *rq, p->scx.flags &=3D ~SCX_TASK_IN_CUSTODY; } =20 -static void local_dsq_post_enq(struct scx_dispatch_q *dsq, struct task_str= uct *p, - u64 enq_flags) +static void local_dsq_post_enq(struct scx_sched *sch, struct scx_dispatch_= q *dsq, + struct task_struct *p, u64 enq_flags) { struct rq *rq =3D container_of(dsq, struct rq, scx.local_dsq); bool preempt =3D false; =20 - call_task_dequeue(scx_root, rq, p, 0); + call_task_dequeue(sch, rq, p, 0); =20 /* * If @rq is in balance, the CPU is already vacant and looking for the @@ -1606,7 +1606,7 @@ static void dispatch_enqueue(struct scx_sched *sch, s= truct rq *rq, * concurrently in a non-atomic way. */ if (is_local) { - local_dsq_post_enq(dsq, p, enq_flags); + local_dsq_post_enq(sch, dsq, p, enq_flags); } else { /* * Task on global/bypass DSQ: leave custody, task on @@ -2192,7 +2192,8 @@ static void wakeup_preempt_scx(struct rq *rq, struct = task_struct *p, int wake_fl schedule_reenq_local(rq, 0); } =20 -static void move_local_task_to_local_dsq(struct task_struct *p, u64 enq_fl= ags, +static void move_local_task_to_local_dsq(struct scx_sched *sch, + struct task_struct *p, u64 enq_flags, struct scx_dispatch_q *src_dsq, struct rq *dst_rq) { @@ -2212,7 +2213,7 @@ static void move_local_task_to_local_dsq(struct task_= struct *p, u64 enq_flags, dsq_inc_nr(dst_dsq, p, enq_flags); p->scx.dsq =3D dst_dsq; =20 - local_dsq_post_enq(dst_dsq, p, enq_flags); + local_dsq_post_enq(sch, dst_dsq, p, enq_flags); } =20 /** @@ -2433,7 +2434,7 @@ static struct rq *move_task_between_dsqs(struct scx_s= ched *sch, /* @p is going from a non-local DSQ to a local DSQ */ if (src_rq =3D=3D dst_rq) { task_unlink_from_dsq(p, src_dsq); - move_local_task_to_local_dsq(p, enq_flags, + move_local_task_to_local_dsq(sch, p, enq_flags, src_dsq, dst_rq); raw_spin_unlock(&src_dsq->lock); } else { @@ -2486,7 +2487,7 @@ static bool consume_dispatch_q(struct scx_sched *sch,= struct rq *rq, =20 if (rq =3D=3D task_rq) { task_unlink_from_dsq(p, dsq); - move_local_task_to_local_dsq(p, enq_flags, dsq, rq); + move_local_task_to_local_dsq(sch, p, enq_flags, dsq, rq); raw_spin_unlock(&dsq->lock); return true; } --=20 2.43.0