Linux filesystem development
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>
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>
Subject: Re: [PATCH v2] pidfs: ensure that PIDFS_INFO_EXIT is available
Date: Wed, 19 Mar 2025 09:14:09 +0100	[thread overview]
Message-ID: <20250319-behielt-zensieren-e63e234730d2@brauner> (raw)
In-Reply-To: <20250318142601.GA19943@redhat.com>

On Tue, Mar 18, 2025 at 03:46:54PM +0100, Oleg Nesterov wrote:
> I'll try to actually read this patch (and pidfs: improve multi-threaded
> exec and premature thread-group leader exit polling) tomorrow, but I am
> a bit confused after the quick glance...
> 
> 
> On 03/18, Christian Brauner wrote:
> >
> > +static inline bool pidfs_pid_valid(struct pid *pid, const struct path *path,
> > +				   unsigned int flags)
> > +{
> > +	enum pid_type type;
> > +
> > +	if (flags & CLONE_PIDFD)
> > +		return true;
> 
> OK, this is clear.
> 
> > +	if (flags & PIDFD_THREAD)
> > +		type = PIDTYPE_PID;
> > +	else
> > +		type = PIDTYPE_TGID;
> > +
> > +	/*
> > +	 * Since pidfs_exit() is called before struct pid's task linkage
> > +	 * is removed the case where the task got reaped but a dentry
> > +	 * was already attached to struct pid and exit information was
> > +	 * recorded and published can be handled correctly.
> > +	 */
> > +	if (unlikely(!pid_has_task(pid, type))) {
> > +		struct inode *inode = d_inode(path->dentry);
> > +		return !!READ_ONCE(pidfs_i(inode)->exit_info);
> > +	}
> 
> Why pidfs_pid_valid() can't simply return false if !pid_has_task(pid,type) ?
> 
> pidfd_open() paths check pid_has_task() too and fail if it returns NULL.
> If this task is already reaped when pidfs_pid_valid() is called, we can
> pretend it was reaped before sys_pidfd_open() was called?

We could for sure but why would we. If we know that exit information is
available then returning a pidfd can still be valuable for userspace as
they can retrieve exit information via PIDFD_INFO_EXIT and it really
doesn't hurt to do this.

  reply	other threads:[~2025-03-19  8:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-18  8:34 [PATCH v2] pidfs: ensure that PIDFS_INFO_EXIT is available Christian Brauner
2025-03-18 14:46 ` Oleg Nesterov
2025-03-19  8:14   ` Christian Brauner [this message]
2025-03-19 12:05     ` Oleg Nesterov

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=20250319-behielt-zensieren-e63e234730d2@brauner \
    --to=brauner@kernel.org \
    --cc=daan.j.demeyer@gmail.com \
    --cc=jlayton@kernel.org \
    --cc=lennart@poettering.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=me@yhndnzj.com \
    --cc=oleg@redhat.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