linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>,
	 maple-tree@lists.infradead.org, linux-mm@kvack.org,
	 linux-kernel@vger.kernel.org, Mark Brown <broonie@kernel.org>
Subject: [PATCH 4/5] regmap: Wrap maple tree locking
Date: Thu, 22 Aug 2024 20:13:38 +0100	[thread overview]
Message-ID: <20240822-b4-regmap-maple-nolock-v1-4-d5e6dbae3396@kernel.org> (raw)
In-Reply-To: <20240822-b4-regmap-maple-nolock-v1-0-d5e6dbae3396@kernel.org>

In preparation for using the regmap lock when available with the maple
tree lock wrap all the maple tree locking with some local functions and
only do the maple tree locking if the maple tree has it's own lock.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/base/regmap/regcache-maple.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/drivers/base/regmap/regcache-maple.c b/drivers/base/regmap/regcache-maple.c
index 2dea9d259c49..d2de3eba1646 100644
--- a/drivers/base/regmap/regcache-maple.c
+++ b/drivers/base/regmap/regcache-maple.c
@@ -13,6 +13,18 @@
 
 #include "internal.h"
 
+static inline void regmap_mas_lock(struct ma_state *mas)
+{
+	if (!mt_external_lock(mas->tree))
+		mas_lock(mas);
+}
+
+static inline void regmap_mas_unlock(struct ma_state *mas)
+{
+	if (!mt_external_lock(mas->tree))
+		mas_unlock(mas);
+}
+
 static int regcache_maple_read(struct regmap *map,
 			       unsigned int reg, unsigned int *value)
 {
@@ -89,12 +101,12 @@ static int regcache_maple_write(struct regmap *map, unsigned int reg,
 	 * is redundant, but we need to take it due to lockdep asserts
 	 * in the maple tree code.
 	 */
-	mas_lock(&mas);
+	regmap_mas_lock(&mas);
 
 	mas_set_range(&mas, index, last);
 	ret = mas_store_gfp(&mas, entry, map->alloc_flags);
 
-	mas_unlock(&mas);
+	regmap_mas_unlock(&mas);
 
 	if (ret == 0) {
 		kfree(lower);
@@ -118,7 +130,7 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
 	lower = NULL;
 	upper = NULL;
 
-	mas_lock(&mas);
+	regmap_mas_lock(&mas);
 
 	mas_for_each(&mas, entry, max) {
 		/*
@@ -126,7 +138,7 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
 		 * Maple lock is redundant, but we need to take it due
 		 * to lockdep asserts in the maple tree code.
 		 */
-		mas_unlock(&mas);
+		regmap_mas_unlock(&mas);
 
 		/* Do we need to save any of this entry? */
 		if (mas.index < min) {
@@ -156,7 +168,7 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
 		}
 
 		kfree(entry);
-		mas_lock(&mas);
+		regmap_mas_lock(&mas);
 		mas_erase(&mas);
 
 		/* Insert new nodes with the saved data */
@@ -178,7 +190,7 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
 	}
 
 out:
-	mas_unlock(&mas);
+	regmap_mas_unlock(&mas);
 out_unlocked:
 	kfree(lower);
 	kfree(upper);
@@ -300,11 +312,11 @@ static int regcache_maple_exit(struct regmap *map)
 	if (!mt)
 		return 0;
 
-	mas_lock(&mas);
+	regmap_mas_lock(&mas);
 	mas_for_each(&mas, entry, UINT_MAX)
 		kfree(entry);
 	__mt_destroy(mt);
-	mas_unlock(&mas);
+	regmap_mas_unlock(&mas);
 
 	kfree(mt);
 	map->cache = NULL;
@@ -327,13 +339,13 @@ static int regcache_maple_insert_block(struct regmap *map, int first,
 	for (i = 0; i < last - first + 1; i++)
 		entry[i] = map->reg_defaults[first + i].def;
 
-	mas_lock(&mas);
+	regmap_mas_lock(&mas);
 
 	mas_set_range(&mas, map->reg_defaults[first].reg,
 		      map->reg_defaults[last].reg);
 	ret = mas_store_gfp(&mas, entry, map->alloc_flags);
 
-	mas_unlock(&mas);
+	regmap_mas_unlock(&mas);
 
 	if (ret)
 		kfree(entry);

-- 
2.39.2



  parent reply	other threads:[~2024-08-22 19:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-22 19:13 [PATCH 0/5] regmap: Improve lock handling with maple tree Mark Brown
2024-08-22 19:13 ` [PATCH 1/5] maple_tree: Allow external locks to be configured with their map Mark Brown
2024-08-22 19:21   ` Matthew Wilcox
2024-08-22 19:48     ` Mark Brown
2024-08-22 19:55       ` Matthew Wilcox
2024-08-22 20:45         ` Mark Brown
2024-08-22 19:13 ` [PATCH 2/5] regmap: Hold the regmap lock when allocating and freeing the cache Mark Brown
     [not found]   ` <CGME20240828100239eucas1p2afc0d3088c66468061baf81c5676882a@eucas1p2.samsung.com>
2024-08-28 10:02     ` Marek Szyprowski
2024-08-28 11:32       ` Mark Brown
2024-08-22 19:13 ` [PATCH 3/5] regmap: Use locking during kunit tests Mark Brown
2024-08-22 19:13 ` Mark Brown [this message]
2024-08-22 19:13 ` [PATCH 5/5] regmap: Don't double lock maple cache when using a regmap provided lock Mark Brown
2024-08-23 22:57 ` (subset) [PATCH 0/5] regmap: Improve lock handling with maple tree Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240822-b4-regmap-maple-nolock-v1-4-d5e6dbae3396@kernel.org \
    --to=broonie@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=cristian.ciocaltea@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=maple-tree@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).