From: Christian Brauner <christian.brauner@ubuntu.com>
To: oleg@redhat.com, linux-kernel@vger.kernel.org
Cc: aarcange@redhat.com, akpm@linux-foundation.org,
christian@kellner.me, cyphar@cyphar.com,
elena.reshetova@intel.com, guro@fb.com, jannh@google.com,
ldv@altlinux.org, linux-api@vger.kernel.org,
linux-kselftest@vger.kernel.org, mhocko@suse.com,
mingo@kernel.org, peterz@infradead.org, shuah@kernel.org,
tglx@linutronix.de, viro@zeniv.linux.org.uk,
Christian Brauner <christian.brauner@ubuntu.com>
Subject: [PATCH v2 5/5] pid: use task_alive() in pidfd_open()
Date: Wed, 16 Oct 2019 17:36:06 +0200 [thread overview]
Message-ID: <20191016153606.2326-5-christian.brauner@ubuntu.com> (raw)
In-Reply-To: <20191016153606.2326-1-christian.brauner@ubuntu.com>
Use the new task_alive() helper in pidfd_open(). This simplifies the
code and avoids taking rcu_read_{lock,unlock}() and leads to overall
nicer code.
Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
---
/* v1 */
patch not present
/* v2 */
patch introduced
---
kernel/pid.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/kernel/pid.c b/kernel/pid.c
index 70ad4a9f728c..1f425b6c4c47 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -497,7 +497,7 @@ static int pidfd_create(struct pid *pid)
*/
SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
{
- int fd, ret;
+ int fd;
struct pid *p;
if (flags)
@@ -510,13 +510,11 @@ SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
if (!p)
return -ESRCH;
- ret = 0;
- rcu_read_lock();
- if (!pid_task(p, PIDTYPE_TGID))
- ret = -EINVAL;
- rcu_read_unlock();
+ if (task_alive(p, PIDTYPE_TGID))
+ fd = pidfd_create(p);
+ else
+ fd = -EINVAL;
- fd = ret ?: pidfd_create(p);
put_pid(p);
return fd;
}
--
2.23.0
next prev parent reply other threads:[~2019-10-16 15:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-15 14:13 [PATCH 1/2] pidfd: verify task is alive when printing fdinfo Christian Brauner
2019-10-15 14:13 ` [PATCH 2/2] test: verify fdinfo for pidfd of reaped process Christian Brauner
2019-10-16 12:07 ` Christian Kellner
2019-10-15 14:43 ` [PATCH 1/2] pidfd: verify task is alive when printing fdinfo Oleg Nesterov
2019-10-15 14:56 ` Christian Brauner
2019-10-15 15:43 ` Oleg Nesterov
2019-10-16 15:36 ` [PATCH v2 1/5] " Christian Brauner
2019-10-16 15:36 ` [PATCH v2 2/5] test: verify fdinfo for pidfd of reaped process Christian Brauner
2019-10-16 15:36 ` [PATCH v2 3/5] pid: use task_alive() in __change_pid() Christian Brauner
2019-10-16 15:36 ` [PATCH v2 4/5] exit: use task_alive() in do_wait() Christian Brauner
2019-10-16 15:36 ` Christian Brauner [this message]
2019-10-16 16:24 ` [PATCH v2 1/5] pidfd: verify task is alive when printing fdinfo Oleg Nesterov
2019-10-16 16:31 ` Christian Brauner
2019-10-17 8:54 ` Oleg Nesterov
2019-10-17 10:18 ` [PATCH v3 1/5] pidfd: check pid has attached task in fdinfo Christian Brauner
2019-10-17 10:18 ` [PATCH v3 2/5] test: verify fdinfo for pidfd of reaped process Christian Brauner
2019-10-17 10:18 ` [PATCH v3 3/5] pid: use pid_has_task() in __change_pid() Christian Brauner
2019-10-17 10:18 ` [PATCH v3 4/5] exit: use pid_has_task() in do_wait() Christian Brauner
2019-10-17 10:18 ` [PATCH v3 5/5] pid: use pid_has_task() in pidfd_open() Christian Brauner
2019-10-18 15:05 ` [PATCH v3 1/5] pidfd: check pid has attached task in fdinfo Christian Brauner
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=20191016153606.2326-5-christian.brauner@ubuntu.com \
--to=christian.brauner@ubuntu.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=christian@kellner.me \
--cc=cyphar@cyphar.com \
--cc=elena.reshetova@intel.com \
--cc=guro@fb.com \
--cc=jannh@google.com \
--cc=ldv@altlinux.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--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 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).