Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pidfs: remove pidfs_{get,put}_pid()

Now that we stash persistent information in struct pid there's no need
to play volatile games with pinning struct pid via dentries in pidfs.

Link: https://lore.kernel.org/20250618-work-pidfs-persistent-v2-8-98f3456fd552@kernel.org
Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>

+1 -47
-6
fs/coredump.c
··· 898 898 retval = kernel_connect(socket, (struct sockaddr *)(&addr), 899 899 addr_len, O_NONBLOCK | SOCK_COREDUMP); 900 900 901 - /* 902 - * ... Make sure to only put our reference after connect() took 903 - * its own reference keeping the pidfs entry alive ... 904 - */ 905 - pidfs_put_pid(cprm.pid); 906 - 907 901 if (retval) { 908 902 if (retval == -EAGAIN) 909 903 coredump_report_failure("Coredump socket %s receive queue full", addr.sun_path);
+1 -34
fs/pidfs.c
··· 895 895 * pidfs_register_pid - register a struct pid in pidfs 896 896 * @pid: pid to pin 897 897 * 898 - * Register a struct pid in pidfs. Needs to be paired with 899 - * pidfs_put_pid() to not risk leaking the pidfs dentry and inode. 898 + * Register a struct pid in pidfs. 900 899 * 901 900 * Return: On success zero, on error a negative error code is returned. 902 901 */ ··· 1004 1005 pidfd_file->f_flags |= (flags & PIDFD_THREAD); 1005 1006 1006 1007 return pidfd_file; 1007 - } 1008 - 1009 - /** 1010 - * pidfs_get_pid - pin a struct pid through pidfs 1011 - * @pid: pid to pin 1012 - * 1013 - * Similar to pidfs_register_pid() but only valid if the caller knows 1014 - * there's a reference to the @pid through a dentry already that can't 1015 - * go away. 1016 - */ 1017 - void pidfs_get_pid(struct pid *pid) 1018 - { 1019 - if (!pid) 1020 - return; 1021 - WARN_ON_ONCE(!stashed_dentry_get(&pid->stashed)); 1022 - } 1023 - 1024 - /** 1025 - * pidfs_put_pid - drop a pidfs reference 1026 - * @pid: pid to drop 1027 - * 1028 - * Drop a reference to @pid via pidfs. This is only safe if the 1029 - * reference has been taken via pidfs_get_pid(). 1030 - */ 1031 - void pidfs_put_pid(struct pid *pid) 1032 - { 1033 - might_sleep(); 1034 - 1035 - if (!pid) 1036 - return; 1037 - VFS_WARN_ON_ONCE(!pid->stashed); 1038 - dput(pid->stashed); 1039 1008 } 1040 1009 1041 1010 void __init pidfs_init(void)
-2
include/linux/pidfs.h
··· 14 14 #endif 15 15 extern const struct dentry_operations pidfs_dentry_operations; 16 16 int pidfs_register_pid(struct pid *pid); 17 - void pidfs_get_pid(struct pid *pid); 18 - void pidfs_put_pid(struct pid *pid); 19 17 void pidfs_free_pid(struct pid *pid); 20 18 21 19 #endif /* _LINUX_PID_FS_H */
-5
net/unix/af_unix.c
··· 646 646 return; 647 647 } 648 648 649 - if (sk->sk_peer_pid) 650 - pidfs_put_pid(sk->sk_peer_pid); 651 - 652 649 if (u->addr) 653 650 unix_release_addr(u->addr); 654 651 ··· 766 769 swap(peercred->peer_pid, pid); 767 770 swap(peercred->peer_cred, cred); 768 771 769 - pidfs_put_pid(pid); 770 772 put_pid(pid); 771 773 put_cred(cred); 772 774 } ··· 798 802 799 803 spin_lock(&sk->sk_peer_lock); 800 804 sk->sk_peer_pid = get_pid(peersk->sk_peer_pid); 801 - pidfs_get_pid(sk->sk_peer_pid); 802 805 sk->sk_peer_cred = get_cred(peersk->sk_peer_cred); 803 806 spin_unlock(&sk->sk_peer_lock); 804 807 }