From patchwork Thu Aug 22 19:13:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13774108 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 575E0C3DA4A for ; Thu, 22 Aug 2024 19:15:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D15136B029D; Thu, 22 Aug 2024 15:15:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C75A76B029E; Thu, 22 Aug 2024 15:15:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF05F6B029F; Thu, 22 Aug 2024 15:15:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 87C456B029D for ; Thu, 22 Aug 2024 15:15:53 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 35AA6121468 for ; Thu, 22 Aug 2024 19:15:53 +0000 (UTC) X-FDA: 82480836186.12.0A58C5A Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf15.hostedemail.com (Postfix) with ESMTP id B71DCA0037 for ; Thu, 22 Aug 2024 19:15:50 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eQ4qPlhC; spf=pass (imf15.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724354110; a=rsa-sha256; cv=none; b=H/fO0L/4dXxbhoW9J8pj4ln0TAw1WOys0QlB5HlaILtdCgn12WVHxg24uHEZkqeyNtwVLw e5IjVkUHTroNAUpu2l7xUcG17IQc4b8aCDXTrRMv8qRhgYcov43JDxXhI7xPEgO2ji+E0X ZfltjhDaZwI+vIcSPXv9SosRgOMWA7I= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eQ4qPlhC; spf=pass (imf15.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724354110; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sxy/y6Rwq+r4k6Toyu+9jWODJ9zeQW7BlpEjw7HxNDQ=; b=E8Lg5Lb/dyg5LrWl0Oao4+UmxTzp+CZpyxerQNh5+gw/8DnlIj8pwG2DoYJN1dpGQd669C s1wagIv7NllzkgGu21vPnU013B19NqhPzadny7IxCjetKozaANhBfWZVTNWiVElCX4Ylpz /GzuMQ0LsJ+mSDzJ9/+etcW7hY+bqQA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id B4703CE105F; Thu, 22 Aug 2024 19:15:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 023A0C4AF0C; Thu, 22 Aug 2024 19:15:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724354147; bh=OBqVs0rQ1CiMM5qFzO+/1VLNqF3w4XsS2CGy4hdAxGo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eQ4qPlhCEF5YOCmpS0UQxZkWeNJnWOrGyMTUxRDoGMV1K/l8JrhpiL6AifpkVLFxS zbAmo4PxMIeb2WCG60SI2idnnmpWISI8RVAnAS473bn258XmFMpcCxpM/abZAhM9xI RBPWYvWEyc1U/dqLTram27k6u6sGyVCZlHqdh3oVmmAk4ykUCT2IOTicjVZWvC6Xz6 3HiBR1FfmhbN6l/M+yOxjKBk3fbyOLaFg4B5svWlWkxjrBnLMbZSrSFL4NFp29Yqgp tgO2RxxGsOhCxACfahu28n2ttUOOYI+lKrPEk0r0Rj9XoizMPmmQUT7Mrn+qzeBHHo xwMQOijbW3JGw== From: Mark Brown Date: Thu, 22 Aug 2024 20:13:38 +0100 Subject: [PATCH 4/5] regmap: Wrap maple tree locking MIME-Version: 1.0 Message-Id: <20240822-b4-regmap-maple-nolock-v1-4-d5e6dbae3396@kernel.org> References: <20240822-b4-regmap-maple-nolock-v1-0-d5e6dbae3396@kernel.org> In-Reply-To: <20240822-b4-regmap-maple-nolock-v1-0-d5e6dbae3396@kernel.org> To: "Liam R. Howlett" Cc: Cristian Ciocaltea , maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=3250; i=broonie@kernel.org; h=from:subject:message-id; bh=OBqVs0rQ1CiMM5qFzO+/1VLNqF3w4XsS2CGy4hdAxGo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmx45Yne4Rw9lYzvkFQau2dor1n8Sxe2Cwjon6K vB1crJHzDmJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZseOWAAKCRAk1otyXVSH 0FcvB/4iyrhgWnvNVoQrKpcsLNdus42nmx8ZEdApoeflQqenqNixTVrspLKArPh6dm2ctgbXD5H sfEYxli/gChtp9Lyt9ruD+Gxlqd9pM3b3UhLz/xDCHjL15rOI3+WRBt/IdBm3n/a/mHC/2Zx5Kl wEiC7L5gZ9/qoHwYCnYpY+csxYn8hqOcUTdMdQeNLsC9OXfugWH40RTCy1L45wtDBx2kzOXVoLp s6o5oDhR5CF/utYgzqwlI/P0JD/7D/FQDFbxxCeUitdy/qA0IrHHJXpUwBX/DnBedPB73k25yYr lGAf0F+jW5wpaKlKp06AfsSyRqT38pQHFZPR01nPyEwLgWK2 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: ok965sqcti86h9w5xu4g96wjmup8ik9p X-Rspamd-Queue-Id: B71DCA0037 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724354150-640520 X-HE-Meta: U2FsdGVkX18HkuTPMA/0y/fzQX6pgg0Xnbh0b1ynMjW0R01+5ijIsgOz92+CcHr2EgjjXggOBjX5s4u+4rG9ZFxwNegMTzDaUcGHZHZcf4IGTT7klwAanHAoZ/siBO3NqWIFqryfySHUnpAzwU+L3QFNWtRHmm3IgRHpr15B6kKrBPzQrKcxXih9ekx+ebLIV04l9eexW366CQiLX37Lh2fKEC6KBNRddXs8ia2fGa82BtpCzyFEdyKe5H5T86IGi5WSJSLBBTy4v22qJ73vBTsh1g/NTqusQgMzYD68yVMLVSHcD6yo2echiTANVU+Mb4+6+reTpYpdjOGWOU3kqsCiq68shrW29wBLwzAMzYKm/qiJ+4tVTExc27kr6TohSUxuZHgFAr4tiRyOppdy7g9dXee+WdakVYQ5btmuzlzGDYGRCoGs25XfJPUl3SmggcDFGGq1eX9WtWJhsw0JApe5rphPc8euyrKIYBORkBqEIxRqQm3YrG7WcOL2Jmai5nDwuUP0AJY+JSN3/raDXTcvz1A/tOyu9/N1BQKmlY7S9LUcDZT0AcvwmQTjagXSfxbaZ8xeXhlD0b9GgidZgnp0OGPtRJYHrTuO3AIc5f7TyzmYVyCEQi87/0Yu99eq4k40kfxPCLA+zQmPaStJu6NryWlgSEaDh6Qvrf3Sk17RWfkke2zVVXtR9qqTChu5ZdwKbZqOoVoWmGi9/v+PYCtfjeMKqUkoPgZJiIs3PiAzu8wzMdTdyNlY9kdvZY/+d3R8uhbd0VWYdTtVTmTzkDZtykBtbfC24D2elj3e+53eRJ3Vi4yDlurMimu3/uEDDiuvMqmXCeNnr80NZptIl+FVZ15W2Ypvve8nhLpE5FiPvRVnFduF6F9cHFciOty8Z5Hi8OD76sBRB/lbeCtMVl25tF9EZb1uNq39kCJXrESvZl/xUAPzAhLbjExfKQDLlcY+aQoLfr6Ja1mkr8n 7zGbHtsU SI4jeC2/nCQ+ARmhj0KNur6dGCU4JEFcW/E10nWN9nudbsDetdh7Rpw9vLPNCQB7jVqIs4jX6pHPw+rQ5TaM0dHUxO+e9SGe9fwYzfdERAkLcFmt9PjlOSrPLqMYLqwNKFlWO2khtq0S8w664TH1ABbe/8rN4y6NIHxaLAhio+LLkBCEF0XZot8baB+1lrxw+e3Ttp77/Aa0YKcyyBN8zxd9xitc+lkMM7VjrxZSEop5s0clgVSO+7l08lA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- 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);