linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KEYS: Reduce smp_mb() calls in key_put()
@ 2025-04-30 15:25 Jarkko Sakkinen
  2025-05-03 14:39 ` Jarkko Sakkinen
  2025-05-03 22:19 ` David Howells
  0 siblings, 2 replies; 16+ messages in thread
From: Jarkko Sakkinen @ 2025-04-30 15:25 UTC (permalink / raw)
  To: keyrings
  Cc: Jarkko Sakkinen, David Howells, Lukas Wunner, Ignat Korchagin,
	Herbert Xu, David S. Miller, Peter Huewe, Jason Gunthorpe,
	Paul Moore, James Morris, Serge E. Hallyn, James Bottomley,
	Mimi Zohar, linux-crypto, linux-kernel, linux-integrity,
	linux-security-module

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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-05-12 12:07 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-30 15:25 [PATCH] KEYS: Reduce smp_mb() calls in key_put() Jarkko Sakkinen
2025-05-03 14:39 ` Jarkko Sakkinen
2025-05-03 15:02   ` Herbert Xu
2025-05-04 16:55     ` Jarkko Sakkinen
2025-05-03 22:19 ` David Howells
2025-05-04  0:35   ` Herbert Xu
2025-05-04  5:36     ` [PATCH] KEYS: Invert FINAL_PUT bit Herbert Xu
2025-05-04  7:44     ` David Howells
2025-05-04  7:52       ` [v2 PATCH] " Herbert Xu
2025-05-09  9:34         ` kernel test robot
2025-05-09  9:45           ` [v3 " Herbert Xu
2025-05-12  9:19           ` David Howells
2025-05-12 11:42             ` Jarkko Sakkinen
2025-05-12 12:01             ` David Howells
2025-05-12 12:07               ` Herbert Xu
2025-05-04 16:42   ` [PATCH] KEYS: Reduce smp_mb() calls in key_put() Jarkko Sakkinen

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).