ns: rework reference counting
Subsystems (7)
Christian Brauner
maintainercover ns: rework reference counting
Stop open accesses to the reference counts and cargo-culting the same code in all namespace. Use a set of dedicated helpers and make the actual count private.
---
Christian Brauner (14):
ns: add reference count helpers
mnt: port to ns_ref_*() helpers
cgroup: port to ns_ref_*() helpers
ipc: port to ns_ref_*() helpers
pid: port to ns_ref_*() helpers
time: port to ns_ref_*() helpers
user: port to ns_ref_*() helpers
net-sysfs: use check_net()
net: use check_net()
ipv4: use check_net()
uts: port to ns_ref_*() helpers
net: port to ns_ref_*() helpers
nsfs: port to ns_ref_*() helpers
ns: rename to __ns_ref
fs/mount.h | 2 +- fs/namespace.c | 4 ++-- fs/nsfs.c | 2 +- include/linux/cgroup_namespace.h | 4 ++-- include/linux/ipc_namespace.h | 4 ++-- include/linux/ns_common.h | 47 ++++++++++++++++++++++++++++++---------- include/linux/pid_namespace.h | 2 +- include/linux/time_namespace.h | 4 ++-- include/linux/user_namespace.h | 4 ++-- include/linux/uts_namespace.h | 4 ++-- include/net/net_namespace.h | 8 +++---- init/version-timestamp.c | 2 +- ipc/msgutil.c | 2 +- ipc/namespace.c | 2 +- kernel/cgroup/cgroup.c | 2 +- kernel/nscommon.c | 2 +- kernel/pid.c | 2 +- kernel/pid_namespace.c | 4 ++-- kernel/time/namespace.c | 2 +- kernel/user.c | 2 +- kernel/user_namespace.c | 2 +- net/core/net-sysfs.c | 6 ++--- net/core/net_namespace.c | 2 +- net/ipv4/inet_timewait_sock.c | 4 ++-- net/ipv4/tcp_metrics.c | 2 +- 25 files changed, 73 insertions(+), 48 deletions(-)
---
base-commit: 3f9cc273c16f63b5d584ec4e767918765c44316b
change-id: 20250917-work-namespace-ns_ref-357162ca7aa8
Christian Brauner
maintainerPATCH 1/14 ns: add reference count helpers
--- include/linux/ns_common.h | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-)
include/linux/ns_common.h +35 -10
@@ -43,16 +43,24 @@ struct ns_common {int __ns_common_init (struct ns_common *ns,const struct proc_ns_operations *ops,int inum);void __ns_common_free (struct ns_common *ns); -#define to_ns_common (__ns) \ - _Generic((__ns), \ - struct cgroup_namespace *: &(__ns)->ns, \ - struct ipc_namespace *: &(__ns)->ns, \ - struct mnt_namespace *: &(__ns)->ns, \ - struct net *: &(__ns)->ns, \ - struct pid_namespace *: &(__ns)->ns, \ - struct time_namespace *: &(__ns)->ns, \ - struct user_namespace *: &(__ns)->ns, \ - struct uts_namespace *: &(__ns)->ns) +#define to_ns_common (__ns) \ + _Generic((__ns), \ + struct cgroup_namespace *: &(__ns)->ns, \ + const struct cgroup_namespace *: &(__ns)->ns, \ + struct ipc_namespace *: &(__ns)->ns, \ + const struct ipc_namespace *: &(__ns)->ns, \ + struct mnt_namespace *: &(__ns)->ns, \ + const struct mnt_namespace *: &(__ns)->ns, \ + struct net *: &(__ns)->ns, \ + const struct net *: &(__ns)->ns, \ + struct pid_namespace *: &(__ns)->ns, \ + const struct pid_namespace *: &(__ns)->ns, \ + struct time_namespace *: &(__ns)->ns, \ + const struct time_namespace *: &(__ns)->ns, \ + struct user_namespace *: &(__ns)->ns, \ + const struct user_namespace *: &(__ns)->ns, \ + struct uts_namespace *: &(__ns)->ns, \ + const struct uts_namespace *: &(__ns)->ns)#define ns_init_inum (__ns) \ _Generic((__ns), \
@@ -85,4 +93,21 @@ void __ns_common_free(struct ns_common *ns);#define ns_common_free (__ns) __ns_common_free(to_ns_common((__ns))) +static __always_inline __must_check bool __ns_ref_put(struct ns_common *ns) +{ +return refcount_dec_and_test (&ns->count); +} + +static __always_inline __must_check bool __ns_ref_get(struct ns_common *ns) +{ +return refcount_inc_not_zero (&ns->count); +} + +#define ns_ref_read (__ns) refcount_read(&to_ns_common((__ns))->count) +#define ns_ref_inc (__ns) refcount_inc(&to_ns_common((__ns))->count) +#define ns_ref_get (__ns) __ns_ref_get(to_ns_common((__ns))) +#define ns_ref_put (__ns) __ns_ref_put(to_ns_common((__ns))) +#define ns_ref_put_and_lock (__ns, __lock) \ + refcount_dec_and_lock(&to_ns_common((__ns))->count, (__lock)) +#endif
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 2/14 mnt: port to ns_ref_*() helpers
In reply to Christian BraunerStop accessing ns.count directly.
--- fs/mount.h | 2 +- fs/namespace.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
fs/mount.h +1 -1
@@ -143,7 +143,7 @@ static inline void detach_mounts(struct dentry *dentry)static inline void get_mnt_ns (struct mnt_namespace *ns) { -refcount_inc (&ns->ns.count); +ns_ref_inc (ns); }extern seqlock_t mount_lock;
fs/namespace.c +2 -2
@@ -2111,7 +2111,7 @@ struct mnt_namespace *get_sequential_mnt_ns(struct mnt_namespace *mntns, bool pr* the mount namespace and it might already be on its * deathbed. */ -if (!refcount_inc_not_zero (&mntns->ns.count)) +if (!ns_ref_get (mntns))continue ;return mntns;
@@ -6080,7 +6080,7 @@ void __init mnt_init(void)void put_mnt_ns (struct mnt_namespace *ns) { -if (!refcount_dec_and_test (&ns->ns.count)) +if (!ns_ref_put (ns))return ;namespace_lock (); emptied_ns = ns;
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 3/14 cgroup: port to ns_ref_*() helpers
In reply to Christian BraunerStop accessing ns.count directly.
--- include/linux/cgroup_namespace.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/cgroup_namespace.h +2 -2
@@ -29,12 +29,12 @@ int cgroup_path_ns(struct cgroup *cgrp, char *buf, size_t buflen,static inline void get_cgroup_ns (struct cgroup_namespace *ns) { -refcount_inc (&ns->ns.count); +ns_ref_inc (ns); }static inline void put_cgroup_ns (struct cgroup_namespace *ns) { -if (refcount_dec_and_test (&ns->ns.count)) +if (ns_ref_put (ns))free_cgroup_ns (ns); }
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 4/14 ipc: port to ns_ref_*() helpers
In reply to Christian BraunerStop accessing ns.count directly.
--- include/linux/ipc_namespace.h | 4 ++-- ipc/namespace.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/ipc_namespace.h +2 -2
@@ -140,14 +140,14 @@ extern struct ipc_namespace *copy_ipcs(unsigned long flags,static inline struct ipc_namespace *get_ipc_ns (struct ipc_namespace *ns) {if (ns) -refcount_inc (&ns->ns.count); +ns_ref_inc (ns);return ns; }static inline struct ipc_namespace *get_ipc_ns_not_zero (struct ipc_namespace *ns) {if (ns) { -if (refcount_inc_not_zero (&ns->ns.count)) +if (ns_ref_get (ns))return ns; }
ipc/namespace.c +1 -1
@@ -199,7 +199,7 @@ static void free_ipc(struct work_struct *unused)*/ void put_ipc_ns (struct ipc_namespace *ns) { -if (refcount_dec_and_lock (&ns->ns.count, &mq_lock)) { +if (ns_ref_put_and_lock (ns, &mq_lock)) {mq_clear_sbinfo (ns);spin_unlock (&mq_lock);
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 5/14 pid: port to ns_ref_*() helpers
In reply to Christian BraunerStop accessing ns.count directly.
--- include/linux/pid_namespace.h | 2 +- kernel/pid_namespace.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/pid_namespace.h +1 -1
@@ -62,7 +62,7 @@ static inline struct pid_namespace *to_pid_ns(struct ns_common *ns)static inline struct pid_namespace *get_pid_ns (struct pid_namespace *ns) {if (ns != &init_pid_ns) -refcount_inc (&ns->ns.count); +ns_ref_inc (ns);return ns; }
kernel/pid_namespace.c +2 -2
@@ -169,7 +169,7 @@ static void destroy_pid_namespace_work(struct work_struct *work) parent = ns->parent;destroy_pid_namespace (ns); ns = parent; - }while (ns != &init_pid_ns &&refcount_dec_and_test (&ns->ns.count)); + }while (ns != &init_pid_ns &&ns_ref_put (ns)); } struct pid_namespace *copy_pid_ns(unsigned long flags,
@@ -184,7 +184,7 @@ struct pid_namespace *copy_pid_ns(unsigned long flags,void put_pid_ns (struct pid_namespace *ns) { -if (ns && ns != &init_pid_ns &&refcount_dec_and_test (&ns->ns.count)) +if (ns && ns != &init_pid_ns &&ns_ref_put (ns))schedule_work (&ns->work); }EXPORT_SYMBOL_GPL (put_pid_ns);
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 6/14 time: port to ns_ref_*() helpers
In reply to Christian BraunerStop accessing ns.count directly.
--- include/linux/time_namespace.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/time_namespace.h +2 -2
@@ -44,7 +44,7 @@ extern void timens_commit(struct task_struct *tsk, struct time_namespace *ns);static inline struct time_namespace *get_time_ns (struct time_namespace *ns) { -refcount_inc (&ns->ns.count); +ns_ref_inc (ns);return ns; }
@@ -57,7 +57,7 @@ struct page *find_timens_vvar_page(struct vm_area_struct *vma);static inline void put_time_ns (struct time_namespace *ns) { -if (refcount_dec_and_test (&ns->ns.count)) +if (ns_ref_put (ns))free_time_ns (ns); }
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 7/14 user: port to ns_ref_*() helpers
In reply to Christian BraunerStop accessing ns.count directly.
--- include/linux/user_namespace.h | 4 ++-- kernel/user_namespace.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/user_namespace.h +2 -2
@@ -176,7 +176,7 @@ static inline struct user_namespace *to_user_ns(struct ns_common *ns)static inline struct user_namespace *get_user_ns (struct user_namespace *ns) {if (ns) -refcount_inc (&ns->ns.count); +ns_ref_inc (ns);return ns; }
@@ -186,7 +186,7 @@ extern void __put_user_ns(struct user_namespace *ns);static inline void put_user_ns (struct user_namespace *ns) { -if (ns &&refcount_dec_and_test (&ns->ns.count)) +if (ns &&ns_ref_put (ns))__put_user_ns (ns); }
kernel/user_namespace.c +1 -1
@@ -225,7 +225,7 @@ static void free_user_ns(struct work_struct *work)kfree_rcu (ns, ns.ns_rcu);dec_user_namespaces (ucounts); ns = parent; - }while (refcount_dec_and_test (&parent->ns.count)); + }while (ns_ref_put (parent)); }void __put_user_ns (struct user_namespace *ns)
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 8/14 net-sysfs: use check_net()
In reply to Christian BraunerDon't directly acess the namespace count. There's even a dedicated helper for this.
--- net/core/net-sysfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/core/net-sysfs.c +3 -3
@@ -1328,7 +1328,7 @@ net_rx_queue_update_kobjects(struct net_device *dev, int old_num, int new_num)struct netdev_rx_queue *queue = &dev->_rx[i];struct kobject *kobj = &queue->kobj; -if (!refcount_read (&dev_net (dev)->ns.count)) +if (!check_net (dev_net (dev))) kobj->uevent_suppress =1 ;if (dev->sysfs_rx_queue_group)sysfs_remove_group (kobj, dev->sysfs_rx_queue_group);
@@ -2061,7 +2061,7 @@ netdev_queue_update_kobjects(struct net_device *dev, int old_num, int new_num)while (--i >= new_num) {struct netdev_queue *queue = dev->_tx + i; -if (!refcount_read (&dev_net (dev)->ns.count)) +if (!check_net (dev_net (dev))) queue->kobj.uevent_suppress =1 ;if (netdev_uses_bql (dev))
@@ -2315,7 +2315,7 @@ void netdev_unregister_kobject(struct net_device *ndev) {struct device *dev = &ndev->dev; -if (!refcount_read (&dev_net (ndev)->ns.count)) +if (!check_net (dev_net (ndev)))dev_set_uevent_suppress (dev,1 );kobject_get (&dev->kobj);
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 9/14 net: use check_net()
In reply to Christian BraunerDon't directly acess the namespace count. There's even a dedicated helper for this.
--- net/core/net_namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/net_namespace.c +1 -1
@@ -315,7 +315,7 @@ int peernet2id_alloc(struct net *net, struct net *peer, gfp_t gfp) {int id; -if (refcount_read (&net->ns.count) ==0 ) +if (!check_net (net))return NETNSA_NSID_NOT_ASSIGNED ;spin_lock (&net->nsid_lock);
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 10/14 ipv4: use check_net()
In reply to Christian BraunerDon't directly acess the namespace count. There's even a dedicated helper for this.
--- net/ipv4/inet_timewait_sock.c | 4 ++-- net/ipv4/tcp_metrics.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
net/ipv4/inet_timewait_sock.c +2 -2
@@ -329,13 +329,13 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo) TCPF_NEW_SYN_RECV))continue ; -if (refcount_read (&sock_net (sk)->ns.count)) +if (check_net (sock_net (sk)))continue ;if (unlikely (!refcount_inc_not_zero (&sk->sk_refcnt)))continue ; -if (refcount_read (&sock_net (sk)->ns.count)) { +if (check_net (sock_net (sk))) {sock_gen_put (sk); goto restart; }
net/ipv4/tcp_metrics.c +1 -1
@@ -912,7 +912,7 @@ static void tcp_metrics_flush_all(struct net *net)spin_lock_bh (&tcp_metrics_lock);for (tm =deref_locked (*pp); tm; tm =deref_locked (*pp)) { match = net ?net_eq (tm_net (tm), net) : - !refcount_read (&tm_net (tm)->ns.count); + !check_net (tm_net (tm));if (match) {rcu_assign_pointer (*pp, tm->tcpm_next);kfree_rcu (tm, rcu_head);
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 11/14 uts: port to ns_ref_*() helpers
In reply to Christian BraunerStop accessing ns.count directly.
--- include/linux/uts_namespace.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/uts_namespace.h +2 -2
@@ -25,7 +25,7 @@ static inline struct uts_namespace *to_uts_ns(struct ns_common *ns)static inline void get_uts_ns (struct uts_namespace *ns) { -refcount_inc (&ns->ns.count); +ns_ref_inc (ns); } extern struct uts_namespace *copy_utsname(unsigned long flags,
@@ -34,7 +34,7 @@ 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)) +if (ns_ref_put (ns))free_uts_ns (ns); }
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 12/14 net: port to ns_ref_*() helpers
In reply to Christian BraunerStop accessing ns.count directly.
--- include/net/net_namespace.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
include/net/net_namespace.h +4 -4
@@ -270,7 +270,7 @@ static inline struct net *to_net_ns(struct ns_common *ns)/* Try using get_net_track() instead */ static inline struct net *get_net (struct net *net) { -refcount_inc (&net->ns.count); +ns_ref_inc (net);return net; }
@@ -281,7 +281,7 @@ static inline struct net *maybe_get_net(struct net *net)* exists. If the reference count is zero this * function fails and returns NULL. */ -if (!refcount_inc_not_zero (&net->ns.count)) +if (!ns_ref_get (net)) net =NULL ;return net; }
@@ -289,7 +289,7 @@ static inline struct net *maybe_get_net(struct net *net)/* Try using put_net_track() instead */ static inline void put_net (struct net *net) { -if (refcount_dec_and_test (&net->ns.count)) +if (ns_ref_put (net))__put_net (net); }
@@ -301,7 +301,7 @@ int net_eq(const struct net *net1, const struct net *net2)static inline int check_net (const struct net *net) { -return refcount_read (&net->ns.count) !=0 ; +return ns_ref_read (net) !=0 ; }void net_drop_ns (void *);
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 13/14 nsfs: port to ns_ref_*() helpers
In reply to Christian BraunerStop accessing ns.count directly.
--- fs/nsfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nsfs.c +1 -1
@@ -492,7 +492,7 @@ static struct dentry *nsfs_fh_to_dentry(struct super_block *sb, struct fid *fh,VFS_WARN_ON_ONCE (ns->ops->type != fid->ns_type);VFS_WARN_ON_ONCE (ns->inum != fid->ns_inum); -if (!refcount_inc_not_zero (&ns->count)) +if (!__ns_ref_get (ns))return NULL ; }
Signature · 1 line
2.47.3
Christian Brauner
maintainerPATCH 14/14 ns: rename to __ns_ref
In reply to Christian BraunerMake it easier to grep and rename to ns_count.
--- include/linux/ns_common.h | 12 ++++++------ init/version-timestamp.c | 2 +- ipc/msgutil.c | 2 +- kernel/cgroup/cgroup.c | 2 +- kernel/nscommon.c | 2 +- kernel/pid.c | 2 +- kernel/time/namespace.c | 2 +- kernel/user.c | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-)
include/linux/ns_common.h +6 -6
@@ -29,7 +29,7 @@ struct ns_common {struct dentry *stashed;const struct proc_ns_operations *ops;unsigned int inum; -refcount_t count; +refcount_t __ns_ref;/* do not use directly */ union { struct { u64 ns_id;
@@ -95,19 +95,19 @@ void __ns_common_free(struct ns_common *ns); static __always_inline __must_check bool __ns_ref_put(struct ns_common *ns) { -return refcount_dec_and_test (&ns->count); +return refcount_dec_and_test (&ns->__ns_ref); } static __always_inline __must_check bool __ns_ref_get(struct ns_common *ns) { -return refcount_inc_not_zero (&ns->count); +return refcount_inc_not_zero (&ns->__ns_ref); } -#define ns_ref_read (__ns) refcount_read(&to_ns_common((__ns))->count) -#define ns_ref_inc (__ns) refcount_inc(&to_ns_common((__ns))->count) +#define ns_ref_read (__ns) refcount_read(&to_ns_common((__ns))->__ns_ref) +#define ns_ref_inc (__ns) refcount_inc(&to_ns_common((__ns))->__ns_ref)#define ns_ref_get (__ns) __ns_ref_get(to_ns_common((__ns)))#define ns_ref_put (__ns) __ns_ref_put(to_ns_common((__ns)))#define ns_ref_put_and_lock (__ns, __lock) \ - refcount_dec_and_lock(&to_ns_common((__ns))->count, (__lock)) + refcount_dec_and_lock(&to_ns_common((__ns))->__ns_ref, (__lock))#endif
init/version-timestamp.c +1 -1
@@ -8,7 +8,7 @@#include <linux/utsname.h> struct uts_namespace init_uts_ns = { - .ns.count =REFCOUNT_INIT (2 ), + .ns.__ns_ref =REFCOUNT_INIT (2 ), .name = { .sysname =UTS_SYSNAME , .nodename =UTS_NODENAME ,
ipc/msgutil.c +1 -1
@@ -27,7 +27,7 @@ DEFINE_SPINLOCK(mq_lock);* and not CONFIG_IPC_NS. */ struct ipc_namespace init_ipc_ns = { - .ns.count =REFCOUNT_INIT (1 ), + .ns.__ns_ref =REFCOUNT_INIT (1 ), .user_ns = &init_user_ns, .ns.inum =PROC_IPC_INIT_INO , #ifdef CONFIG_IPC_NS
kernel/cgroup/cgroup.c +1 -1
@@ -219,7 +219,7 @@ static bool have_favordynmods __ro_after_init = IS_ENABLED(CONFIG_CGROUP_FAVOR_D/* cgroup namespace for init task */ struct cgroup_namespace init_cgroup_ns = { - .ns.count =REFCOUNT_INIT (2 ), + .ns.__ns_ref =REFCOUNT_INIT (2 ), .user_ns = &init_user_ns, .ns.ops = &cgroupns_operations, .ns.inum =PROC_CGROUP_INIT_INO ,
kernel/nscommon.c +1 -1
@@ -5,7 +5,7 @@int __ns_common_init (struct ns_common *ns,const struct proc_ns_operations *ops,int inum) { -refcount_set (&ns->count,1 ); +refcount_set (&ns->__ns_ref,1 ); ns->stashed =NULL ; ns->ops = ops; ns->ns_id =0 ;
kernel/pid.c +1 -1
@@ -71,7 +71,7 @@ static int pid_max_max = PID_MAX_LIMIT;* the scheme scales to up to 4 million PIDs, runtime. */ struct pid_namespace init_pid_ns = { - .ns.count =REFCOUNT_INIT (2 ), + .ns.__ns_ref =REFCOUNT_INIT (2 ), .idr =IDR_INIT (init_pid_ns.idr), .pid_allocated =PIDNS_ADDING , .level =0 ,
kernel/time/namespace.c +1 -1
@@ -480,7 +480,7 @@ const struct proc_ns_operations timens_for_children_operations = { };struct time_namespace init_time_ns = { - .ns.count =REFCOUNT_INIT (3 ), + .ns.__ns_ref =REFCOUNT_INIT (3 ), .user_ns = &init_user_ns, .ns.inum =PROC_TIME_INIT_INO , .ns.ops = &timens_operations,
kernel/user.c +1 -1
@@ -65,7 +65,7 @@ struct user_namespace init_user_ns = { .nr_extents = 1, }, }, - .ns.count = REFCOUNT_INIT(3), + .ns.__ns_ref = REFCOUNT_INIT(3), .owner = GLOBAL_ROOT_UID, .group = GLOBAL_ROOT_GID, .ns.inum = PROC_USER_INIT_INO,
Signature · 1 line
2.47.3
Quoted 5 lines · Christian Brauner
Stop open accesses to the reference counts and cargo-culting the same code in all namespace. Use a set of dedicated helpers and make the actual count private.
Signed-off-by Christian Brauner <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 47 lines
---
Christian Brauner (14):
ns: add reference count helpers
mnt: port to ns_ref_*() helpers
cgroup: port to ns_ref_*() helpers
ipc: port to ns_ref_*() helpers
pid: port to ns_ref_*() helpers
time: port to ns_ref_*() helpers
user: port to ns_ref_*() helpers
net-sysfs: usecheck_net()
net: usecheck_net()
ipv4: usecheck_net()
uts: port to ns_ref_*() helpers
net: port to ns_ref_*() helpers
nsfs: port to ns_ref_*() helpers
ns: rename to__ns_reffs/mount.h | 2 +- fs/namespace.c | 4 ++-- fs/nsfs.c | 2 +- include/linux/cgroup_namespace.h | 4 ++-- include/linux/ipc_namespace.h | 4 ++-- include/linux/ns_common.h | 47 ++++++++++++++++++++++++++++++---------- include/linux/pid_namespace.h | 2 +- include/linux/time_namespace.h | 4 ++-- include/linux/user_namespace.h | 4 ++-- include/linux/uts_namespace.h | 4 ++-- include/net/net_namespace.h | 8 +++---- init/version-timestamp.c | 2 +- ipc/msgutil.c | 2 +- ipc/namespace.c | 2 +- kernel/cgroup/cgroup.c | 2 +- kernel/nscommon.c | 2 +- kernel/pid.c | 2 +- kernel/pid_namespace.c | 4 ++-- kernel/time/namespace.c | 2 +- kernel/user.c | 2 +- kernel/user_namespace.c | 2 +- net/core/net-sysfs.c | 6 ++--- net/core/net_namespace.c | 2 +- net/ipv4/inet_timewait_sock.c | 4 ++-- net/ipv4/tcp_metrics.c | 2 +- 25 files changed, 73 insertions(+), 48 deletions(-)---
base-commit:3f9cc273c16f63b5d584ec4e767918765c44316b
change-id: 20250917-work-namespace-ns_ref-357162ca7aa8
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Michal Koutný
maintainerRe: [PATCH 14/14] ns: rename to __ns_ref
In reply to Christian BraunerHi.
include/linux/ns_common.h struct ns_common { · line 32
Quoted 8 lines · Christian Brauner
include/linux/ns_common.h +1
-1@@ -29,7 +29,7 @@ struct ns_common {struct dentry *stashed;const struct proc_ns_operations *ops;unsigned int inum; -refcount_t count; +refcount_t __ns_ref;/* do not use directly */
+ refcount_t __ns_ref; /* do not use directly unless initializing */
Or a helper macro like
#define NS_REFCOUNT_INIT(v) .ns.__ns_ref = REFCOUNT_INIT((v))
include/linux/ns_common.h
Quoted 7 lines
include/linux/ns_common.h +1
-1/* cgroup namespace for init task */ struct cgroup_namespace init_cgroup_ns = { - .ns.count =REFCOUNT_INIT (2 ), + .ns.__ns_ref =REFCOUNT_INIT (2 ),include/linux/ns_common.h +0
-0.user_ns = &init_user_ns, .ns.ops = &cgroupns_operations, .ns.inum = PROC_CGROUP_INIT_INO,
The double underscore stands out here.
Regards,
Michal
Re: [PATCH 03/14] cgroup: port to ns_ref_*() helpers
In reply to Christian BraunerQuoted 3 lines · Christian Brauner
Stop accessing ns.count directly.
Signed-off-by Christian Brauner <[email protected]>
Thanks.
Signature · 1 line
tejun
Re: [PATCH 06/14] time: port to ns_ref_*() helpers
In reply to Christian BraunerQuoted 3 lines · Christian Brauner
Stop accessing ns.count directly.
Signed-off-by Christian Brauner <[email protected]>
Re: [PATCH 14/14] ns: rename to __ns_ref
In reply to Christian BraunerQuoted 3 lines · Christian Brauner
Make it easier to grep and rename to
ns_count.Signed-off-by Christian Brauner <[email protected]>