linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] ns: minor tweaks
@ 2025-09-22 12:42 Christian Brauner
  2025-09-22 12:42 ` [PATCH 1/3] cgroup: add missing ns_common include Christian Brauner
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Christian Brauner @ 2025-09-22 12:42 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Amir Goldstein, Josef Bacik, Jeff Layton, Mike Yuan,
	Zbigniew Jędrzejewski-Szmek, Lennart Poettering,
	Aleksa Sarai, Alexander Viro, Jan Kara, Tejun Heo,
	Johannes Weiner, Michal Koutný, Jakub Kicinski,
	Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner, cgroups,
	linux-kernel, netdev, Christian Brauner

A few minor tweaks for the namespace rework.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
Christian Brauner (3):
      cgroup: add missing ns_common include
      ns: simplify ns_common_init() further
      ns: add ns_debug()

 fs/namespace.c                   |  4 +--
 include/linux/cgroup_namespace.h |  2 ++
 include/linux/ns_common.h        | 30 ++++++++++++++++++++---
 ipc/namespace.c                  |  2 +-
 kernel/cgroup/namespace.c        |  2 +-
 kernel/nscommon.c                | 53 ++++++++++++++++++++++++++++++++++++++++
 kernel/pid_namespace.c           |  2 +-
 kernel/time/namespace.c          |  2 +-
 kernel/user_namespace.c          |  2 +-
 kernel/utsname.c                 |  2 +-
 net/core/net_namespace.c         |  9 +------
 11 files changed, 90 insertions(+), 20 deletions(-)
---
base-commit: 7cf730321132e726ff949c6f3c0d5c598788f7a2
change-id: 20250922-work-namespace-ns_common-fixes-d6a9af922878


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] cgroup: add missing ns_common include
  2025-09-22 12:42 [PATCH 0/3] ns: minor tweaks Christian Brauner
@ 2025-09-22 12:42 ` Christian Brauner
  2025-09-22 13:37   ` Jan Kara
  2025-09-22 15:44   ` Tejun Heo
  2025-09-22 12:42 ` [PATCH 2/3] ns: simplify ns_common_init() further Christian Brauner
  2025-09-22 12:42 ` [PATCH 3/3] ns: add ns_debug() Christian Brauner
  2 siblings, 2 replies; 9+ messages in thread
From: Christian Brauner @ 2025-09-22 12:42 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Amir Goldstein, Josef Bacik, Jeff Layton, Mike Yuan,
	Zbigniew Jędrzejewski-Szmek, Lennart Poettering,
	Aleksa Sarai, Alexander Viro, Jan Kara, Tejun Heo,
	Johannes Weiner, Michal Koutný, Jakub Kicinski,
	Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner, cgroups,
	linux-kernel, netdev, Christian Brauner

Add the missing include of the ns_common header.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 include/linux/cgroup_namespace.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/cgroup_namespace.h b/include/linux/cgroup_namespace.h
index b7dbf4d623d2..81ccbdee425b 100644
--- a/include/linux/cgroup_namespace.h
+++ b/include/linux/cgroup_namespace.h
@@ -2,6 +2,8 @@
 #ifndef _LINUX_CGROUP_NAMESPACE_H
 #define _LINUX_CGROUP_NAMESPACE_H
 
+#include <linux/ns_common.h>
+
 struct cgroup_namespace {
 	struct ns_common	ns;
 	struct user_namespace	*user_ns;

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] ns: simplify ns_common_init() further
  2025-09-22 12:42 [PATCH 0/3] ns: minor tweaks Christian Brauner
  2025-09-22 12:42 ` [PATCH 1/3] cgroup: add missing ns_common include Christian Brauner
@ 2025-09-22 12:42 ` Christian Brauner
  2025-09-22 13:41   ` Jan Kara
  2025-09-22 21:36   ` Thomas Gleixner
  2025-09-22 12:42 ` [PATCH 3/3] ns: add ns_debug() Christian Brauner
  2 siblings, 2 replies; 9+ messages in thread
From: Christian Brauner @ 2025-09-22 12:42 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Amir Goldstein, Josef Bacik, Jeff Layton, Mike Yuan,
	Zbigniew Jędrzejewski-Szmek, Lennart Poettering,
	Aleksa Sarai, Alexander Viro, Jan Kara, Tejun Heo,
	Johannes Weiner, Michal Koutný, Jakub Kicinski,
	Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner, cgroups,
	linux-kernel, netdev, Christian Brauner

Simply derive the ns operations from the namespace type.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/namespace.c            |  4 ++--
 include/linux/ns_common.h | 30 ++++++++++++++++++++++++++----
 ipc/namespace.c           |  2 +-
 kernel/cgroup/namespace.c |  2 +-
 kernel/pid_namespace.c    |  2 +-
 kernel/time/namespace.c   |  2 +-
 kernel/user_namespace.c   |  2 +-
 kernel/utsname.c          |  2 +-
 net/core/net_namespace.c  |  9 +--------
 9 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 271cd6294c8a..d65917ec5544 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -4104,9 +4104,9 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool a
 	}
 
 	if (anon)
-		ret = ns_common_init_inum(new_ns, &mntns_operations, MNT_NS_ANON_INO);
+		ret = ns_common_init_inum(new_ns, MNT_NS_ANON_INO);
 	else
-		ret = ns_common_init(new_ns, &mntns_operations);
+		ret = ns_common_init(new_ns);
 	if (ret) {
 		kfree(new_ns);
 		dec_mnt_namespaces(ucounts);
diff --git a/include/linux/ns_common.h b/include/linux/ns_common.h
index aea8528d799a..56492cd9ff8d 100644
--- a/include/linux/ns_common.h
+++ b/include/linux/ns_common.h
@@ -25,6 +25,17 @@ extern struct time_namespace init_time_ns;
 extern struct user_namespace init_user_ns;
 extern struct uts_namespace init_uts_ns;
 
+extern const struct proc_ns_operations netns_operations;
+extern const struct proc_ns_operations utsns_operations;
+extern const struct proc_ns_operations ipcns_operations;
+extern const struct proc_ns_operations pidns_operations;
+extern const struct proc_ns_operations pidns_for_children_operations;
+extern const struct proc_ns_operations userns_operations;
+extern const struct proc_ns_operations mntns_operations;
+extern const struct proc_ns_operations cgroupns_operations;
+extern const struct proc_ns_operations timens_operations;
+extern const struct proc_ns_operations timens_for_children_operations;
+
 struct ns_common {
 	struct dentry *stashed;
 	const struct proc_ns_operations *ops;
@@ -84,10 +95,21 @@ void __ns_common_free(struct ns_common *ns);
 		struct user_namespace *:   &init_user_ns,   \
 		struct uts_namespace *:    &init_uts_ns)
 
-#define ns_common_init(__ns, __ops) \
-	__ns_common_init(to_ns_common(__ns), __ops, (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0))
-
-#define ns_common_init_inum(__ns, __ops, __inum) __ns_common_init(to_ns_common(__ns), __ops, __inum)
+#define to_ns_operations(__ns)                                                                         \
+	_Generic((__ns),                                                                               \
+		struct cgroup_namespace *: (IS_ENABLED(CONFIG_CGROUPS) ? &cgroupns_operations : NULL), \
+		struct ipc_namespace *:    (IS_ENABLED(CONFIG_IPC_NS)  ? &ipcns_operations    : NULL), \
+		struct mnt_namespace *:    &mntns_operations,                                          \
+		struct net *:              (IS_ENABLED(CONFIG_NET_NS)  ? &netns_operations    : NULL), \
+		struct pid_namespace *:    (IS_ENABLED(CONFIG_PID_NS)  ? &pidns_operations    : NULL), \
+		struct time_namespace *:   (IS_ENABLED(CONFIG_TIME_NS) ? &timens_operations   : NULL), \
+		struct user_namespace *:   (IS_ENABLED(CONFIG_USER_NS) ? &userns_operations   : NULL), \
+		struct uts_namespace *:    (IS_ENABLED(CONFIG_UTS_NS)  ? &utsns_operations    : NULL))
+
+#define ns_common_init(__ns) \
+	__ns_common_init(to_ns_common(__ns), to_ns_operations(__ns), (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0))
+
+#define ns_common_init_inum(__ns, __inum) __ns_common_init(to_ns_common(__ns), to_ns_operations(__ns), __inum)
 
 #define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns)))
 
diff --git a/ipc/namespace.c b/ipc/namespace.c
index bd85d1c9d2c2..d89dfd718d2b 100644
--- a/ipc/namespace.c
+++ b/ipc/namespace.c
@@ -62,7 +62,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
 	if (ns == NULL)
 		goto fail_dec;
 
-	err = ns_common_init(ns, &ipcns_operations);
+	err = ns_common_init(ns);
 	if (err)
 		goto fail_free;
 
diff --git a/kernel/cgroup/namespace.c b/kernel/cgroup/namespace.c
index 16ead7508371..04c98338ac08 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 = kzalloc(sizeof(struct cgroup_namespace), GFP_KERNEL_ACCOUNT);
 	if (!new_ns)
 		return ERR_PTR(-ENOMEM);
-	ret = ns_common_init(new_ns, &cgroupns_operations);
+	ret = ns_common_init(new_ns);
 	if (ret)
 		return ERR_PTR(ret);
 	ns_tree_add(new_ns);
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 162f5fb63d75..a262a3f19443 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -103,7 +103,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
 	if (ns->pid_cachep == NULL)
 		goto out_free_idr;
 
-	err = ns_common_init(ns, &pidns_operations);
+	err = ns_common_init(ns);
 	if (err)
 		goto out_free_idr;
 
diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c
index 7aa4d6fedd49..9f26e61be044 100644
--- a/kernel/time/namespace.c
+++ b/kernel/time/namespace.c
@@ -97,7 +97,7 @@ static struct time_namespace *clone_time_ns(struct user_namespace *user_ns,
 	if (!ns->vvar_page)
 		goto fail_free;
 
-	err = ns_common_init(ns, &timens_operations);
+	err = ns_common_init(ns);
 	if (err)
 		goto fail_free_page;
 
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index f9df45c46235..e1559e8a8a02 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -126,7 +126,7 @@ int create_user_ns(struct cred *new)
 
 	ns->parent_could_setfcap = cap_raised(new->cap_effective, CAP_SETFCAP);
 
-	ret = ns_common_init(ns, &userns_operations);
+	ret = ns_common_init(ns);
 	if (ret)
 		goto fail_free;
 
diff --git a/kernel/utsname.c b/kernel/utsname.c
index 95d733eb2c98..00001592ad13 100644
--- a/kernel/utsname.c
+++ b/kernel/utsname.c
@@ -50,7 +50,7 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns,
 	if (!ns)
 		goto fail_dec;
 
-	err = ns_common_init(ns, &utsns_operations);
+	err = ns_common_init(ns);
 	if (err)
 		goto fail_free;
 
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index d5e3fd819163..bdea7d5fac56 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -400,16 +400,9 @@ static __net_init void preinit_net_sysctl(struct net *net)
 /* init code that must occur even if setup_net() is not called. */
 static __net_init int preinit_net(struct net *net, struct user_namespace *user_ns)
 {
-	const struct proc_ns_operations *ns_ops;
 	int ret;
 
-#ifdef CONFIG_NET_NS
-	ns_ops = &netns_operations;
-#else
-	ns_ops = NULL;
-#endif
-
-	ret = ns_common_init(net, ns_ops);
+	ret = ns_common_init(net);
 	if (ret)
 		return ret;
 

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] ns: add ns_debug()
  2025-09-22 12:42 [PATCH 0/3] ns: minor tweaks Christian Brauner
  2025-09-22 12:42 ` [PATCH 1/3] cgroup: add missing ns_common include Christian Brauner
  2025-09-22 12:42 ` [PATCH 2/3] ns: simplify ns_common_init() further Christian Brauner
@ 2025-09-22 12:42 ` Christian Brauner
  2025-09-22 13:42   ` Jan Kara
  2 siblings, 1 reply; 9+ messages in thread
From: Christian Brauner @ 2025-09-22 12:42 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Amir Goldstein, Josef Bacik, Jeff Layton, Mike Yuan,
	Zbigniew Jędrzejewski-Szmek, Lennart Poettering,
	Aleksa Sarai, Alexander Viro, Jan Kara, Tejun Heo,
	Johannes Weiner, Michal Koutný, Jakub Kicinski,
	Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner, cgroups,
	linux-kernel, netdev, Christian Brauner

Add ns_debug() that asserts that the correct operations are used for the
namespace type.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 kernel/nscommon.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/kernel/nscommon.c b/kernel/nscommon.c
index 7aa2be6a0c32..3cef89ddef41 100644
--- a/kernel/nscommon.c
+++ b/kernel/nscommon.c
@@ -2,6 +2,55 @@
 
 #include <linux/ns_common.h>
 #include <linux/proc_ns.h>
+#include <linux/vfsdebug.h>
+
+#ifdef CONFIG_DEBUG_VFS
+static void ns_debug(struct ns_common *ns, const struct proc_ns_operations *ops)
+{
+	switch (ns->ops->type) {
+#ifdef CONFIG_CGROUPS
+	case CLONE_NEWCGROUP:
+		VFS_WARN_ON_ONCE(ops != &cgroupns_operations);
+		break;
+#endif
+#ifdef CONFIG_IPC_NS
+	case CLONE_NEWIPC:
+		VFS_WARN_ON_ONCE(ops != &ipcns_operations);
+		break;
+#endif
+	case CLONE_NEWNS:
+		VFS_WARN_ON_ONCE(ops != &mntns_operations);
+		break;
+#ifdef CONFIG_NET_NS
+	case CLONE_NEWNET:
+		VFS_WARN_ON_ONCE(ops != &netns_operations);
+		break;
+#endif
+#ifdef CONFIG_PID_NS
+	case CLONE_NEWPID:
+		VFS_WARN_ON_ONCE(ops != &pidns_operations);
+		break;
+#endif
+#ifdef CONFIG_TIME_NS
+	case CLONE_NEWTIME:
+		VFS_WARN_ON_ONCE(ops != &timens_operations);
+		break;
+#endif
+#ifdef CONFIG_USER_NS
+	case CLONE_NEWUSER:
+		VFS_WARN_ON_ONCE(ops != &userns_operations);
+		break;
+#endif
+#ifdef CONFIG_UTS_NS
+	case CLONE_NEWUTS:
+		VFS_WARN_ON_ONCE(ops != &utsns_operations);
+		break;
+#endif
+	default:
+		VFS_WARN_ON_ONCE(true);
+	}
+}
+#endif
 
 int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops, int inum)
 {
@@ -12,6 +61,10 @@ int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops,
 	RB_CLEAR_NODE(&ns->ns_tree_node);
 	INIT_LIST_HEAD(&ns->ns_list_node);
 
+#ifdef CONFIG_DEBUG_VFS
+	ns_debug(ns, ops);
+#endif
+
 	if (inum) {
 		ns->inum = inum;
 		return 0;

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] cgroup: add missing ns_common include
  2025-09-22 12:42 ` [PATCH 1/3] cgroup: add missing ns_common include Christian Brauner
@ 2025-09-22 13:37   ` Jan Kara
  2025-09-22 15:44   ` Tejun Heo
  1 sibling, 0 replies; 9+ messages in thread
From: Jan Kara @ 2025-09-22 13:37 UTC (permalink / raw)
  To: Christian Brauner
  Cc: linux-fsdevel, Amir Goldstein, Josef Bacik, Jeff Layton,
	Mike Yuan, Zbigniew Jędrzejewski-Szmek, Lennart Poettering,
	Aleksa Sarai, Alexander Viro, Jan Kara, Tejun Heo,
	Johannes Weiner, Michal Koutný, Jakub Kicinski,
	Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner, cgroups,
	linux-kernel, netdev

On Mon 22-09-25 14:42:35, Christian Brauner wrote:
> Add the missing include of the ns_common header.
> 
> Signed-off-by: Christian Brauner <brauner@kernel.org>

Sure. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  include/linux/cgroup_namespace.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/include/linux/cgroup_namespace.h b/include/linux/cgroup_namespace.h
> index b7dbf4d623d2..81ccbdee425b 100644
> --- a/include/linux/cgroup_namespace.h
> +++ b/include/linux/cgroup_namespace.h
> @@ -2,6 +2,8 @@
>  #ifndef _LINUX_CGROUP_NAMESPACE_H
>  #define _LINUX_CGROUP_NAMESPACE_H
>  
> +#include <linux/ns_common.h>
> +
>  struct cgroup_namespace {
>  	struct ns_common	ns;
>  	struct user_namespace	*user_ns;
> 
> -- 
> 2.47.3
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] ns: simplify ns_common_init() further
  2025-09-22 12:42 ` [PATCH 2/3] ns: simplify ns_common_init() further Christian Brauner
@ 2025-09-22 13:41   ` Jan Kara
  2025-09-22 21:36   ` Thomas Gleixner
  1 sibling, 0 replies; 9+ messages in thread
From: Jan Kara @ 2025-09-22 13:41 UTC (permalink / raw)
  To: Christian Brauner
  Cc: linux-fsdevel, Amir Goldstein, Josef Bacik, Jeff Layton,
	Mike Yuan, Zbigniew Jędrzejewski-Szmek, Lennart Poettering,
	Aleksa Sarai, Alexander Viro, Jan Kara, Tejun Heo,
	Johannes Weiner, Michal Koutný, Jakub Kicinski,
	Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner, cgroups,
	linux-kernel, netdev

On Mon 22-09-25 14:42:36, Christian Brauner wrote:
> Simply derive the ns operations from the namespace type.
> 
> Signed-off-by: Christian Brauner <brauner@kernel.org>

Nice! As much as I already feel pity for the guy who'll be reading all
these macros to figure out how some ns gets initialized :) feel free to
add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/namespace.c            |  4 ++--
>  include/linux/ns_common.h | 30 ++++++++++++++++++++++++++----
>  ipc/namespace.c           |  2 +-
>  kernel/cgroup/namespace.c |  2 +-
>  kernel/pid_namespace.c    |  2 +-
>  kernel/time/namespace.c   |  2 +-
>  kernel/user_namespace.c   |  2 +-
>  kernel/utsname.c          |  2 +-
>  net/core/net_namespace.c  |  9 +--------
>  9 files changed, 35 insertions(+), 20 deletions(-)
> 
> diff --git a/fs/namespace.c b/fs/namespace.c
> index 271cd6294c8a..d65917ec5544 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -4104,9 +4104,9 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool a
>  	}
>  
>  	if (anon)
> -		ret = ns_common_init_inum(new_ns, &mntns_operations, MNT_NS_ANON_INO);
> +		ret = ns_common_init_inum(new_ns, MNT_NS_ANON_INO);
>  	else
> -		ret = ns_common_init(new_ns, &mntns_operations);
> +		ret = ns_common_init(new_ns);
>  	if (ret) {
>  		kfree(new_ns);
>  		dec_mnt_namespaces(ucounts);
> diff --git a/include/linux/ns_common.h b/include/linux/ns_common.h
> index aea8528d799a..56492cd9ff8d 100644
> --- a/include/linux/ns_common.h
> +++ b/include/linux/ns_common.h
> @@ -25,6 +25,17 @@ extern struct time_namespace init_time_ns;
>  extern struct user_namespace init_user_ns;
>  extern struct uts_namespace init_uts_ns;
>  
> +extern const struct proc_ns_operations netns_operations;
> +extern const struct proc_ns_operations utsns_operations;
> +extern const struct proc_ns_operations ipcns_operations;
> +extern const struct proc_ns_operations pidns_operations;
> +extern const struct proc_ns_operations pidns_for_children_operations;
> +extern const struct proc_ns_operations userns_operations;
> +extern const struct proc_ns_operations mntns_operations;
> +extern const struct proc_ns_operations cgroupns_operations;
> +extern const struct proc_ns_operations timens_operations;
> +extern const struct proc_ns_operations timens_for_children_operations;
> +
>  struct ns_common {
>  	struct dentry *stashed;
>  	const struct proc_ns_operations *ops;
> @@ -84,10 +95,21 @@ void __ns_common_free(struct ns_common *ns);
>  		struct user_namespace *:   &init_user_ns,   \
>  		struct uts_namespace *:    &init_uts_ns)
>  
> -#define ns_common_init(__ns, __ops) \
> -	__ns_common_init(to_ns_common(__ns), __ops, (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0))
> -
> -#define ns_common_init_inum(__ns, __ops, __inum) __ns_common_init(to_ns_common(__ns), __ops, __inum)
> +#define to_ns_operations(__ns)                                                                         \
> +	_Generic((__ns),                                                                               \
> +		struct cgroup_namespace *: (IS_ENABLED(CONFIG_CGROUPS) ? &cgroupns_operations : NULL), \
> +		struct ipc_namespace *:    (IS_ENABLED(CONFIG_IPC_NS)  ? &ipcns_operations    : NULL), \
> +		struct mnt_namespace *:    &mntns_operations,                                          \
> +		struct net *:              (IS_ENABLED(CONFIG_NET_NS)  ? &netns_operations    : NULL), \
> +		struct pid_namespace *:    (IS_ENABLED(CONFIG_PID_NS)  ? &pidns_operations    : NULL), \
> +		struct time_namespace *:   (IS_ENABLED(CONFIG_TIME_NS) ? &timens_operations   : NULL), \
> +		struct user_namespace *:   (IS_ENABLED(CONFIG_USER_NS) ? &userns_operations   : NULL), \
> +		struct uts_namespace *:    (IS_ENABLED(CONFIG_UTS_NS)  ? &utsns_operations    : NULL))
> +
> +#define ns_common_init(__ns) \
> +	__ns_common_init(to_ns_common(__ns), to_ns_operations(__ns), (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0))
> +
> +#define ns_common_init_inum(__ns, __inum) __ns_common_init(to_ns_common(__ns), to_ns_operations(__ns), __inum)
>  
>  #define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns)))
>  
> diff --git a/ipc/namespace.c b/ipc/namespace.c
> index bd85d1c9d2c2..d89dfd718d2b 100644
> --- a/ipc/namespace.c
> +++ b/ipc/namespace.c
> @@ -62,7 +62,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
>  	if (ns == NULL)
>  		goto fail_dec;
>  
> -	err = ns_common_init(ns, &ipcns_operations);
> +	err = ns_common_init(ns);
>  	if (err)
>  		goto fail_free;
>  
> diff --git a/kernel/cgroup/namespace.c b/kernel/cgroup/namespace.c
> index 16ead7508371..04c98338ac08 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 = kzalloc(sizeof(struct cgroup_namespace), GFP_KERNEL_ACCOUNT);
>  	if (!new_ns)
>  		return ERR_PTR(-ENOMEM);
> -	ret = ns_common_init(new_ns, &cgroupns_operations);
> +	ret = ns_common_init(new_ns);
>  	if (ret)
>  		return ERR_PTR(ret);
>  	ns_tree_add(new_ns);
> diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
> index 162f5fb63d75..a262a3f19443 100644
> --- a/kernel/pid_namespace.c
> +++ b/kernel/pid_namespace.c
> @@ -103,7 +103,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
>  	if (ns->pid_cachep == NULL)
>  		goto out_free_idr;
>  
> -	err = ns_common_init(ns, &pidns_operations);
> +	err = ns_common_init(ns);
>  	if (err)
>  		goto out_free_idr;
>  
> diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c
> index 7aa4d6fedd49..9f26e61be044 100644
> --- a/kernel/time/namespace.c
> +++ b/kernel/time/namespace.c
> @@ -97,7 +97,7 @@ static struct time_namespace *clone_time_ns(struct user_namespace *user_ns,
>  	if (!ns->vvar_page)
>  		goto fail_free;
>  
> -	err = ns_common_init(ns, &timens_operations);
> +	err = ns_common_init(ns);
>  	if (err)
>  		goto fail_free_page;
>  
> diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
> index f9df45c46235..e1559e8a8a02 100644
> --- a/kernel/user_namespace.c
> +++ b/kernel/user_namespace.c
> @@ -126,7 +126,7 @@ int create_user_ns(struct cred *new)
>  
>  	ns->parent_could_setfcap = cap_raised(new->cap_effective, CAP_SETFCAP);
>  
> -	ret = ns_common_init(ns, &userns_operations);
> +	ret = ns_common_init(ns);
>  	if (ret)
>  		goto fail_free;
>  
> diff --git a/kernel/utsname.c b/kernel/utsname.c
> index 95d733eb2c98..00001592ad13 100644
> --- a/kernel/utsname.c
> +++ b/kernel/utsname.c
> @@ -50,7 +50,7 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns,
>  	if (!ns)
>  		goto fail_dec;
>  
> -	err = ns_common_init(ns, &utsns_operations);
> +	err = ns_common_init(ns);
>  	if (err)
>  		goto fail_free;
>  
> diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
> index d5e3fd819163..bdea7d5fac56 100644
> --- a/net/core/net_namespace.c
> +++ b/net/core/net_namespace.c
> @@ -400,16 +400,9 @@ static __net_init void preinit_net_sysctl(struct net *net)
>  /* init code that must occur even if setup_net() is not called. */
>  static __net_init int preinit_net(struct net *net, struct user_namespace *user_ns)
>  {
> -	const struct proc_ns_operations *ns_ops;
>  	int ret;
>  
> -#ifdef CONFIG_NET_NS
> -	ns_ops = &netns_operations;
> -#else
> -	ns_ops = NULL;
> -#endif
> -
> -	ret = ns_common_init(net, ns_ops);
> +	ret = ns_common_init(net);
>  	if (ret)
>  		return ret;
>  
> 
> -- 
> 2.47.3
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] ns: add ns_debug()
  2025-09-22 12:42 ` [PATCH 3/3] ns: add ns_debug() Christian Brauner
@ 2025-09-22 13:42   ` Jan Kara
  0 siblings, 0 replies; 9+ messages in thread
From: Jan Kara @ 2025-09-22 13:42 UTC (permalink / raw)
  To: Christian Brauner
  Cc: linux-fsdevel, Amir Goldstein, Josef Bacik, Jeff Layton,
	Mike Yuan, Zbigniew Jędrzejewski-Szmek, Lennart Poettering,
	Aleksa Sarai, Alexander Viro, Jan Kara, Tejun Heo,
	Johannes Weiner, Michal Koutný, Jakub Kicinski,
	Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner, cgroups,
	linux-kernel, netdev

On Mon 22-09-25 14:42:37, Christian Brauner wrote:
> Add ns_debug() that asserts that the correct operations are used for the
> namespace type.
> 
> Signed-off-by: Christian Brauner <brauner@kernel.org>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  kernel/nscommon.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
> 
> diff --git a/kernel/nscommon.c b/kernel/nscommon.c
> index 7aa2be6a0c32..3cef89ddef41 100644
> --- a/kernel/nscommon.c
> +++ b/kernel/nscommon.c
> @@ -2,6 +2,55 @@
>  
>  #include <linux/ns_common.h>
>  #include <linux/proc_ns.h>
> +#include <linux/vfsdebug.h>
> +
> +#ifdef CONFIG_DEBUG_VFS
> +static void ns_debug(struct ns_common *ns, const struct proc_ns_operations *ops)
> +{
> +	switch (ns->ops->type) {
> +#ifdef CONFIG_CGROUPS
> +	case CLONE_NEWCGROUP:
> +		VFS_WARN_ON_ONCE(ops != &cgroupns_operations);
> +		break;
> +#endif
> +#ifdef CONFIG_IPC_NS
> +	case CLONE_NEWIPC:
> +		VFS_WARN_ON_ONCE(ops != &ipcns_operations);
> +		break;
> +#endif
> +	case CLONE_NEWNS:
> +		VFS_WARN_ON_ONCE(ops != &mntns_operations);
> +		break;
> +#ifdef CONFIG_NET_NS
> +	case CLONE_NEWNET:
> +		VFS_WARN_ON_ONCE(ops != &netns_operations);
> +		break;
> +#endif
> +#ifdef CONFIG_PID_NS
> +	case CLONE_NEWPID:
> +		VFS_WARN_ON_ONCE(ops != &pidns_operations);
> +		break;
> +#endif
> +#ifdef CONFIG_TIME_NS
> +	case CLONE_NEWTIME:
> +		VFS_WARN_ON_ONCE(ops != &timens_operations);
> +		break;
> +#endif
> +#ifdef CONFIG_USER_NS
> +	case CLONE_NEWUSER:
> +		VFS_WARN_ON_ONCE(ops != &userns_operations);
> +		break;
> +#endif
> +#ifdef CONFIG_UTS_NS
> +	case CLONE_NEWUTS:
> +		VFS_WARN_ON_ONCE(ops != &utsns_operations);
> +		break;
> +#endif
> +	default:
> +		VFS_WARN_ON_ONCE(true);
> +	}
> +}
> +#endif
>  
>  int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops, int inum)
>  {
> @@ -12,6 +61,10 @@ int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops,
>  	RB_CLEAR_NODE(&ns->ns_tree_node);
>  	INIT_LIST_HEAD(&ns->ns_list_node);
>  
> +#ifdef CONFIG_DEBUG_VFS
> +	ns_debug(ns, ops);
> +#endif
> +
>  	if (inum) {
>  		ns->inum = inum;
>  		return 0;
> 
> -- 
> 2.47.3
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] cgroup: add missing ns_common include
  2025-09-22 12:42 ` [PATCH 1/3] cgroup: add missing ns_common include Christian Brauner
  2025-09-22 13:37   ` Jan Kara
@ 2025-09-22 15:44   ` Tejun Heo
  1 sibling, 0 replies; 9+ messages in thread
From: Tejun Heo @ 2025-09-22 15:44 UTC (permalink / raw)
  To: Christian Brauner
  Cc: linux-fsdevel, Amir Goldstein, Josef Bacik, Jeff Layton,
	Mike Yuan, Zbigniew Jędrzejewski-Szmek, Lennart Poettering,
	Aleksa Sarai, Alexander Viro, Jan Kara, Johannes Weiner,
	Michal Koutný, Jakub Kicinski, Anna-Maria Behnsen,
	Frederic Weisbecker, Thomas Gleixner, cgroups, linux-kernel,
	netdev

On Mon, Sep 22, 2025 at 02:42:35PM +0200, Christian Brauner wrote:
> Add the missing include of the ns_common header.
> 
> Signed-off-by: Christian Brauner <brauner@kernel.org>

Acked-by: Tejun Heo <tj@kernel.org>

Please let me know if you want this to go through the cgroup tree.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] ns: simplify ns_common_init() further
  2025-09-22 12:42 ` [PATCH 2/3] ns: simplify ns_common_init() further Christian Brauner
  2025-09-22 13:41   ` Jan Kara
@ 2025-09-22 21:36   ` Thomas Gleixner
  1 sibling, 0 replies; 9+ messages in thread
From: Thomas Gleixner @ 2025-09-22 21:36 UTC (permalink / raw)
  To: Christian Brauner, linux-fsdevel
  Cc: Amir Goldstein, Josef Bacik, Jeff Layton, Mike Yuan,
	Zbigniew Jędrzejewski-Szmek, Lennart Poettering,
	Aleksa Sarai, Alexander Viro, Jan Kara, Tejun Heo,
	Johannes Weiner, Michal Koutný, Jakub Kicinski,
	Anna-Maria Behnsen, Frederic Weisbecker, cgroups, linux-kernel,
	netdev, Christian Brauner

On Mon, Sep 22 2025 at 14:42, Christian Brauner wrote:
> Simply derive the ns operations from the namespace type.
>
> Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
>  fs/namespace.c            |  4 ++--
>  include/linux/ns_common.h | 30 ++++++++++++++++++++++++++----
>  ipc/namespace.c           |  2 +-
>  kernel/cgroup/namespace.c |  2 +-
>  kernel/pid_namespace.c    |  2 +-
>  kernel/time/namespace.c   |  2 +-

Acked-by: Thomas Gleixner <tglx@linutronix.de>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-09-22 21:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22 12:42 [PATCH 0/3] ns: minor tweaks Christian Brauner
2025-09-22 12:42 ` [PATCH 1/3] cgroup: add missing ns_common include Christian Brauner
2025-09-22 13:37   ` Jan Kara
2025-09-22 15:44   ` Tejun Heo
2025-09-22 12:42 ` [PATCH 2/3] ns: simplify ns_common_init() further Christian Brauner
2025-09-22 13:41   ` Jan Kara
2025-09-22 21:36   ` Thomas Gleixner
2025-09-22 12:42 ` [PATCH 3/3] ns: add ns_debug() Christian Brauner
2025-09-22 13:42   ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).