From nobody Tue Jun 16 12:43:31 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 4CCAA13B584 for ; Mon, 20 Apr 2026 03:56:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776657415; cv=none; b=UHcgbJLhtR+6XoGSx4AH1MTRhIcvw8MK9P5NfLRHOQnCL/c/72E5rXJbD330hpQ06zYbusyQEsyxKWbIjsBtz7f4d6/kuulhE4RrfpiXNn+DJ+ExVOr2IHt26OuJcZ9Yvr9un5qMDsLFJrOH3ljVWkzdO5Gmx600ISdlYVTPxKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776657415; c=relaxed/simple; bh=CPL9C3DOrCuBOfPZ1meRAqIwv+6lKuQTMnf5xulDzd4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=QaGbvewzRfSzqICmbaP5txU9N500A1XeLR90as4dauqjpJBMtQw0pgzYZw3cnmIyFn0VzHQM0BxplJX9EB6c/qor5fWQD/+IqMBEqU8bryyJ2YwvoIxoebDI1pH4UUHt1Y0vfQEPLV69Es65SAV9SFQwC+mYAuRD+ZvZDrj8mMA= 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=akemfgSs; arc=none smtp.client-ip=209.85.210.178 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="akemfgSs" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-82fb2d0c5d1so333991b3a.0 for ; Sun, 19 Apr 2026 20:56:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776657414; x=1777262214; 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=WTfxrUjUGYbPZHY/a+J5CZ0Xndiokl52ZuC/OYTjXsQ=; b=akemfgSs6eR3aW65cQCDs3IGl0ZyMzYlizhXsiGckExXhNP9SQA8ivMOljExWpFZyi niJjKp/PrMNVZE963o+NzpP+/ddgPOpLMIyxBT8so/zYM130rsLLn05gnsVMRqUNkhYp YUuRRsP7rwsXK2ZxsybScgmtjMk/S222nt4UsZJXMxpcnWzFYyU6xzDKbjsiJReTJBuz tlWyAalZBQRBF/bmCdNpc7Ncv9rG/Wns3WFudOCXSZzcCQ1MwTnqtWz96pcoxD8QArzi RsY1VjwKCy4eGYf9Jw0K5Bq+O9Q2sYBlKnyugNolfO8uN9iM/hyZscI4H9klz2bfxIsB +ubw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776657414; x=1777262214; 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=WTfxrUjUGYbPZHY/a+J5CZ0Xndiokl52ZuC/OYTjXsQ=; b=dHXYy/NsHzIos4up2RCxEhTzby6GrrOin7zGoIxueb/e1by6KxqQgVI0knim59QuNw JYthWZZt9l8XN6e1+z4s5OuNgl9X724K9xIgZMogf4SEGwL4iLgAntOqTMprGiC4fNBB pZcknQGqhyv4rhQ4dwl2xmo+Bw7rsSyVz6Ur6SIL6R73liwPsuvQ6fnCOR2ev4ytIz3M o+jJxPFDD7LxCpRZxqONG3lpX2e+A5TL1DMU2uG6KrqOcCOkHd9qV0oknmjqOUDTMwzs 1nRYKXYWES+NtiTjDOUni33u3PDnEzDDAQop+Y/0s3XLT9ywHoEa3pEU/Dt5Jlj1lDGI nEXA== X-Forwarded-Encrypted: i=1; AFNElJ/Y2q33Hu0jUI17qyYtVTEhFeD9QQ6izkhM2YtwQpcXgmGq/0D4SyGK9dvJfKVIGWL5rwu9/Bcv9Pd81wk=@vger.kernel.org X-Gm-Message-State: AOJu0YyoueLdyxfAYBzyz0Uqlo32XerlvrFQYe3EjQuzBp2I4AeKdGU/ xwll8+0yCfIvLiMd3yMKGJkhY0/NTbkH31e+E+6vjTQNqu3XyBPOgr89 X-Gm-Gg: AeBDiethXI0MqyNTZmqo09koWhTSsgh+gbwbyYx7SJ9EpxThv6Z/wmlz90izU3deSb6 hkBy9mC/2Mk7ozBxNd8QW9V+DbHeywTtulW/c0QjzhJOEBBVf4oX7oj3NkGqRoSWy2Q0C0RJRtv HltPRpP+KboZluYIYPS+wZ5tQdneJdK/zxyGKmcgjCnw7XyTLMEV+S7AVVZr5A89T5Tnphm3ljq pomK9MwfueKLd05H4GIqc0mx7oyNgugzR3eci6pNBU/BxHQqk6EcOi4xLCaBHJiRFzVK00kp5jn HUIGdGDJVFyqz8uRrGH2/YLPhxq423zC3SFRgnTMoBusGErv3X7sgh/KgwucrBiMhlA+BARfug+ fNTGxu11n/IfzOrmz0+uEYVxh7V5cUtbcbdGePbanmHdoQGnNruTJdIctq0JQzsalMjDtOSgh3Y 61UDQVlCx6CnbjChbiXsIWhxi9eU6/Sg1UbmWZCIuGWVHBKT04nAfO0TFHu1kxk24Cznqu1/d16 q7hfH/D+ljpAQ== X-Received: by 2002:a05:6a20:3c89:b0:3a2:cbd1:11f with SMTP id adf61e73a8af0-3a2cbd1126dmr1600834637.5.1776657413704; Sun, 19 Apr 2026 20:56:53 -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-c797704c332sm6534019a12.30.2026.04.19.20.56.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2026 20:56:53 -0700 (PDT) From: zhidao su X-Google-Original-From: zhidao su To: Tejun Heo , David Vernet Cc: Andrea Righi , Changwoo Min , sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, zhidao su Subject: [PATCH v2] sched_ext: Honor SCX_OPS_ALWAYS_ENQ_IMMED on framework-internal goto-local paths Date: Mon, 20 Apr 2026 11:56:46 +0800 Message-ID: <20260420035646.1715762-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable SCX_OPS_ALWAYS_ENQ_IMMED promises that SCX_ENQ_IMMED is set on all local DSQ enqueues. scx_vet_enq_flags() enforces this for BPF kfunc callers (scx_bpf_dsq_insert, scx_bpf_dsq_move_*), but the framework-internal goto-local paths in do_enqueue_task() =E2=80=94 PF_EXITING, migration-disab= led, and !scx_rq_online fallbacks =E2=80=94 bypass scx_vet_enq_flags() entirely. When a scheduler sets SCX_OPS_ALWAYS_ENQ_IMMED, tasks hitting these goto-local paths arrive at dispatch_enqueue() without SCX_ENQ_IMMED in enq_flags, violating the flag's documented semantics. This can be observed with trace_printk instrumentation at the enqueue: label while running a multi-threaded fork-exit workload under a scheduler with SCX_OPS_ALWAYS_ENQ_IMMED: Before (scx_simple + ALWAYS_ENQ_IMMED, 2 CPUs, mmap-contention exit): 95 PF_EXITING local enqueues, 95/95 IMMED=3D0 ALW=3D1 <-- bug After: 1030 PF_EXITING local enqueues, 1030/1030 IMMED=3D1 ALW=3D1 <-- fixed Fix by checking SCX_OPS_ALWAYS_ENQ_IMMED at the enqueue: label and setting SCX_ENQ_IMMED when dispatching to a local DSQ. This mirrors what scx_vet_enq_flags() does for BPF callers. Fixes: 3229ac4a5ef5 ("sched_ext: Add SCX_OPS_ALWAYS_ENQ_IMMED ops flag") Signed-off-by: zhidao su --- v2: Resend to correct a submission error in v1 where unrelated files were accidentally included in the patch. The code change is identical; only kernel/sched/ext.c is modified. Apologies for the noise. --- kernel/sched/ext.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 9628c64e5592..0758f5e5a8f0 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -1859,7 +1859,9 @@ static void do_enqueue_task(struct rq *rq, struct tas= k_struct *p, u64 enq_flags, * Clear persistent TASK_IMMED for fresh enqueues, see dsq_inc_nr(). * Note that exiting and migration-disabled tasks that skip * ops.enqueue() below will lose IMMED protection unless - * %SCX_OPS_ENQ_EXITING / %SCX_OPS_ENQ_MIGRATION_DISABLED are set. + * %SCX_OPS_ENQ_EXITING / %SCX_OPS_ENQ_MIGRATION_DISABLED are set, + * or %SCX_OPS_ALWAYS_ENQ_IMMED is enabled (which re-applies IMMED + * at the enqueue: label below). */ p->scx.flags &=3D ~SCX_TASK_IMMED; =20 @@ -1949,6 +1951,17 @@ static void do_enqueue_task(struct rq *rq, struct ta= sk_struct *p, u64 enq_flags, */ touch_core_sched(rq, p); refill_task_slice_dfl(sch, p); + + /* + * Honor %SCX_OPS_ALWAYS_ENQ_IMMED for framework-internal local DSQ + * enqueues (PF_EXITING, migration-disabled, !online fallbacks). + * scx_vet_enq_flags() already handles this for BPF kfunc callers, + * but the goto-local paths above bypass it. + */ + if ((sch->ops.flags & SCX_OPS_ALWAYS_ENQ_IMMED) && + dsq =3D=3D &rq->scx.local_dsq) + enq_flags |=3D SCX_ENQ_IMMED; + dispatch_enqueue(sch, rq, dsq, p, enq_flags); } =20 --=20 2.43.0