* [PATCH] pidfs: reduce wait_pidfd lock scope
@ 2025-11-04 23:05 Christian Brauner
0 siblings, 0 replies; only message in thread
From: Christian Brauner @ 2025-11-04 23:05 UTC (permalink / raw)
To: linux-fsdevel; +Cc: linux-kernel, Christian Brauner
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 <brauner@kernel.org>
---
fs/pidfs.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/fs/pidfs.c b/fs/pidfs.c
index 0ef5b47d796a..d2e74c069b4f 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2025-11-04 23:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-04 23:05 [PATCH] pidfs: reduce wait_pidfd lock scope Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).