From patchwork Thu Aug 22 19:13:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13776868 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 B706AC5320E for ; Sun, 25 Aug 2024 18:31:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D51B8D002A; Sun, 25 Aug 2024 14:31:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 327F88D002D; Sun, 25 Aug 2024 14:31:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1004A8D0029; Sun, 25 Aug 2024 14:31:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 835358D002A for ; Sun, 25 Aug 2024 14:31:49 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 388B9A0850 for ; Sun, 25 Aug 2024 18:31:49 +0000 (UTC) X-FDA: 82491611538.15.B7EC620 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf27.hostedemail.com (Postfix) with ESMTP id 76C5D40008 for ; Sun, 25 Aug 2024 18:31:47 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=U5b70VjH; spf=pass (imf27.hostedemail.com: domain of broonie@kernel.org designates 147.75.193.91 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=1724610688; 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=N6X1Khho36JaLXCuq0P+l/ItnC82nH13pAouozhEhbM=; b=7arDKi1VzML42bnbB1R9BI6UgvubJ9HIGu3J9K0vHZq9P1BLLewaPcXzFGl1thV5Fwz8s7 wEEkUTHNOBiEb1oDJB4lLCV4YjDi7XthBvMeC27tYsKobAfdyBgdRUX3NH8lcWKSbbNibR GZsJXgjfp0Ho/KsIQuXEWpVPjIF3Ed8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=U5b70VjH; spf=pass (imf27.hostedemail.com: domain of broonie@kernel.org designates 147.75.193.91 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=1724610688; a=rsa-sha256; cv=none; b=iJfeOV1+eKnoY+R90KIgtWCcIYlBotxmMFR6cfkcTjdkXKjEGMrmAr7etEMyRu9L+X0NSv RjKZoAu3Ic3cBilnsOZMKZk1+5tUWzrVf0GqJO3RAOIucjq0Xoa64fCKr7/re0m9WED9hf BL+tJdpj3WNfjrTV6TNZkA821Km0oUg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 2DF9EA413F5; Thu, 22 Aug 2024 19:15:43 +0000 (UTC) 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 MIME-Version: 1.0 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 X-Rspam-User: X-Stat-Signature: ggwheq845mted6dj3m8nprkrm665uoxb X-Rspamd-Queue-Id: 76C5D40008 X-Rspamd-Server: rspam11 X-HE-Tag: 1724610707-607901 X-HE-Meta: U2FsdGVkX18IiMLokN7fZJnmsqZPs64kgxBgN39m6zxFnEeORykVc3RQTSq8Em5Kv+3816XOpkkqXWNp5FOi9JNETSywSIsPVu3EaqhCQU5u4Mxuo/ru7F55YnVRzGKXqICGNm8Hlho5ZdDdtMZxD0hcQ9IZtJ6weOvmGikTIXk+vXO75s82EdhPNhZ9AGrjH9wB1jQ+r9Mm3SRH+GKHDLa6ModcRRi/J1lydpagV/ErzDqCRw1mFI/urPOPfIU3KBiFXrewDedUcSqTJqvcV363SjiXZQszyO3XfkB+eAfThRS8v5OkGl66gYcrUOwsOhjlqCKWwe5vkruKjr1CUrQO8KpEpvffVg/lqGWSW/S/KdVsMkFIYDtoapMUXqfBS0DRZM3wdu42iqrv3zCbtpbL0eN8OXxQHyw7RpZIk5WhKM6s/Hzjj5+f1z2i7HVC79EbIFWebV70UEuE5VGduLNRE2xYt9IQvK4lg0RkDTwjoRI9n7D9axOJ6nf60O6UzUtwjvO4Psi12HgC14aAKc0V5LDjekMjp0Y7zqS3kjS+Zp/itHkAOi3S3qE/Xgdnl/Ex8eozztltqm4BWirWP/O8skRClm/1JBbZiIXQMECz4wY7/WFK2u6n3iwxIf8mbEhq0MsZTnDlfGjPS8c3gyllxERzIXHcH5govVfUZpUu49pmPM+PsrlLvgD5AFgKGk9+7tDbiF36yy5tS7uonc4fkR8GC2b1BPTvfVeLrrMesBIMlnaHYV63WhImdSyn7MFRxV3pAEIidSARKMtQ3aor3O3Fh2kF/kmXsEK/ebKa/J8t2oAicA6hN6JdcXJ+A8vdDRfuqQv4o+5GE/Xwik1OVz+QR03g8Jao+8z1L4CbKzt9J1f7/+gDK7yUj87eQw6k9L3wPYfuYShW0zyFngCxAz+pnPvpgJWFDq0nFmvDqA8HfHtQwIrh0CWnWkwNrZntRnKNZz/HKJOHzZg 5961fLAo PAywTES0E14ZlIM0AT6nik3gUqd2D2FmAHmkzTGZqzF/6mGUPO11RxVtdAd1BJPqPZRWDQVdcAMZ1TAUkNou3cP7PuN4Edu7PK15kHOSYXjMeQpws+SXlnh/pOxdF2jLc2RvzPeTwE7NZt+OawblLBlRFKTyXLI/vBKQu+J4AQX7JCHNN7gDLi9ustF1dYoK9A3t4s6QbJo2eUYTRaQqVrUc0DJZamSk9bV5AMAFqG+TkcP68SR+XZWOqOmKOkwd3tw4Hk4qQ0r4uBKG1rC86AKE8Qex+cKL9MY/I 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: 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 *dev, #define regmap_init_raw_ram(dev, config, data) \ __regmap_lockdep_wrapper(__regmap_init_raw_ram, #dev, dev, config, data) +#ifdef CONFIG_LOCKDEP +static inline void regmap_set_lockdep(struct regmap *m, struct lockdep_map *l) +{ + m->lockdep = l; +} +#else +#define regmap_set_lockdep(m, l) +#endif + #endif diff --git a/drivers/base/regmap/regcache-maple.c b/drivers/base/regmap/regcache-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 = mt; +#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 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 = 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 = regmap_lock_spinlock; map->unlock = 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 = true; lockdep_set_class_and_name(&map->mutex, lock_key, lock_name); + regmap_set_lockdep(map, &map->mutex.dep_map); } map->lock_arg = map; }