diff mbox series

[v2,03/15] pidfs: move setting flags into pidfs_alloc_file()

Message ID 20250304-work-pidfs-kill_on_last_close-v2-3-44fdacfaa7b7@kernel.org (mailing list archive)
State New
Headers show
Series pidfs: provide information after task has been reaped | expand

Commit Message

Christian Brauner March 4, 2025, 9:41 a.m. UTC
Instead od adding it into __pidfd_prepare() place it where the actual
file allocation happens and update the outdated comment.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/pidfs.c    | 4 ++++
 kernel/fork.c | 5 -----
 2 files changed, 4 insertions(+), 5 deletions(-)

Comments

Jeff Layton March 4, 2025, 12:53 p.m. UTC | #1
On Tue, 2025-03-04 at 10:41 +0100, Christian Brauner wrote:
> Instead od adding it into __pidfd_prepare() place it where the actual
> file allocation happens and update the outdated comment.
> 
> Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
>  fs/pidfs.c    | 4 ++++
>  kernel/fork.c | 5 -----
>  2 files changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/pidfs.c b/fs/pidfs.c
> index aa8c8bda8c8f..ecc0dd886714 100644
> --- a/fs/pidfs.c
> +++ b/fs/pidfs.c
> @@ -696,6 +696,10 @@ struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags)
>  		return ERR_PTR(ret);
>  
>  	pidfd_file = dentry_open(&path, flags, current_cred());
> +	/* Raise PIDFD_THREAD explicitly as do_dentry_open() strips it. */
> +	if (!IS_ERR(pidfd_file))
> +		pidfd_file->f_flags |= (flags & PIDFD_THREAD);
> +
>  	path_put(&path);
>  	return pidfd_file;
>  }
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 6230f5256bc5..8eac9cd3385b 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -2042,11 +2042,6 @@ static int __pidfd_prepare(struct pid *pid, unsigned int flags, struct file **re
>  	if (IS_ERR(pidfd_file))
>  		return PTR_ERR(pidfd_file);
>  
> -	/*
> -	 * anon_inode_getfile() ignores everything outside of the
> -	 * O_ACCMODE | O_NONBLOCK mask, set PIDFD_THREAD manually.
> -	 */
> -	pidfd_file->f_flags |= (flags & PIDFD_THREAD);
>  	*ret = pidfd_file;
>  	return take_fd(pidfd);
>  }
> 

Reviewed-by: Jeff Layton <jlayton@kernel.org>
diff mbox series

Patch

diff --git a/fs/pidfs.c b/fs/pidfs.c
index aa8c8bda8c8f..ecc0dd886714 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -696,6 +696,10 @@  struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags)
 		return ERR_PTR(ret);
 
 	pidfd_file = dentry_open(&path, flags, current_cred());
+	/* Raise PIDFD_THREAD explicitly as do_dentry_open() strips it. */
+	if (!IS_ERR(pidfd_file))
+		pidfd_file->f_flags |= (flags & PIDFD_THREAD);
+
 	path_put(&path);
 	return pidfd_file;
 }
diff --git a/kernel/fork.c b/kernel/fork.c
index 6230f5256bc5..8eac9cd3385b 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2042,11 +2042,6 @@  static int __pidfd_prepare(struct pid *pid, unsigned int flags, struct file **re
 	if (IS_ERR(pidfd_file))
 		return PTR_ERR(pidfd_file);
 
-	/*
-	 * anon_inode_getfile() ignores everything outside of the
-	 * O_ACCMODE | O_NONBLOCK mask, set PIDFD_THREAD manually.
-	 */
-	pidfd_file->f_flags |= (flags & PIDFD_THREAD);
 	*ret = pidfd_file;
 	return take_fd(pidfd);
 }