[PATCH] KEYS: Reduce smp_mb() calls in key_put()

Jarkko Sakkinen
2025-04-30T15:26:04Z

Rely only on the memory ordering of spin_unlock() when setting
KEY_FLAG_FINAL_PUT under key->user->lock in key_put().

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
security/keys/key.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/security/keys/key.c b/security/keys/key.c
index 7198cd2ac3a3..aecbd624612d 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -656,10 +656,12 @@ void key_put(struct key *key)
spin_lock_irqsave(&key->user->lock, flags);
key->user->qnkeys--;
key->user->qnbytes -= key->quotalen;
+ set_bit(KEY_FLAG_FINAL_PUT, &key->flags);
spin_unlock_irqrestore(&key->user->lock, flags);
+ } else {
+ set_bit(KEY_FLAG_FINAL_PUT, &key->flags);
+ smp_mb(); /* key->user before FINAL_PUT set. */
}
- smp_mb(); /* key->user before FINAL_PUT set. */
- set_bit(KEY_FLAG_FINAL_PUT, &key->flags);
schedule_work(&key_gc_work);
}
}
--
2.47.2