From nobody Thu Oct 2 11:48:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53921303A1E; Wed, 17 Sep 2025 10:28:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104920; cv=none; b=XzwvDim4SsCv5aLokyAJSVKi8JOiMAHNT7jdK12NEzbmdWJ2GzC2xno7PxNGsZIVnKB4QrsosURVQuwuCV7V/YLBTdpOpvq8i9AmR1NXnnLEWkzIT9q1NAVl+qWB+u66D35Ng4E9OZR3JIcUOrZXpMWIWoj6mkTZh/hSBrtV/+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104920; c=relaxed/simple; bh=AvdOHxfXHrvdoBdIQ10mM48HLMw4+4GPk3SqftCCZM8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=urWqCGLg2z33z2FZympYVzYILNuil+r+M1hLNQdnFovhSLacpjoQQx+EgrE+3Sh0ZJogQ2i/iLpPc5aA5Z/3KWPFViNM/h1T9ThyzXxrKmB6ZG0LLRopXF2pL0vNWPSzoq2/UfHVJCRGmkpb2bl85oWU8daw5KR97YFXEunBW8c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CCvOjRku; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CCvOjRku" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0C83C4CEF0; Wed, 17 Sep 2025 10:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758104920; bh=AvdOHxfXHrvdoBdIQ10mM48HLMw4+4GPk3SqftCCZM8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CCvOjRku2B74YaC9Bka/d9l72iV8shu4Hyh985EQuiHZLwIg6mlg2nIY41KwQQ6Bc jkwytlzDNUjAxBLflKZwffEGwrW6uJ3vD6IA96Hf9jKnpoNtim213UAjt1Ejhbr1Pm AygPg8zbDkOzKyvXQ2zE6Qaak/o/W9aUJXGWi8AkYpbzOro8D4orMx3SBFm+rbO4X7 OaEpwtIRcqtAhes+JjA8T7rSJTDrA4j47RvtePyA+/LdeqjmVNMCvsdG859T5dNZ8i ECTnIqAXOjEcazVfzujiKC2sZwGsCnRbGaxv4ux8/kPFAFtQUcgSkKUh5K3FJLX+lf uWsSZc113ZA8A== From: Christian Brauner Date: Wed, 17 Sep 2025 12:28:00 +0200 Subject: [PATCH 1/9] uts: split namespace into separate header Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250917-work-namespace-ns_common-v1-1-1b3bda8ef8f2@kernel.org> References: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> In-Reply-To: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> To: linux-fsdevel@vger.kernel.org Cc: Amir Goldstein , Josef Bacik , Jeff Layton , Mike Yuan , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Lennart Poettering , Daan De Meyer , Aleksa Sarai , Alexander Viro , Jan Kara , Tejun Heo , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Jakub Kicinski , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-56183 X-Developer-Signature: v=1; a=openpgp-sha256; l=4023; i=brauner@kernel.org; h=from:subject:message-id; bh=AvdOHxfXHrvdoBdIQ10mM48HLMw4+4GPk3SqftCCZM8=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWSc6vVtMrnXf4f9QPm3ewud93cf5324KylFcJVGaUvwy l18DvslOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACbS9Z6R4QWL18ufq5W+NauJ SJxYd2B7+G0Rw8oL2nmPhTq2shcmszL8T83NvbeBwemVTGj2psWibJNeh1j/ypzmaiJ0dZHF7X9 /uQA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 We have dedicated headers for all namespace types. Add one for the uts namespace as well. Now it's consistent for all namespace types. Signed-off-by: Christian Brauner Reviewed-by: Jan Kara --- include/linux/uts_namespace.h | 65 +++++++++++++++++++++++++++++++++++++++= ++++ include/linux/utsname.h | 58 +------------------------------------- 2 files changed, 66 insertions(+), 57 deletions(-) diff --git a/include/linux/uts_namespace.h b/include/linux/uts_namespace.h new file mode 100644 index 000000000000..c2b619bb4e57 --- /dev/null +++ b/include/linux/uts_namespace.h @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_UTS_NAMESPACE_H +#define _LINUX_UTS_NAMESPACE_H + +#include +#include + +struct user_namespace; +extern struct user_namespace init_user_ns; + +struct uts_namespace { + struct new_utsname name; + struct user_namespace *user_ns; + struct ucounts *ucounts; + struct ns_common ns; +} __randomize_layout; + +extern struct uts_namespace init_uts_ns; + +#ifdef CONFIG_UTS_NS +static inline struct uts_namespace *to_uts_ns(struct ns_common *ns) +{ + return container_of(ns, struct uts_namespace, ns); +} + +static inline void get_uts_ns(struct uts_namespace *ns) +{ + refcount_inc(&ns->ns.count); +} + +extern struct uts_namespace *copy_utsname(unsigned long flags, + struct user_namespace *user_ns, struct uts_namespace *old_ns); +extern void free_uts_ns(struct uts_namespace *ns); + +static inline void put_uts_ns(struct uts_namespace *ns) +{ + if (refcount_dec_and_test(&ns->ns.count)) + free_uts_ns(ns); +} + +void uts_ns_init(void); +#else +static inline void get_uts_ns(struct uts_namespace *ns) +{ +} + +static inline void put_uts_ns(struct uts_namespace *ns) +{ +} + +static inline struct uts_namespace *copy_utsname(unsigned long flags, + struct user_namespace *user_ns, struct uts_namespace *old_ns) +{ + if (flags & CLONE_NEWUTS) + return ERR_PTR(-EINVAL); + + return old_ns; +} + +static inline void uts_ns_init(void) +{ +} +#endif + +#endif /* _LINUX_UTS_NAMESPACE_H */ diff --git a/include/linux/utsname.h b/include/linux/utsname.h index 5d34c4f0f945..547bd4439706 100644 --- a/include/linux/utsname.h +++ b/include/linux/utsname.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include =20 enum uts_proc { UTS_PROC_ARCH, @@ -18,62 +18,6 @@ enum uts_proc { UTS_PROC_DOMAINNAME, }; =20 -struct user_namespace; -extern struct user_namespace init_user_ns; - -struct uts_namespace { - struct new_utsname name; - struct user_namespace *user_ns; - struct ucounts *ucounts; - struct ns_common ns; -} __randomize_layout; -extern struct uts_namespace init_uts_ns; - -#ifdef CONFIG_UTS_NS -static inline struct uts_namespace *to_uts_ns(struct ns_common *ns) -{ - return container_of(ns, struct uts_namespace, ns); -} - -static inline void get_uts_ns(struct uts_namespace *ns) -{ - refcount_inc(&ns->ns.count); -} - -extern struct uts_namespace *copy_utsname(unsigned long flags, - struct user_namespace *user_ns, struct uts_namespace *old_ns); -extern void free_uts_ns(struct uts_namespace *ns); - -static inline void put_uts_ns(struct uts_namespace *ns) -{ - if (refcount_dec_and_test(&ns->ns.count)) - free_uts_ns(ns); -} - -void uts_ns_init(void); -#else -static inline void get_uts_ns(struct uts_namespace *ns) -{ -} - -static inline void put_uts_ns(struct uts_namespace *ns) -{ -} - -static inline struct uts_namespace *copy_utsname(unsigned long flags, - struct user_namespace *user_ns, struct uts_namespace *old_ns) -{ - if (flags & CLONE_NEWUTS) - return ERR_PTR(-EINVAL); - - return old_ns; -} - -static inline void uts_ns_init(void) -{ -} -#endif - #ifdef CONFIG_PROC_SYSCTL extern void uts_proc_notify(enum uts_proc proc); #else --=20 2.47.3 From nobody Thu Oct 2 11:48:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C44E52F7AA3; Wed, 17 Sep 2025 10:28:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104925; cv=none; b=X0Kvj5dyi12d69muDHRDN0YaiIt21NzlcaR1cxGr9PmZeHIoWUxgTr3IPFamzFtPzqmakabS+OV7tE5gF69ZnE7PbchTPw/N8sT9ecl04gtrsg5cIQOritWfbOjp8IS7HDDVNGIezsH6MuSoNv44D0FaSPHRGY0YoDewadowmIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104925; c=relaxed/simple; bh=7IxtHM+V3qkSMuMxxb4C83WRBdh/pZ/dABcbRzXFT34=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XdOKHQF1Xo5MPhCwRtKbZz3pmn8BV+AE3Ur/TMwU1mJlAW7sfDmnEKGO1Fe9bfEyoAcg5gedYVHzMhs8aemVa/gtrvhlp8JhB6dr1ima8J7GVKZldk9hp+y57lp6mJyOlWr6caXulPiOtgdEfaHXBjWFqVBh8n1EslRe+wIOlZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eFcXr37r; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eFcXr37r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4D57C4CEF0; Wed, 17 Sep 2025 10:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758104925; bh=7IxtHM+V3qkSMuMxxb4C83WRBdh/pZ/dABcbRzXFT34=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eFcXr37r1T0tT6dV8/G6uX5BzrUt2GqahU0oGcnr4ruxc/2fx2aAXCMEFio8J5RQw NmYhg1HCaePjwCxkQgEuFQYYIxn3C/coDPVXPbFrUv6+KV3ru+5hMik1L+vreVM6Wi XHBFvXdQsw1ObtTIWNexbtiVXmmxvGxG6MeZ4UTz6/VMPfY0Us0MxBnLFLroU080sA ggtWoXKbt4AOMqQIfXTV+THaDwIYfawzu2Kd7L5UuLap1UJf+WUlJRuoSla0EGLT6i /MJnNjXRrDMz32DLR0AcFJoGbwrnwAMhVBMLqOTyEFvGShbU/L5/Et69TQZw4UMzgE Ae8qlhPT9Ad8A== From: Christian Brauner Date: Wed, 17 Sep 2025 12:28:01 +0200 Subject: [PATCH 2/9] mnt: expose pointer to init_mnt_ns Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250917-work-namespace-ns_common-v1-2-1b3bda8ef8f2@kernel.org> References: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> In-Reply-To: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> To: linux-fsdevel@vger.kernel.org Cc: Amir Goldstein , Josef Bacik , Jeff Layton , Mike Yuan , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Lennart Poettering , Daan De Meyer , Aleksa Sarai , Alexander Viro , Jan Kara , Tejun Heo , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Jakub Kicinski , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-56183 X-Developer-Signature: v=1; a=openpgp-sha256; l=1604; i=brauner@kernel.org; h=from:subject:message-id; bh=7IxtHM+V3qkSMuMxxb4C83WRBdh/pZ/dABcbRzXFT34=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWSc6vXlmKRy+EeWkvjnmoDPT7qZ2HjebcmWLLtx7+05m eNvEmt9O0pZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACZyT5Phr/S1bQxyHLXsVTW7 bO7s9b1ewVptt5d5GSfXnzq18mdrLjD84UzzUgiXbgzT7N6pYerfuSoh84TJBJ21flkPt5vec3b mAAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 There's various scenarios where we need to know whether we are in the initial set of namespaces or not to e.g., shortcut permission checking. All namespaces expose that information. Let's do that too. Signed-off-by: Christian Brauner Reviewed-by: Jan Kara --- fs/namespace.c | 2 ++ include/linux/mnt_namespace.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/fs/namespace.c b/fs/namespace.c index a68998449698..c8251545d57e 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -81,6 +81,7 @@ static DECLARE_RWSEM(namespace_sem); static HLIST_HEAD(unmounted); /* protected by namespace_sem */ static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */ static struct mnt_namespace *emptied_ns; /* protected by namespace_sem */ +struct mnt_namespace *init_mnt_ns; =20 #ifdef CONFIG_FSNOTIFY LIST_HEAD(notify_list); /* protected by namespace_sem */ @@ -6037,6 +6038,7 @@ static void __init init_mount_tree(void) set_fs_root(current->fs, &root); =20 ns_tree_add(ns); + init_mnt_ns =3D ns; } =20 void __init mnt_init(void) diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h index 70b366b64816..7e23c8364a9c 100644 --- a/include/linux/mnt_namespace.h +++ b/include/linux/mnt_namespace.h @@ -11,6 +11,8 @@ struct fs_struct; struct user_namespace; struct ns_common; =20 +extern struct mnt_namespace *init_mnt_ns; + extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespa= ce *, struct user_namespace *, struct fs_struct *); extern void put_mnt_ns(struct mnt_namespace *ns); --=20 2.47.3 From nobody Thu Oct 2 11:48:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DB8A31B806; Wed, 17 Sep 2025 10:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104930; cv=none; b=pXf3UrDh6RY1QoDog57Qp0CulsXKIXCnfocpmOYInWNiYcsWOMMdL5Wr/zdU5NXjkwO/1W1xJvMwJV27s6vegPK0FiWRH4v4DXCDCuFXE9ld1i8RSrYvPiqXd9KywZk2Mbb0KkzNuOviVDPp3BjWkfPDDJVq+QmsjdnmL8lmmYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104930; c=relaxed/simple; bh=6UhKFWFtlZyAnCDgJbep43ULSJMkO6/IpQ3ovrb6i44=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UpEb19f1cj3CkvtujRMZz2/sbX4qzMlXW2/degCzHZKWBbGC9a7T8EwU8FHAUHwIV3GX1B9DAhJJJTMT9A7t5rAj+10jaESVJXdwFMsGSlFIm+gERPHxba5rLM20kdobFcDmvfl2Cn6E/PsgxuLuIFrji6J+zsA9PTuTzIwMtvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MjqlbDTT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MjqlbDTT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC46AC4CEF5; Wed, 17 Sep 2025 10:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758104930; bh=6UhKFWFtlZyAnCDgJbep43ULSJMkO6/IpQ3ovrb6i44=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MjqlbDTTNbFAkM8xvkV7B7RB2lOo21kwFAgRHzG6Y0ACouQmuQl17HFL/vp5XRVNc bjTcCIqv8eg7k3FubNZtEAx/7GBr2KUq/F55sZ2FrKrhAgd5jyH4lmyJEeG/WSwPdR wIWvYdSCgR7mOV45Osan3R+L9lu47BMCifkC7UIhkHscX9gustpLp1tReqGskrK9w2 B3ZFmUik85psi4Yputs0MVeqf9FeZMsMAZJ2NtA0W90/NSmGJufi0zEfFD3MQzft4l b/OyxU8svycSvCIVNj5iaSfJ1Rq/rhdpoTo44SjhM47X/HIEAyzghM74FCwkHKeA2a 8lK2yXmX/xNIA== From: Christian Brauner Date: Wed, 17 Sep 2025 12:28:02 +0200 Subject: [PATCH 3/9] nscommon: move to separate file Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250917-work-namespace-ns_common-v1-3-1b3bda8ef8f2@kernel.org> References: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> In-Reply-To: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> To: linux-fsdevel@vger.kernel.org Cc: Amir Goldstein , Josef Bacik , Jeff Layton , Mike Yuan , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Lennart Poettering , Daan De Meyer , Aleksa Sarai , Alexander Viro , Jan Kara , Tejun Heo , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Jakub Kicinski , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-56183 X-Developer-Signature: v=1; a=openpgp-sha256; l=2942; i=brauner@kernel.org; h=from:subject:message-id; bh=6UhKFWFtlZyAnCDgJbep43ULSJMkO6/IpQ3ovrb6i44=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWSc6vVr+DWv1W0x86HzK9Y/uWt/7g+jIIP8zou3Fq9I/ /9CV6r0ZkcpC4MYF4OsmCKLQ7tJuNxynorNRpkaMHNYmUCGMHBxCsBETp1nZNjg3x0X0iDwccJZ YYP9orXf3kzX/cRzIEtd83OG5iK3NymMDAul5kQ+CJxXwXfmmEfIrKMT0988rbLpUT+gWbriTMc nNQYA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 It's really awkward spilling the ns common infrastructure into multiple headers. Move it to a separate file. Signed-off-by: Christian Brauner Reviewed-by: Jan Kara --- include/linux/ns_common.h | 3 +++ include/linux/proc_ns.h | 19 ------------------- kernel/Makefile | 2 +- kernel/nscommon.c | 21 +++++++++++++++++++++ 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/include/linux/ns_common.h b/include/linux/ns_common.h index 7224072cccc5..78b17fe80b62 100644 --- a/include/linux/ns_common.h +++ b/include/linux/ns_common.h @@ -31,6 +31,9 @@ struct ns_common { }; }; =20 +int ns_common_init(struct ns_common *ns, const struct proc_ns_operations *= ops, + bool alloc_inum); + #define to_ns_common(__ns) \ _Generic((__ns), \ struct cgroup_namespace *: &(__ns)->ns, \ diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h index 7f89f0829e60..9f21670b5824 100644 --- a/include/linux/proc_ns.h +++ b/include/linux/proc_ns.h @@ -66,25 +66,6 @@ static inline void proc_free_inum(unsigned int inum) {} =20 #endif /* CONFIG_PROC_FS */ =20 -static inline int ns_common_init(struct ns_common *ns, - const struct proc_ns_operations *ops, - bool alloc_inum) -{ - if (alloc_inum) { - int ret; - ret =3D proc_alloc_inum(&ns->inum); - if (ret) - return ret; - } - refcount_set(&ns->count, 1); - ns->stashed =3D NULL; - ns->ops =3D ops; - ns->ns_id =3D 0; - RB_CLEAR_NODE(&ns->ns_tree_node); - INIT_LIST_HEAD(&ns->ns_list_node); - return 0; -} - #define ns_free_inum(ns) proc_free_inum((ns)->inum) =20 #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private) diff --git a/kernel/Makefile b/kernel/Makefile index b807516a1b43..1f48f7cd2d7b 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -8,7 +8,7 @@ obj-y =3D fork.o exec_domain.o panic.o \ sysctl.o capability.o ptrace.o user.o \ signal.o sys.o umh.o workqueue.o pid.o task_work.o \ extable.o params.o \ - kthread.o sys_ni.o nsproxy.o nstree.o \ + kthread.o sys_ni.o nsproxy.o nstree.o nscommon.o \ notifier.o ksysfs.o cred.o reboot.o \ async.o range.o smpboot.o ucount.o regset.o ksyms_common.o =20 diff --git a/kernel/nscommon.c b/kernel/nscommon.c new file mode 100644 index 000000000000..ebf4783d0505 --- /dev/null +++ b/kernel/nscommon.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include + +int ns_common_init(struct ns_common *ns, const struct proc_ns_operations *= ops, + bool alloc_inum) +{ + if (alloc_inum) { + int ret; + ret =3D proc_alloc_inum(&ns->inum); + if (ret) + return ret; + } + refcount_set(&ns->count, 1); + ns->stashed =3D NULL; + ns->ops =3D ops; + ns->ns_id =3D 0; + RB_CLEAR_NODE(&ns->ns_tree_node); + INIT_LIST_HEAD(&ns->ns_list_node); + return 0; +} --=20 2.47.3 From nobody Thu Oct 2 11:48:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E41B32D5D3; Wed, 17 Sep 2025 10:28:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104935; cv=none; b=pgigppbeVQxjfFPSjUzPwDs/jtx15JXxQiZo+e/zZNx7BDwjq1lmcl/vUmjX5/YokH25MKUAn0jow02gawCho+KZlXbp3qZf/25Ja19G7LJdOobVRfzt92jfl5LZNmubpC2BS11JRar8Zn8+I+edS6nTPicHJlSBowUx/R11jcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104935; c=relaxed/simple; bh=SsZE3XmD+yCPUHrqRLeweA2GPr1r2EaHz2fY+2nM1AE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IGqRHR13NHTBkcohAQrnMQNowj0pCrJVBsdkp73TGuHt055Ev38F/JyiGEIY28D7qc9jcn5PQGmHDtPZvelMVE6intIbLS173LsWc17UhNgey/9QrFKdhDch0zcfKr6ZYvRrYIlnG0JMzJPwRbPKopTN0v+yvEVDL8d1gutMfD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kBFwtgpe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kBFwtgpe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83932C4CEF0; Wed, 17 Sep 2025 10:28:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758104934; bh=SsZE3XmD+yCPUHrqRLeweA2GPr1r2EaHz2fY+2nM1AE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kBFwtgpepfshYuZnD4klIHAOM96iSsxdZORRZKQTKsXx4Nzb89fQYAS4ZBqwkEK5O HCyxCs0A0wjM3txjEs31x3Qtter6wsVwL9YEMFGV5+vL/ZArcC5ZThqGwt2WTxQ43k Ej4nzRnoOPKKJuBHCIyix4Ll+O9X5amXFmfALWC8Jx4bF0PpMnTXmPe2Dj5OXhPoHR 7F+BpSCzc3NncLBMmNkf1Y98wAlUiN0IuR58tRB/5rF3TiI++Asalw0GD5FJ+rcOnG REAAhGWQeDBvCZhu8oMYBbsFxuW5nlgsUILo60sVd7SRLiO1gtaNn3Xv90qrZmRfT9 ucoPn17rBN8og== From: Christian Brauner Date: Wed, 17 Sep 2025 12:28:03 +0200 Subject: [PATCH 4/9] cgroup: split namespace into separate header Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250917-work-namespace-ns_common-v1-4-1b3bda8ef8f2@kernel.org> References: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> In-Reply-To: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> To: linux-fsdevel@vger.kernel.org Cc: Amir Goldstein , Josef Bacik , Jeff Layton , Mike Yuan , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Lennart Poettering , Daan De Meyer , Aleksa Sarai , Alexander Viro , Jan Kara , Tejun Heo , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Jakub Kicinski , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-56183 X-Developer-Signature: v=1; a=openpgp-sha256; l=4120; i=brauner@kernel.org; h=from:subject:message-id; bh=SsZE3XmD+yCPUHrqRLeweA2GPr1r2EaHz2fY+2nM1AE=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWSc6vUzPxpiPOlleeT9LW8TFr6fXbtGYsXk46/5th96z 3F6h//eWx2lLAxiXAyyYoosDu0m4XLLeSo2G2VqwMxhZQIZwsDFKQATWbqD4X/Ukr0NYb7/ZJRn tAsXfbHwunEt09D0Y9/x90uOyEb8vHWTkWHhQx3nF4d5LnYni11q69vgUGx709nZa9Yc6Z3XF6d J23AAAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 We have dedicated headers for all namespace types. Add one for the cgroup namespace as well. Now it's consistent for all namespace types and easy to figure out what to include. Signed-off-by: Christian Brauner Acked-by: Tejun Heo Reviewed-by: Jan Kara --- include/linux/cgroup.h | 51 +----------------------------------- include/linux/cgroup_namespace.h | 56 ++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 57 insertions(+), 50 deletions(-) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 9ca25346f7cb..5156fed8cbc3 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -27,6 +27,7 @@ #include =20 #include +#include =20 struct kernel_clone_args; =20 @@ -783,56 +784,6 @@ static inline void cgroup_sk_free(struct sock_cgroup_d= ata *skcd) {} =20 #endif /* CONFIG_CGROUP_DATA */ =20 -struct cgroup_namespace { - struct ns_common ns; - struct user_namespace *user_ns; - struct ucounts *ucounts; - struct css_set *root_cset; -}; - -extern struct cgroup_namespace init_cgroup_ns; - -#ifdef CONFIG_CGROUPS - -static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns) -{ - return container_of(ns, struct cgroup_namespace, ns); -} - -void free_cgroup_ns(struct cgroup_namespace *ns); - -struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, - struct user_namespace *user_ns, - struct cgroup_namespace *old_ns); - -int cgroup_path_ns(struct cgroup *cgrp, char *buf, size_t buflen, - struct cgroup_namespace *ns); - -static inline void get_cgroup_ns(struct cgroup_namespace *ns) -{ - refcount_inc(&ns->ns.count); -} - -static inline void put_cgroup_ns(struct cgroup_namespace *ns) -{ - if (refcount_dec_and_test(&ns->ns.count)) - free_cgroup_ns(ns); -} - -#else /* !CONFIG_CGROUPS */ - -static inline void free_cgroup_ns(struct cgroup_namespace *ns) { } -static inline struct cgroup_namespace * -copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns, - struct cgroup_namespace *old_ns) -{ - return old_ns; -} - -static inline void get_cgroup_ns(struct cgroup_namespace *ns) { } -static inline void put_cgroup_ns(struct cgroup_namespace *ns) { } - -#endif /* !CONFIG_CGROUPS */ =20 #ifdef CONFIG_CGROUPS =20 diff --git a/include/linux/cgroup_namespace.h b/include/linux/cgroup_namesp= ace.h new file mode 100644 index 000000000000..c02bb76c5e32 --- /dev/null +++ b/include/linux/cgroup_namespace.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_CGROUP_NAMESPACE_H +#define _LINUX_CGROUP_NAMESPACE_H + +struct cgroup_namespace { + struct ns_common ns; + struct user_namespace *user_ns; + struct ucounts *ucounts; + struct css_set *root_cset; +}; + +extern struct cgroup_namespace init_cgroup_ns; + +#ifdef CONFIG_CGROUPS + +static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns) +{ + return container_of(ns, struct cgroup_namespace, ns); +} + +void free_cgroup_ns(struct cgroup_namespace *ns); + +struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, + struct user_namespace *user_ns, + struct cgroup_namespace *old_ns); + +int cgroup_path_ns(struct cgroup *cgrp, char *buf, size_t buflen, + struct cgroup_namespace *ns); + +static inline void get_cgroup_ns(struct cgroup_namespace *ns) +{ + refcount_inc(&ns->ns.count); +} + +static inline void put_cgroup_ns(struct cgroup_namespace *ns) +{ + if (refcount_dec_and_test(&ns->ns.count)) + free_cgroup_ns(ns); +} + +#else /* !CONFIG_CGROUPS */ + +static inline void free_cgroup_ns(struct cgroup_namespace *ns) { } +static inline struct cgroup_namespace * +copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns, + struct cgroup_namespace *old_ns) +{ + return old_ns; +} + +static inline void get_cgroup_ns(struct cgroup_namespace *ns) { } +static inline void put_cgroup_ns(struct cgroup_namespace *ns) { } + +#endif /* !CONFIG_CGROUPS */ + +#endif /* _LINUX_CGROUP_NAMESPACE_H */ --=20 2.47.3 From nobody Thu Oct 2 11:48:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F1AD32D5D3; Wed, 17 Sep 2025 10:29:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104940; cv=none; b=QX/hn10n7Wpu3wl9lhtbAM8rnHSI7P1+l2+MkPw+j7FocHSucW6KuB1uPiW7sCvi5hATKxmROXPPhLcwZd+0yi6wzO+rAt275XGKWjmBbVBPR3EIloboKo/goIUDVW4TV3KbEVEdv23h/WKc+1WDtSuMfrQrRwz4VlJItkvHLIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104940; c=relaxed/simple; bh=6GX+edfqAtvCu/yle/NskZ5IXtOjExmscE2dvb5jQ6M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A/peenwdxtkyTA8wPKrU00r2gNrrobKoa7ov3eS6F9rZwogwXDOE6qsBK+EgXu3LnYZA4drJHkFYoVXdhDqs4JS76u5GQmAJ6KOERWnHnbglbbilwt45L5Rd4SdeKkuwSxB4tU6JmET/FTrG06m2r6ZsWW8jgSxMTalHb9Bbts0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OyzXfDbi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OyzXfDbi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55E6EC4CEF5; Wed, 17 Sep 2025 10:28:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758104939; bh=6GX+edfqAtvCu/yle/NskZ5IXtOjExmscE2dvb5jQ6M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OyzXfDbimMLy0Fx6M58fD+mofgMhOwDSKHAjSn2Q8XEqZHN5uehbaG7Oxt7hco8dX S/Yc6LyoBOqiKFLjtWmPdkRf0jEBbV31vpcxLHIChjd4ZIyFe6KSJqw8xrm7tp61EP 9ESUpyC6cjj7RjwIME8gUaS3mFolg1WPBcYNGxk6TWueEv4UycIDrzYXbP1t5UruA+ bUNfD+9OasjHXjGm044YKg8+t8CubPsrsP6H8uFMDH9C+nGhKdJA3Xh0y9fyYdjCl3 iqi9Xub1hGIhpnWhZjvCwRCBcTIMCBNup6lIW4KKLVZg1ZZV2wcPluUsq+sw2aa42R QXKUH22emII/w== From: Christian Brauner Date: Wed, 17 Sep 2025 12:28:04 +0200 Subject: [PATCH 5/9] nsfs: add inode number for anon namespace Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250917-work-namespace-ns_common-v1-5-1b3bda8ef8f2@kernel.org> References: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> In-Reply-To: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> To: linux-fsdevel@vger.kernel.org Cc: Amir Goldstein , Josef Bacik , Jeff Layton , Mike Yuan , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Lennart Poettering , Daan De Meyer , Aleksa Sarai , Alexander Viro , Jan Kara , Tejun Heo , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Jakub Kicinski , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-56183 X-Developer-Signature: v=1; a=openpgp-sha256; l=610; i=brauner@kernel.org; h=from:subject:message-id; bh=6GX+edfqAtvCu/yle/NskZ5IXtOjExmscE2dvb5jQ6M=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWSc6vXbcW4j+6HSZy4aqupNiQ7HlKKdM7huMdxWmvLxi OCqJw35HaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABM5c4jhf7ho4xn59Gfsq/Vk juzJilotpCe+a+7jhl1H+aMn5E96Zsbwz8gwuE21Pzfx/GSba0bO+TZ/Wplm+p/mv8RqYfHmqbk mGwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Add an inode number anonymous namespaces. Signed-off-by: Christian Brauner Reviewed-by: Jan Kara --- include/uapi/linux/nsfs.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/uapi/linux/nsfs.h b/include/uapi/linux/nsfs.h index 5d5bf22464c9..e098759ec917 100644 --- a/include/uapi/linux/nsfs.h +++ b/include/uapi/linux/nsfs.h @@ -53,6 +53,9 @@ enum init_ns_ino { TIME_NS_INIT_INO =3D 0xEFFFFFFAU, NET_NS_INIT_INO =3D 0xEFFFFFF9U, MNT_NS_INIT_INO =3D 0xEFFFFFF8U, +#ifdef __KERNEL__ + MNT_NS_ANON_INO =3D 0xEFFFFFF7U, +#endif }; =20 struct nsfs_file_handle { --=20 2.47.3 From nobody Thu Oct 2 11:48:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E7B630F55F; Wed, 17 Sep 2025 10:29:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104945; cv=none; b=jNsHWL+M62Jrlif7WanyyQGg2xZST45WXw2jQQuJzX9mXAFdnPNKOnBmK+dJgCE08itcMpyvnpE6MwkVlw9eBcl2/3riDMncFYdjn2ji2zUaQxDmSVWGkxDLwBH01WEbrCKH7RIPQpdi5HXAeFPOXPuOjvYnb080TT3QOISHD0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104945; c=relaxed/simple; bh=f298TfwuvucZhjfVOeyD006aIc08Nj0ksyFjV9TrheE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VylywV4NWrt6FwCzOyBWbax4osfJi+k84oxs1aAziFfj5FsPUQczFEMczWb25p0FaBZcjqyRvMIxst1a16SrgJUs8mRph93Yc3a0Z7r1xb9JVt97FowDShcRT9XKBoJEEG5tfTVqfBnGPZs203uuNFhDCRtA+EQyNrqdYLUS+A4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AZpdSPUX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AZpdSPUX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E9DCC4CEF0; Wed, 17 Sep 2025 10:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758104944; bh=f298TfwuvucZhjfVOeyD006aIc08Nj0ksyFjV9TrheE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AZpdSPUXb6GPTxoFoMx/SlfoQ4N2zP6FvEiU2hQoND291C+TOhQ1Did/LdhrDaohx 6cNj2GTRY+4JcyRhatogOCUPbsa2Z4h8RPPTSPNlWBnifkoT+Ez78UesRljoqRmAx8 TKdFnQW6LAOk5MzN03tZhA54xfE80Heh9ceGyic3CRmxZof9bK337KN8NxilA033OB yXgrmxmaKF3yE7ujQwJsZqnFUgGXOit6geSeLkxY14rnlRgzYLwWnddheRb+i4cNO3 3SFfwfPTqhd/lzHK76c+FRYdqiBvDid6bI4FU7rCkzRqvZaJ9im65p4yVtJy9+RRMp AxFT6GyApDAkw== From: Christian Brauner Date: Wed, 17 Sep 2025 12:28:05 +0200 Subject: [PATCH 6/9] mnt: simplify ns_common_init() handling Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250917-work-namespace-ns_common-v1-6-1b3bda8ef8f2@kernel.org> References: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> In-Reply-To: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> To: linux-fsdevel@vger.kernel.org Cc: Amir Goldstein , Josef Bacik , Jeff Layton , Mike Yuan , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Lennart Poettering , Daan De Meyer , Aleksa Sarai , Alexander Viro , Jan Kara , Tejun Heo , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Jakub Kicinski , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-56183 X-Developer-Signature: v=1; a=openpgp-sha256; l=1817; i=brauner@kernel.org; h=from:subject:message-id; bh=f298TfwuvucZhjfVOeyD006aIc08Nj0ksyFjV9TrheE=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWSc6vWbzt/s5PnEzvc8yxQn3gdyQu9VuB9ctdjlLvwr8 NdUm6mqHaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABN5eonhr+CiQut/3KfPX6u/ 9VjisEl3Zf4UxnbHfZcuR2urMJkyTGf4Z7u83vvT2+1fc2Y+mj355bH7ViemWk64vyMqdIn1tjW muuwA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Assign the reserved MNT_NS_ANON_INO sentinel to anonymous mount namespaces and cleanup the initial mount ns allocation. This is just a preparatory patch and the ns->inum check in ns_common_init() will be dropped in the next patch. Signed-off-by: Christian Brauner Reviewed-by: Jan Kara --- fs/namespace.c | 7 ++++--- kernel/nscommon.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index c8251545d57e..09e4ecd44972 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -4104,6 +4104,8 @@ static struct mnt_namespace *alloc_mnt_ns(struct user= _namespace *user_ns, bool a return ERR_PTR(-ENOMEM); } =20 + if (anon) + new_ns->ns.inum =3D MNT_NS_ANON_INO; ret =3D ns_common_init(&new_ns->ns, &mntns_operations, !anon); if (ret) { kfree(new_ns); @@ -6020,10 +6022,9 @@ static void __init init_mount_tree(void) if (IS_ERR(mnt)) panic("Can't create rootfs"); =20 - ns =3D alloc_mnt_ns(&init_user_ns, true); + ns =3D alloc_mnt_ns(&init_user_ns, false); if (IS_ERR(ns)) panic("Can't allocate initial namespace"); - ns->ns.inum =3D PROC_MNT_INIT_INO; m =3D real_mount(mnt); ns->root =3D m; ns->nr_mounts =3D 1; @@ -6037,7 +6038,7 @@ static void __init init_mount_tree(void) set_fs_pwd(current->fs, &root); set_fs_root(current->fs, &root); =20 - ns_tree_add(ns); + ns_tree_add_raw(ns); init_mnt_ns =3D ns; } =20 diff --git a/kernel/nscommon.c b/kernel/nscommon.c index ebf4783d0505..e10fad8afe61 100644 --- a/kernel/nscommon.c +++ b/kernel/nscommon.c @@ -5,7 +5,7 @@ int ns_common_init(struct ns_common *ns, const struct proc_ns_operations *= ops, bool alloc_inum) { - if (alloc_inum) { + if (alloc_inum && !ns->inum) { int ret; ret =3D proc_alloc_inum(&ns->inum); if (ret) --=20 2.47.3 From nobody Thu Oct 2 11:48:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38D6735084A; Wed, 17 Sep 2025 10:29:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104950; cv=none; b=qO2HurJuN0bqF709DYTHmhqOW93n61vU/H6CZ5eRDIKulFfgd7YG9MiAXGnd8dPzwUqkxG8t566iTSPhugEutqt/x3svE7r4gJNj4uVn6ZsZwMDcj8AClbQGri9y0zEldPvryoccBGhENI/xy86rEA0gipjm2tXS8P5CdPSK0lk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104950; c=relaxed/simple; bh=3Hqga83UDAk5jGtzoEZoqgWwOQ+JDaB906VMcmnlsao=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FyKDpgQkiEaMpP+120ixM+PwDTpiREBdOC/wTYmVYxAIMq4sw0wHu5shtyRDXyudpfvZwenPO8KjMtr6RkQL7IchtlIe2GA3zW1LPWZ2eT/evn7mqlekeNxKmieg3/oCujmItoanfqjBP/0CFv0KrXeCR1+S9WVynpTJk55UqZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZTbkJxOo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZTbkJxOo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36447C4CEF5; Wed, 17 Sep 2025 10:29:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758104949; bh=3Hqga83UDAk5jGtzoEZoqgWwOQ+JDaB906VMcmnlsao=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZTbkJxOoP4FsrDFZpKG89wT8zHS98PFuQq9r6FpbTkfnElZxJVpTFdt/qW0HGo2wk 5rcPG2+CK99G6SaAjJME1vbmirza+C+RoDPk1TkWQl7qbIaURRWBdZDNQAfWsEPlht mTe/+mrT7t5bIQLY09G+cF8HalMdmC3MQqn/zxd930dM4LNNlw/MW1jzdWK261tDaZ yMCKcik4DePh7/3mlPbbYPSgeTqUyepoHXZdRQFWAs8nutAQv8GZgR7Kw1SLEf91O4 yQITTitys5JUamEFayYmeO/o86czPsM6hP/9cv+tDyESE96JWbQ2l4m/+MUKCGoH5n 9bAZCOd+UEnfw== From: Christian Brauner Date: Wed, 17 Sep 2025 12:28:06 +0200 Subject: [PATCH 7/9] net: centralize ns_common initialization Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250917-work-namespace-ns_common-v1-7-1b3bda8ef8f2@kernel.org> References: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> In-Reply-To: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> To: linux-fsdevel@vger.kernel.org Cc: Amir Goldstein , Josef Bacik , Jeff Layton , Mike Yuan , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Lennart Poettering , Daan De Meyer , Aleksa Sarai , Alexander Viro , Jan Kara , Tejun Heo , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Jakub Kicinski , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-56183 X-Developer-Signature: v=1; a=openpgp-sha256; l=1838; i=brauner@kernel.org; h=from:subject:message-id; bh=3Hqga83UDAk5jGtzoEZoqgWwOQ+JDaB906VMcmnlsao=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWSc6vUrqJFKfr2kvlDV9qOstrlsX98Pi7wDlhfv6Bmaz arvYqzsKGVhEONikBVTZHFoNwmXW85TsdkoUwNmDisTyBAGLk4BmMjiFoa/QkrXa+KCfX7t2p2S es62TFW44+ht65Q94ec+2now6x2NYfjvcnDCHJaFPZXrw38x/51yWyPm2saSdT6JMzrbXHKqY75 wAAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Centralize ns_common initialization. Signed-off-by: Christian Brauner Reviewed-by: Jan Kara --- net/core/net_namespace.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index a57b3cda8dbc..897f4927df9e 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -409,7 +409,7 @@ static __net_init int preinit_net(struct net *net, stru= ct user_namespace *user_n ns_ops =3D NULL; #endif =20 - ret =3D ns_common_init(&net->ns, ns_ops, false); + ret =3D ns_common_init(&net->ns, ns_ops, true); if (ret) return ret; =20 @@ -597,6 +597,7 @@ struct net *copy_net_ns(unsigned long flags, net_passive_dec(net); dec_ucounts: dec_net_namespaces(ucounts); + ns_free_inum(&net->ns); return ERR_PTR(rv); } return net; @@ -718,6 +719,7 @@ static void cleanup_net(struct work_struct *work) #endif put_user_ns(net->user_ns); net_passive_dec(net); + ns_free_inum(&net->ns); } WRITE_ONCE(cleanup_net_task, NULL); } @@ -831,31 +833,12 @@ static void net_ns_net_debugfs(struct net *net) =20 static __net_init int net_ns_net_init(struct net *net) { - int ret =3D 0; - - if (net =3D=3D &init_net) - net->ns.inum =3D PROC_NET_INIT_INO; - else - ret =3D proc_alloc_inum(&to_ns_common(net)->inum); - if (ret) - return ret; - net_ns_net_debugfs(net); return 0; } =20 -static __net_exit void net_ns_net_exit(struct net *net) -{ - /* - * Initial network namespace doesn't exit so we don't need any - * special checks here. - */ - ns_free_inum(&net->ns); -} - static struct pernet_operations __net_initdata net_ns_ops =3D { .init =3D net_ns_net_init, - .exit =3D net_ns_net_exit, }; =20 static const struct nla_policy rtnl_net_policy[NETNSA_MAX + 1] =3D { --=20 2.47.3 From nobody Thu Oct 2 11:48:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCC603081A6; Wed, 17 Sep 2025 10:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104954; cv=none; b=sIBKblVDZwChvj2zXZJr45fifZNC/Acy0e+9AUE1T17MU9W658YhLtj1IwfFvsHwxmilA9XW5vD2zXziPi/4/h/dkf68IgAOUK/wE+P9z7i1LqkpJk1kVRDZq3dpqs5x4ZSd0CWo0lfm5E+FwhLClhKjhiialXXK4hzwmAG53N0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104954; c=relaxed/simple; bh=CMPBxNtATUlgpLmzq6VKksLBVJ3sJD7dJN0BZeoB1OM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ls6ASdRdArM9ik8Mi7DGJ/XnFA9kDfsQv4KDKHzpGH3/HGXMZnZMkjo/mu0QvuJxFwLN0nmQ4Q66tAUZj6Nw6N4ZupabEs9t1lw1xtpD8ren/i2z15s/EU89vUBUOub+wLp2L0rmUIrhH+l3wbXTxAwyxnrn0v8i36zXFgclZmk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VYrFoRFN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VYrFoRFN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30FC9C4CEF0; Wed, 17 Sep 2025 10:29:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758104954; bh=CMPBxNtATUlgpLmzq6VKksLBVJ3sJD7dJN0BZeoB1OM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VYrFoRFNYQzCzaYSja/GF2tDvQCcNb/PpGEUlxo030BiaNSuGZjhMQku72HxWAYVK zZC8BuCK61SfSgi4zS39RE+te7b9nAxZ9gh08BH/UdCb1iu510xGrklfJK8ssA/sXq 7i74HUs1mABhLcKJJf+8Iib+XN3q4+A0Z6t3Ebu0ZBCtcLcKe9Iydie9G372+r5Jig Ej2zBkt4HJgdqeSbCqWN+aur+0pEfPb0FRs39pE16szLuh//lBHiMJCYgfNXQQEvsa Efzu7qL27zSMktCdUVq65EJvNX8d6l60WLbHExua6Mfxggr6/+Kbpx51RknDQpIQUT 1MPyGlFMdolAg== From: Christian Brauner Date: Wed, 17 Sep 2025 12:28:07 +0200 Subject: [PATCH 8/9] nscommon: simplify initialization Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250917-work-namespace-ns_common-v1-8-1b3bda8ef8f2@kernel.org> References: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> In-Reply-To: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> To: linux-fsdevel@vger.kernel.org Cc: Amir Goldstein , Josef Bacik , Jeff Layton , Mike Yuan , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Lennart Poettering , Daan De Meyer , Aleksa Sarai , Alexander Viro , Jan Kara , Tejun Heo , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Jakub Kicinski , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-56183 X-Developer-Signature: v=1; a=openpgp-sha256; l=7890; i=brauner@kernel.org; h=from:subject:message-id; bh=CMPBxNtATUlgpLmzq6VKksLBVJ3sJD7dJN0BZeoB1OM=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWSc6vVburvA4+TVUD85l29npL/MVtS/ZZkSdk76vligQ 85+t0TWjlIWBjEuBlkxRRaHdpNwueU8FZuNMjVg5rAygQxh4OIUgInMkWRkaFjlc4Dt2MmnKx7Y n3c+uLT+39nP6x9n7d20es+mD2kbE44y/Per3WSvHOj0wskzYPmnd7cLA6IbzlXe4Il0a3309uv +KhYA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 There's a lot of information that namespace implementers don't need to know about at all. Encapsulate this all in the initialization helper. Signed-off-by: Christian Brauner Reviewed-by: Jan Kara --- fs/namespace.c | 5 +++-- include/linux/ns_common.h | 41 +++++++++++++++++++++++++++++++++++++++-- ipc/namespace.c | 2 +- kernel/cgroup/namespace.c | 2 +- kernel/nscommon.c | 17 ++++++++--------- kernel/pid_namespace.c | 2 +- kernel/time/namespace.c | 2 +- kernel/user_namespace.c | 2 +- kernel/utsname.c | 2 +- net/core/net_namespace.c | 2 +- 10 files changed, 57 insertions(+), 20 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index 09e4ecd44972..31eb0e8f21eb 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -4105,8 +4105,9 @@ static struct mnt_namespace *alloc_mnt_ns(struct user= _namespace *user_ns, bool a } =20 if (anon) - new_ns->ns.inum =3D MNT_NS_ANON_INO; - ret =3D ns_common_init(&new_ns->ns, &mntns_operations, !anon); + ret =3D ns_common_init_inum(new_ns, &mntns_operations, MNT_NS_ANON_INO); + else + ret =3D ns_common_init(new_ns, &mntns_operations); if (ret) { kfree(new_ns); dec_mnt_namespaces(ucounts); diff --git a/include/linux/ns_common.h b/include/linux/ns_common.h index 78b17fe80b62..284bba2b7c43 100644 --- a/include/linux/ns_common.h +++ b/include/linux/ns_common.h @@ -16,6 +16,15 @@ struct time_namespace; struct user_namespace; struct uts_namespace; =20 +extern struct cgroup_namespace init_cgroup_ns; +extern struct ipc_namespace init_ipc_ns; +extern struct mnt_namespace *init_mnt_ns; +extern struct net init_net; +extern struct pid_namespace init_pid_ns; +extern struct time_namespace init_time_ns; +extern struct user_namespace init_user_ns; +extern struct uts_namespace init_uts_ns; + struct ns_common { struct dentry *stashed; const struct proc_ns_operations *ops; @@ -31,8 +40,7 @@ struct ns_common { }; }; =20 -int ns_common_init(struct ns_common *ns, const struct proc_ns_operations *= ops, - bool alloc_inum); +int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations= *ops, int inum); =20 #define to_ns_common(__ns) \ _Generic((__ns), \ @@ -45,4 +53,33 @@ int ns_common_init(struct ns_common *ns, const struct pr= oc_ns_operations *ops, struct user_namespace *: &(__ns)->ns, \ struct uts_namespace *: &(__ns)->ns) =20 +#define ns_init_inum(__ns) \ + _Generic((__ns), \ + struct cgroup_namespace *: CGROUP_NS_INIT_INO, \ + struct ipc_namespace *: IPC_NS_INIT_INO, \ + struct mnt_namespace *: MNT_NS_INIT_INO, \ + struct net *: NET_NS_INIT_INO, \ + struct pid_namespace *: PID_NS_INIT_INO, \ + struct time_namespace *: TIME_NS_INIT_INO, \ + struct user_namespace *: USER_NS_INIT_INO, \ + struct uts_namespace *: UTS_NS_INIT_INO) + +#define ns_init_ns(__ns) \ + _Generic((__ns), \ + struct cgroup_namespace *: &init_cgroup_ns, \ + struct ipc_namespace *: &init_ipc_ns, \ + struct mnt_namespace *: init_mnt_ns, \ + struct net *: &init_net, \ + struct pid_namespace *: &init_pid_ns, \ + struct time_namespace *: &init_time_ns, \ + struct user_namespace *: &init_user_ns, \ + struct uts_namespace *: &init_uts_ns) + +#define ns_common_init(__ns, __ops) \ + __ns_common_init(&(__ns)->ns, __ops, \ + (((__ns) =3D=3D ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0)) + +#define ns_common_init_inum(__ns, __ops, __inum) \ + __ns_common_init(&(__ns)->ns, __ops, __inum) + #endif diff --git a/ipc/namespace.c b/ipc/namespace.c index 89588819956b..0f8bbd18a475 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c @@ -62,7 +62,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_na= mespace *user_ns, if (ns =3D=3D NULL) goto fail_dec; =20 - err =3D ns_common_init(&ns->ns, &ipcns_operations, true); + err =3D ns_common_init(ns, &ipcns_operations); if (err) goto fail_free; =20 diff --git a/kernel/cgroup/namespace.c b/kernel/cgroup/namespace.c index 5a327914b565..d928c557e28b 100644 --- a/kernel/cgroup/namespace.c +++ b/kernel/cgroup/namespace.c @@ -27,7 +27,7 @@ static struct cgroup_namespace *alloc_cgroup_ns(void) new_ns =3D kzalloc(sizeof(struct cgroup_namespace), GFP_KERNEL_ACCOUNT); if (!new_ns) return ERR_PTR(-ENOMEM); - ret =3D ns_common_init(&new_ns->ns, &cgroupns_operations, true); + ret =3D ns_common_init(new_ns, &cgroupns_operations); if (ret) return ERR_PTR(ret); ns_tree_add(new_ns); diff --git a/kernel/nscommon.c b/kernel/nscommon.c index e10fad8afe61..c3a90bb665ad 100644 --- a/kernel/nscommon.c +++ b/kernel/nscommon.c @@ -1,21 +1,20 @@ // SPDX-License-Identifier: GPL-2.0-only =20 #include +#include =20 -int ns_common_init(struct ns_common *ns, const struct proc_ns_operations *= ops, - bool alloc_inum) +int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations= *ops, int inum) { - if (alloc_inum && !ns->inum) { - int ret; - ret =3D proc_alloc_inum(&ns->inum); - if (ret) - return ret; - } refcount_set(&ns->count, 1); ns->stashed =3D NULL; ns->ops =3D ops; ns->ns_id =3D 0; RB_CLEAR_NODE(&ns->ns_tree_node); INIT_LIST_HEAD(&ns->ns_list_node); - return 0; + + if (inum) { + ns->inum =3D inum; + return 0; + } + return proc_alloc_inum(&ns->inum); } diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 9b327420309e..170757c265c2 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -103,7 +103,7 @@ static struct pid_namespace *create_pid_namespace(struc= t user_namespace *user_ns if (ns->pid_cachep =3D=3D NULL) goto out_free_idr; =20 - err =3D ns_common_init(&ns->ns, &pidns_operations, true); + err =3D ns_common_init(ns, &pidns_operations); if (err) goto out_free_idr; =20 diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c index 20b65f90549e..ce8e952104a7 100644 --- a/kernel/time/namespace.c +++ b/kernel/time/namespace.c @@ -97,7 +97,7 @@ static struct time_namespace *clone_time_ns(struct user_n= amespace *user_ns, if (!ns->vvar_page) goto fail_free; =20 - err =3D ns_common_init(&ns->ns, &timens_operations, true); + err =3D ns_common_init(ns, &timens_operations); if (err) goto fail_free_page; =20 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index cfb0e28f2779..db9f0463219c 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -126,7 +126,7 @@ int create_user_ns(struct cred *new) =20 ns->parent_could_setfcap =3D cap_raised(new->cap_effective, CAP_SETFCAP); =20 - ret =3D ns_common_init(&ns->ns, &userns_operations, true); + ret =3D ns_common_init(ns, &userns_operations); if (ret) goto fail_free; =20 diff --git a/kernel/utsname.c b/kernel/utsname.c index a682830742d3..399888be66bd 100644 --- a/kernel/utsname.c +++ b/kernel/utsname.c @@ -50,7 +50,7 @@ static struct uts_namespace *clone_uts_ns(struct user_nam= espace *user_ns, if (!ns) goto fail_dec; =20 - err =3D ns_common_init(&ns->ns, &utsns_operations, true); + err =3D ns_common_init(ns, &utsns_operations); if (err) goto fail_free; =20 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 897f4927df9e..fdb266bbdf93 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -409,7 +409,7 @@ static __net_init int preinit_net(struct net *net, stru= ct user_namespace *user_n ns_ops =3D NULL; #endif =20 - ret =3D ns_common_init(&net->ns, ns_ops, true); + ret =3D ns_common_init(net, ns_ops); if (ret) return ret; =20 --=20 2.47.3 From nobody Thu Oct 2 11:48:25 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0ABAD36C089; Wed, 17 Sep 2025 10:29:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104960; cv=none; b=W5Ampax1tG1Eid8MUbZKLYNZ9NJkTnKkDdGbBazHHaG0lN4ZzKLGhlGc09gsfSWErkNSyazTs8BP2Vv6rVStMOG4fIFcQqS4RGuuJxmqBHpi/T8rWAc/r9lJlJ080Tq9o4AKcTgCmsnUAV/DBZGLl+zG9/KeY9m7nAuwEFl1T60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758104960; c=relaxed/simple; bh=ytXUVuRhFL2Z6NxX49D7FGEXV8wRySnj7wZZcy3g2hw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TOvmbhiyo62BhUuysohUdRXAM1Zrh+i2oo5301wtwgXMcGRBslfU5fPj3W4+Ip8YXfm8DePF4ReV05uIiFJdkdVxhLhMfJnVtOs5YnLtyjP7FXD90wtdNcifP3a5FIPqatPJOynux6vSGailCfDSDRmX1vQviqcsCDQUsY3N+CY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Gorm2omj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Gorm2omj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C60DC4CEF0; Wed, 17 Sep 2025 10:29:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758104959; bh=ytXUVuRhFL2Z6NxX49D7FGEXV8wRySnj7wZZcy3g2hw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Gorm2omjhgozGjfbkc3lGBFqws6mJOT8moEN/MqjLxiy1KyUb1JXEwjpym3JWoU0P 4buI4jXUxadgENvkIuXApYHKTrSIkzC32TC1ZjAa/oUCDkEZkEfMy3c4PGqfcFTY5T DUl9abrxXbzi32a2Nr8z8AWrUErNvcOL8q2pynUZpvYeWDuH9Qd/JSqcSjBTQboLTF YOlcVSPwrMWjxT9rzs/KoOPTuKn1zgj4xqH7BsidPzMlGVa5L5Mw8jDYzWaNepjZgw 9Xj6K2lyrIbzfxtMjU0NFokOb4FkTeuf776k/C5uVOlC+ptcNAHRo+rzj3UfosZLpC tp5h+vgqL9CYA== From: Christian Brauner Date: Wed, 17 Sep 2025 12:28:08 +0200 Subject: [PATCH 9/9] ns: add ns_common_free() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250917-work-namespace-ns_common-v1-9-1b3bda8ef8f2@kernel.org> References: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> In-Reply-To: <20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org> To: linux-fsdevel@vger.kernel.org Cc: Amir Goldstein , Josef Bacik , Jeff Layton , Mike Yuan , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Lennart Poettering , Daan De Meyer , Aleksa Sarai , Alexander Viro , Jan Kara , Tejun Heo , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Jakub Kicinski , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-56183 X-Developer-Signature: v=1; a=openpgp-sha256; l=7062; i=brauner@kernel.org; h=from:subject:message-id; bh=ytXUVuRhFL2Z6NxX49D7FGEXV8wRySnj7wZZcy3g2hw=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWSc6vU7VnPgb5xAyW3ru5V2F6bNdJEx0rRf6FFx0KPt/ urP5qrGHaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABPZkcnwv/iTuOi5/4scpDjm OK768M1ubqKuZFuX4ObDDAoyr2w/6DH89zJ+us/AS9fx8eu7re0T/rC17m3gX73hfKVQYN4jdsZ yVgA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 And drop ns_free_inum(). Anything common that can be wasted centrally should be wasted in the new common helper. Signed-off-by: Christian Brauner Reviewed-by: Jan Kara --- fs/namespace.c | 4 ++-- include/linux/ns_common.h | 3 +++ include/linux/proc_ns.h | 2 -- ipc/namespace.c | 4 ++-- kernel/cgroup/namespace.c | 2 +- kernel/nscommon.c | 5 +++++ kernel/pid_namespace.c | 4 ++-- kernel/time/namespace.c | 2 +- kernel/user_namespace.c | 4 ++-- kernel/utsname.c | 2 +- net/core/net_namespace.c | 4 ++-- 11 files changed, 21 insertions(+), 15 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index 31eb0e8f21eb..03bd04559e69 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -4083,7 +4083,7 @@ static void dec_mnt_namespaces(struct ucounts *ucount= s) static void free_mnt_ns(struct mnt_namespace *ns) { if (!is_anon_ns(ns)) - ns_free_inum(&ns->ns); + ns_common_free(ns); dec_mnt_namespaces(ns->ucounts); mnt_ns_tree_remove(ns); } @@ -4155,7 +4155,7 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags= , struct mnt_namespace *ns, new =3D copy_tree(old, old->mnt.mnt_root, copy_flags); if (IS_ERR(new)) { namespace_unlock(); - ns_free_inum(&new_ns->ns); + ns_common_free(ns); dec_mnt_namespaces(new_ns->ucounts); mnt_ns_release(new_ns); return ERR_CAST(new); diff --git a/include/linux/ns_common.h b/include/linux/ns_common.h index 284bba2b7c43..5094c0147b54 100644 --- a/include/linux/ns_common.h +++ b/include/linux/ns_common.h @@ -41,6 +41,7 @@ struct ns_common { }; =20 int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations= *ops, int inum); +void __ns_common_free(struct ns_common *ns); =20 #define to_ns_common(__ns) \ _Generic((__ns), \ @@ -82,4 +83,6 @@ int __ns_common_init(struct ns_common *ns, const struct p= roc_ns_operations *ops, #define ns_common_init_inum(__ns, __ops, __inum) \ __ns_common_init(&(__ns)->ns, __ops, __inum) =20 +#define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns))) + #endif diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h index 9f21670b5824..08016f6e0e6f 100644 --- a/include/linux/proc_ns.h +++ b/include/linux/proc_ns.h @@ -66,8 +66,6 @@ static inline void proc_free_inum(unsigned int inum) {} =20 #endif /* CONFIG_PROC_FS */ =20 -#define ns_free_inum(ns) proc_free_inum((ns)->inum) - #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private) =20 #endif /* _LINUX_PROC_NS_H */ diff --git a/ipc/namespace.c b/ipc/namespace.c index 0f8bbd18a475..09d261a1a2aa 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c @@ -97,7 +97,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_na= mespace *user_ns, =20 fail_put: put_user_ns(ns->user_ns); - ns_free_inum(&ns->ns); + ns_common_free(ns); fail_free: kfree(ns); fail_dec: @@ -161,7 +161,7 @@ static void free_ipc_ns(struct ipc_namespace *ns) =20 dec_ipc_namespaces(ns->ucounts); put_user_ns(ns->user_ns); - ns_free_inum(&ns->ns); + ns_common_free(ns); kfree(ns); } =20 diff --git a/kernel/cgroup/namespace.c b/kernel/cgroup/namespace.c index d928c557e28b..16ead7508371 100644 --- a/kernel/cgroup/namespace.c +++ b/kernel/cgroup/namespace.c @@ -40,7 +40,7 @@ void free_cgroup_ns(struct cgroup_namespace *ns) put_css_set(ns->root_cset); dec_cgroup_namespaces(ns->ucounts); put_user_ns(ns->user_ns); - ns_free_inum(&ns->ns); + ns_common_free(ns); /* Concurrent nstree traversal depends on a grace period. */ kfree_rcu(ns, ns.ns_rcu); } diff --git a/kernel/nscommon.c b/kernel/nscommon.c index c3a90bb665ad..7c1b07e2a6c9 100644 --- a/kernel/nscommon.c +++ b/kernel/nscommon.c @@ -18,3 +18,8 @@ int __ns_common_init(struct ns_common *ns, const struct p= roc_ns_operations *ops, } return proc_alloc_inum(&ns->inum); } + +void __ns_common_free(struct ns_common *ns) +{ + proc_free_inum(ns->inum); +} diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 170757c265c2..27e2dd9ee051 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -127,7 +127,7 @@ static struct pid_namespace *create_pid_namespace(struc= t user_namespace *user_ns return ns; =20 out_free_inum: - ns_free_inum(&ns->ns); + ns_common_free(ns); out_free_idr: idr_destroy(&ns->idr); kmem_cache_free(pid_ns_cachep, ns); @@ -152,7 +152,7 @@ static void destroy_pid_namespace(struct pid_namespace = *ns) ns_tree_remove(ns); unregister_pidns_sysctls(ns); =20 - ns_free_inum(&ns->ns); + ns_common_free(ns); =20 idr_destroy(&ns->idr); call_rcu(&ns->rcu, delayed_free_pidns); diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c index ce8e952104a7..d49c73015d6e 100644 --- a/kernel/time/namespace.c +++ b/kernel/time/namespace.c @@ -255,7 +255,7 @@ void free_time_ns(struct time_namespace *ns) ns_tree_remove(ns); dec_time_namespaces(ns->ucounts); put_user_ns(ns->user_ns); - ns_free_inum(&ns->ns); + ns_common_free(ns); __free_page(ns->vvar_page); /* Concurrent nstree traversal depends on a grace period. */ kfree_rcu(ns, ns.ns_rcu); diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index db9f0463219c..32406bcab526 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -165,7 +165,7 @@ int create_user_ns(struct cred *new) #ifdef CONFIG_PERSISTENT_KEYRINGS key_put(ns->persistent_keyring_register); #endif - ns_free_inum(&ns->ns); + ns_common_free(ns); fail_free: kmem_cache_free(user_ns_cachep, ns); fail_dec: @@ -220,7 +220,7 @@ static void free_user_ns(struct work_struct *work) #endif retire_userns_sysctls(ns); key_free_user_ns(ns); - ns_free_inum(&ns->ns); + ns_common_free(ns); /* Concurrent nstree traversal depends on a grace period. */ kfree_rcu(ns, ns.ns_rcu); dec_user_namespaces(ucounts); diff --git a/kernel/utsname.c b/kernel/utsname.c index 399888be66bd..95d733eb2c98 100644 --- a/kernel/utsname.c +++ b/kernel/utsname.c @@ -98,7 +98,7 @@ void free_uts_ns(struct uts_namespace *ns) ns_tree_remove(ns); dec_uts_namespaces(ns->ucounts); put_user_ns(ns->user_ns); - ns_free_inum(&ns->ns); + ns_common_free(ns); /* Concurrent nstree traversal depends on a grace period. */ kfree_rcu(ns, ns.ns_rcu); } diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index fdb266bbdf93..fdbaf5f8ac78 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -597,7 +597,7 @@ struct net *copy_net_ns(unsigned long flags, net_passive_dec(net); dec_ucounts: dec_net_namespaces(ucounts); - ns_free_inum(&net->ns); + ns_common_free(net); return ERR_PTR(rv); } return net; @@ -719,7 +719,7 @@ static void cleanup_net(struct work_struct *work) #endif put_user_ns(net->user_ns); net_passive_dec(net); - ns_free_inum(&net->ns); + ns_common_free(net); } WRITE_ONCE(cleanup_net_task, NULL); } --=20 2.47.3