Skip to content

Commit 390d967

Browse files
committed
pidfs: reduce wait_pidfd lock scope
There's no need to hold the lock after we realized that pid->attr is set. We're holding a reference to struct pid so it won't go away and pidfs_exit() is called once per struct pid. Link: https://patch.msgid.link/20251105-work-pidfs-wait_pidfd-lock-v1-1-02638783be07@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent a45ff1c commit 390d967

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

fs/pidfs.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -634,17 +634,19 @@ void pidfs_exit(struct task_struct *tsk)
634634

635635
might_sleep();
636636

637-
guard(spinlock_irq)(&pid->wait_pidfd.lock);
638-
attr = pid->attr;
639-
if (!attr) {
640-
/*
641-
* No one ever held a pidfd for this struct pid.
642-
* Mark it as dead so no one can add a pidfs
643-
* entry anymore. We're about to be reaped and
644-
* so no exit information would be available.
645-
*/
646-
pid->attr = PIDFS_PID_DEAD;
647-
return;
637+
/* Synchronize with pidfs_register_pid(). */
638+
scoped_guard(spinlock_irq, &pid->wait_pidfd.lock) {
639+
attr = pid->attr;
640+
if (!attr) {
641+
/*
642+
* No one ever held a pidfd for this struct pid.
643+
* Mark it as dead so no one can add a pidfs
644+
* entry anymore. We're about to be reaped and
645+
* so no exit information would be available.
646+
*/
647+
pid->attr = PIDFS_PID_DEAD;
648+
return;
649+
}
648650
}
649651

650652
/*

0 commit comments

Comments
 (0)