Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796108656; b=xqEhvAKzBmgBC1+b3NsM3zTuSR0CA1SFoqi/CZIx31ciiGcjZnhUH8/8+AiOQc63Kqaj 5MC22CklBCuL/7q+VX7IPDtzGMYI0gR6MeL/hfrLLSpqstVgSHsU1jiSIliLq5KMyhbOM wzImKvi+oO03kDThK2xKtedHxeVigjJC7KNAOqCwBdLuXC5WYC0Qihxi6vvcCHkZu2iDJ M5CDnQq3cKfM3/zlvNEuJ3iZn+2ATZ3P96wtjfAiltqFQnkoZKLYlzuDThmWGBo0ivoPu pmuJAO/VGZlzIh+qx61r16TQi4eX9lMcfFSpVkPwnWjWbulFtLVpitzElOtKWSazF0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796108656; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=HUSDPt1TddRDaodcaQqKD5i2mxdIv4b6F9BKSUvhgbA=; b=GtdfR9BOVY5HLif0lJhIOy0EVDvXmYXO+AKBDWRRihu54OtM0t6kxX6Az3AJE/AGzDL1 jq6EA1IcWS9eKMtc0MjqWcCsVo+4WFX/O2dwA3eCgQYfSn0u+sSJWGRu/xBHIhUUVqmeK l8MYFi9lXPsfljIyxb+Utj+MXUhbz86tppb4jum1qBgn9P24QWFHZ6OdcmFXbTWdhMISy Jke03io9ltUNOpTT4N5OVqrYC/nHo1402ki8dj6fHnHaYDvulZRIbh17+GXUrtDo0p+08 I9LqpnekLZeWIVfrY8/U5p/qGwc9USL1BLYqev0Aa8ryTERF4qMs9msuAAogxQlge+A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SqijvQua; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A652606A31A for ; Tue, 1 Dec 2026 07:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SqijvQua Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CB5F1F00893; Tue, 1 Dec 2026 07:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796108655; bh=HUSDPt1TddRDaodcaQqKD5i2mxdIv4b6F9BKSUvhgbA=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=SqijvQuaJcYADiVjEn9V/xdas0SaJm6zJNZaI2bDvgFHQlRK7ErTIw3pzJ6+xnS6v 136YIruLmO2dBbqpaYq7jQRjPaoLtsdGZFkleeL1AiKKjpVSipuUQTmhlWVDufPqsy lUwL3oTPC1eSwBSkfQYlF9SrxQV7pnGgGMyCCppZMjEDvPVHWJ2nhclgS+O6GhRXAw 5YFsakK//2279SfqIij9p9hHGEgK6p+C4XIivb0jss3qHsfkhP2UCc3b/IDRlDfuHi Yvot74wF+FPQBpzsY2YNSqA1OpR7mNfLeOH/EKYn49rSlLYLGEfVrRQ1uKnLPeNYE5 ZtbQKW8cY65Ig== Date: Mon, 30 Nov 2026 21:04:14 -1000 From: Tejun Heo To: Kumar Kartikeya Dwivedi Cc: bpf@vger.kernel.org, Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eduard Zingerman , Emil Tsalapatis , Ihor Solodrai , kkd@meta.com, kernel-team@meta.com Subject: Re: [PATCH bpf-next v1 73/73] sched_ext: Treat a cancelled program as a scheduler error Message-ID: References: <48315625f3762d677648ac0786736eec034c54c2.1796099738.git.memxor@gmail.com> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <48315625f3762d677648ac0786736eec034c54c2.1796099738.git.memxor@gmail.com> On Tue, Dec 01, 2026 at 05:39:40AM +0100, Kumar Kartikeya Dwivedi wrote: > The kernel can now cancel a BPF program. It ends the program early at a > loop that runs out of time, at a fault in arena or at bpf_throw(). The > program returns a default value, which is 0 for a program of a scheduler, > and does not finish its work. > > Currently sched_ext keeps calling a scheduler whose program was cancelled, > until the watchdog finds a task that has not run: > > void BPF_STRUCT_OPS(cs_enqueue, struct task_struct *p, u64 flags) > { > nr_enqueued++; <- in arena, the page is gone > scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, slice, flags); > } > > ops.enqueue() is cancelled at the fault, and the task gets into no queue. > A cancelled ops.select_cpu() returns 0, which is a CPU, and a cancelled > ops.init_task() returns 0, which is success. > > The BPF core calls ->cancelled() of struct bpf_struct_ops when a program of > the struct_ops was cancelled. Implement it for sched_ext_ops and > sched_ext_ops_cid. It finds the scheduler of the program with > scx_prog_sched() and calls scx_error() for it, so the error goes exactly > where scx_bpf_error() of that program would go. The first cancelled > program disables the scheduler, with a runtime error: > > program (ops., id ) was unwound, see its stderr stream > > The stderr stream of the program says why the kernel cancelled it. > > ->cancelled() runs in the context of the cancelled program. scx_error() is > safe there: it takes no lock and can be called under the rq lock, in a > timer callback and in NMI. > > Two things stay as they are: > > - The callbacks of the scheduler are still called until the disable path > has finished, as after scx_bpf_error() today. > - A cancelled program for which scx_prog_sched() finds no scheduler is not > reported. > > Cc: Tejun Heo > Co-developed-by: Alexei Starovoitov > Signed-off-by: Alexei Starovoitov > Signed-off-by: Kumar Kartikeya Dwivedi Acked-by: Tejun Heo Working abort finally. This is exciting. Thanks for working on this. -- tejun