From nobody Sat Feb 7 23:23:13 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 583B6EB64DA for ; Thu, 20 Jul 2023 17:20:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231338AbjGTRU2 (ORCPT ); Thu, 20 Jul 2023 13:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbjGTRU0 (ORCPT ); Thu, 20 Jul 2023 13:20:26 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BF85CC for ; Thu, 20 Jul 2023 10:20:25 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-66872d4a141so708383b3a.1 for ; Thu, 20 Jul 2023 10:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689873625; x=1690478425; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=u0xewG1cvw/piPahukDeQcAUXVw/NemttoACGhlUIf0=; b=RcbofajWQQtwxWLyIGuP7sdbMlaKu21GK2CL4Tws++gJGiZcwugJ6RdOVJxGjFcjwE ydVpr91UvvuIScmlQl/SAXRD3TdHkSuaBhpa+5T345iZrzm2BoG5MFgBH97sjXt0WN6d cQyY6PERJcbLjjiNP0J95sGol+1hJF4/igCIY52lYEEjso/lhAyD9Ppy1UFaUALmplb8 RoS0jwXQ94Lf+VZa+f4f3RDa4eClJXixl8rki5NOGIz0B2KYMc4jmxx5oHOc0qKNzJqh J/L8LGXUfiI5irx0Z82x09SKDNQdmeLIQDlmdahQnquUVRxX4tUGwLJsKI/dt2xJHWtf VPSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689873625; x=1690478425; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=u0xewG1cvw/piPahukDeQcAUXVw/NemttoACGhlUIf0=; b=TpYdswo7G/b4wA2vh8HJ2nihI1Wh1N76cPxkW3WejJr8+KE0ubbe5HSK76BdYRXb7P wg66i38kiw+8eEdrKmCd6Nid7W7TVjK1Om4zZv7gqxSPVm20FhqORRh4Np7dj9MXcUcj W8bmvJ2Zk/C5fRJhEBPx2ZP0rplymaSz1ntw6SGV4w8a56JpzScWp9klwMnd7zyFRoYr yETjhzCDKtEUtzQMXPR1HRKYYKjoVay3H+Z3mjjW25rquUUOoVAobhEEpO1qrx0w7L4a v9B680wx51ux6Kd2CSTO5Y18WcE0/bhp8N7r9PT7iMSgqlr7OXqMLM53wUCfeOp6sP06 serQ== X-Gm-Message-State: ABy/qLbwoXDvGM3m+mBHWNC9LfGeCDGN93yl9T0yeZw5/tX0PxmdF7vb +80rPRCHjRYfMOZ0Oe7lVL8= X-Google-Smtp-Source: APBJJlHwTCE/qfs//TO920/kd2Wc7nex4YRjMcedVAyflYwacyVGjzbIvdvESKr7onneRWRk6STQ+w== X-Received: by 2002:a05:6a00:2d9e:b0:668:6eed:7c0f with SMTP id fb30-20020a056a002d9e00b006686eed7c0fmr6685187pfb.12.1689873624907; Thu, 20 Jul 2023 10:20:24 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id t14-20020aa7938e000000b00659b8313d08sm1457885pfe.78.2023.07.20.10.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 10:20:24 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Mark Brown Cc: Greg Kroah-Hartman , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, Guenter Roeck , Dan Carpenter Subject: [PATCH] regmap: maple: Use alloc_flags for memory allocations Date: Thu, 20 Jul 2023 10:20:21 -0700 Message-Id: <20230720172021.2617326-1-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" REGCACHE_MAPLE needs to allocate memory for regmap operations. This results in lockdep splats if used with fast_io since fast_io uses spinlocks for locking. BUG: sleeping function called from invalid context at include/linux/sched/m= m.h:306 in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 167, name: kunit_t= ry_catch preempt_count: 1, expected: 0 1 lock held by kunit_try_catch/167: #0: 838e9c10 (regmap_kunit:86:(config)->lock){....}-{2:2}, at: regmap_lock= _spinlock+0x14/0x1c irq event stamp: 146 hardirqs last enabled at (145): [<8078bfa8>] crng_make_state+0x1a0/0x294 hardirqs last disabled at (146): [<80c5f62c>] _raw_spin_lock_irqsave+0x7c/0= x80 softirqs last enabled at (0): [<80110cc4>] copy_process+0x810/0x216c softirqs last disabled at (0): [<00000000>] 0x0 CPU: 0 PID: 167 Comm: kunit_try_catch Tainted: G N 6.5.0-rc= 1-00028-gc4be22597a36-dirty #6 Hardware name: Generic DT based system unwind_backtrace from show_stack+0x18/0x1c show_stack from dump_stack_lvl+0x38/0x5c dump_stack_lvl from __might_resched+0x188/0x2d0 __might_resched from __kmem_cache_alloc_node+0x1f4/0x258 __kmem_cache_alloc_node from __kmalloc+0x48/0x170 __kmalloc from regcache_maple_write+0x194/0x248 regcache_maple_write from _regmap_write+0x88/0x140 _regmap_write from regmap_write+0x44/0x68 regmap_write from basic_read_write+0x8c/0x27c basic_read_write from kunit_generic_run_threadfn_adapter+0x1c/0x28 kunit_generic_run_threadfn_adapter from kthread+0xf8/0x120 kthread from ret_from_fork+0x14/0x3c Exception stack(0x881a5fb0 to 0x881a5ff8) 5fa0: 00000000 00000000 00000000 000000= 00 5fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000000= 00 5fe0: 00000000 00000000 00000000 00000000 00000013 00000000 Use map->alloc_flags instead of GFP_KERNEL for memory allocations to fix the problem. Fixes: f033c26de5a5 ("regmap: Add maple tree based register cache") Cc: Dan Carpenter Signed-off-by: Guenter Roeck --- drivers/base/regmap/regcache-maple.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/base/regmap/regcache-maple.c b/drivers/base/regmap/reg= cache-maple.c index 283c2e02a298..41edd6a430eb 100644 --- a/drivers/base/regmap/regcache-maple.c +++ b/drivers/base/regmap/regcache-maple.c @@ -74,7 +74,7 @@ static int regcache_maple_write(struct regmap *map, unsig= ned int reg, rcu_read_unlock(); =20 entry =3D kmalloc((last - index + 1) * sizeof(unsigned long), - GFP_KERNEL); + map->alloc_flags); if (!entry) return -ENOMEM; =20 @@ -92,7 +92,7 @@ static int regcache_maple_write(struct regmap *map, unsig= ned int reg, mas_lock(&mas); =20 mas_set_range(&mas, index, last); - ret =3D mas_store_gfp(&mas, entry, GFP_KERNEL); + ret =3D mas_store_gfp(&mas, entry, map->alloc_flags); =20 mas_unlock(&mas); =20 @@ -134,7 +134,7 @@ static int regcache_maple_drop(struct regmap *map, unsi= gned int min, =20 lower =3D kmemdup(entry, ((min - mas.index) * sizeof(unsigned long)), - GFP_KERNEL); + map->alloc_flags); if (!lower) { ret =3D -ENOMEM; goto out_unlocked; @@ -148,7 +148,7 @@ static int regcache_maple_drop(struct regmap *map, unsi= gned int min, upper =3D kmemdup(&entry[max + 1], ((mas.last - max) * sizeof(unsigned long)), - GFP_KERNEL); + map->alloc_flags); if (!upper) { ret =3D -ENOMEM; goto out_unlocked; @@ -162,7 +162,7 @@ static int regcache_maple_drop(struct regmap *map, unsi= gned int min, /* Insert new nodes with the saved data */ if (lower) { mas_set_range(&mas, lower_index, lower_last); - ret =3D mas_store_gfp(&mas, lower, GFP_KERNEL); + ret =3D mas_store_gfp(&mas, lower, map->alloc_flags); if (ret !=3D 0) goto out; lower =3D NULL; @@ -170,7 +170,7 @@ static int regcache_maple_drop(struct regmap *map, unsi= gned int min, =20 if (upper) { mas_set_range(&mas, upper_index, upper_last); - ret =3D mas_store_gfp(&mas, upper, GFP_KERNEL); + ret =3D mas_store_gfp(&mas, upper, map->alloc_flags); if (ret !=3D 0) goto out; upper =3D NULL; @@ -320,7 +320,7 @@ static int regcache_maple_insert_block(struct regmap *m= ap, int first, unsigned long *entry; int i, ret; =20 - entry =3D kcalloc(last - first + 1, sizeof(unsigned long), GFP_KERNEL); + entry =3D kcalloc(last - first + 1, sizeof(unsigned long), map->alloc_fla= gs); if (!entry) return -ENOMEM; =20 @@ -331,7 +331,7 @@ static int regcache_maple_insert_block(struct regmap *m= ap, int first, =20 mas_set_range(&mas, map->reg_defaults[first].reg, map->reg_defaults[last].reg); - ret =3D mas_store_gfp(&mas, entry, GFP_KERNEL); + ret =3D mas_store_gfp(&mas, entry, map->alloc_flags); =20 mas_unlock(&mas); =20 --=20 2.39.2