linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, Jeff Layton <jlayton@kernel.org>,
	Lennart Poettering <lennart@poettering.net>,
	Daan De Meyer <daan.j.demeyer@gmail.com>,
	Mike Yuan <me@yhndnzj.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC 3/4] pidfd: improve uapi when task isn't found
Date: Fri, 4 Apr 2025 16:53:24 +0200	[thread overview]
Message-ID: <20250404145323.GE3720@redhat.com> (raw)
In-Reply-To: <20250404-roben-zoodirektor-13cb8d1acefe@brauner>

On 04/04, Christian Brauner wrote:
>
> On Fri, Apr 04, 2025 at 02:37:38PM +0200, Oleg Nesterov wrote:
> > And... the code looks a bit overcomplicated to me, why not simply
> >
> > 	int pidfd_prepare(struct pid *pid, unsigned int flags, struct file **ret)
> > 	{
> > 		if (!pid_has_task(pid, PIDTYPE_PID))
> > 			return -ESRCH;
> >
> > 		if (!(flags & PIDFD_THREAD) && !pid_has_task(pid, PIDTYPE_TGID))
> > 			return -ENOENT;
>
> I thought that checking PIDTYPE_PID first could cause misleading results
> where we report ENOENT where we should report ESRCH: If the task was
> released after the successful PIDTYPE_PID check for a pid that was never
> a thread-group leader we report ENOENT.

Hmm... but the code above can only return ENOENT if !(flags & PIDFD_THREAD),
so in this case -ENOENT is correct?

I guess -ENOENT would be wrong if this pid _was_ a leader pid and we
race with __unhash_process() which does

	detach_pid(post->pids, p, PIDTYPE_PID);
	if (group_dead)
		detach_pid(post->pids, p, PIDTYPE_TGID);

but without tasklist_lock (or additional barries in both pidfd_prepare() and
__unhash_process() pidfd_prepare() can see the result of these 2 detach_pid()'s
in any order anyway. So I don't think the code above is "more" racy.

Although perhaps we can rely on the fact the the 1st detach_pid(PIDTYPE_PID)
does wake_up(pid->wait_pidfd) and use pid->wait_pidfd->lock to avoid the
races, not sure...

But,

> But I can adapt that to you scheme.

Again, up to you, whatever you prefer.

Oleg.


  reply	other threads:[~2025-04-04 14:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03 14:09 [PATCH RFC 0/4] pidfd: improve uapi when task isn't found Christian Brauner
2025-04-03 14:09 ` [PATCH RFC 1/4] selftests/pidfd: adapt to recent changes Christian Brauner
2025-04-03 14:09 ` [PATCH RFC 2/4] pidfd: remove unneeded NULL check from pidfd_prepare() Christian Brauner
2025-04-03 14:09 ` [PATCH RFC 3/4] pidfd: improve uapi when task isn't found Christian Brauner
2025-04-04 12:37   ` Oleg Nesterov
2025-04-04 13:38     ` Christian Brauner
2025-04-04 14:53       ` Oleg Nesterov [this message]
2025-04-09 15:38         ` Christian Brauner
2025-04-09 18:18           ` [RFC PATCH] pidfs: ensure consistent ENOENT/ESRCH reporting Christian Brauner
2025-04-09 18:40             ` Oleg Nesterov
2025-04-10 10:18               ` Oleg Nesterov
2025-04-10 10:43                 ` Christian Brauner
2025-04-10 13:10                   ` Oleg Nesterov
2025-04-10 20:05                     ` Christian Brauner
2025-04-10 20:24                       ` Christian Brauner
2025-04-11 11:08                         ` Christian Brauner
2025-04-11 11:25                           ` Oleg Nesterov
2025-04-11 11:41                             ` Oleg Nesterov
2025-04-03 14:09 ` [PATCH RFC 4/4] selftest/pidfd: add test for thread-group leader pidfd open for thread 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=20250404145323.GE3720@redhat.com \
    --to=oleg@redhat.com \
    --cc=brauner@kernel.org \
    --cc=daan.j.demeyer@gmail.com \
    --cc=jlayton@kernel.org \
    --cc=lennart@poettering.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@yhndnzj.com \
    /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).