From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796347679; b=3w+Bkko/exfNumm/R7OY8lgUQoPqZDntbyfi87hTiguhZC6DLkU2kijX9ZttXDygiGke 2jH9zzAL3yR3f9E8msY6NDo1hMTUyRCsvPJC6vxFQe5bUzHg+wox2bGuo9r6Hebt98h6I hyCkz7t/Kn4yygRRUA/YoovFPPaJrr2J2x0pwkTPU4jBbdDghPC9e3ztEeuQTpHBV0l/N BP8ERidMnNAiF/kvudHgylFQCaJLyriSGCk//myxXX1RmHugbld1wFu7CWcW/iIN6rQpn byA/vsulv5JnwwRrOX/jK1qYd7Eg/GJXAeS6sW9Yfj79Ic8/tF47f913BTPAW84HncA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796347679; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=AYc0fS2apToF4bz9yFW8iAqaPDhsESzo1LRIcrQ8aUA=; b=3g62IfeNZ4QlLt0TU7GUGBcGhh7rMxz/Y8xY8TH8MPqG7E3luiAVnZR0LWN4496kVAMJ XEq682Wgoonb2YIHQVPpHVr+kcJZPOItDkcZhcmVMkilXK9JVS/1v85+xWavoPa8gduex 3tRRezTf9Xobld/Oq+EmbCMXmdnf3W95SdD8hjQoqqbbCknPgGXkPKjTtW8jYPsvRm93z K9gWNoTpD3fnJbJuy3VAQiX/IslpH8ognFjiDm0iip8MTvpqcIQ7HgiAOdmBiXWyyhsgS WtClBbDCZz4oO/NKgdF7VV1yr4svvoetdJsyo9YvTmJg9spnTDRRzMhpXfIY4ox6i6g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=AMFGb3yV; arc=none smtp.remote-ip=74.125.82.48 Received: from mail-dl1-f48.google.com (mail-dl1-f48.google.com [74.125.82.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62A61606A322 for ; Fri, 4 Dec 2026 01:27:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 62A61606A322 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.a=rsa-sha256 header.s=20260707 header.b=AMFGb3yV Received: by mail-dl1-f48.google.com with SMTP id a92af1059eb24-170135e43c7so885677c88.0 for ; Thu, 03 Dec 2026 17:27:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796347679; x=1796952479; 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:content-type; bh=AYc0fS2apToF4bz9yFW8iAqaPDhsESzo1LRIcrQ8aUA=; b=AMFGb3yVCJET9+nFz6BltnUhYcK3OvvkLra9uOUFdIfB4O/3VmPx4sibagB1V2naPo A1HM5wyQExlDpcqr4O9Vezp+pQfwieSjajtMG7mzGNGe8Gm8ZYYzcTKyFXE5S2+TT4LF fcKUaAiohcpOe2JUyUJhVvpRkoYM7nTkFfmKoc54/3Jsu2Pe65g2O/vPGPtEDu/iNo0o 99QNpdJ4OOXryK6+8gv+NUCw+LfrDcoRkkbtLCJ3JPj8gfk+eAFtAEhLy3pAr9KgoNV2 sW60bDHXcy5PUP7zAt/3WDz42eX/CUiebGSj7MLcCej/DhtE/IzMDZ4ybiSJFFL5Dc3k 4VkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796347679; x=1796952479; 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:content-type; bh=AYc0fS2apToF4bz9yFW8iAqaPDhsESzo1LRIcrQ8aUA=; b=t+YvWjpvDw3HybhPxLHtSf7tsY3a6QdVeEwGmXi64Dugl52shkCo7rFewum2wMKphf okqkr6esebKc9v1+LRI7088Fofrukv2KqiGo1mcywB3FBOIRCO7Mkqkwy3HkFUY19GSI jmOhPN9P0UZNZEp4t+L1nUapD5R3SWuF+MNSdEPYeHhqNdWIGmsFWSyYPwD86ZPDE2Y0 7yABaVu7mCGI0ojfiS/1e6uda035NK46ctRaWK1+J9rx7T3Ll7KqECRjFbC5TUE+j7Sm YXPqJYGEwE/4b11nrcj1WTbGoyFCJbs0WSiH+HgeW9QRrLdVPDlVJtfNzs1VvBoAzf3G OkfA== X-Forwarded-Encrypted: i=1; AL+hErEIXB8NzI0btV88bEkUzJeIOWxFovD9NLDri4p0UCNDuh7q0Cnll+JRI6LnNhorQiP4jNJb6ukX6sz0pEc=@vger.kernel.org X-Gm-Message-State: APuU4Z/0oK3BDBu6M/IX6Efa80WMRrLqmaLEm6ENPNxHIDno3Ti7TtnD DRSl0X9QwqKY5rWMPNn8nJ9tAhcwqCYIT5E9uDbtoef7PiF8Kl4HJ9Gj X-Gm-Gg: AZFdTZdpPK2f8c62b7nBxAIY8p95JB4K9nNlYw31n9u4QGbO7gpCbkMf8BOW0Dr8JAH 9iMNfMeI5FRNeKuNxditOP+cfwBCqZXcAU+SJha45Svj0aw1bQSYe5X2bYgJS4tHO/UgSNnFASF HXq/fYnmkr2knuiatlJXJEgcLSBL9vyvkK/Qkb6emeCymTHJDQG4NLzRAhcrAipEAlFgBTQpRGo ISxv6m9WLTEhBnL1IE0tJE48/DI8Uayx0nauAON+Yckm/t1Wdi9eSzSEJYjJohZqsPFylfr2Q2H fFxTQZdkALUQJc7hSf2yrMlMCWOrs9Q0PrZTn6KZbxS8YRt46cjAiK9CxId7H6HtgEm+bbsQ357 1RC+hyHQUSjd3xivFe/A9T76YgYPgBo7Z3QnO53NCoBvPgocdue2g0nSFja9dJXKTL51P9ADY7X 1MY978ng6wpeAahzpM2cCWVREE7nRb5MoDd1eXKBaT9S2pvriijv0MXPevkBvJsnhfKgPVVEz7N aLS95WGJGJbZTE379FC5I557JuzKt7TE2K8+pJTQFDQhZ5BB9KzpVn6BWVYgga7Z9T3akoKAyGL 1n5xBAl/kZa4N3qtrbif8inzp2ofVKBn5yXHxjPs/8DUIQ95rK2swcs8Hp9IAZOeKg== X-Received: by 2002:a05:701b:270d:b0:1b5:32d7:7d73 with SMTP id a92af1059eb24-1b5d710bb33mr680818c88.30.1796347678543; Thu, 03 Dec 2026 17:27:58 -0800 (PST) Received: from 6610b1a2ef46 ([203.116.140.24]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d644109esm2376547c88.8.2026.12.03.17.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 17:27:58 -0800 (PST) From: Hang Zhengyang To: Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak Cc: Cheng-Yang Chou , Barret Rhoden , Josh Don , Hao Luo , sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH sched_ext/for-7.4-fixes 1/2] sched_ext: Don't enable or disable a task being forked on class changes Date: Fri, 4 Dec 2026 01:27:43 +0000 Message-ID: <20261204012744.195571-2-hang.zhengyang1010@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261204012744.195571-1-hang.zhengyang1010@gmail.com> References: <20261204012744.195571-1-hang.zhengyang1010@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A new task is visible by PID before scx_post_fork() runs and stays in SCX_TASK_INIT until then. If another task moves it to or off the ext class with sched_setscheduler() in that window, switching_to_scx() enables it or switched_from_scx() disables it, and scx_post_fork() then makes its own transition. ops.enable() runs twice, or ops.disable() runs for a task that was never enabled, and the state check warns: [ 8.241338] sched_ext: Invalid task state transition 0x4000000 -> 0x8000000 for scxfk[266] Leave such a task to scx_post_fork() in both callbacks, and make scx_post_fork() set READY and check the class under the rq lock that the callbacks hold. Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class") Cc: stable@vger.kernel.org # v6.12+ Signed-off-by: Hang Zhengyang --- kernel/sched/ext/ext.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c index 4139b90d37fb..95149321b18f 100644 --- a/kernel/sched/ext/ext.c +++ b/kernel/sched/ext/ext.c @@ -4959,6 +4959,11 @@ int scx_fork(struct task_struct *p, struct kernel_clone_args *kargs) void scx_post_fork(struct task_struct *p) { if (scx_init_task_enabled) { + struct rq_flags rf; + struct rq *rq; + + /* synchronize against switching_to_scx() and switched_from_scx() */ + rq = task_rq_lock(p, &rf); scx_set_task_state(p, SCX_TASK_READY); /* @@ -4966,14 +4971,9 @@ void scx_post_fork(struct task_struct *p) * Otherwise, it'll be enabled in switching_to_scx() if and * when it's ever configured to run with a SCHED_EXT policy. */ - if (p->sched_class == &ext_sched_class) { - struct rq_flags rf; - struct rq *rq; - - rq = task_rq_lock(p, &rf); + if (p->sched_class == &ext_sched_class) scx_enable_task(scx_task_sched(p), p); - task_rq_unlock(rq, p, &rf); - } + task_rq_unlock(rq, p, &rf); } scoped_guard(raw_spinlock_irq, &scx_tasks_lock) { @@ -5107,7 +5107,13 @@ static void switching_to_scx(struct rq *rq, struct task_struct *p) if (task_dead_and_done(p)) return; - scx_enable_task(sch, p); + /* + * Only a task being forked can be %INIT here. Enabling the root and + * re-homing take a task from %INIT to %READY under the rq lock held + * here. scx_post_fork() enables a task being forked. + */ + if (scx_get_task_state(p) != SCX_TASK_INIT) + scx_enable_task(sch, p); /* * set_cpus_allowed_scx() is not called while @p is associated with a @@ -5137,10 +5143,14 @@ static void switched_from_scx(struct rq *rq, struct task_struct *p) * scx_disable_task() would WARN on the non-%ENABLED state and trigger a * NONE -> READY validation failure. * - * Either way, reset @p after ops.disable() has seen the final values. A - * %NONE @p can still be a rescuee under the parent. + * %INIT means @p is being forked and hasn't been enabled yet. + * scx_post_fork() leaves it %READY if it is no longer on the ext class. + * + * In all cases, reset @p after ops.disable() has seen the final values. + * A %NONE @p can still be a rescuee under the parent. */ - if (scx_get_task_state(p) != SCX_TASK_NONE) + if (scx_get_task_state(p) != SCX_TASK_NONE && + scx_get_task_state(p) != SCX_TASK_INIT) scx_disable_task(scx_task_sched(p), p); scx_reset_task_fields(rq, p); } -- 2.53.0