From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795180731; b=F15vXtimO73dwt7Es696Mn2QVMIAExzoBJRxVy0/rKHIal3kvGmkQLPRn3V0HVsxu84w T17cc3IHCz+4pgcEJ47WvAcc9cwJAe6LZZzAV5ECPt4tLqYRoDAhFJXiTNbxszTSWfuap 5sDJHGrBUCqgSLOSOdGxfBRYkoRM6rnwGighvyq1ICCGkAwiMw3PjX9z6rdHNnMAGWltH oliTg9uHiGXnpC7Tz7IG0guY4+XJujYiAdZNBtSxRn7VNmn/EN78wPOWX/zTlbacEa5uu XUL3FtpZ+rZSsiojNcNuI5tVqg0/awUNX6WefCn7JL8wgdQY7DJihejneOQBFMR1b9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795180731; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=YAQTVNIYZ/0Tbx2obltQhn42YTPBHmmwY733kBIibzM=; b=PSXOCKAVFNK/SdWB+TDOLAdcAMVB63Q2soJ2FgRUx0LFQQGt8BClKiniaBhnpbllGrrL xIKggHYWd9Wnqc3mWgscUs62MHTXHPo+1bDm+eNs7gv1DiKLoBcLbzuvODuMBAdkg7dYJ j5/HFkOMPsITMnYgT5IioFMCthlmHMWjYirQLhuahxa19zvOGOLbWOGaIOTsJj4g2nXnh RCmThwTAsCWFK+Q0PUr61vABwXSmHgNKgtGg09RI0zyS+1/QuxwiCVQRZwFpAXvr7L5VG snzYwKhbeFmaosnvw3BabMTWx8bnTAfwtCDMJK40V8DjgefOPzwCPonV+o+4go/2J6g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=amutable.com; spf=pass smtp.mailfrom=amutable.com; dkim=pass header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b="UI/9rv+D"; arc=none smtp.remote-ip=209.85.218.45 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 22192606A32A for ; Fri, 20 Nov 2026 13:18:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 22192606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=amutable.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amutable.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=UI/9rv+D Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-c51373ae637so135959566b.3 for ; Fri, 20 Nov 2026 05:18:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amutable-com.20260707.gappssmtp.com; s=20260707; t=1795180728; x=1795785528; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to:content-type; bh=YAQTVNIYZ/0Tbx2obltQhn42YTPBHmmwY733kBIibzM=; b=UI/9rv+DZdDezz6z4q5V4bbLRvq2PUwTXKvmGLgkStPFRG3MFzpLEzZUOMicEVzjqv h9WskxL6pQRjVp6LW7wNLul6TdE5DMEMvMtKHVto1kDWUtXl4YZysNnP5izuUm6Wyf00 02kOc+/ogItTG9aLvdGftl8BuwMr3ddEGZP8CscGYWnM7MnxJ1gdPDJRCMKsqAHhAduA 5fYf+0m8yQ6qc78NG4siN795mYwXAc6BQzyhcrtUI3sLGXErAQdCZNzpNCRSgoDhZ53Q BTlXcoGhXILqja8hQmBbLSiQNTaIckFhQCA59sphyqAh5AgpCytcMtf2fggUT1oBCS51 FT4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795180728; x=1795785528; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=YAQTVNIYZ/0Tbx2obltQhn42YTPBHmmwY733kBIibzM=; b=Br44Lbcqf5xIyjU7ABs4slxTVcA7FtP5XkX9uBjnV9I6DS/FC9u/Gs/fRtZeDVbwKz MUDSQAVL1tri6UglpUC9zx0qTHcEgTClVkU7cz6Pv0USzOX+hbxBvoR3Rc4nGi2GbA5X jby52jmzIHLt8hWIK8B7CvUctEj0hfnSuxKsAw1YEA/uki939eaVzf9yMfQ4xgQr03pB RQT2tPG+BLktAGltrpYxoqOechS1LqukjpjlwAqRog84u9diUt0b++CYamPnuGT/wAba FHmt85OXqHRMOBvFQiiqfdScO9ft6xqtjAtcRryjUpfGGQzgW6JEHH+eYghvL47IlL5+ MEVA== X-Forwarded-Encrypted: i=1; AL+hErF3kauB7y3IbqBdY6aZR3VTO5Hscu4rxbTsQHQmAe1au56gxHrH4uNtp/0Sd4TX4ONVy+iEHYcXDf1dSnFVh5A=@vger.kernel.org X-Gm-Message-State: APuU4Z90r9QkYBKg5dqN9u9+otLR7ksR4XH9IgXCPDSMxEhWGaPSKe/d C7vMRAgWajemSmnHGDNsYCKvxZXSY98lGe7x5AGEePpanjZlokIEXsJCOicwZy7xBh/1 X-Gm-Gg: AYBFou2M2KlIxxSD+XfMs7OTWI9rgXqovGuJQnbxFwmlqEvholR7gTivLjyktE3snKe OLl9ePRadsu3H9OwgfCW/yuKdNvXzyfkyU+XkfbVWxmqCP64BnHuxR+q3ogAbphcXjdPozRL08o axPZHq2VglnKJLlzTqwUCnGUC1ml86Q6ezHRbTqGafiFynerAHCmSZaoH4Gnrtn2+s7hcRpyUp5 VB7mKWThwEZbr45rd2XxEdkF6XMcWbeDvjJqM42Yzd/pdhcdWSsAF5drboH4u5KSd2A7c+K7TSY OmnFXb9IL0NuJ2AIjE+RNtsOgTX4Ndmrxdpe7+XeL33vHz0ZhDc2soLc8JlHEaXgjFZegbM+EKU xX1DySW8RzjtxLbKwa1Qm13HOaAvxsvMn3ncznA55C4liYYcK12stn47etS+QIpTwmA8f6CwtpB dlxw8W5JDhl+4L+qhL1CGTHOPE7yjxuh+8uZqIdS0QMvNlzYrKCedfjSRBVHjaAL+HaX7sz2u6o Dhy6uYijsPaNJZDH+DNqycP7Gd+pFu87o6wf8sxP96hCllUs1CZzw1tS9er+2zHul2sk4mvW2Fm If5g1WbPzUSp3+PYLTb0wMCSG1bwIeM+0pYF+0Cw9w6gAl8OB3QJHJlb81wtcN8V2Q== X-Received: by 2002:a17:907:a890:b0:c41:55b4:d88b with SMTP id a640c23a62f3a-c513ab14402mr338807466b.43.1795180728386; Fri, 20 Nov 2026 05:18:48 -0800 (PST) Received: from [10.0.0.233] (tmo-084-188.customers.d1-online.com. [80.187.84.188]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c513acfe3b0sm93731066b.8.2026.11.20.05.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 05:18:47 -0800 (PST) Message-ID: Subject: Re: [RFC PATCH v4 03/14] rootns: Track init lifecycle via copy_process() and pid_namespace From: Alexander Mikhalitsyn To: Jarkko Sakkinen , linux-fsdevel@vger.kernel.org Cc: linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, Albert Ou , Alexander Gordeev , Alexander Viro , Alexandre Ghiti , Andreas Larsson , Andrew Morton , Andy Lutomirski , Andy Lutomirski , Anna-Maria Behnsen , Arnd Bergmann , Ben Segall , Borislav Petkov , Casey Schaufler , Catalin Marinas , Christian Borntraeger , Christian Brauner , "Christophe Leroy (CS GROUP)" , Chris Zankel , Dave Hansen , David Hildenbrand , David Howells , Davidlohr Bueso , "David S. Miller" , Dietmar Eggemann , Frederic Weisbecker , Geert Uytterhoeven , "Hallgrimur H. Gunnarsson" , Heiko Carstens , Helge Deller , "H. Peter Anvin" , Ingo Molnar , "James E.J. Bottomley" , Jan Kara , John Johansen , John Paul Adrian Glaubitz , Jonathan Corbet , Josef Bacik , Juri Lelli , Kees Cook , K Prateek Nayak , "Liam R. Howlett" , Lorenzo Stoakes , Madhavan Srinivasan , Magnus Lindholm , Manfred Spraul , Mark Rutland , Matt Turner , Max Filippov , Mel Gorman , Michael Ellerman , Michal Hocko , Michal Simek , Mike Rapoport , Neal Gompa , Nicholas Piggin , Palmer Dabbelt , Paul Moore , Paul Walmsley , Pavel Tikhomirov , Peter Zijlstra , Randy Dunlap , Richard Henderson , Rich Felker , "Ritesh Harjani (IBM)" , Russell King , Serge Hallyn , Shrikanth Hegde , Shuah Khan , Steven Rostedt , Suren Baghdasaryan , Sven Schnelle , Thomas Bogendoerfer , Thomas Gleixner , Valentin Schneider , Vasily Gorbik , Vincent Guittot , Vincenzo Frascino , Vlastimil Babka , Will Deacon , Yoshinori Sato , Zygmunt Krynicki Date: Fri, 20 Nov 2026 14:18:43 +0100 In-Reply-To: <20261119224312.1037966-4-jarkko@kernel.org> References: <20261119224312.1037966-1-jarkko@kernel.org> <20261119224312.1037966-4-jarkko@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-0+deb13u1 X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Fri, 2026-11-20 at 00:43 +0200, Jarkko Sakkinen wrote: > A root namespace needs to record its init thread group's PID when > bootstrapped and capture its exit status once all processes in the > root > namespace have terminated, without serializing normal fork() and > exit() > paths inside the container. >=20 > Commit the bootstrap child reaper, bind pid_ns->rootns, and wake > waiters > in copy_rootns() after attach_pid(PIDTYPE_PID), and invoke > exit_rootns() > from zap_pid_ns_processes() after the root namespace's PID namespace > has > killed and reaped all member tasks. >=20 > Co-developed-by: David Howells > Signed-off-by: David Howells > Signed-off-by: Jarkko Sakkinen > --- > =C2=A0include/linux/pid_namespace.h |=C2=A0 4 ++++ > =C2=A0include/linux/rootns.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | = 15 ++++++++++++++ > =C2=A0kernel/fork.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 3 +++ > =C2=A0kernel/pid_namespace.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |= =C2=A0 2 ++ > =C2=A0kernel/rootns.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 38 > +++++++++++++++++++++++++++++++++++ > =C2=A05 files changed, 62 insertions(+) >=20 > diff --git a/include/linux/pid_namespace.h > b/include/linux/pid_namespace.h > index b20baaa7e62b..6fd959f4d0d4 100644 > --- a/include/linux/pid_namespace.h > +++ b/include/linux/pid_namespace.h > @@ -15,6 +15,7 @@ > =C2=A0#define MAX_PID_NS_LEVEL 32 > =C2=A0 > =C2=A0struct fs_pin; > +struct rootns; > =C2=A0 > =C2=A0#if defined(CONFIG_SYSCTL) && defined(CONFIG_MEMFD_CREATE) > =C2=A0/* modes for vm.memfd_noexec sysctl */ > @@ -45,6 +46,9 @@ struct pid_namespace { > =C2=A0 struct user_namespace *user_ns; > =C2=A0 struct ucounts *ucounts; > =C2=A0 int reboot; /* group exit code if this pidns was > rebooted */ > +#ifdef CONFIG_ROOTNS > + struct rootns *rootns; > +#endif > =C2=A0 struct ns_common ns; > =C2=A0 struct work_struct work; > =C2=A0} __randomize_layout; > diff --git a/include/linux/rootns.h b/include/linux/rootns.h > index 3f59415efadb..0557ce75195d 100644 > --- a/include/linux/rootns.h > +++ b/include/linux/rootns.h > @@ -13,6 +13,8 @@ > =C2=A0struct file; > =C2=A0struct nsproxy; > =C2=A0struct pid; > +struct pid_namespace; > +struct task_struct; > =C2=A0struct user_namespace; > =C2=A0 > =C2=A0enum rootns_state { > @@ -41,6 +43,9 @@ struct rootns { > =C2=A0struct rootns *get_rootns(struct rootns *c); > =C2=A0void put_rootns(struct rootns *c); > =C2=A0bool is_rootns_file(struct file *file); > +void copy_rootns(struct task_struct *tsk, struct pid *pid, > + struct rootns *rootns); > +void exit_rootns(struct pid_namespace *pid_ns, struct task_struct > *tsk); > =C2=A0#else > =C2=A0static inline struct rootns *get_rootns(struct rootns *c) > =C2=A0{ > @@ -55,6 +60,16 @@ static inline bool is_rootns_file(struct file > *file) > =C2=A0{ > =C2=A0 return false; > =C2=A0} > + > +static inline void copy_rootns(struct task_struct *tsk, struct pid > *pid, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct rootns *rootns) > +{ > +} > + > +static inline void exit_rootns(struct pid_namespace *pid_ns, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct task_struct *tsk) > +{ > +} > =C2=A0#endif /* CONFIG_ROOTNS */ > =C2=A0 > =C2=A0#endif /* _LINUX_ROOTNS_H */ > diff --git a/kernel/fork.c b/kernel/fork.c > index 5efceb8d58a7..08fc28ad1eed 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -83,6 +83,7 @@ > =C2=A0#include > =C2=A0#include > =C2=A0#include > +#include > =C2=A0#include > =C2=A0#include > =C2=A0#include > @@ -2576,6 +2577,8 @@ __latent_entropy struct task_struct > *copy_process( > =C2=A0 =C2=A0 &p->signal->thread_head); > =C2=A0 } > =C2=A0 attach_pid(p, PIDTYPE_PID); > + if (thread_group_leader(p)) > + copy_rootns(p, pid, NULL); > =C2=A0 nr_threads++; > =C2=A0 } > =C2=A0 total_forks++; > diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c > index 127a5fd23e70..081c27aa85bd 100644 > --- a/kernel/pid_namespace.c > +++ b/kernel/pid_namespace.c > @@ -24,6 +24,7 @@ > =C2=A0#include > =C2=A0#include > =C2=A0#include > +#include > =C2=A0#include > =C2=A0#include "pid_sysctl.h" > =C2=A0 > @@ -280,6 +281,7 @@ void zap_pid_ns_processes(struct pid_namespace > *pid_ns) > =C2=A0 current->signal->group_exit_code =3D pid_ns->reboot; > =C2=A0 Dear Jarkko, > =C2=A0 acct_exit_ns(pid_ns); > + exit_rootns(pid_ns, me); We have a very similar mechanism around pidfd's to track exit information for a task. As far as I can see we already have (struct rootns *)->init_pid reference, so we can get exit information for free (look for PIDFD_INFO_EXIT). Kind regards, Alex > =C2=A0 return; > =C2=A0} > =C2=A0 > diff --git a/kernel/rootns.c b/kernel/rootns.c > index 3bbf7677080e..bde7cf4baebe 100644 > --- a/kernel/rootns.c > +++ b/kernel/rootns.c > @@ -183,3 +183,41 @@ bool is_rootns_file(struct file *file) > =C2=A0{ > =C2=A0 return file->f_op =3D=3D &rootns_fops; > =C2=A0} > + > +void copy_rootns(struct task_struct *tsk, struct pid *pid, struct > rootns *c) > +{ > + if (likely(!c || !is_child_reaper(pid))) > + return; > + > + scoped_guard(spinlock, &c->lock) { > + if (c->state !=3D ROOTNS_FORKING) > + return; > + ns_of_pid(pid)->rootns =3D get_rootns(c); > + WRITE_ONCE(c->init_pid, get_pid(pid)); > + WRITE_ONCE(c->state, ROOTNS_RUNNING); > + } > + wake_up_all(&c->waitq); > +} > + > +void exit_rootns(struct pid_namespace *pid_ns, struct task_struct > *tsk) > +{ > + struct rootns *c =3D pid_ns->rootns; > + struct task_struct *leader; > + int status; > + > + if (!c) > + return; > + > + leader =3D tsk->group_leader; > + status =3D (tsk->signal->flags & SIGNAL_GROUP_EXIT) ? > + tsk->signal->group_exit_code : leader->exit_code; > + > + scoped_guard(spinlock, &c->lock) { > + c->exit_code =3D status; > + WRITE_ONCE(c->state, ROOTNS_DEAD); > + } > + > + pid_ns->rootns =3D NULL; > + wake_up_poll(&c->waitq, EPOLLHUP); > + put_rootns(c); > +}