netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][RFC] don't bother with path_get()/path_put() in unix_open_file()
@ 2025-07-12  5:41 Al Viro
  2025-07-12  6:38 ` Kuniyuki Iwashima
  2025-07-15  9:46 ` Christian Brauner
  0 siblings, 2 replies; 6+ messages in thread
From: Al Viro @ 2025-07-12  5:41 UTC (permalink / raw)
  To: netdev; +Cc: linux-fsdevel

Once unix_sock ->path is set, we are guaranteed that its ->path will remain
unchanged (and pinned) until the socket is closed.  OTOH, dentry_open()
does not modify the path passed to it.

IOW, there's no need to copy unix_sk(sk)->path in unix_open_file() - we
can just pass it to dentry_open() and be done with that.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 52b155123985..019ba2609b66 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -3191,7 +3191,6 @@ EXPORT_SYMBOL_GPL(unix_outq_len);
 
 static int unix_open_file(struct sock *sk)
 {
-	struct path path;
 	struct file *f;
 	int fd;
 
@@ -3201,27 +3200,20 @@ static int unix_open_file(struct sock *sk)
 	if (!smp_load_acquire(&unix_sk(sk)->addr))
 		return -ENOENT;
 
-	path = unix_sk(sk)->path;
-	if (!path.dentry)
+	if (!unix_sk(sk)->path.dentry)
 		return -ENOENT;
 
-	path_get(&path);
-
 	fd = get_unused_fd_flags(O_CLOEXEC);
 	if (fd < 0)
-		goto out;
+		return fd;
 
-	f = dentry_open(&path, O_PATH, current_cred());
+	f = dentry_open(&unix_sk(sk)->path, O_PATH, current_cred());
 	if (IS_ERR(f)) {
 		put_unused_fd(fd);
-		fd = PTR_ERR(f);
-		goto out;
+		return PTR_ERR(f);
 	}
 
 	fd_install(fd, f);
-out:
-	path_put(&path);
-
 	return fd;
 }
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH][RFC] don't bother with path_get()/path_put() in unix_open_file()
  2025-07-12  5:41 [PATCH][RFC] don't bother with path_get()/path_put() in unix_open_file() Al Viro
@ 2025-07-12  6:38 ` Kuniyuki Iwashima
  2025-07-14  8:24   ` Christian Brauner
  2025-07-15  9:46 ` Christian Brauner
  1 sibling, 1 reply; 6+ messages in thread
From: Kuniyuki Iwashima @ 2025-07-12  6:38 UTC (permalink / raw)
  To: viro; +Cc: linux-fsdevel, netdev, kuniyu

From: Al Viro <viro@zeniv.linux.org.uk>
Date: Sat, 12 Jul 2025 06:41:57 +0100
> Once unix_sock ->path is set, we are guaranteed that its ->path will remain
> unchanged (and pinned) until the socket is closed.  OTOH, dentry_open()
> does not modify the path passed to it.
> 
> IOW, there's no need to copy unix_sk(sk)->path in unix_open_file() - we
> can just pass it to dentry_open() and be done with that.
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Sounds good.  I confirmed vfs_open() copies the passed const path ptr.

Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>


> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index 52b155123985..019ba2609b66 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -3191,7 +3191,6 @@ EXPORT_SYMBOL_GPL(unix_outq_len);
>  
>  static int unix_open_file(struct sock *sk)
>  {
> -	struct path path;
>  	struct file *f;
>  	int fd;
>  
> @@ -3201,27 +3200,20 @@ static int unix_open_file(struct sock *sk)
>  	if (!smp_load_acquire(&unix_sk(sk)->addr))
>  		return -ENOENT;
>  
> -	path = unix_sk(sk)->path;
> -	if (!path.dentry)
> +	if (!unix_sk(sk)->path.dentry)
>  		return -ENOENT;
>  
> -	path_get(&path);
> -
>  	fd = get_unused_fd_flags(O_CLOEXEC);
>  	if (fd < 0)
> -		goto out;
> +		return fd;
>  
> -	f = dentry_open(&path, O_PATH, current_cred());
> +	f = dentry_open(&unix_sk(sk)->path, O_PATH, current_cred());
>  	if (IS_ERR(f)) {
>  		put_unused_fd(fd);
> -		fd = PTR_ERR(f);
> -		goto out;
> +		return PTR_ERR(f);
>  	}
>  
>  	fd_install(fd, f);
> -out:
> -	path_put(&path);
> -
>  	return fd;
>  }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][RFC] don't bother with path_get()/path_put() in unix_open_file()
  2025-07-12  6:38 ` Kuniyuki Iwashima
@ 2025-07-14  8:24   ` Christian Brauner
  2025-07-14 15:04     ` Al Viro
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Brauner @ 2025-07-14  8:24 UTC (permalink / raw)
  To: Kuniyuki Iwashima; +Cc: viro, linux-fsdevel, netdev

On Sat, Jul 12, 2025 at 06:38:33AM +0000, Kuniyuki Iwashima wrote:
> From: Al Viro <viro@zeniv.linux.org.uk>
> Date: Sat, 12 Jul 2025 06:41:57 +0100
> > Once unix_sock ->path is set, we are guaranteed that its ->path will remain
> > unchanged (and pinned) until the socket is closed.  OTOH, dentry_open()
> > does not modify the path passed to it.
> > 
> > IOW, there's no need to copy unix_sk(sk)->path in unix_open_file() - we
> > can just pass it to dentry_open() and be done with that.
> > 
> > Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> 
> Sounds good.  I confirmed vfs_open() copies the passed const path ptr.
> 
> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>

I can just throw that into the SCM_PIDFD branch?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][RFC] don't bother with path_get()/path_put() in unix_open_file()
  2025-07-14  8:24   ` Christian Brauner
@ 2025-07-14 15:04     ` Al Viro
  2025-07-14 16:11       ` Kuniyuki Iwashima
  0 siblings, 1 reply; 6+ messages in thread
From: Al Viro @ 2025-07-14 15:04 UTC (permalink / raw)
  To: Christian Brauner; +Cc: Kuniyuki Iwashima, linux-fsdevel, netdev

On Mon, Jul 14, 2025 at 10:24:11AM +0200, Christian Brauner wrote:
> On Sat, Jul 12, 2025 at 06:38:33AM +0000, Kuniyuki Iwashima wrote:
> > From: Al Viro <viro@zeniv.linux.org.uk>
> > Date: Sat, 12 Jul 2025 06:41:57 +0100
> > > Once unix_sock ->path is set, we are guaranteed that its ->path will remain
> > > unchanged (and pinned) until the socket is closed.  OTOH, dentry_open()
> > > does not modify the path passed to it.
> > > 
> > > IOW, there's no need to copy unix_sk(sk)->path in unix_open_file() - we
> > > can just pass it to dentry_open() and be done with that.
> > > 
> > > Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> > 
> > Sounds good.  I confirmed vfs_open() copies the passed const path ptr.
> > 
> > Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
> 
> I can just throw that into the SCM_PIDFD branch?

Fine by me; the thing is, I don't have anything else in the area at the moment
(and won't until -rc1 - CLASS(get_unused_fd) series will stray there, but
it's not settled enough yet, so it's definitely the next cycle fodder).

So if you (or netdev folks) already have anything going on in the af_unix.c,
I've no problem with that thing going there.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][RFC] don't bother with path_get()/path_put() in unix_open_file()
  2025-07-14 15:04     ` Al Viro
@ 2025-07-14 16:11       ` Kuniyuki Iwashima
  0 siblings, 0 replies; 6+ messages in thread
From: Kuniyuki Iwashima @ 2025-07-14 16:11 UTC (permalink / raw)
  To: Al Viro; +Cc: Christian Brauner, linux-fsdevel, netdev

On Mon, Jul 14, 2025 at 8:04 AM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> On Mon, Jul 14, 2025 at 10:24:11AM +0200, Christian Brauner wrote:
> > On Sat, Jul 12, 2025 at 06:38:33AM +0000, Kuniyuki Iwashima wrote:
> > > From: Al Viro <viro@zeniv.linux.org.uk>
> > > Date: Sat, 12 Jul 2025 06:41:57 +0100
> > > > Once unix_sock ->path is set, we are guaranteed that its ->path will remain
> > > > unchanged (and pinned) until the socket is closed.  OTOH, dentry_open()
> > > > does not modify the path passed to it.
> > > >
> > > > IOW, there's no need to copy unix_sk(sk)->path in unix_open_file() - we
> > > > can just pass it to dentry_open() and be done with that.
> > > >
> > > > Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> > >
> > > Sounds good.  I confirmed vfs_open() copies the passed const path ptr.
> > >
> > > Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
> >
> > I can just throw that into the SCM_PIDFD branch?
>
> Fine by me; the thing is, I don't have anything else in the area at the moment
> (and won't until -rc1 - CLASS(get_unused_fd) series will stray there, but
> it's not settled enough yet, so it's definitely the next cycle fodder).
>
> So if you (or netdev folks) already have anything going on in the af_unix.c,
> I've no problem with that thing going there.

AFAIK, there's no conflicting changes around unix_open_file() in
net-next, and this is more of vfs stuff, so whichever is fine to me.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][RFC] don't bother with path_get()/path_put() in unix_open_file()
  2025-07-12  5:41 [PATCH][RFC] don't bother with path_get()/path_put() in unix_open_file() Al Viro
  2025-07-12  6:38 ` Kuniyuki Iwashima
@ 2025-07-15  9:46 ` Christian Brauner
  1 sibling, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2025-07-15  9:46 UTC (permalink / raw)
  To: netdev, Al Viro; +Cc: Christian Brauner, linux-fsdevel

On Sat, 12 Jul 2025 06:41:57 +0100, Al Viro wrote:
> Once unix_sock ->path is set, we are guaranteed that its ->path will remain
> unchanged (and pinned) until the socket is closed.  OTOH, dentry_open()
> does not modify the path passed to it.
> 
> IOW, there's no need to copy unix_sk(sk)->path in unix_open_file() - we
> can just pass it to dentry_open() and be done with that.
> 
> [...]

Applied to the vfs-6.17.pidfs branch of the vfs/vfs.git tree.
Patches in the vfs-6.17.pidfs branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.17.pidfs

[1/1] don't bother with path_get()/path_put() in unix_open_file()
      https://git.kernel.org/vfs/vfs/c/1f531e35c146

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-07-15  9:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-12  5:41 [PATCH][RFC] don't bother with path_get()/path_put() in unix_open_file() Al Viro
2025-07-12  6:38 ` Kuniyuki Iwashima
2025-07-14  8:24   ` Christian Brauner
2025-07-14 15:04     ` Al Viro
2025-07-14 16:11       ` Kuniyuki Iwashima
2025-07-15  9:46 ` Christian Brauner

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).