Skip to content

Commit 804d679

Browse files
committed
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 parent 0f93d71 commit 804d679

4 files changed

Lines changed: 1 addition & 47 deletions

File tree

fs/coredump.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -898,12 +898,6 @@ void do_coredump(const kernel_siginfo_t *siginfo)
898898
retval = kernel_connect(socket, (struct sockaddr *)(&addr),
899899
addr_len, O_NONBLOCK | SOCK_COREDUMP);
900900

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-
907901
if (retval) {
908902
if (retval == -EAGAIN)
909903
coredump_report_failure("Coredump socket %s receive queue full", addr.sun_path);

fs/pidfs.c

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,7 @@ static void pidfs_put_data(void *data)
895895
* pidfs_register_pid - register a struct pid in pidfs
896896
* @pid: pid to pin
897897
*
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.
900899
*
901900
* Return: On success zero, on error a negative error code is returned.
902901
*/
@@ -1007,38 +1006,6 @@ struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags)
10071006
return pidfd_file;
10081007
}
10091008

1010-
/**
1011-
* pidfs_get_pid - pin a struct pid through pidfs
1012-
* @pid: pid to pin
1013-
*
1014-
* Similar to pidfs_register_pid() but only valid if the caller knows
1015-
* there's a reference to the @pid through a dentry already that can't
1016-
* go away.
1017-
*/
1018-
void pidfs_get_pid(struct pid *pid)
1019-
{
1020-
if (!pid)
1021-
return;
1022-
WARN_ON_ONCE(!stashed_dentry_get(&pid->stashed));
1023-
}
1024-
1025-
/**
1026-
* pidfs_put_pid - drop a pidfs reference
1027-
* @pid: pid to drop
1028-
*
1029-
* Drop a reference to @pid via pidfs. This is only safe if the
1030-
* reference has been taken via pidfs_get_pid().
1031-
*/
1032-
void pidfs_put_pid(struct pid *pid)
1033-
{
1034-
might_sleep();
1035-
1036-
if (!pid)
1037-
return;
1038-
VFS_WARN_ON_ONCE(!pid->stashed);
1039-
dput(pid->stashed);
1040-
}
1041-
10421009
void __init pidfs_init(void)
10431010
{
10441011
pidfs_attr_cachep = kmem_cache_create("pidfs_attr_cache", sizeof(struct pidfs_attr), 0,

include/linux/pidfs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ void pidfs_coredump(const struct coredump_params *cprm);
1414
#endif
1515
extern const struct dentry_operations pidfs_dentry_operations;
1616
int pidfs_register_pid(struct pid *pid);
17-
void pidfs_get_pid(struct pid *pid);
18-
void pidfs_put_pid(struct pid *pid);
1917
void pidfs_free_pid(struct pid *pid);
2018

2119
#endif /* _LINUX_PID_FS_H */

net/unix/af_unix.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,6 @@ static void unix_sock_destructor(struct sock *sk)
646646
return;
647647
}
648648

649-
if (sk->sk_peer_pid)
650-
pidfs_put_pid(sk->sk_peer_pid);
651-
652649
if (u->addr)
653650
unix_release_addr(u->addr);
654651

@@ -769,7 +766,6 @@ static void drop_peercred(struct unix_peercred *peercred)
769766
swap(peercred->peer_pid, pid);
770767
swap(peercred->peer_cred, cred);
771768

772-
pidfs_put_pid(pid);
773769
put_pid(pid);
774770
put_cred(cred);
775771
}
@@ -802,7 +798,6 @@ static void copy_peercred(struct sock *sk, struct sock *peersk)
802798

803799
spin_lock(&sk->sk_peer_lock);
804800
sk->sk_peer_pid = get_pid(peersk->sk_peer_pid);
805-
pidfs_get_pid(sk->sk_peer_pid);
806801
sk->sk_peer_cred = get_cred(peersk->sk_peer_cred);
807802
spin_unlock(&sk->sk_peer_lock);
808803
}

0 commit comments

Comments
 (0)