Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge patch series "ns: minor tweaks"

Christian Brauner <brauner@kernel.org> says:

* Add a missing include into the cgroup namespace header.
* Simplify ns_common_init{_inum}() and derive the namespace operations
from the namespace type.
* Add debug asserts into ns_common_init{_inum}() to catch bugs.

* patches from https://lore.kernel.org/20250922-work-namespace-ns_common-fixes-v1-0-3c26aeb30831@kernel.org:
ns: add ns_debug()
ns: simplify ns_common_init() further
cgroup: add missing ns_common include

Signed-off-by: Christian Brauner <brauner@kernel.org>

+89 -19
+2 -2
fs/namespace.c
··· 4104 4104 } 4105 4105 4106 4106 if (anon) 4107 - ret = ns_common_init_inum(new_ns, &mntns_operations, MNT_NS_ANON_INO); 4107 + ret = ns_common_init_inum(new_ns, MNT_NS_ANON_INO); 4108 4108 else 4109 - ret = ns_common_init(new_ns, &mntns_operations); 4109 + ret = ns_common_init(new_ns); 4110 4110 if (ret) { 4111 4111 kfree(new_ns); 4112 4112 dec_mnt_namespaces(ucounts);
+2
include/linux/cgroup_namespace.h
··· 2 2 #ifndef _LINUX_CGROUP_NAMESPACE_H 3 3 #define _LINUX_CGROUP_NAMESPACE_H 4 4 5 + #include <linux/ns_common.h> 6 + 5 7 struct cgroup_namespace { 6 8 struct ns_common ns; 7 9 struct user_namespace *user_ns;
+25 -3
include/linux/ns_common.h
··· 25 25 extern struct user_namespace init_user_ns; 26 26 extern struct uts_namespace init_uts_ns; 27 27 28 + extern const struct proc_ns_operations netns_operations; 29 + extern const struct proc_ns_operations utsns_operations; 30 + extern const struct proc_ns_operations ipcns_operations; 31 + extern const struct proc_ns_operations pidns_operations; 32 + extern const struct proc_ns_operations pidns_for_children_operations; 33 + extern const struct proc_ns_operations userns_operations; 34 + extern const struct proc_ns_operations mntns_operations; 35 + extern const struct proc_ns_operations cgroupns_operations; 36 + extern const struct proc_ns_operations timens_operations; 37 + extern const struct proc_ns_operations timens_for_children_operations; 38 + 28 39 struct ns_common { 29 40 struct dentry *stashed; 30 41 const struct proc_ns_operations *ops; ··· 95 84 struct user_namespace *: &init_user_ns, \ 96 85 struct uts_namespace *: &init_uts_ns) 97 86 98 - #define ns_common_init(__ns, __ops) \ 99 - __ns_common_init(to_ns_common(__ns), __ops, (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0)) 87 + #define to_ns_operations(__ns) \ 88 + _Generic((__ns), \ 89 + struct cgroup_namespace *: (IS_ENABLED(CONFIG_CGROUPS) ? &cgroupns_operations : NULL), \ 90 + struct ipc_namespace *: (IS_ENABLED(CONFIG_IPC_NS) ? &ipcns_operations : NULL), \ 91 + struct mnt_namespace *: &mntns_operations, \ 92 + struct net *: (IS_ENABLED(CONFIG_NET_NS) ? &netns_operations : NULL), \ 93 + struct pid_namespace *: (IS_ENABLED(CONFIG_PID_NS) ? &pidns_operations : NULL), \ 94 + struct time_namespace *: (IS_ENABLED(CONFIG_TIME_NS) ? &timens_operations : NULL), \ 95 + struct user_namespace *: (IS_ENABLED(CONFIG_USER_NS) ? &userns_operations : NULL), \ 96 + struct uts_namespace *: (IS_ENABLED(CONFIG_UTS_NS) ? &utsns_operations : NULL)) 100 97 101 - #define ns_common_init_inum(__ns, __ops, __inum) __ns_common_init(to_ns_common(__ns), __ops, __inum) 98 + #define ns_common_init(__ns) \ 99 + __ns_common_init(to_ns_common(__ns), to_ns_operations(__ns), (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0)) 100 + 101 + #define ns_common_init_inum(__ns, __inum) __ns_common_init(to_ns_common(__ns), to_ns_operations(__ns), __inum) 102 102 103 103 #define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns))) 104 104
+1 -1
ipc/namespace.c
··· 62 62 if (ns == NULL) 63 63 goto fail_dec; 64 64 65 - err = ns_common_init(ns, &ipcns_operations); 65 + err = ns_common_init(ns); 66 66 if (err) 67 67 goto fail_free; 68 68
+1 -1
kernel/cgroup/namespace.c
··· 27 27 new_ns = kzalloc(sizeof(struct cgroup_namespace), GFP_KERNEL_ACCOUNT); 28 28 if (!new_ns) 29 29 return ERR_PTR(-ENOMEM); 30 - ret = ns_common_init(new_ns, &cgroupns_operations); 30 + ret = ns_common_init(new_ns); 31 31 if (ret) 32 32 return ERR_PTR(ret); 33 33 ns_tree_add(new_ns);
+53
kernel/nscommon.c
··· 2 2 3 3 #include <linux/ns_common.h> 4 4 #include <linux/proc_ns.h> 5 + #include <linux/vfsdebug.h> 6 + 7 + #ifdef CONFIG_DEBUG_VFS 8 + static void ns_debug(struct ns_common *ns, const struct proc_ns_operations *ops) 9 + { 10 + switch (ns->ops->type) { 11 + #ifdef CONFIG_CGROUPS 12 + case CLONE_NEWCGROUP: 13 + VFS_WARN_ON_ONCE(ops != &cgroupns_operations); 14 + break; 15 + #endif 16 + #ifdef CONFIG_IPC_NS 17 + case CLONE_NEWIPC: 18 + VFS_WARN_ON_ONCE(ops != &ipcns_operations); 19 + break; 20 + #endif 21 + case CLONE_NEWNS: 22 + VFS_WARN_ON_ONCE(ops != &mntns_operations); 23 + break; 24 + #ifdef CONFIG_NET_NS 25 + case CLONE_NEWNET: 26 + VFS_WARN_ON_ONCE(ops != &netns_operations); 27 + break; 28 + #endif 29 + #ifdef CONFIG_PID_NS 30 + case CLONE_NEWPID: 31 + VFS_WARN_ON_ONCE(ops != &pidns_operations); 32 + break; 33 + #endif 34 + #ifdef CONFIG_TIME_NS 35 + case CLONE_NEWTIME: 36 + VFS_WARN_ON_ONCE(ops != &timens_operations); 37 + break; 38 + #endif 39 + #ifdef CONFIG_USER_NS 40 + case CLONE_NEWUSER: 41 + VFS_WARN_ON_ONCE(ops != &userns_operations); 42 + break; 43 + #endif 44 + #ifdef CONFIG_UTS_NS 45 + case CLONE_NEWUTS: 46 + VFS_WARN_ON_ONCE(ops != &utsns_operations); 47 + break; 48 + #endif 49 + default: 50 + VFS_WARN_ON_ONCE(true); 51 + } 52 + } 53 + #endif 5 54 6 55 int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops, int inum) 7 56 { ··· 60 11 ns->ns_id = 0; 61 12 RB_CLEAR_NODE(&ns->ns_tree_node); 62 13 INIT_LIST_HEAD(&ns->ns_list_node); 14 + 15 + #ifdef CONFIG_DEBUG_VFS 16 + ns_debug(ns, ops); 17 + #endif 63 18 64 19 if (inum) { 65 20 ns->inum = inum;
+1 -1
kernel/pid_namespace.c
··· 103 103 if (ns->pid_cachep == NULL) 104 104 goto out_free_idr; 105 105 106 - err = ns_common_init(ns, &pidns_operations); 106 + err = ns_common_init(ns); 107 107 if (err) 108 108 goto out_free_idr; 109 109
+1 -1
kernel/time/namespace.c
··· 97 97 if (!ns->vvar_page) 98 98 goto fail_free; 99 99 100 - err = ns_common_init(ns, &timens_operations); 100 + err = ns_common_init(ns); 101 101 if (err) 102 102 goto fail_free_page; 103 103
+1 -1
kernel/user_namespace.c
··· 126 126 127 127 ns->parent_could_setfcap = cap_raised(new->cap_effective, CAP_SETFCAP); 128 128 129 - ret = ns_common_init(ns, &userns_operations); 129 + ret = ns_common_init(ns); 130 130 if (ret) 131 131 goto fail_free; 132 132
+1 -1
kernel/utsname.c
··· 50 50 if (!ns) 51 51 goto fail_dec; 52 52 53 - err = ns_common_init(ns, &utsns_operations); 53 + err = ns_common_init(ns); 54 54 if (err) 55 55 goto fail_free; 56 56
+1 -8
net/core/net_namespace.c
··· 400 400 /* init code that must occur even if setup_net() is not called. */ 401 401 static __net_init int preinit_net(struct net *net, struct user_namespace *user_ns) 402 402 { 403 - const struct proc_ns_operations *ns_ops; 404 403 int ret; 405 404 406 - #ifdef CONFIG_NET_NS 407 - ns_ops = &netns_operations; 408 - #else 409 - ns_ops = NULL; 410 - #endif 411 - 412 - ret = ns_common_init(net, ns_ops); 405 + ret = ns_common_init(net); 413 406 if (ret) 414 407 return ret; 415 408