From nobody Thu Apr 2 18:53:49 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 C6C7C3A6F07 for ; Thu, 26 Mar 2026 20:42:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774557770; cv=none; b=H6RiuoiV24DtwBYDIgn6Pi+B9HFGJOUlIfbr3fCSwsFi7PEg6yjgkBWIypQU8bM3+YtLtGKO3cmqh2IYQvRS3pvQUqWt8OZsqp3gC58LMlkcjyvTDvQAZ3IBWrXSF1tRuKH7PcS10Kdwr75SII+nXCCdD98pIK+TTwzYHDKdCFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774557770; c=relaxed/simple; bh=sjr0pvglsqscc3vE3CGBUirkr1tZeu6bXqIK38JFGYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lT/BLSPDPaceshs7TpRYrcEuJYpuUEzVB4cAf1CppxmBFyEwMeE4QLDf7/bokvgi+OEyuOjwu5eWNKTGaviOLAFrAq9r75OfAuE4zZ5Jk9+8EGLQQiCw7kGr07fuGtML9S5V0iGYIOz4UyVK3RwgRrNYu80ZoIwRWV0jJq5x/zY= 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=BLXDI7Kn; arc=none smtp.client-ip=209.85.214.180 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="BLXDI7Kn" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2ab39b111b9so6334165ad.1 for ; Thu, 26 Mar 2026 13:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774557768; x=1775162568; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7/EjjtWJV/7DiKNlIfPwibx36CB9xJaEZVo+QaHyNNU=; b=BLXDI7KnGBiXTnPaaLMWueM11ZZ6pG1yCO7KgAayOZ0+FIQoFnhOjlzgf7TCXw+36J FGm3wMyNJi5t9iFmpuXbb9w+twpqB7jTbaX9BIzdoTvxFpjpdgLmRnzYC/0tlbW5RV0S hsXSOddSkZy0CObhAzj3YDvNAoDmWDNrRnXftdcdCBfsSYOgSncLiaXuS5JdcKaAGEA+ zQ0vToYI+4NNvs4eVH9wCecn3UPQ+v1v8PwPMepc82FVBxyGDDsmIa8hH+isY9zMbz0C wTjJN6bN0vcysmEuTWNZSWtgCZea8N+y50ysqI3/NjfRnwtdXZYqlOniX08zbIji38Q5 8ozA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774557768; x=1775162568; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7/EjjtWJV/7DiKNlIfPwibx36CB9xJaEZVo+QaHyNNU=; b=bOTdxy4IO0p/kVBUVOLxMBLywH6w1mNuk77pEoBVPr4umyiKFnyX9D+VHNR1bWgNP1 /LI5UVJ3TLGE35KqH/tK6iqdUdIt9FHUAZBqfNjADLpcLW14U/p/uqQ88FHVtQRHh0xr WIPuVH6My87fgpaRCp7bwUYulTXSrN/U6XqxXkHf91jY6RF/r/8XPlqEVAtITcWZIZKb A2f2mokpgjz71xTml3+E5HMFYcobfz91jEpMUNpgbXXpZ2GQeN6bSmbAiUi56lCtZtj7 V260p4L7k3O97bzduPyCw1UsLObsig9emQKxM33H5xC0spUy6AQ+7T3Gra/1nVd8kqSO i8bg== X-Gm-Message-State: AOJu0YzG4Q91uExu7tHtettOJydYjK1sX/s9BX9mk2ofRbWSAp9KfmwU H6TPR+49ZYQEq8fQoUNACvBT6/gmIdIKnJ0AqHpUvlouskfIrnePNrIj X-Gm-Gg: ATEYQzx3n7Oraq5Vyyt6sS9MUgyplflLKSAaFBj8N3NU5940lZ6xRy9LehDu+hFXAWx wyUxIjMSoPR0/8CtQ3Kcr+uOCyvB+BMe/W//cXVa8wMDho/kvXUEcdQkkwGFtKIAL0S/xVypatu 8xCt6WjzikUuTwnZizDt7QLqV0K4BkGIXhVpQbfro1Kcf6IpFQivFOiAt/mUKOwqgK9HNFgVC7t lvWxMoxyangZOZjmYeCGgNRTkekJB2sWbc60iEki/NPvqWVjshj85Ma+E00BHI7UkdMPtJpVnKB DLaQGNopZjId19VyDwxOJxFYJdySOCznLSGw+c1uTMD/9E/Br1p0gaHUTejlz7muR4RbUgEFnex XIkKkO95mrE4OSw08o16+AbHb2UjVSOTadElXOKW7dk0e/CDUU2DDk0o+etGQI1IN/eshTLc9mH HAfBFz22w1UG+t0OSDK+P45vuXgCgN1qXg4FFRfNKPcPFRrmOAH6DNYt8R4BI2ydzX7xaDqklgU zw= X-Received: by 2002:a17:903:1a23:b0:2b0:3f7f:8115 with SMTP id d9443c01a7336-2b0cdcb7d34mr153505ad.24.1774557768136; Thu, 26 Mar 2026 13:42:48 -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 d9443c01a7336-2b0cbfd17d9sm4004905ad.25.2026.03.26.13.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 13:42:47 -0700 (PDT) From: zhidao su X-Google-Original-From: zhidao su To: sched-ext@lists.linux.dev Cc: linux-kernel@vger.kernel.org, tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com, peterz@infradead.org, mingo@redhat.com, zhidao su Subject: [PATCH 1/4] tools/sched_ext: compat.bpf.h: fix scx_bpf_dsq_reenq___compat signature Date: Fri, 27 Mar 2026 04:42:35 +0800 Message-ID: <20260326204238.3755737-2-suzhidao@xiaomi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260326204238.3755737-1-suzhidao@xiaomi.com> References: <20260326204238.3755737-1-suzhidao@xiaomi.com> 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" scx_bpf_dsq_reenq() is declared with KF_IMPLICIT_ARGS in the kernel BTF, which means the BPF verifier automatically injects the struct bpf_prog_aux *aux parameter. The BPF-side weak symbol declaration must NOT include the implicit parameter. The previous declaration included an explicit aux__prog parameter, which caused BPF programs calling scx_bpf_dsq_reenq() through the compat macro to fail verification on kernels where the kfunc is available. Fix the declaration to match the calling convention expected by the verifier (2 parameters: dsq_id and reenq_flags). Fixes: c50dcf533149 ("selftests/sched_ext: Add tests for SCX_ENQ_IMMED and = scx_bpf_dsq_reenq()") Signed-off-by: zhidao su --- tools/sched_ext/include/scx/compat.bpf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/sched_ext/include/scx/compat.bpf.h b/tools/sched_ext/inc= lude/scx/compat.bpf.h index 654b566bd94a..6fbacc909b8b 100644 --- a/tools/sched_ext/include/scx/compat.bpf.h +++ b/tools/sched_ext/include/scx/compat.bpf.h @@ -405,7 +405,7 @@ static inline void scx_bpf_reenqueue_local(void) * v6.20: New scx_bpf_dsq_reenq() that allows re-enqueues on more DSQs. Th= is * will eventually deprecate scx_bpf_reenqueue_local(). */ -void scx_bpf_dsq_reenq___compat(u64 dsq_id, u64 reenq_flags, const struct = bpf_prog_aux *aux__prog) __ksym __weak; +void scx_bpf_dsq_reenq___compat(u64 dsq_id, u64 reenq_flags) __ksym __weak; =20 static inline bool __COMPAT_has_generic_reenq(void) { @@ -415,7 +415,7 @@ static inline bool __COMPAT_has_generic_reenq(void) static inline void scx_bpf_dsq_reenq(u64 dsq_id, u64 reenq_flags) { if (bpf_ksym_exists(scx_bpf_dsq_reenq___compat)) - scx_bpf_dsq_reenq___compat(dsq_id, reenq_flags, NULL); + scx_bpf_dsq_reenq___compat(dsq_id, reenq_flags); else if (dsq_id =3D=3D SCX_DSQ_LOCAL && reenq_flags =3D=3D 0) scx_bpf_reenqueue_local(); else --=20 2.43.0 From nobody Thu Apr 2 18:53:49 2026 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 547913A6EE2 for ; Thu, 26 Mar 2026 20:42:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774557773; cv=none; b=uFyLEdx5U6SsfSzu70zMsSyfTnKD1izyxrPVzdgzr1SbQ5neJhsXW1fy4/Rz3HhBXF8Mzsk4Z086pRMbxu1qAoPs5ZqlBR7lOu3ILw0eSLv4wkS7Z7gOBlvxOOZyUHfT8GVDLFCoLSTw1aXSa22xSdayo5b5Yg3s4HfioI7Y2yg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774557773; c=relaxed/simple; bh=Q65uh6cjjBWAZ3c12PK6mxOEKiuylXPXPaMvVDeeBbE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AagY2cT4Ha120TyF8udwhRpACpOfDPcgQyMdze5Sla4SPWRn6Kri//oNvqc4+nnWB+zluedaLXJb+dmMuJhIVMwfi7ivDs/Tl7/jUYB7D/7EJ9sWsDaT4MwbsVvfEtYpTBjcRq75bzxLh6LN3oPe+MtoKX9sjzrtekqGB+1RGtU= 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=NQG8s7Ga; arc=none smtp.client-ip=209.85.216.42 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="NQG8s7Ga" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-3591cc98871so663551a91.3 for ; Thu, 26 Mar 2026 13:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774557771; x=1775162571; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mEZyVDr5e3OviCxoRt/q1KOLbWsrmmGkIE7t73Pzwgc=; b=NQG8s7Ga9L9d7vblA570UiJtP3krEpW7/FppQ15gUrx7w6pTFDRKqQLM/CM3gCwb/A mVGnO6tPpzKewDxDgmBZu1rTwKkbBGPbTTx9nEEtaN4doGgtAjQbi2c+EJfMj5mDPh3m K0dqSps8ypiGxvdLUS5QoTi/YUaIMw2/X1H7E0Y1OSbiMgC1B7LLYYeuU+zoznh01kbf KeLq/2rqIUxRParLxqYyVrRMOfSQbmEDajz8KxsW4kqMJGeaDVaiS/B957TxWaAtMqb2 ilx58O7B7GALG/5DFljnP+tMSBRbtjg5CYqbcNWgd6IXUOAhbzkMbZJTtH+xEdBL2v1f Jefw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774557771; x=1775162571; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=mEZyVDr5e3OviCxoRt/q1KOLbWsrmmGkIE7t73Pzwgc=; b=JMw3vcys77NHmbXKsEbepGReVfltyAYTkKgz/1ScY1Ebobypt6aEaTae9ljnANCDIo sJt3taKsaqiMaCeQCN5KSlmyX3MrZq0D/jQXtijqaJvuVifjeKuskL/Y6tqGmTm+6wkL TUv1AwISw80qyyq6474AEJSyWH/ufzrBmETauKnt0H7tbctZVQwrKFx4fkZUtf+eHX9H nuKjTUnwPb4RWXclPv+ToWYawah93G9HBQOda1uqwCOoBvAkkinfPXj+MWa1S7o0A8dN q1BpcKCD/RV30Fb2TPL1Vhfvik7fdELl8RHpAHPVWzHlYL93/dPyD2m7rQumQC4h+cwP cXtA== X-Gm-Message-State: AOJu0YxLdNJ9xK3IyWqtHjFxYNOf3ow89Y2l73OCGyoJct0O8F+HH5wO oZ3oZvmQKjqiNTtl0buZoatzfSuwLk+Ad0j/LAZ2XS5yaiztK1Qpmm76 X-Gm-Gg: ATEYQzz2JL7VJovDxh3S4VMpSf/hnQP7ZISOpVJn9XhKNd1dGOgjQrY34CzRorg+eLB FM/cajBetRRjGE6HjH89TLYk9ny64dNSOWLFVFtiV4AQ5pFe9Am78xQgDAoY4zi6+PlfyJnAwjY 1WYvw/IcALh6jdlajNEsEwtcq1Ts4H6OEbtkazDlYspawhqdtSjeZtek7Ve7jsVYGXphIeJy0vF qNvbAt/LfWfvXOe94FOHaK3EPIl4NmoXXLDDl+m8Cw98Utm2S6FZPRlZXTiJj4MqQTjCkBh2jr5 x6LZse9badJSZGGQXPO752hzbnWxcvSNkqSkOjDX5KD1l+5xMWSjeT5CRrVHP0ntpix0ZbJIzyO OLT91gIzI7AbNNwvZsxjZBQCdPXRssoFw37KpgQHCYD3U2h6XEB6/SOHIM0XKeZSQWfYIEV7xoO tbjNqf74FgWi4BCKty5ILfNryUjE2HRPHbOGkKYVsjdjxyLZb1uZhAUZGAX1nfmUdPpIpLrhJ9d 58= X-Received: by 2002:a17:902:d487:b0:2ae:6457:3099 with SMTP id d9443c01a7336-2b0cdc9e5b5mr185225ad.26.1774557771457; Thu, 26 Mar 2026 13:42:51 -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 d9443c01a7336-2b0cbfd17d9sm4004905ad.25.2026.03.26.13.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 13:42:51 -0700 (PDT) From: zhidao su X-Google-Original-From: zhidao su To: sched-ext@lists.linux.dev Cc: linux-kernel@vger.kernel.org, tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com, peterz@infradead.org, mingo@redhat.com, zhidao su Subject: [PATCH 2/4] selftests/sched_ext: enq_immed: fix IMMED reenqueue livelock Date: Fri, 27 Mar 2026 04:42:36 +0800 Message-ID: <20260326204238.3755737-3-suzhidao@xiaomi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260326204238.3755737-1-suzhidao@xiaomi.com> References: <20260326204238.3755737-1-suzhidao@xiaomi.com> 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" When the IMMED slow path fires, ops.enqueue() is called with SCX_ENQ_REENQ and SCX_TASK_REENQ_IMMED set. The original code fell through to the normal enqueue path, which re-inserted the task into SCX_DSQ_LOCAL_ON|0 (CPU 0's local DSQ) with SCX_ENQ_IMMED still present. This immediately re-triggered the slow path, which called ops.enqueue() again, creating an infinite cycle. After SCX_REENQ_LOCAL_MAX_REPEAT (256) iterations the kernel aborts with BUG_ON. Additionally, the dispatch handler consumed from SCX_DSQ_GLOBAL even though no tasks were ever placed there, so it was a no-op. Fix by redirecting reenqueued tasks to SCX_DSQ_GLOBAL so they escape the CPU 0 local DSQ orbit, breaking the cycle. Remove the now-pointless scx_bpf_dsq_move_to_local(SCX_DSQ_GLOBAL) call from dispatch. Fixes: c50dcf533149 ("selftests/sched_ext: Add tests for SCX_ENQ_IMMED and = scx_bpf_dsq_reenq()") Signed-off-by: zhidao su --- tools/testing/selftests/sched_ext/enq_immed.bpf.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/sched_ext/enq_immed.bpf.c b/tools/test= ing/selftests/sched_ext/enq_immed.bpf.c index 805dd0256218..a006f07334ef 100644 --- a/tools/testing/selftests/sched_ext/enq_immed.bpf.c +++ b/tools/testing/selftests/sched_ext/enq_immed.bpf.c @@ -35,6 +35,15 @@ void BPF_STRUCT_OPS(enq_immed_enqueue, struct task_struc= t *p, u64 enq_flags) =20 if (reason =3D=3D SCX_TASK_REENQ_IMMED) __sync_fetch_and_add(&nr_immed_reenq, 1); + + /* + * The slow path re-enqueues IMMED tasks that couldn't run + * immediately. Avoid re-pinning them to CPU 0's local DSQ, + * which would trigger another slow-path cycle (livelock). + * Send them to the global DSQ instead. + */ + scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags); + return; } =20 if (p->tgid =3D=3D (pid_t)test_tgid) @@ -47,7 +56,6 @@ void BPF_STRUCT_OPS(enq_immed_enqueue, struct task_struct= *p, u64 enq_flags) =20 void BPF_STRUCT_OPS(enq_immed_dispatch, s32 cpu, struct task_struct *prev) { - scx_bpf_dsq_move_to_local(SCX_DSQ_GLOBAL, 0); } =20 void BPF_STRUCT_OPS(enq_immed_exit, struct scx_exit_info *ei) --=20 2.43.0 From nobody Thu Apr 2 18:53:49 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 7A9F93A6F00 for ; Thu, 26 Mar 2026 20:42:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774557776; cv=none; b=mumTCeePNMNyLLxKo9xHwJ4XPmnTHGFDEUqaWIQG5kUCAbpMrE4lrp8fLXPQnv79iFrYJ69pfWZyiza19FBlSyv4ffDzUoCoJoPl+UVYGpptwBG/g4joYDspPfHpK6Z+nVTIS7Qq1N53dVTU/ZaDctO2KqqkfdqGXDqO1Ust+vA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774557776; c=relaxed/simple; bh=/F4faJlCk5xFIpMdFjvblOLbKJepVT7BEZ3H6ShzYpk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ebLulDR67RHfb7n97rbWCu/u4UZTzQo2gEFCcCoQPy2+/cxQ2dUUdl6FTwMwqfkuE95/Zb9f2pJbmH9NWEmLPP25VKT4j8i78hwYDvMz9R+RSAk6sqmRmOXd5rRPDL+f9z21Tzz+e/FJWi0LgZ8p+RGAwlNKjkRlHgKeFLOgz00= 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=TqTJj3yk; arc=none smtp.client-ip=209.85.214.182 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="TqTJj3yk" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2adbfab4501so6875735ad.2 for ; Thu, 26 Mar 2026 13:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774557775; x=1775162575; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dQWmRiTvxEJUeJjwhYuVUrdZjK9tcpL66RkPZ6C4zEY=; b=TqTJj3yk9VVuSOqnw9pbE5BQJJbaH5i1uD+Ic33Sz+KngAz/1b9aXjFW39uamOJ+s2 B4+AcKqGDlXg7JvNK5JtsO6wTpshoAVX7dk9e4qmGLQ7UiJumKs6kT1zsOgi4MphZ2q+ jB0EF1Nu1enZ/dEn7jukfAU+2F/+r4MqeAo5sLeUA64anufCLUm3dc0USN56LRNt2oHl Nv3MJgqVyDMl0la6WUuuGNB5+iAKV4em6g4+xMdrWSIeVfsZQFd32KnK3Cc/H44a85fD oo0jNwq0PoGgZ5ZYSsIdYN+bijpjLk3zabeK725Qc8rvpsAlsgn2/hKwYAxTeZEVxsyA fKuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774557775; x=1775162575; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dQWmRiTvxEJUeJjwhYuVUrdZjK9tcpL66RkPZ6C4zEY=; b=Urzo+FXfivXzaKsOM98T/Ts9ZWw62Bp3+fT0ti4wo2lA4qzh1SZkVCuhDgeleulCFy WIX1SUQWz17pmRd77ZZuLhrqrGXp8mGjvKNSXiZ6j+zu0cM0Fm7aLm8CgFiKMhIWEsLn Ls03EsKY/766979T2I7SQg25JiK2kg+l8Rk+hUgMygNmEAhk12A7dg7AZijk4FAJmbUJ nE17eMDJz5XDwOpFxeZT8GrbEZbvE1UfSgAGlURl/S3/zHX4fChCSVQN+9lI7YjMoAid rtaGxbSkT/NBn0Dh3Ip0bu9t6sYOQ6njIBj4F5DWCl1+Vzm+kMD9FLmIRtpYdU6Q0WUg iLow== X-Gm-Message-State: AOJu0YxNt6TYI+Cz1UKECIQNjYasQ2CNvF+5u+TKsH+rlbKYVGxBY5Uk xzRCamSNWcmx4ai/0jXh5IV8VX81jQCyqD5PbQSzJP5mp9672nQxj6sc X-Gm-Gg: ATEYQzyngHQCJJM6uPbWzNCNHRhhnK0PU2kopAmGWWXhUlMGte3IALXCFTJleYzocE6 hBbHob6Fsb2kJitr9ADbdA+h6L4sxGCrwxqq9n27yhKnwpZ+TQOUPYNXGVeM/a45iLzIR7KMt7+ 91fR4V4K9bY9wOum5d1NVMeZ44/84GwKOt0YrkQ2yM+xfBVJIwrBan8NCzX9rP0mRHeZ3C9E4hz EoRy/6FQlOp9nFqiC22dNfWksjfETupbmsuLIe0FCLjJIYYJcDyU1yA9UEkUNH8sFO/OByLWP1z 9blNeXuGif8vRU1ef+3HIHurY5mmtI6ftqjI1RRZHaQFdm8HCGRW6h3aXR5Y1nbeNiYki6NTbyN wHBJrGkl1QuzNB2Fu9hLsibzUR4vTeH5UYoWHIvQl35L8/h6S3N8Kn2hiACwF1f84McvdmgjxTE 4v53gvrqpgoPL0u9q4STTFyoSAzOxh7Ijn9VZFKxtzyjeFOx83uhj+DSSWfab+E4BX3GZsVBP9A 5k= X-Received: by 2002:a17:902:e952:b0:2ae:803e:6c12 with SMTP id d9443c01a7336-2b0cdbf704cmr414835ad.6.1774557774864; Thu, 26 Mar 2026 13:42:54 -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 d9443c01a7336-2b0cbfd17d9sm4004905ad.25.2026.03.26.13.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 13:42:54 -0700 (PDT) From: zhidao su X-Google-Original-From: zhidao su To: sched-ext@lists.linux.dev Cc: linux-kernel@vger.kernel.org, tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com, peterz@infradead.org, mingo@redhat.com, zhidao su Subject: [PATCH 3/4] selftests/sched_ext: dsq_reenq: fix reliability with two-DSQ design Date: Fri, 27 Mar 2026 04:42:37 +0800 Message-ID: <20260326204238.3755737-4-suzhidao@xiaomi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260326204238.3755737-1-suzhidao@xiaomi.com> References: <20260326204238.3755737-1-suzhidao@xiaomi.com> 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" The original test used a single USER_DSQ for both holding tasks and triggering scx_bpf_dsq_reenq(). ops.dispatch() consumed directly from USER_DSQ, which raced with the 5 ms BPF timer: by the time the timer fired, dispatch had already drained USER_DSQ, so scx_bpf_dsq_reenq() found no tasks to reenqueue and nr_reenq_kfunc remained zero. Fix with a two-DSQ design: - USER_DSQ: tasks land here on initial enqueue; ops.dispatch() never consumes from it, so tasks accumulate and the timer always finds them. - RUN_DSQ: reenqueued tasks (SCX_ENQ_REENQ path) land here; dispatch consumes from RUN_DSQ so tasks can run. This guarantees scx_bpf_dsq_reenq() always observes tasks in USER_DSQ and nr_reenq_kfunc is reliably incremented every timer tick. Fixes: c50dcf533149 ("selftests/sched_ext: Add tests for SCX_ENQ_IMMED and = scx_bpf_dsq_reenq()") Signed-off-by: zhidao su --- .../selftests/sched_ext/dsq_reenq.bpf.c | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/sched_ext/dsq_reenq.bpf.c b/tools/test= ing/selftests/sched_ext/dsq_reenq.bpf.c index 750bb10508df..ccce75a99d8a 100644 --- a/tools/testing/selftests/sched_ext/dsq_reenq.bpf.c +++ b/tools/testing/selftests/sched_ext/dsq_reenq.bpf.c @@ -2,9 +2,15 @@ /* * Validate scx_bpf_dsq_reenq() semantics on user DSQs. * - * A BPF timer periodically calls scx_bpf_dsq_reenq() on a user DSQ, - * causing tasks to be re-enqueued through ops.enqueue() with SCX_ENQ_REENQ - * set and SCX_TASK_REENQ_KFUNC recorded in p->scx.flags. + * Worker tasks are placed into USER_DSQ. ops.dispatch() does NOT consume + * from USER_DSQ directly, so tasks accumulate there between timer ticks. + * A BPF timer fires every 5 ms and calls scx_bpf_dsq_reenq(USER_DSQ, 0), + * which re-enqueues every task in USER_DSQ through ops.enqueue() with + * SCX_ENQ_REENQ set and SCX_TASK_REENQ_KFUNC in p->scx.flags. + * + * Reenqueued tasks are placed into RUN_DSQ so ops.dispatch() can pick them + * up and run them. This two-queue design guarantees tasks remain in + * USER_DSQ long enough for the timer to observe them. * * The test verifies: * - scx_bpf_dsq_reenq() triggers ops.enqueue() with SCX_ENQ_REENQ @@ -18,7 +24,13 @@ char _license[] SEC("license") =3D "GPL"; =20 UEI_DEFINE(uei); =20 +/* + * USER_DSQ: tasks sit here between timer ticks so scx_bpf_dsq_reenq() + * can observe and re-enqueue them. + * RUN_DSQ: tasks land here after reenqueue and are consumed by dispatch. + */ #define USER_DSQ 0 +#define RUN_DSQ 1 =20 /* * SCX_TASK_REENQ_REASON_MASK and SCX_TASK_REENQ_KFUNC are exported via @@ -58,27 +70,36 @@ static int reenq_timerfn(void *map, int *key, struct bp= f_timer *timer) =20 void BPF_STRUCT_OPS(dsq_reenq_enqueue, struct task_struct *p, u64 enq_flag= s) { - /* - * If this is a kfunc-triggered reenqueue, verify that - * SCX_TASK_REENQ_KFUNC is recorded in p->scx.flags. - */ if (enq_flags & SCX_ENQ_REENQ) { u32 reason =3D p->scx.flags & SCX_TASK_REENQ_REASON_MASK; =20 if (reason =3D=3D SCX_TASK_REENQ_KFUNC) __sync_fetch_and_add(&nr_reenq_kfunc, 1); + + /* + * Reenqueued tasks go to RUN_DSQ so dispatch() can run them. + * Keeping them in USER_DSQ would cause the timer to reenqueue + * them again endlessly without ever running. + */ + scx_bpf_dsq_insert(p, RUN_DSQ, SCX_SLICE_DFL, enq_flags); + return; } =20 /* - * Always dispatch to USER_DSQ so the timer can reenqueue tasks again - * on the next tick. + * Non-reenqueue path: place the task in USER_DSQ. ops.dispatch() + * does not consume USER_DSQ directly, so tasks sit here until the + * timer fires and calls scx_bpf_dsq_reenq(USER_DSQ, 0). */ scx_bpf_dsq_insert(p, USER_DSQ, SCX_SLICE_DFL, enq_flags); } =20 void BPF_STRUCT_OPS(dsq_reenq_dispatch, s32 cpu, struct task_struct *prev) { - scx_bpf_dsq_move_to_local(USER_DSQ, 0); + /* + * Only consume from RUN_DSQ (tasks that have been through the + * reenqueue path). USER_DSQ is deliberately left for the timer. + */ + scx_bpf_dsq_move_to_local(RUN_DSQ, 0); } =20 s32 BPF_STRUCT_OPS_SLEEPABLE(dsq_reenq_init) @@ -91,6 +112,10 @@ s32 BPF_STRUCT_OPS_SLEEPABLE(dsq_reenq_init) if (ret) return ret; =20 + ret =3D scx_bpf_create_dsq(RUN_DSQ, -1); + if (ret) + return ret; + if (!__COMPAT_has_generic_reenq()) { scx_bpf_error("scx_bpf_dsq_reenq() not available"); return -EOPNOTSUPP; --=20 2.43.0 From nobody Thu Apr 2 18:53:49 2026 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 CDD323A5E82 for ; Thu, 26 Mar 2026 20:42:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774557780; cv=none; b=LI9ChDo2xhLzP93OIIHEX6KA5fHfTMtMha5Wn0zErSbixElAl+528QKzg6CCud4/CSi8WDv+u5pEaa2ZKqTTKKp2MXj693380iwCEVb+bQvbcb8ZbQgGwIQhmwIIC1dSUCKN3iFPiYVZUeFS4zzkGoDmS28tlMAXZxz7y9QHUr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774557780; c=relaxed/simple; bh=ETl5BcbglksFteo5kDYeab5aTtRy2qhdq/fkOmHb96o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=utOUuo+xTou4V6A4qV+K+Ed2UrC8cunwG+DyIBT2ZD6/X8wwzvHp8Okr32rphnqy6MYEHtQJGmM2NDJl3jtwuCc708tfPPp1W9qSpGbf/j95Vk8+2jIB7bnJ/qu5c4nKqrD7cWYng8/BddyYN7pmJ0gs/nC1DZqX6cCK70aIi9c= 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=YB2MoFE0; arc=none smtp.client-ip=209.85.215.177 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="YB2MoFE0" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-c73c990a96dso750182a12.0 for ; Thu, 26 Mar 2026 13:42:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774557778; x=1775162578; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PlGZ0nbQG26TwYl+c9kepBTMonB66LTBudTEARXlFvI=; b=YB2MoFE0+ENa9GLHqDm+ugPMfpE6WPjuQTIPyjkSu2inukDQJMkoj0/2/MANrD8sQT vIcFl8pcEIGoi8EU0i/cWhZ5M5+xYZlNMomLKJ+g84RTmL2JJDlvZhMZ4LRiurgHFzKd j+m5sGdbPxLTE5FIH575+m1a20+hXRdlsGZP9/d8Nk5uCi3aL2gPlp4PcTuh9JPtj+x1 6s2xH+6G0MA3fLzO+f684lviRBqwMcaLf5epy+BqtpN4IgnxUwc6nh8WhZDAPQRon94r oAJKcxhZJ1F6MUxnzkhCnnANF7das33yXehFsDsD+T1ISq4FA8waL8iTp2RN16sHvCLN 4UiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774557778; x=1775162578; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PlGZ0nbQG26TwYl+c9kepBTMonB66LTBudTEARXlFvI=; b=Gn+TKVKVWI02mikKQ/w2CZk/j5qpm5lsmyv6xo3Z/iOYECaKGZP9QSO5KoyF9ovIHs 1bCknZyh8YcXaBXVGwpH40k9/+mx/B6FxI7iacQEbrHmf7mfLsM9yJ05xngsA62Xw/ap jO0uPowNd6bbHaR5px4iGR0mV7geQs66gMsOGw45JNpb8+knq1nA7sNOh33eq4g9NOoJ atbLdiTEwHXSNV1sVwKAV6RWXMDtz/FSuhtFY9zEc0Mutl3V9yjL27ByMNB9SsR46kiC elpQtS6XclnHvT8cIvTcGyFUXnKkqRDGFxM/zO94TDgqo6N+PrZxpyC9vwtFnoswS0Kw WG6g== X-Gm-Message-State: AOJu0YxkkzglbMOdHfyfF+3/rSpf7bWb34Fu+6Es5/h5VcwF887naIdA gtQqy0mKQMU2LVvLJU3pnd7l/+17/fbjFZW+rJOX0O0KLJzYvchMT2EJ X-Gm-Gg: ATEYQzxDBsWQgP2xRC0hOgg/GGZ9doD63W9kXiVcZAv/Wrzsu9NjJ5TJqMlaArLdKOF 1mqz/MW0AOJDJlQVQvyooysrjGH6XeofnWjSPwRICeCzTO3ROhHD61GOjJqy+lHC9+g8Jx0JjlC osbIbKTArx5o3ZgqaJe4uQ1Hpw/aTcN0JLMvEvRHR+iRALaug4L0d4uvvojOm4/xFGFPx/S0xkp rjSTdBzvsmgv+qmhgwfL+RusUr4q4fSAH1hlTiOg4U2A4vDShxmNfNS0CqYInJK+ZoSMfwQQqCN e3T8O4atCvS1Gakc1h7muXQU6DHW4YPj3PlKA2gIbA3j4u7PIlG6GCn1uasTqFhkYg25Hw0h6ID zlQ4SMXdoUb54LE0Ho+gmCeN44dQVMGbuDHdP8bcOSKrS+oTw/1V87Stty6klbX9k5ht0kKZ5I0 kPeEqGTv1WxbX3reBHmsk9ZNEXTYS8IkCb7ABnWxhmca4/KGgJX6rIDQYLv1KFuPlNs4ZYHqnYf sYorgt559LMQA== X-Received: by 2002:a17:903:1450:b0:2b0:5626:f75d with SMTP id d9443c01a7336-2b0cdcb7d29mr112655ad.26.1774557778157; Thu, 26 Mar 2026 13:42:58 -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 d9443c01a7336-2b0cbfd17d9sm4004905ad.25.2026.03.26.13.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 13:42:57 -0700 (PDT) From: zhidao su X-Google-Original-From: zhidao su To: sched-ext@lists.linux.dev Cc: linux-kernel@vger.kernel.org, tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com, peterz@infradead.org, mingo@redhat.com, zhidao su Subject: [PATCH 4/4] selftests/sched_ext: consume_immed: fix reliability with CPU affinity Date: Fri, 27 Mar 2026 04:42:38 +0800 Message-ID: <20260326204238.3755737-5-suzhidao@xiaomi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260326204238.3755737-1-suzhidao@xiaomi.com> References: <20260326204238.3755737-1-suzhidao@xiaomi.com> 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" Two bugs prevented the IMMED slow path from triggering reliably: 1. Dispatch consumed at most one task per ops.dispatch() call. The IMMED slow path requires dsq->nr > 1 in the local DSQ after a scx_bpf_dsq_move_to_local() call. With only one call per dispatch, the local DSQ never accumulated two tasks. Fix: loop up to 8 times in dispatch, draining USER_DSQ into the local DSQ. On the second iteration the local DSQ already has one task; inserting a second raises dsq->nr to 2, triggering schedule_reenq_local and calling ops.enqueue() with SCX_TASK_REENQ_IMMED. 2. Workers were not pinned to CPU 0, so the scheduler spread them across all CPUs. USER_DSQ typically had only 0-1 tasks when CPU 0 dispatched, so the loop's second iteration rarely found a second task. Fix: pin all NUM_WORKERS threads to CPU 0 via pthread_attr_setaffinity_np(). With all workers competing for CPU 0, USER_DSQ always has a backlog, and every dispatch loop reliably accumulates 2+ tasks. Also move nr_consume_immed_reenq read to after bpf_link__destroy() so the kernel has fully flushed all counter updates before we check the assertion. Fixes: c50dcf533149 ("selftests/sched_ext: Add tests for SCX_ENQ_IMMED and = scx_bpf_dsq_reenq()") Signed-off-by: zhidao su --- .../selftests/sched_ext/consume_immed.bpf.c | 19 +++++++++++++++---- .../selftests/sched_ext/consume_immed.c | 15 ++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/sched_ext/consume_immed.bpf.c b/tools/= testing/selftests/sched_ext/consume_immed.bpf.c index 9c7808f5abe1..a2a4ee2ee95b 100644 --- a/tools/testing/selftests/sched_ext/consume_immed.bpf.c +++ b/tools/testing/selftests/sched_ext/consume_immed.bpf.c @@ -55,10 +55,21 @@ void BPF_STRUCT_OPS(consume_immed_enqueue, struct task_= struct *p, =20 void BPF_STRUCT_OPS(consume_immed_dispatch, s32 cpu, struct task_struct *p= rev) { - if (cpu =3D=3D 0) - scx_bpf_dsq_move_to_local(USER_DSQ, SCX_ENQ_IMMED); - else - scx_bpf_dsq_move_to_local(SCX_DSQ_GLOBAL, 0); + int i; + + if (cpu !=3D 0) + return; + + /* + * Drain USER_DSQ into the local DSQ with SCX_ENQ_IMMED. Once two or + * more tasks accumulate in the local DSQ, dsq->nr > 1 triggers the + * IMMED slow path (schedule_reenq_local), re-enqueuing IMMED tasks + * through ops.enqueue() with SCX_TASK_REENQ_IMMED. + */ + for (i =3D 0; i < 8; i++) { + if (!scx_bpf_dsq_move_to_local(USER_DSQ, SCX_ENQ_IMMED)) + break; + } } =20 s32 BPF_STRUCT_OPS_SLEEPABLE(consume_immed_init) diff --git a/tools/testing/selftests/sched_ext/consume_immed.c b/tools/test= ing/selftests/sched_ext/consume_immed.c index 7f9594cfa9cb..41e66cd5e879 100644 --- a/tools/testing/selftests/sched_ext/consume_immed.c +++ b/tools/testing/selftests/sched_ext/consume_immed.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include "consume_immed.bpf.skel.h" @@ -77,20 +78,28 @@ static enum scx_test_status run(void *ctx) =20 stop_workers =3D false; for (i =3D 0; i < NUM_WORKERS; i++) { - SCX_FAIL_IF(pthread_create(&workers[i], NULL, worker_fn, NULL), + pthread_attr_t attr; + cpu_set_t cpuset; + + pthread_attr_init(&attr); + CPU_ZERO(&cpuset); + CPU_SET(0, &cpuset); + pthread_attr_setaffinity_np(&attr, sizeof(cpuset), &cpuset); + SCX_FAIL_IF(pthread_create(&workers[i], &attr, worker_fn, NULL), "Failed to create worker %d", i); + pthread_attr_destroy(&attr); } =20 sleep(TEST_DURATION_SEC); =20 - reenq =3D skel->bss->nr_consume_immed_reenq; - stop_workers =3D true; for (i =3D 0; i < NUM_WORKERS; i++) pthread_join(workers[i], NULL); =20 bpf_link__destroy(link); =20 + reenq =3D skel->bss->nr_consume_immed_reenq; + SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_UNREG)); SCX_GT(reenq, 0); =20 --=20 2.43.0