pidfs: reduce wait_pidfd lock scope
Christian Brauner
maintainerPATCH 1/1 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.
Signed-off-by Christian Brauner <[email protected]>
--- fs/pidfs.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
fs/pidfs.c +13 -11
@@ -613,17 +613,19 @@ void pidfs_exit(struct task_struct *tsk)might_sleep (); -guard (spinlock_irq)(&pid->wait_pidfd.lock); - attr = pid->attr; -if (!attr) { -/* -* No one ever held a pidfd for this struct pid. -* Mark it as dead so no one can add a pidfs -* entry anymore. We're about to be reaped and -* so no exit information would be available. -*/ - pid->attr =PIDFS_PID_DEAD ; -return ; +/* Synchronize with pidfs_register_pid(). */ + scoped_guard(spinlock_irq, &pid->wait_pidfd.lock) { + attr = pid->attr; +if (!attr) { +/* +* No one ever held a pidfd for this struct pid. +* Mark it as dead so no one can add a pidfs +* entry anymore. We're about to be reaped and +* so no exit information would be available. +*/ + pid->attr =PIDFS_PID_DEAD ; +return ; + } }/*
---
base-commit: a20432b6571ddc02e86c549f582d61ac5a89ca40
change-id: 20251105-work-pidfs-wait_pidfd-lock-a1b0d38cf13d