Unverified Commit 1f84344c authored by Christian Brauner's avatar Christian Brauner
Browse files

Merge patch series "ns: rework reference counting"

Christian Brauner <brauner@kernel.org> says:

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.

* patches from https://lore.kernel.org/20250918-work-namespace-ns_ref-v1-0-1b0a98ee041e@kernel.org

:
  ns: rename to __ns_ref
  nsfs: port to ns_ref_*() helpers
  net: port to ns_ref_*() helpers
  uts: port to ns_ref_*() helpers
  ipv4: use check_net()
  net: use check_net()
  net-sysfs: use check_net()
  user: port to ns_ref_*() helpers
  time: port to ns_ref_*() helpers
  pid: port to ns_ref_*() helpers
  ipc: port to ns_ref_*() helpers
  cgroup: port to ns_ref_*() helpers
  mnt: port to ns_ref_*() helpers
  ns: add reference count helpers

Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parents bb57289f 024596a4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;
+3 −3
Original line number Diff line number Diff line
@@ -2110,7 +2110,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;
@@ -6015,7 +6015,7 @@ struct mnt_namespace init_mnt_ns = {
	.ns.inum	= PROC_MNT_INIT_INO,
	.ns.ops		= &mntns_operations,
	.user_ns	= &init_user_ns,
	.ns.count	= REFCOUNT_INIT(1),
	.ns.__ns_ref	= REFCOUNT_INIT(1),
	.passive	= REFCOUNT_INIT(1),
	.mounts		= RB_ROOT,
	.poll		= __WAIT_QUEUE_HEAD_INITIALIZER(init_mnt_ns.poll),
@@ -6084,7 +6084,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;
+1 −1
Original line number Diff line number Diff line
@@ -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;
	}

+2 −2
Original line number Diff line number Diff line
@@ -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);
}

+2 −2
Original line number Diff line number Diff line
@@ -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;
	}

Loading