From: Kirill Tkhai <ktkhai@virtuozzo.com>
To: christian.brauner@ubuntu.com, akpm@linux-foundation.org,
ebiederm@xmission.com, viro@zeniv.linux.org.uk,
adobriyan@gmail.com, davem@davemloft.net,
linux-kernel@vger.kernel.org, ktkhai@virtuozzo.com
Subject: [PATCH 4/8] pid: Use generic ns_common::count
Date: Mon, 03 Aug 2020 13:16:32 +0300 [thread overview]
Message-ID: <159644979226.604812.7512601754841882036.stgit@localhost.localdomain> (raw)
In-Reply-To: <159644958332.604812.13004003379291842292.stgit@localhost.localdomain>
Convert pid namespace to use generic counter.
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
---
include/linux/pid_namespace.h | 4 +---
kernel/pid.c | 2 +-
kernel/pid_namespace.c | 13 +++----------
3 files changed, 5 insertions(+), 14 deletions(-)
diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
index 5a5cb45ac57e..7c7e627503d2 100644
--- a/include/linux/pid_namespace.h
+++ b/include/linux/pid_namespace.h
@@ -8,7 +8,6 @@
#include <linux/workqueue.h>
#include <linux/threads.h>
#include <linux/nsproxy.h>
-#include <linux/kref.h>
#include <linux/ns_common.h>
#include <linux/idr.h>
@@ -18,7 +17,6 @@
struct fs_pin;
struct pid_namespace {
- struct kref kref;
struct idr idr;
struct rcu_head rcu;
unsigned int pid_allocated;
@@ -43,7 +41,7 @@ extern struct pid_namespace init_pid_ns;
static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
{
if (ns != &init_pid_ns)
- kref_get(&ns->kref);
+ refcount_inc(&ns->ns.count);
return ns;
}
diff --git a/kernel/pid.c b/kernel/pid.c
index de9d29c41d77..3b9e67736ef4 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -72,7 +72,7 @@ int pid_max_max = PID_MAX_LIMIT;
* the scheme scales to up to 4 million PIDs, runtime.
*/
struct pid_namespace init_pid_ns = {
- .kref = KREF_INIT(2),
+ .ns.count = REFCOUNT_INIT(2),
.idr = IDR_INIT(init_pid_ns.idr),
.pid_allocated = PIDNS_ADDING,
.level = 0,
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 0e5ac162c3a8..d02dc1696edf 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -102,7 +102,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
goto out_free_idr;
ns->ns.ops = &pidns_operations;
- kref_init(&ns->kref);
+ refcount_set(&ns->ns.count, 1);
ns->level = level;
ns->parent = get_pid_ns(parent_pid_ns);
ns->user_ns = get_user_ns(user_ns);
@@ -148,22 +148,15 @@ struct pid_namespace *copy_pid_ns(unsigned long flags,
return create_pid_namespace(user_ns, old_ns);
}
-static void free_pid_ns(struct kref *kref)
-{
- struct pid_namespace *ns;
-
- ns = container_of(kref, struct pid_namespace, kref);
- destroy_pid_namespace(ns);
-}
-
void put_pid_ns(struct pid_namespace *ns)
{
struct pid_namespace *parent;
while (ns != &init_pid_ns) {
parent = ns->parent;
- if (!kref_put(&ns->kref, free_pid_ns))
+ if (!refcount_dec_and_test(&ns->ns.count))
break;
+ destroy_pid_namespace(ns);
ns = parent;
}
}
next prev parent reply other threads:[~2020-08-03 10:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-03 10:16 [PATCH 0/8] namespaces: Introduce generic refcount Kirill Tkhai
2020-08-03 10:16 ` [PATCH 1/8] ns: Add common refcount into ns_common add use it as counter for net_ns Kirill Tkhai
2020-08-04 12:21 ` Eric W. Biederman
2020-08-04 12:48 ` Kirill Tkhai
2020-08-04 13:52 ` Eric W. Biederman
2020-08-04 14:36 ` Kirill Tkhai
2020-08-03 10:16 ` [PATCH 2/8] uts: Use generic ns_common::count Kirill Tkhai
2020-08-03 10:16 ` [PATCH 3/8] ipc: " Kirill Tkhai
2020-08-03 10:16 ` Kirill Tkhai [this message]
2020-08-03 10:16 ` [PATCH 5/8] user: " Kirill Tkhai
2020-08-03 10:16 ` [PATCH 6/8] mnt: " Kirill Tkhai
2020-08-03 10:16 ` [PATCH 7/8] cgroup: " Kirill Tkhai
2020-08-03 10:17 ` [PATCH 8/8] time: " Kirill Tkhai
2020-08-04 11:56 ` [PATCH 0/8] namespaces: Introduce generic refcount Christian Brauner
2020-08-04 12:11 ` Eric W. Biederman
2020-08-04 12:30 ` Christian Brauner
2020-08-04 13:21 ` Eric W. Biederman
2020-08-04 14:57 ` Christian Brauner
2020-08-04 21:38 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=159644979226.604812.7512601754841882036.stgit@localhost.localdomain \
--to=ktkhai@virtuozzo.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=christian.brauner@ubuntu.com \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.