[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20251105-work-pidfs-wait_pidfd-lock-v1-1-02638783be07@kernel.org>
Date: Wed, 05 Nov 2025 00:05:01 +0100
From: Christian Brauner <brauner@...nel.org>
To: linux-fsdevel@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, Christian Brauner <brauner@...nel.org>
Subject: [PATCH] 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 <brauner@...nel.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
Powered by blists - more mailing lists