From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796476342; b=PWxXgMCJnr8GdGWxeQSR1+uVP/x8XFqiO25p+j7q7aczNP6yolYKZu4BO89nk16P+hG6 uaOkd9WvakWfdnIrADfx05Q6iI47ppkbIlO6iQMLfhl8m6Nvfq5Gi1Mbd3HYPr8AGIDBq IgchntODZwgqim7zzWjmlCz2KbbmryQv05LH4WjVjPaBJoUfvwV28baTdIoh5p+oFXkTW efyb7jyqOdc65eS70Bl2vWpixKuEj8MKHcjLU5xunftkPZQhnL4QuJDomxZoSecKJ5HaX 1qLcnCC1nEiae34J2XTgsGFm0QKLlahHL5HlKncxDDRCA8bopG9+a0jVXbVAjBe1eow== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796476342; h=Received:DKIM-Signature:Received:Received:X-ME-Sender: X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:Received:X-Mailer: MIME-Version:X-ThreadId:Date:From:To:Cc:Message-Id:In-Reply-To: References:Subject:Content-Type:Content-Transfer-Encoding; bh=eM7PA07fY8POtyfpuynVvgTnlMSaqFALIYU/PntdyUY=; b=wONYL89fj+I5ePAZpniCdqORpR2TKQv3AB9pejg1PSTBRyYnxa9DIf/4r3LXfdORffVe u7cJv1tDHQ55uPgo6LIZL2IQNJp4F38haprdIDKBDBDABBbTlCjJzpNTtvRUKVJRzFcvu NlR5IADUfr/FQUv2xGENRq+CWvcbrLRw+FxvD9RSxXZcU4VLCuRU7v75H9c0LFe7nCdN6 L2GBhVOgsUkKwSGyLkpXvRUUEZSOUchH9eEVbcE/CKZRDb93B4LAGjwU0vyJ9Va7mco7d cMcPLUkmL8ygaolrZvf7Tr69ksq1i++T2nvEHfaPjDPQApl2jse4Ebw9JJsxvc8utqw== 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=ga8ljIKo; 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 6257B606A322; Sat, 5 Dec 2026 13:12:22 +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=ga8ljIKo Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD1DB1F00A10; Sat, 5 Dec 2026 13:12:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796476342; bh=eM7PA07fY8POtyfpuynVvgTnlMSaqFALIYU/PntdyUY=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=ga8ljIKoG86euckcFanmRXXoUldqaJcfxro0kgMIn9Vgh5Bu/Ph2PdlrkFhjlcEKf QHRILSr28CWU0YHJxgi8gJoSSpJJxIbwfr6X3x2J2EDQXbbqlqMgupGRxcFal8YaWv lJSJ7cosdp0LYs1ZSbjedRNuHA0jrPTLCEvy2rOQ90XhGKGavGgHa+fDcb9CNvb63O kP0Ex+u36NM6ozjeD4DMTixW/mf8bpzIwvkABfayBD+Mc3UEIB2UlSjwYYNb5ZfcaN nW4dQcIoTDlUjxUyVVJDgnbEUcyXc3yRbqJM8MVBv3p/utgc89s8r1rqiWWWuz259M OMuRjB6nSWzAg== Received: from stl-compute-04.internal (stl-compute-04.internal [10.204.2.64]) by mailfauth.stl.internal (Postfix) with ESMTP id 63387780043; Sat, 5 Dec 2026 08:12:21 -0500 (EST) Received: from stl-imap-13 ([10.204.2.104]) by stl-compute-04.internal (MEProxy); Sat, 05 Dec 2026 08:12:21 -0500 X-ME-Sender: X-ME-Proxy-Cause: dmFkZTFq+Kc9DnW6RKmBEq6GeEuNHCzie/EEpHczT4JiDPIEzFTZr8abuwEHkqoEEIcsKr Z/Lz3V6CwQMEoDSer/7cKuky6tIQrHGP16ujU7teorn9NeBxdxsKZ41ZpZuCo6t8MFgnqQ c4xVnyNnbdwLWEnSpZY0F7yHKidRQAtyP4PfilZWIv1rudEqM6z3Ac1oYIvZ+fX308gtT9 vT0YYI3u36+Y8ZYFmi9kbuVUKR/DsXq/lmAUEuaOcrEp4IvaiCHfjHGxqKGmAfIRdjwwfI IrBcyj4ttW35MLna8TZ/U3Im1kKI7yMG5dH8FBpOuolXjikywENF22UuNqwGjAJI1/rgB5 dht6Cgvje6yzrV50WRnS73GoX+ffuZNhpb2l9Pudf5jYGVWG2ygTsbOLHNAuU4nV0abg1f 7MmwQ/HdnhBAdbdMcD5ZiiLWv7iAwP7ZJ+e3ce+QEjgWnxx+06oxw9UeeohwoxubCEIPfP W4srmdsOqNXS0e9sdLaFqj688lli73+pFBL58a0bkLt8r++/WTajCk7ldKSmAx3HlCqOwa 97zrROub5ui4YoskoGNujbQXn1KMyCZZpa8dgpdxd39kV01IXXicXuXL4Ybi+EcL7MJHLL zNj59Thtr4F5zcpvwRnGUbIz6TZ/z0W37m2W7Lx8Zr9Yxu7sYAka/iBMRH7Q X-ME-Proxy: Feedback-ID: iccae4b50:Fastmail Received: by mailuser.stl.internal (Postfix, from userid 501) id 1FA4EF60088; Sat, 5 Dec 2026 08:12:21 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-ThreadId: AuvvtD4j5FdZ Date: Sat, 05 Dec 2026 08:12:00 -0500 From: "Chris Mason" To: brauner@kernel.org, oleg@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, peterz@infradead.org, mingo@redhat.com, kees@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, bsingharora@gmail.com, eddyz87@gmail.com, memxor@gmail.com, yonghong.song@linux.dev, martin.lau@linux.dev, song@kernel.org, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, sched-ext@lists.linux.dev, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, mason@kernel.org Message-Id: <20261204233428.14861-3-mason@kernel.org> In-Reply-To: <20261204233428.14861-1-mason@kernel.org> References: <20261204233428.14861-1-mason@kernel.org> Subject: [PATCH v2 2/8] exec, cgroup, prlimit: prepare for group_leader resets Content-Type: text/plain Content-Transfer-Encoding: 7bit This is a prep patch that allows us to reset group_leader in release_task(). exec and cgroup migration walk the threads with next_thread(t), which wraps from the last thread to t->group_leader. If t is released meanwhile, that would be t itself, and the walk would never end. So use for_each_thread() there. do_prlimit() reads tsk->group_leader for task_lock(), and again for task_unlock(). So let prlimit64() hold tasklist_lock unless tsk is current. Signed-off-by: Chris Mason --- fs/exec.c | 4 ++-- include/linux/sched/signal.h | 4 ++-- kernel/cgroup/cgroup.c | 24 ++++++++++++------------ kernel/sys.c | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 8d2b14e1d455c..b3b80a47fb657 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1621,10 +1621,10 @@ static void check_unsafe_exec(struct linux_binprm *bprm) * from another sub-thread until de_thread() succeeds, this * state is protected by cred_guard_mutex we hold. */ - n_fs = 1; + n_fs = 0; read_seqlock_excl(&p->fs->seq); rcu_read_lock(); - for_other_threads(p, t) { + for_each_thread(p, t) { if (t->fs == p->fs) n_fs++; } diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 0adb51ab15428..cf73f4dd6946a 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -663,8 +663,8 @@ extern void flush_itimer_signals(void); extern bool current_is_single_threaded(void); /* - * Without tasklist/siglock it is only rcu-safe if g can't exit/exec, - * otherwise next_thread(t) will never reach g after list_del_rcu(g). + * Needs tasklist/siglock, otherwise next_thread(t) may never reach g + * after t or g has been released. Use for_each_thread() under RCU. */ #define while_each_thread(g, t) \ while ((t = next_thread(t)) != g) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index b3657e72db99e..640af2d4551d1 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3075,12 +3075,12 @@ int cgroup_migrate(struct task_struct *leader, bool threadgroup, * spin_lock_irq() implies RCU critical section here. */ spin_lock_irq(&css_set_lock); - task = leader; - do { - cgroup_migrate_add_task(task, mgctx); - if (!threadgroup) - break; - } while_each_thread(leader, task); + if (threadgroup) { + for_each_thread(leader, task) + cgroup_migrate_add_task(task, mgctx); + } else { + cgroup_migrate_add_task(leader, mgctx); + } spin_unlock_irq(&css_set_lock); return cgroup_migrate_execute(mgctx); @@ -3103,12 +3103,12 @@ int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader, /* look up all src csets */ spin_lock_irq(&css_set_lock); - task = leader; - do { - cgroup_migrate_add_src(task_css_set(task), dst_cgrp, &mgctx); - if (!threadgroup) - break; - } while_each_thread(leader, task); + if (threadgroup) { + for_each_thread(leader, task) + cgroup_migrate_add_src(task_css_set(task), dst_cgrp, &mgctx); + } else { + cgroup_migrate_add_src(task_css_set(leader), dst_cgrp, &mgctx); + } spin_unlock_irq(&css_set_lock); /* prepare dst csets and commit */ diff --git a/kernel/sys.c b/kernel/sys.c index 755bfa5ccd92c..9cb8eac08b7d2 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -1764,10 +1764,10 @@ SYSCALL_DEFINE4(prlimit64, pid_t, pid, unsigned int, resource, get_task_struct(tsk); rcu_read_unlock(); - need_tasklist = !same_thread_group(tsk, current); + need_tasklist = tsk != current; if (need_tasklist) { /* - * Ensure we can't race with group exit or de_thread(), + * Ensure we can't race with release_task() or de_thread(), * so tsk->group_leader can't be freed or changed until * read_unlock(tasklist_lock) below. */