lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231103161635.1902667-2-aahringo@redhat.com>
Date:   Fri,  3 Nov 2023 12:16:35 -0400
From:   Alexander Aring <aahringo@...hat.com>
To:     will@...nel.org
Cc:     gfs2@...ts.linux.dev, aahringo@...hat.com, peterz@...radead.org,
        boqun.feng@...il.com, mark.rutland@....com,
        linux-kernel@...r.kernel.org
Subject: [RFC 2/2] kref: introduce kref_put_lockptr() and use lockptr

This patch switches to make kref_put_lock() more locktype independend by
introducing kref_put_lockptr() and using refcount_dec_and_lockptr(). The
user can now pass a lockptr and do the specific locktype operation by
parameters. The current kref_put_mutex() and kref_put_lock() has been
adapted to use the new kref_put_lockptr() implementation for existing
users.

Signed-off-by: Alexander Aring <aahringo@...hat.com>
---
 include/linux/kref.h | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/include/linux/kref.h b/include/linux/kref.h
index d32e21a2538c..09bc79435dbb 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -68,26 +68,33 @@ static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref)
 	return 0;
 }
 
-static inline int kref_put_mutex(struct kref *kref,
-				 void (*release)(struct kref *kref),
-				 struct mutex *lock)
+static inline int kref_put_lockptr(struct kref *kref,
+				   void (*release)(struct kref *kref),
+				   void (*lock)(void *lockptr),
+				   void (*unlock)(void *lockptr),
+				   void *lockptr)
 {
-	if (refcount_dec_and_mutex_lock(&kref->refcount, lock)) {
+	if (refcount_dec_and_lockptr(&kref->refcount, lock, unlock, lockptr)) {
 		release(kref);
 		return 1;
 	}
 	return 0;
 }
 
+static inline int kref_put_mutex(struct kref *kref,
+				 void (*release)(struct kref *kref),
+				 struct mutex *lock)
+{
+	return kref_put_lockptr(kref, release, lockptr_mutex_lock,
+				lockptr_mutex_unlock, lock);
+}
+
 static inline int kref_put_lock(struct kref *kref,
 				void (*release)(struct kref *kref),
 				spinlock_t *lock)
 {
-	if (refcount_dec_and_lock(&kref->refcount, lock)) {
-		release(kref);
-		return 1;
-	}
-	return 0;
+	return kref_put_lockptr(kref, release, lockptr_spin_lock,
+				lockptr_spin_unlock, lock);
 }
 
 /**
-- 
2.39.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ