From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (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 64E302DECC6 for ; Tue, 9 Dec 2025 22:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765319773; cv=none; b=bLCGHyL/p8PGHL4un8XPtafBdS3EENPapxklbONFOACYKCa2iIzgyPwuKpA9181RRhy8JDwNdE0VxUje5z2NLkd9q9MxA4F5Yh9VzOvCwcRsyFMj5ej7sDcCtC9powRiOU8x8MnljzPkN3Klmi42AJyEYVaevy/5/nPbtJaLvvw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765319773; c=relaxed/simple; bh=1GfgVhapWgGpkPQS1glpXT8EeTUtczYpWBuPImq24Kc=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:From:To:Cc: References:In-Reply-To; b=hJ9dN6jytaNL6mlIqEUwbVFdKAAv1d0j/ArNhNtDsmzPTd5CAbi1tYhRMbtaronfAXkvmZpfXHyaZOqL835pQiLHBiYjYPgdO4bpjqrs5cWauzpulgxPs9qIgm8NZ/if0hNCm+8Xop1RVhlMiK3oBxnj77sr5E0Z/N7hvb9F3cw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com; spf=pass smtp.mailfrom=etsalapatis.com; dkim=pass (2048-bit key) header.d=etsalapatis-com.20230601.gappssmtp.com header.i=@etsalapatis-com.20230601.gappssmtp.com header.b=nf3TBRKw; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=etsalapatis-com.20230601.gappssmtp.com header.i=@etsalapatis-com.20230601.gappssmtp.com header.b="nf3TBRKw" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-8b2f0f9e4cbso26139285a.0 for ; Tue, 09 Dec 2025 14:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsalapatis-com.20230601.gappssmtp.com; s=20230601; t=1765319769; x=1765924569; darn=vger.kernel.org; h=in-reply-to:references:cc:to:from:subject:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xMDjrbgm3fd7/vhfQib/L2JYfPytQjquusIcJU5ydyE=; b=nf3TBRKwxqJUN6U+gCXLrSiISy+omCJJ6Twrm3vxAt6pRlI+sQYdK97fjtj4yuB6Pc 7RDEct3OW/6R6eSWdaISeYsl3KDhdERoc1oCYpzEWagO8ZbWswDQt6dFE9p+N/e13DoL vg0a1gRMTXKrevnjb5tOrZjVHWnHj6TuH1W09GLqGAm5CBqBvxmbaPThpSClAr/xeHmg qedBxoh7jV53SuovCa9qaOv2HLJx/kLTVcorXC1TLHHIGTAfOOyXXamK0MqyJa334xws k9MdESPkxBgiQBXOY9d69PkqCwIFWc3WQwNE8BxejON381bJggUwm9mgmkC0MnNYD80E tKfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765319769; x=1765924569; h=in-reply-to:references:cc:to:from:subject:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xMDjrbgm3fd7/vhfQib/L2JYfPytQjquusIcJU5ydyE=; b=Kv/ssQUFijTBy5yR9f4/BA6M0NMYIhLY2GgizJvwAjfDF4a4s4649h7eZR22qpOdp1 wUvou0gcyM7B1+pN5fqboMDLreJW5ZCqLb6tZWeRHYihlm6J79HG/KoldTeXVkPF+y6U aWAV1zQKF52YK1w6e6mMKhwuajqrtpUcMnj8fOa0LXv0jKFvnamHP0epkyBFKJ2o9d5x LYrNCJHZTgGpEVSO897yYP+9/uxu2iCSv6msIRhiO+KEWmhfzSVr61LoGFkmilaNB2ph MkMciAAEs4B8VQ6T3QRycHi3jT9CbGjDw3kqV9a8VEkrsE6MuhwQSnKQPxJgNZGLHMZx TERw== X-Forwarded-Encrypted: i=1; AJvYcCVMFTyd+aDUQJ2eOpnJHIc6zEUGteGhd6877BK5sD96+TSBBgFX39E97qv6YbrmUl0CgaYNNSzbC3juzEE=@vger.kernel.org X-Gm-Message-State: AOJu0YytswYXzw+gsgo2zdZc9eQer5qXUu7+VOJZwxWj9mGGhxEKGyNW MaYMN8sZPzyVdQPG50wkS7nZ2IbD/BTkEpoKAboXOq6I9n8ndHF/0UZOXB+Md95PjRA= X-Gm-Gg: ASbGncuUUvw0dgxmNV0wBH7cpYwouBjIswCb3k4lfQgux7M8fPKiox747t0pJH7NUvm PVnghXCfDwBy6BMJUEzRFLcOQ93Vr896kxW1poTq3tmiV/BaPP2Xc+ScMuO6wcVOd46wmoQbtex /+SBVbTEPCLDG5KxSJFGig0GFiG5GoFnH/eCvPP9+J4t1f86I/hXSOTn1F+OrMNnCjfBAaHXPw9 NsfRJQPy/JMZ5EWmDX2qi34afrbgowGsOvUj0bBkQLPDX9ewHf7eTRiM/6ApXu+eDxqUrI1WDIS j/dmOxRlBH/JZsqMvdJCao+PnNdaQaHG+pBZDaLgzFgoT15B+XvLyCyv0SoVGyRW1Pm3KuMlnTl 1AgnxGUWLVyC9Fax313xd4irDM9mXiQM2fhxSuO13qfCjGKYMEKiHz/CXVza3SdDdXeT9jRkXJh PUfxLBaUwQm30= X-Google-Smtp-Source: AGHT+IH1jG12E5R/nTMy7dymzHYKkpW1KBjpQvlMRwy0j7dR++9cpTTnCImcH7gDvx5+yn0+N/TlWg== X-Received: by 2002:a05:620a:290c:b0:8b2:9b48:605e with SMTP id af79cd13be357-8b9cea84f9cmr416559885a.38.1765319769122; Tue, 09 Dec 2025 14:36:09 -0800 (PST) Received: from localhost ([140.174.219.137]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8ba52550233sm2700885a.14.2025.12.09.14.36.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Dec 2025 14:36:08 -0800 (PST) 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 Date: Tue, 09 Dec 2025 17:36:07 -0500 Message-Id: Subject: Re: [PATCH sched_ext/for-6.19-fixes] sched_ext: Fix bypass depth leak on scx_enable() failure From: "Emil Tsalapatis" To: "Tejun Heo" , "David Vernet" , "Andrea Righi" , "Changwoo Min" Cc: "Chris Mason" , , , X-Mailer: aerc 0.20.1 References: <286e6f7787a81239e1ce2989b52391ce@kernel.org> In-Reply-To: <286e6f7787a81239e1ce2989b52391ce@kernel.org> On Tue Dec 9, 2025 at 4:04 PM EST, Tejun Heo wrote: > scx_enable() calls scx_bypass(true) to initialize in bypass mode and then > scx_bypass(false) on success to exit. If scx_enable() fails during task > initialization - e.g. scx_cgroup_init() or scx_init_task() returns an err= or - > it jumps to err_disable while bypass is still active. scx_disable_workfn(= ) > then calls scx_bypass(true/false) for its own bypass, leaving the bypass = depth > at 1 instead of 0. This causes the system to remain permanently in bypass= mode > after a failed scx_enable(). > > Failures after task initialization is complete - e.g. scx_tryset_enable_s= tate() > at the end - already call scx_bypass(false) before reaching the error pat= h and > are not affected. This only affects a subset of failure modes. > > Fix it by tracking whether scx_enable() called scx_bypass(true) in a bool= and > having scx_disable_workfn() call an extra scx_bypass(false) to clear it. = This > is a temporary measure as the bypass depth will be moved into the sched > instance, which will make this tracking unnecessary. > > Fixes: 8c2090c504e9 ("sched_ext: Initialize in bypass mode") > Cc: stable@vger.kernel.org # v6.12+ > Reported-by: Chris Mason > Signed-off-by: Tejun Heo Reviewed-by: Emil Tsalapatis > --- > kernel/sched/ext.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > --- a/kernel/sched/ext.c > +++ b/kernel/sched/ext.c > @@ -41,6 +41,13 @@ static bool scx_init_task_enabled; > static bool scx_switching_all; > DEFINE_STATIC_KEY_FALSE(__scx_switched_all); > > +/* > + * Tracks whether scx_enable() called scx_bypass(true). Used to balance = bypass > + * depth on enable failure. Will be removed when bypass depth is moved i= nto the > + * sched instance. > + */ > +static bool scx_bypassed_for_enable; > + > static atomic_long_t scx_nr_rejected =3D ATOMIC_LONG_INIT(0); > static atomic_long_t scx_hotplug_seq =3D ATOMIC_LONG_INIT(0); > > @@ -4318,6 +4325,11 @@ static void scx_disable_workfn(struct kt > scx_dsp_max_batch =3D 0; > free_kick_syncs(); > > + if (scx_bypassed_for_enable) { > + scx_bypassed_for_enable =3D false; > + scx_bypass(false); > + } > + > mutex_unlock(&scx_enable_mutex); > > WARN_ON_ONCE(scx_set_enable_state(SCX_DISABLED) !=3D SCX_DISABLING); > @@ -4970,6 +4982,7 @@ static int scx_enable(struct sched_ext_o > * Init in bypass mode to guarantee forward progress. > */ > scx_bypass(true); > + scx_bypassed_for_enable =3D true; > > for (i =3D SCX_OPI_NORMAL_BEGIN; i < SCX_OPI_NORMAL_END; i++) > if (((void (**)(void))ops)[i]) > @@ -5067,6 +5080,7 @@ static int scx_enable(struct sched_ext_o > scx_task_iter_stop(&sti); > percpu_up_write(&scx_fork_rwsem); > > + scx_bypassed_for_enable =3D false; > scx_bypass(false); > > if (!scx_tryset_enable_state(SCX_ENABLED, SCX_ENABLING)) { > -- > tejun