From nobody Sat Feb 7 23:11:10 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06E731D04A8 for ; Thu, 22 Aug 2024 19:15:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724354142; cv=none; b=V9syqXSaGnJI2A4ObX2rIe4heGQJzonzOivP/P9DfHz8UN+7RAVjb8LuYkng3TcTa9FfZh6W7ArOtzj4bwXsCjeedYP2T8iPZkytkx+v40Ky9MZOfJ+v5S5P+NjWAACME/JsnCOqILpNBjwu+HYb5H+kdhn5QWQ2aVsIGikzrHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724354142; c=relaxed/simple; bh=Gqu8IKz5ZDmSH1qLlC/PQjAsOLa/MoeoFtoKJgAk1OU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SeICOzyP3EV0f7jLFqzB6WKGon6/cK09oR9/n/c4vp0MuAcaYLmFyV+WsJnlt0w7nfIaFVR5Q9yyCcmuZYyfUuIiJFd/R6wQ3+E5Q0PctIYH9FtvHbnwW2bE9jmKNSHiFqYMBHkqLEzTWvIY3k/3K3d3DJfOV3sNboEgIvh47FM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kPW2vXZ6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kPW2vXZ6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A8F0C4AF0B; Thu, 22 Aug 2024 19:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724354141; bh=Gqu8IKz5ZDmSH1qLlC/PQjAsOLa/MoeoFtoKJgAk1OU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kPW2vXZ6T4WX6SqcSVvQ87sShPfOSoI3xRmeRX74DLMs9qD3/ERN716bUlNvLJbLr keuF0jio2tPcQXDawasMd4lbqUVeiojs2KnNGabvua3cBVUH89haltHTNbBamjRnms rx6sCuG0bGgV2774klnzMYZ1H6LhEgI1RBvRxVUzR15XOmAn0/vnPRXabJCcyvWqwz gPl1bix1AkeNi8qPG/yQIZxnw1rkRSPprIaXrklH8n+rLYbrSKWh0u00P1N4xtzZlN symNkSXDWJ0bWyVo5H1AxcxrTKW7fInileEOZ9eVq8l8ZHlpyoD4fHirU08zLT6s2L SCKB7rYyHT4Vg== From: Mark Brown Date: Thu, 22 Aug 2024 20:13:35 +0100 Subject: [PATCH 1/5] maple_tree: Allow external locks to be configured with their map Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240822-b4-regmap-maple-nolock-v1-1-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=1230; i=broonie@kernel.org; h=from:subject:message-id; bh=Gqu8IKz5ZDmSH1qLlC/PQjAsOLa/MoeoFtoKJgAk1OU=; b=owGbwMvMwMWocq27KDak/QLjabUkhrTjfWFP1/QxPVx18BDrR8NLM3vXH4uPO2je4NJyyy9G1 9nlG7tEJ6MRCwMjF4OsmCLL2mcZq9LDJbbOfzT/FcwgViaQKQxcnAIwkXvK7J/ZbVd+TOs9tNrn NYuW9dq1MxNdTXtOagm7KpxbXsdbK3ju2pKreZsUWSVjitr/hWlPsQ+2XPS5iSuz3uBasud3c9l 1D60lzV9/2mWzTETFxnnR1lU1Yt+s0iNjuPdE8G04WqI+4ZhmxW62HzLrZe/7RV2yYqy4V/Cg/K W9/88TGvy9mkd+qQvwRu7pKC1k6rtTva0iPdV7w1mHn5NOyk6NTlbpnRbgIX7FN1hQgo+TU+aqy calQrVf2ebdWyqr0nBrYQQXT8MWj2kG7ofXWXwpkOw4xec/R3PXPLZAhS38bDKBhQVPf9Qmsp7l 01WYIO46PU9jp9rZ4lIWjxfOHQs6KhhV9VTuCMw6dRgA X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Currently the maple tree code allows external locks to be configured by passing the lock itself. This is generally helpful and convenient but is not ideal for situations like the regmap maple tree cache where we support configurable locking at the regmap level and don't have the lock type when we are configuring the maple tree. Add a helper that allows us to pass the dep map directly to help with these situations. Since such code is already peering at the lockdep internals enough to be looking at the map no stub is provided. Signed-off-by: Mark Brown --- include/linux/maple_tree.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index a53ad4dabd7e..bdc6b133abdc 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -193,6 +193,9 @@ typedef struct lockdep_map *lockdep_map_p; #define mt_set_external_lock(mt, lock) \ (mt)->ma_external_lock =3D &(lock)->dep_map =20 +#define mt_set_external_lock_dep_map(mt, dep_map) \ + (mt)->ma_external_lock =3D dep_map + #define mt_on_stack(mt) (mt).ma_external_lock =3D NULL #else typedef struct { /* nothing */ } lockdep_map_p; --=20 2.39.2 From nobody Sat Feb 7 23:11:10 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9E101D0DDE for ; Thu, 22 Aug 2024 19:15:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724354143; cv=none; b=pAqffJuT30RNdsrLQqpmrioAyhxFyPAyBKISjTOXEz2wBHANj0/5VJChstFs9CGZ6+mTU0nAfeZ/hRGXlODxepPpzDr+ftwQ23cDePNGklNFMzJ3ufVqs4rvWuyKiFaYWE/P0H6+xxZUHih1jYN10mHxPd7f7a60pmUXmTlPpTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724354143; c=relaxed/simple; bh=HqTvO4EXWR9m8S4knK2OhOF8g7vD7aNMIK2A6uNJAO8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QQS/PeQNJv4RQ6ikEWJ3fK8Apj/g7f0cZ2hJvT918Wogq+TUdxeEBUvJN7Qv+80Sw6y4W2g/DoHicSlMAC+iIkn+Fuyq9R9kaT/aTT8UG9PoSsX/vyQwCCS8vOVyjIO1DSsLizcHng2mJnhXt5x52+2YAljDIAdxQ5mWQPGEHJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a8HEkCZK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="a8HEkCZK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04B2AC4AF12; Thu, 22 Aug 2024 19:15:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724354143; bh=HqTvO4EXWR9m8S4knK2OhOF8g7vD7aNMIK2A6uNJAO8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=a8HEkCZKnKXnymobpVWtAm4avgezgATDH2uSDC/fqFclh/7AwmwSQiwL/dEuW3oY8 3UtIQ2KUfb7EjB8W/WuyZ1z23awOIEarRePcINmkUSjh0DMtbnxMFpy1mBeAYinWpp 8/NJeni7ZoxLfzbDVs9Dozm4WPgmsIsbhg1DsHRzea6PL3uTgtlsqTYPB/xZskTWOL OOdF7roGhhi2Mf+kQfp0I/ulmuL/rltSGxMaESwTnZYxzPTwohXwqkhi+vpzX0Da3a Hyw9GRXbwqrPQhY8FKARJjylxxTCVWjjzEfyl248uxNq7XROy2463GDs/ORWoPmys2 cHIOQH+EYdfYg== From: Mark Brown Date: Thu, 22 Aug 2024 20:13:36 +0100 Subject: [PATCH 2/5] regmap: Hold the regmap lock when allocating and freeing the cache Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240822-b4-regmap-maple-nolock-v1-2-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=1507; i=broonie@kernel.org; h=from:subject:message-id; bh=HqTvO4EXWR9m8S4knK2OhOF8g7vD7aNMIK2A6uNJAO8=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmx45W7hwqN8635GlhniM9IzBeNxeV+mEbT9v4O hPc/8CuTsWJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZseOVgAKCRAk1otyXVSH 0EOTB/wNrSyae31JmMwCaXdCreGvDhp2iBzo39oKF/d+fEx6wa5Bi1u3nZhgDhj/tZfP+nEjirv WEJdY7o4yBWI4lu9+lSSF9w8sAfo7cmjmQJFGJYnqhBVBQOLtd57WU+unlf60Aj17RxD5VoO6U4 OvF75iSafkKRm5ADTxMPZMdjtKdtNeIwmxZiC9LvhLl4Bx+taoiodUVyIY0GGOtF7uT4joZQKdo QYdy1bY44VKxvI13LI1MFNh6Z7iMxvD1ATfbRmA/dpjcCRDyb/qicbzJ+pO3moKGSIXhENto0cF 4Mbmi9s3Sk1Kq85eRfgJLbtHlMEVPAIS9QjMOAybBqufyqJM X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB For the benefit of the maple tree's lockdep checking hold the lock while creating and exiting the cache. Signed-off-by: Mark Brown --- drivers/base/regmap/regcache.c | 4 ++++ drivers/base/regmap/regmap.c | 1 + 2 files changed, 5 insertions(+) diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index 7ec1ec605335..d3659ba3cc11 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -195,7 +195,9 @@ int regcache_init(struct regmap *map, const struct regm= ap_config *config) if (map->cache_ops->init) { dev_dbg(map->dev, "Initializing %s cache\n", map->cache_ops->name); + map->lock(map->lock_arg); ret =3D map->cache_ops->init(map); + map->unlock(map->lock_arg); if (ret) goto err_free; } @@ -223,7 +225,9 @@ void regcache_exit(struct regmap *map) if (map->cache_ops->exit) { dev_dbg(map->dev, "Destroying %s cache\n", map->cache_ops->name); + map->lock(map->lock_arg); map->cache_ops->exit(map); + map->unlock(map->lock_arg); } } =20 diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index bfc6bc1eb3a4..9ed842d17642 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -1445,6 +1445,7 @@ void regmap_exit(struct regmap *map) struct regmap_async *async; =20 regcache_exit(map); + regmap_debugfs_exit(map); regmap_range_exit(map); if (map->bus && map->bus->free_context) --=20 2.39.2 From nobody Sat Feb 7 23:11:10 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DAF03A8D8 for ; Thu, 22 Aug 2024 19:15:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724354145; cv=none; b=VpCtDCvaVTck1SMZoP9zyu73hwv4ShCgAnh2rEVnJ1S5mOZp8PreDtqlzfGeo2uyxtpeRob3YJUlkJgjUDwajuXZ7rNN5oDytXspLwGSgy3imGdRub2dBKwe1bfN41z7RRDasdBF8+j+8f9c8J8Oypb2XWhviJwdxZmvhv6VfMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724354145; c=relaxed/simple; bh=nMY1SpzGoP8oeW0CCyhb2py/IKmlVcolBjcNTRB94bo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=g4hHS1U+sFfEv+r5SFxnMqm8rBFQGnoinIq1hHpD3wjMixST2EG0zjkpv8vbeJnS2Rb0mVXtPZBnW12ING4tesC065qg0t2qT7Twb6iqfJw6IhfzTpPHZOk2vwLy8Rm5sNHwOsvqkSQbrVfMqILv15Gfr+u55YKWqG1ODgABkp8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FrGKfggg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FrGKfggg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1D39C4AF15; Thu, 22 Aug 2024 19:15:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724354145; bh=nMY1SpzGoP8oeW0CCyhb2py/IKmlVcolBjcNTRB94bo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FrGKfggg0RqKGEADj8upTbVV2vULhc0wuFAIt/NeFlYJCquWifB9+wRiU9uN/Or/e H8suP8YWjg/dQ8M3h82wzChv8r8hdh19M74U6a0k0kRGcR7uxf+ypA16/X+h7v9u8n maqMtaP/o014NIs2SJDABM97eTFoK9RpMD/OBME4cZ95KF26ktf8fMXLgaplVMchVb gYS+EYtPdGyr1Aj/sFeFKmW8qFGVmArgBP6Pi1Af0jJdyUJ2f/40dPlDo0i7GcMKag MrBxCTPRahoFCRbHSOKXDH/LlqZp90Gk6fqi9dSzEp7+vh5PUqnhzer+/YHkiXys9I K3mldEPj0y3gQ== From: Mark Brown Date: Thu, 22 Aug 2024 20:13:37 +0100 Subject: [PATCH 3/5] regmap: Use locking during kunit tests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240822-b4-regmap-maple-nolock-v1-3-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=809; i=broonie@kernel.org; h=from:subject:message-id; bh=nMY1SpzGoP8oeW0CCyhb2py/IKmlVcolBjcNTRB94bo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmx45Xnb0AO+klDAfjuZTanNIr2Sl1IK78oEHoi RHupP7GFl6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZseOVwAKCRAk1otyXVSH 0IlNB/4sujDfssqMAFFVfGMlBY+P/eYdMxzxMqDsvPLXwk3B833qyVPbfKLsdHOCTifxPs29bGU QJOKU4qA5e37G6FnS9t0lTuMjknafH4bdES+sj/FehZQyO7M728TP+F4M9Ata9jS/4RAseCJpSL KZzbTcbYrnSQ/6DVo8c0HoKOeQDMkK/HQajxOBKjMlBsJ0zTDbtG6GGXsKacR04pIrwMQ8f0566 nKG5TQK6lg7jATjGGcxrpcnjvxvaIBXEewIjWFpO92q2mkQODWLzXzFGRUyuZxflsWNSIYntiXs m/br6Oh07fOuV7sDTJx2hiAL/srD4GQfZIXl6MUFj5dhB/t3 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB There is no reason to bypass the locking when running the kunit tests, leave it enabled as standard. Signed-off-by: Mark Brown --- drivers/base/regmap/regmap-kunit.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/base/regmap/regmap-kunit.c b/drivers/base/regmap/regma= p-kunit.c index d790c7df5cac..b80b447c87a2 100644 --- a/drivers/base/regmap/regmap-kunit.c +++ b/drivers/base/regmap/regmap-kunit.c @@ -151,8 +151,6 @@ static struct regmap *gen_regmap(struct kunit *test, struct reg_default *defaults; =20 config->cache_type =3D param->cache; - config->disable_locking =3D config->cache_type =3D=3D REGCACHE_RBTREE || - config->cache_type =3D=3D REGCACHE_MAPLE; =20 if (config->max_register =3D=3D 0) { config->max_register =3D param->from_reg; --=20 2.39.2 From nobody Sat Feb 7 23:11:10 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B82471CEAD0 for ; Thu, 22 Aug 2024 19:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724354147; cv=none; b=FIktMtLDzwCjYMs7ocvhdByEKwJdO83PP7QvaB553uy+lFz53JSpXdywzOohl5Kn8BgCrB7aS4XRlleFOo6jFBHGTSv2VKq/jvtgdxyo8wZGty5ooTKUy1wBc8Q97EBkNdm94i5jGKX99zZO4VzQmsGXdw+s5Mt/MhH91ZRP0X0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724354147; c=relaxed/simple; bh=OBqVs0rQ1CiMM5qFzO+/1VLNqF3w4XsS2CGy4hdAxGo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pWz8ft8dUBxWnBez3bS7/n46qQCYKW8k0PTEUV4DnLqWI2VRgIkHVo4lhUt7oiHFDii+GtcjKeBMeVAiEV+OT6VSXFvWd8rZx4AEc1Jwjo9VJ64HISDG39ZAWHscnf2kMXgkdYPCa1wT5wB6GJBVPkB8mD16mePQ/pVbMLfEKYA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eQ4qPlhC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eQ4qPlhC" 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 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/reg= cache-maple.c index 2dea9d259c49..d2de3eba1646 100644 --- a/drivers/base/regmap/regcache-maple.c +++ b/drivers/base/regmap/regcache-maple.c @@ -13,6 +13,18 @@ =20 #include "internal.h" =20 +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, un= signed 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); =20 mas_set_range(&mas, index, last); ret =3D mas_store_gfp(&mas, entry, map->alloc_flags); =20 - mas_unlock(&mas); + regmap_mas_unlock(&mas); =20 if (ret =3D=3D 0) { kfree(lower); @@ -118,7 +130,7 @@ static int regcache_maple_drop(struct regmap *map, unsi= gned int min, lower =3D NULL; upper =3D NULL; =20 - mas_lock(&mas); + regmap_mas_lock(&mas); =20 mas_for_each(&mas, entry, max) { /* @@ -126,7 +138,7 @@ static int regcache_maple_drop(struct regmap *map, unsi= gned 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); =20 /* 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, unsi= gned int min, } =20 kfree(entry); - mas_lock(&mas); + regmap_mas_lock(&mas); mas_erase(&mas); =20 /* Insert new nodes with the saved data */ @@ -178,7 +190,7 @@ static int regcache_maple_drop(struct regmap *map, unsi= gned int min, } =20 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; =20 - 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); =20 kfree(mt); map->cache =3D NULL; @@ -327,13 +339,13 @@ static int regcache_maple_insert_block(struct regmap = *map, int first, for (i =3D 0; i < last - first + 1; i++) entry[i] =3D map->reg_defaults[first + i].def; =20 - mas_lock(&mas); + regmap_mas_lock(&mas); =20 mas_set_range(&mas, map->reg_defaults[first].reg, map->reg_defaults[last].reg); ret =3D mas_store_gfp(&mas, entry, map->alloc_flags); =20 - mas_unlock(&mas); + regmap_mas_unlock(&mas); =20 if (ret) kfree(entry); --=20 2.39.2 From nobody Sat Feb 7 23:11:10 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 118361D174E for ; Thu, 22 Aug 2024 19:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724354150; cv=none; b=bJP9bER+/vWTfSi7ov4o5Eb84Z0aOZcf+W8BOsHzdGEhhLEgRHeBaw9VE36K7pp8APU12g3o3fUpdkLdrcdnbhkCqJhU8LGAhAxSMbODnsmddSklBld83lTJO9GW5McpVwsCnm8HaUSKbQN6VyQJ/xvCeG5Slq6ckzLW/VaNA2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724354150; c=relaxed/simple; bh=3IkVv+qB4U5hLvXfbSxIYJIDDH95Yvi/JvCEmYiEG0s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H4RJB6MYdmkc8cDQ4rk4Gnz3rNxgM7VaZ5mZvj5SPEAAZ5ARuXkSyrd42z00DMfLnpfB7FAnXZrwbhIBA+pj/hOlyFg4payLYcZFY8yjMOkpAAovXDtkjFmlnF6Up9g16+r8thkyZEoVPJjxLfkPlaqTybZpYgxHjx3ImM1aaYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U5b70VjH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U5b70VjH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC970C4AF12; Thu, 22 Aug 2024 19:15:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724354149; bh=3IkVv+qB4U5hLvXfbSxIYJIDDH95Yvi/JvCEmYiEG0s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=U5b70VjHfQEHCBxGcuJkIaZuR3G/OzNuKadvdXSUyLMPsPPYw5KHYR5RNmZ4R81tr 5U8hq/bgBfqVHmd4RaNTTKLmhWpSIvhs+1HVg8J1r/gN6M/3bfDFx72BPrAIH+F2J8 4BkKW8CP6RYQfXgOngDOsBcq+HnW0dwSD18fvTwkJkAGiZGm1MZgZmVALySIF/io43 R2C3c+1d0mhm0rVhN/thZ5ybKAn9TgKp8m3R/iYdStDyD0ngzF01dzgsCyra/Gg9xY R+7frdyONZQ9KZxnVDe+vfQ++8bueNVc1Mcj44MPYyu6FQWlWFx2JgQyNRuaXtiYaN BWxE0XEfNPTjQ== From: Mark Brown Date: Thu, 22 Aug 2024 20:13:39 +0100 Subject: [PATCH 5/5] regmap: Don't double lock maple cache when using a regmap provided lock Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240822-b4-regmap-maple-nolock-v1-5-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=3508; i=broonie@kernel.org; h=from:subject:message-id; bh=3IkVv+qB4U5hLvXfbSxIYJIDDH95Yvi/JvCEmYiEG0s=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmx45Z28y0ReLetC9q+2YdjmiA9bBTW+merSGJe 7fXi8QJgY+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZseOWQAKCRAk1otyXVSH 0CHEB/4su90f4gO7Qt9qNpuaveRhDVSkPq+70sBLqnd/TbhsYX1jIHDW1A9Qfz5h+u8gLoJJflf jdGXYJ1a+pR5vDp3krO/QpawNW3lwaI6acc1SqbGzseANmX/sVpWjOb6l8plm/vFCdoJVjgVzP2 IHtmE7JEwMP5ldgQAu+610rCQRFeW3Oqr02p1fDApahKnw1hVNOrAWfFWrrmutoQuOYKGceqyo6 Y6dbwEs0nrrGzWyFNSB4C1q8z8eUd5DJw2Jgprqv6mKRiq1ASMR2SWEXlQEfXmTram5pkcbY/3y Me6usgkEUE3WhqMjVulp0qD/k/vxWmd4oAo+/jj9U9jckyf9 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB It is not possible to use the maple tree without holding a lock of some kind, by default the maple tree incorporates a lock but it does have support for registering an external lock which will be asserted against instead. At present regmap uses the maple tree's internal lock which is unfortunate since there is also regmap level locking above the cache which protects the cache data structure and things like read/modify/write operations. Let's reduce the overhead here by telling the maple tree about the regmap level lock for cases where regmap does it's own locking. We also support external and custom locking for regmap, neither of which will benefit from this, but this will cover the vast majority of users. Signed-off-by: Mark Brown --- drivers/base/regmap/internal.h | 12 ++++++++++++ drivers/base/regmap/regcache-maple.c | 9 +++++++++ drivers/base/regmap/regmap.c | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index 83acccdc1008..a5fe052a70ce 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h @@ -59,6 +59,9 @@ struct regmap { unsigned long raw_spinlock_flags; }; }; +#ifdef CONFIG_LOCKDEP + struct lockdep_map *lockdep; +#endif regmap_lock lock; regmap_unlock unlock; void *lock_arg; /* This is passed to lock/unlock functions */ @@ -344,4 +347,13 @@ struct regmap *__regmap_init_raw_ram(struct device *de= v, #define regmap_init_raw_ram(dev, config, data) \ __regmap_lockdep_wrapper(__regmap_init_raw_ram, #dev, dev, config, data) =20 +#ifdef CONFIG_LOCKDEP +static inline void regmap_set_lockdep(struct regmap *m, struct lockdep_map= *l) +{ + m->lockdep =3D l; +} +#else +#define regmap_set_lockdep(m, l) +#endif + #endif diff --git a/drivers/base/regmap/regcache-maple.c b/drivers/base/regmap/reg= cache-maple.c index d2de3eba1646..1247ff3ae397 100644 --- a/drivers/base/regmap/regcache-maple.c +++ b/drivers/base/regmap/regcache-maple.c @@ -365,7 +365,16 @@ static int regcache_maple_init(struct regmap *map) return -ENOMEM; map->cache =3D mt; =20 +#ifdef CONFIG_LOCKDEP + if (map->lockdep) { + mt_init_flags(mt, MT_FLAGS_LOCK_EXTERN); + mt_set_external_lock_dep_map(mt, map->lockdep); + } else { + mt_init(mt); + } +#else mt_init(mt); +#endif =20 if (!map->num_reg_defaults) return 0; diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 9ed842d17642..f66b5ef56cf8 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -729,12 +729,15 @@ struct regmap *__regmap_init(struct device *dev, map->unlock =3D regmap_unlock_raw_spinlock; lockdep_set_class_and_name(&map->raw_spinlock, lock_key, lock_name); + regmap_set_lockdep(map, + &map->raw_spinlock.dep_map); } else { spin_lock_init(&map->spinlock); map->lock =3D regmap_lock_spinlock; map->unlock =3D regmap_unlock_spinlock; lockdep_set_class_and_name(&map->spinlock, lock_key, lock_name); + regmap_set_lockdep(map, &map->spinlock.dep_map); } } else { mutex_init(&map->mutex); @@ -743,6 +746,7 @@ struct regmap *__regmap_init(struct device *dev, map->can_sleep =3D true; lockdep_set_class_and_name(&map->mutex, lock_key, lock_name); + regmap_set_lockdep(map, &map->mutex.dep_map); } map->lock_arg =3D map; } --=20 2.39.2