don't bother with path_get()/path_put() in unix_open_file()
Subsystems (4)
Al Viro
maintainerRFC PATCH 1/1 don't bother with path_get()/path_put() in unix_open_file()
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.
net/unix/af_unix.c +4 -12
@@ -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; }
From: Al Viro <[email protected]>
Date: Sat, 12 Jul 2025 06:41:57 +0100
Quoted 8 lines
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 todentry_open()and be done with that.Signed-off-by Al Viro <[email protected]>
Sounds good. I confirmed vfs_open() copies the passed const path ptr.
Quoted 43 lines
net/unix/af_unix.c +4
-12@@ -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; }
Christian Brauner
maintainerQuoted 6 lines · Kuniyuki Iwashima
From: Al Viro <[email protected]>
Date: Sat, 12 Jul 2025 06:41:57 +0100Quoted 4 lines
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.
Quoted 8 lines
Quoted 4 lines
IOW, there's no need to copy unix_sk(sk)->path in
unix_open_file()- we can just pass it todentry_open()and be done with that.Signed-off-by Al Viro <[email protected]>Sounds good. I confirmed
vfs_open()copies the passed const path ptr.Reviewed-by Kuniyuki Iwashima <[email protected]>
I can just throw that into the SCM_PIDFD branch?
Al Viro
maintainerQuoted 10 lines · Christian Brauner
Quoted 9 lines · Kuniyuki Iwashima
From: Al Viro <[email protected]>
Date: Sat, 12 Jul 2025 06:41:57 +0100Quoted 7 lines
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 todentry_open()and be done with that.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Al Viro <[email protected]>Sounds good. I confirmed
vfs_open()copies the passed const path ptr.Reviewed-by Kuniyuki Iwashima <[email protected]>I can just throw that into the
SCM_PIDFDbranch?
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.
Kuniyuki Iwashima
maintainerQuoted 18 lines · Al Viro
Quoted 16 lines · Christian Brauner
Quoted 14 lines · Kuniyuki Iwashima
From: Al Viro <[email protected]>
Date: Sat, 12 Jul 2025 06:41:57 +0100Quoted 8 lines
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 todentry_open()and be done with that.Signed-off-by Al Viro <[email protected]>Sounds good. I confirmed
vfs_open()copies the passed const path ptr.Reviewed-by Kuniyuki Iwashima <[email protected]>
Quoted 8 lines
Quoted 1 line
I can just throw that into the
SCM_PIDFDbranch?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.
Quoted 8 lines · Al Viro
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 todentry_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