From nobody Wed Dec 17 19:00:28 2025 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 AC1D4C27C40 for ; Wed, 22 Nov 2023 23:51:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344450AbjKVXvd (ORCPT ); Wed, 22 Nov 2023 18:51:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344205AbjKVXv2 (ORCPT ); Wed, 22 Nov 2023 18:51:28 -0500 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [IPv6:2001:41d0:1004:224b::b8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EF511B6 for ; Wed, 22 Nov 2023 15:51:23 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1700697081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U3IFgiJgqfQEqTP3mY1EDkfwuWXxEWC3LQrFnM6wwG0=; b=o+FIqXusREjfbStC1cNUHTsWvY9kFGJ16jE6s+U1SnGpS1KURukjbI2UyEFeeraRy/pgjh kqpIZ3pw+weMnTvISUdoAnJarPlTvRJUXuI4H/CIwl/ypcvB8sloCqYyRFOTjIY2bWc+vL aqKGCQ7JkfTgLU58QnyE4VAf/eGizvg= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org, peterz@infradead.org Cc: boqun.feng@gmail.com, longman@redhat.com, will@kernel.org, mingo@redhat.com, Kent Overstreet Subject: [PATCH 1/6] locking/lockdep: lock_class_is_held() Date: Wed, 22 Nov 2023 18:51:08 -0500 Message-ID: <20231122235113.180132-2-kent.overstreet@linux.dev> In-Reply-To: <20231122235113.180132-1-kent.overstreet@linux.dev> References: <20231122235113.180132-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch adds lock_class_is_held(), which can be used to assert that a particular type of lock is not held. Signed-off-by: Kent Overstreet Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng --- include/linux/lockdep.h | 4 ++++ kernel/locking/lockdep.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index dc2844b071c2..fc86557d2a21 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -344,6 +344,8 @@ extern void lock_unpin_lock(struct lockdep_map *lock, s= truct pin_cookie); #define lockdep_repin_lock(l,c) lock_repin_lock(&(l)->dep_map, (c)) #define lockdep_unpin_lock(l,c) lock_unpin_lock(&(l)->dep_map, (c)) =20 +int lock_class_is_held(struct lock_class_key *key); + /* * Must use lock_map_aquire_try() with override maps to avoid * lockdep thinking they participate in the block chain. @@ -442,6 +444,8 @@ extern int lockdep_is_held(const void *); #define lockdep_repin_lock(l, c) do { (void)(l); (void)(c); } while (0) #define lockdep_unpin_lock(l, c) do { (void)(l); (void)(c); } while (0) =20 +static inline int lock_class_is_held(struct lock_class_key *key) { return = 0; } + #define DEFINE_WAIT_OVERRIDE_MAP(_name, _wait_type) \ struct lockdep_map __maybe_unused _name =3D {} =20 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index e85b5ad3e206..38924d90da85 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -6599,6 +6599,26 @@ void debug_check_no_locks_held(void) } EXPORT_SYMBOL_GPL(debug_check_no_locks_held); =20 +#ifdef CONFIG_LOCKDEP +int lock_class_is_held(struct lock_class_key *key) +{ + struct task_struct *curr =3D current; + struct held_lock *hlock; + + if (unlikely(!debug_locks)) + return 0; + + for (hlock =3D curr->held_locks; + hlock < curr->held_locks + curr->lockdep_depth; + hlock++) + if (hlock->instance->key =3D=3D key) + return 1; + + return 0; +} +EXPORT_SYMBOL_GPL(lock_class_is_held); +#endif + #ifdef __KERNEL__ void debug_show_all_locks(void) { --=20 2.42.0 From nobody Wed Dec 17 19:00:28 2025 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 06EFEC61D9C for ; Wed, 22 Nov 2023 23:51:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344564AbjKVXvg (ORCPT ); Wed, 22 Nov 2023 18:51:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344360AbjKVXv3 (ORCPT ); Wed, 22 Nov 2023 18:51:29 -0500 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [IPv6:2001:41d0:1004:224b::b9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90CF9D4F for ; Wed, 22 Nov 2023 15:51:24 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1700697082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y3qE5L5il8oDBhTKLnVCOy7OUHgjPevBShUas5ZH1Uk=; b=PSpl6a2Zn3bHbuRpI4sK9uJeQj6AFlJEZASfU5Qpttm5GrpJ+f55ILGueeFwrtwhqK5LNP DGzHzzi8BQZ64w2qUHAIGtWTvMKY0buy182Q4yhvJQE9lW6iu5dj1znEJcev2Ve3xWbxJ4 GhMoEm1YIGi13AzGERbtWk0X7yg9qgA= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org, peterz@infradead.org Cc: boqun.feng@gmail.com, longman@redhat.com, will@kernel.org, mingo@redhat.com, Kent Overstreet Subject: [PATCH 2/6] locking/lockdep: lockdep_set_no_check_recursion() Date: Wed, 22 Nov 2023 18:51:09 -0500 Message-ID: <20231122235113.180132-3-kent.overstreet@linux.dev> In-Reply-To: <20231122235113.180132-1-kent.overstreet@linux.dev> References: <20231122235113.180132-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This adds a method to tell lockdep not to check lock ordering within a lock class - but to still check lock ordering w.r.t. other lock types. This is for bcachefs, where for btree node locks we have our own deadlock avoidance strategy w.r.t. other btree node locks (cycle detection), but we still want lockdep to check lock ordering w.r.t. other lock types. Signed-off-by: Kent Overstreet Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng --- include/linux/lockdep.h | 6 ++++++ include/linux/lockdep_types.h | 2 +- kernel/locking/lockdep.c | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index fc86557d2a21..1bc7eb7cb548 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -700,4 +700,10 @@ lockdep_rcu_suspicious(const char *file, const int lin= e, const char *s) } #endif =20 +#ifdef CONFIG_DEBUG_LOCK_ALLOC +void lockdep_set_no_check_recursion(struct lockdep_map *map); +#else +static inline void lockdep_set_no_check_recursion(struct lockdep_map *map)= {} +#endif + #endif /* __LINUX_LOCKDEP_H */ diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h index 2ebc323d345a..aa6bddac2a64 100644 --- a/include/linux/lockdep_types.h +++ b/include/linux/lockdep_types.h @@ -137,7 +137,7 @@ struct lock_class { u8 wait_type_inner; u8 wait_type_outer; u8 lock_type; - /* u8 hole; */ + u8 no_check_recursion; =20 #ifdef CONFIG_LOCK_STAT unsigned long contention_point[LOCKSTAT_POINTS]; diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 38924d90da85..50a0a1ea960a 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3048,6 +3048,9 @@ check_deadlock(struct task_struct *curr, struct held_= lock *next) =20 class =3D hlock_class(prev); =20 + if (class->no_check_recursion) + continue; + if (class->cmp_fn && class->cmp_fn(prev->instance, next->instance) < 0) continue; @@ -3113,6 +3116,10 @@ check_prev_add(struct task_struct *curr, struct held= _lock *prev, return 2; } =20 + if (hlock_class(prev) =3D=3D hlock_class(next) && + hlock_class(prev)->no_check_recursion) + return 2; + if (prev->class_idx =3D=3D next->class_idx) { struct lock_class *class =3D hlock_class(prev); =20 @@ -6732,3 +6739,22 @@ void lockdep_rcu_suspicious(const char *file, const = int line, const char *s) warn_rcu_exit(rcu); } EXPORT_SYMBOL_GPL(lockdep_rcu_suspicious); + +#ifdef CONFIG_DEBUG_LOCK_ALLOC +void lockdep_set_no_check_recursion(struct lockdep_map *lock) +{ + struct lock_class *class =3D lock->class_cache[0]; + unsigned long flags; + + raw_local_irq_save(flags); + lockdep_recursion_inc(); + + if (!class) + class =3D register_lock_class(lock, 0, 0); + if (class) + class->no_check_recursion =3D true; + lockdep_recursion_finish(); + raw_local_irq_restore(flags); +} +EXPORT_SYMBOL_GPL(lockdep_set_no_check_recursion); +#endif --=20 2.42.0 From nobody Wed Dec 17 19:00:28 2025 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 EDE6EC27C40 for ; Wed, 22 Nov 2023 23:51:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344693AbjKVXvo (ORCPT ); Wed, 22 Nov 2023 18:51:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344329AbjKVXva (ORCPT ); Wed, 22 Nov 2023 18:51:30 -0500 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [IPv6:2001:41d0:1004:224b::b3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5216D48 for ; Wed, 22 Nov 2023 15:51:25 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1700697083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PQGfV5VFS8au12LjZrtn8b0tQCOSeXkZ0y56kHJB+7I=; b=Gkx0au90LBttGhlIOAWaKQXy840wWFJArUBU8DkUm5weTz2lBNPc+5O4eonDS+b2QvpRVB lmAvC4PyRvLCKooJw8qaVQU41lyf70kDpt1QH8LZpz8KcMUUgJ8X61QuEVD0QkUt317XXV r1VDWme5nBnBgEfKgUfWZtcGwdtF1No= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org, peterz@infradead.org Cc: boqun.feng@gmail.com, longman@redhat.com, will@kernel.org, mingo@redhat.com, Kent Overstreet , Kent Overstreet Subject: [PATCH 3/6] bcachefs: Assert that btree node locks aren't being leaked Date: Wed, 22 Nov 2023 18:51:10 -0500 Message-ID: <20231122235113.180132-4-kent.overstreet@linux.dev> In-Reply-To: <20231122235113.180132-1-kent.overstreet@linux.dev> References: <20231122235113.180132-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This asserts (when lockdep is enabled) that btree locks aren't held when exiting a btree_trans. Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_gc.c | 3 +++ fs/bcachefs/btree_locking.c | 7 +++++++ fs/bcachefs/btree_types.h | 1 + 3 files changed, 11 insertions(+) diff --git a/fs/bcachefs/btree_gc.c b/fs/bcachefs/btree_gc.c index 136df94e9f84..7e5d52f8ffd7 100644 --- a/fs/bcachefs/btree_gc.c +++ b/fs/bcachefs/btree_gc.c @@ -1087,6 +1087,9 @@ static int bch2_gc_btrees(struct bch_fs *c, bool init= ial, bool metadata_only) unsigned i; int ret =3D 0; =20 + if (initial) + trans->is_initial_gc =3D true; + for (i =3D 0; i < BTREE_ID_NR; i++) ids[i] =3D i; bubble_sort(ids, BTREE_ID_NR, btree_id_gc_phase_cmp); diff --git a/fs/bcachefs/btree_locking.c b/fs/bcachefs/btree_locking.c index 6039278121dc..308c891ad3ca 100644 --- a/fs/bcachefs/btree_locking.c +++ b/fs/bcachefs/btree_locking.c @@ -751,6 +751,13 @@ void bch2_trans_unlock(struct btree_trans *trans) =20 trans_for_each_path(trans, path) __bch2_btree_path_unlock(trans, path); + + /* + * bch2_gc_btree_init_recurse() doesn't use btree iterators for walking + * btree nodes, it implements its own walking: + */ + if (!trans->is_initial_gc) + bch2_assert_btree_nodes_not_locked(); } =20 void bch2_trans_unlock_long(struct btree_trans *trans) diff --git a/fs/bcachefs/btree_types.h b/fs/bcachefs/btree_types.h index ca7526603d06..2326bceb34f8 100644 --- a/fs/bcachefs/btree_types.h +++ b/fs/bcachefs/btree_types.h @@ -399,6 +399,7 @@ struct btree_trans { bool memory_allocation_failure:1; bool journal_transaction_names:1; bool journal_replay_not_finished:1; + bool is_initial_gc:1; bool notrace_relock_fail:1; bool write_locked:1; enum bch_errcode restarted:16; --=20 2.42.0 From nobody Wed Dec 17 19:00:28 2025 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 A747DC27C40 for ; Wed, 22 Nov 2023 23:51:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344686AbjKVXvk (ORCPT ); Wed, 22 Nov 2023 18:51:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344340AbjKVXva (ORCPT ); Wed, 22 Nov 2023 18:51:30 -0500 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91A381B6 for ; Wed, 22 Nov 2023 15:51:26 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1700697085; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c+NluGMH3ACG9C4v9tyqVQmooH2gf0OtbH4WLDdZuu0=; b=BJsnfUsB9ZLj8D6Kc7ijV5SCXDed20HLPXGuLTFxO8HCXbfj4PZyhQtvTG7tbFUx8tPTOF rTLXP125eU5rcyA+YdX/EbKGzKIozsWvGKwF5gD6mq4y0PelGref6XbkacJM0MZJlRTy2m CZJaVNKT/DluYq8juvZ9fNIjz/meEqE= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org, peterz@infradead.org Cc: boqun.feng@gmail.com, longman@redhat.com, will@kernel.org, mingo@redhat.com, Kent Overstreet Subject: [PATCH 4/6] bcachefs: Use lock_class_is_held() for btree locking asserts Date: Wed, 22 Nov 2023 18:51:11 -0500 Message-ID: <20231122235113.180132-5-kent.overstreet@linux.dev> In-Reply-To: <20231122235113.180132-1-kent.overstreet@linux.dev> References: <20231122235113.180132-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_locking.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/bcachefs/btree_locking.c b/fs/bcachefs/btree_locking.c index 308c891ad3ca..ef84b0423deb 100644 --- a/fs/bcachefs/btree_locking.c +++ b/fs/bcachefs/btree_locking.c @@ -16,10 +16,7 @@ void bch2_btree_lock_init(struct btree_bkey_cached_commo= n *b, #ifdef CONFIG_LOCKDEP void bch2_assert_btree_nodes_not_locked(void) { -#if 0 - //Re-enable when lock_class_is_held() is merged: BUG_ON(lock_class_is_held(&bch2_btree_node_lock_key)); -#endif } #endif =20 --=20 2.42.0 From nobody Wed Dec 17 19:00:28 2025 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 D91F5C61D99 for ; Wed, 22 Nov 2023 23:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344643AbjKVXvr (ORCPT ); Wed, 22 Nov 2023 18:51:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344371AbjKVXvc (ORCPT ); Wed, 22 Nov 2023 18:51:32 -0500 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15E491BD for ; Wed, 22 Nov 2023 15:51:28 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1700697086; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mEe01vZuhBVMx1XKVOUDl8ZkWzcchWHj6fYWExZ3dxw=; b=V6veXK29OF4QzImU3qPeNiZFjp8cdDseuoLawYjpHYCdoJYo7Ez+Yvnu/MgU14yaARHHzC yRRj5USqShi96DsHsjjQcaBwAK0Qgxx8uIL3Nu/l9tmExmUbt4qUVdhcdxaPOWDvm0YARv 1907QwNn4icUGogbi1AF03BUxR5jYqc= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org, peterz@infradead.org Cc: boqun.feng@gmail.com, longman@redhat.com, will@kernel.org, mingo@redhat.com, Kent Overstreet , Kent Overstreet Subject: [PATCH 5/6] bcachefs: Check for btree locks held on transaction init Date: Wed, 22 Nov 2023 18:51:12 -0500 Message-ID: <20231122235113.180132-6-kent.overstreet@linux.dev> In-Reply-To: <20231122235113.180132-1-kent.overstreet@linux.dev> References: <20231122235113.180132-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kent Overstreet Ideally we would disallow multiple btree_trans being initialized within the same process - and hopefully we will at some point, the stack usage is excessive - but for now there are a couple places where we do this: - transaction commit error path -> journal reclaim - btree key cache flush - move data path -> do_pending_writes -> write path -> bucket allocation (in the near future when bucket allocation switches to using a freespace btree) In order to avoid deadlocking the first btree_trans must have been unlocked with bch2_trans_unlock() before using the second btree_trans - this patch adds an assertion to bch2_trans_init() that verifies that this has been done when lockdep is enabled. Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_iter.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index 1d734e297eb4..a52fd206f822 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -2854,6 +2854,8 @@ struct btree_trans *__bch2_trans_get(struct bch_fs *c= , unsigned fn_idx) struct btree_trans *trans; struct btree_transaction_stats *s; =20 + bch2_assert_btree_nodes_not_locked(); + trans =3D bch2_trans_alloc(c); =20 memset(trans, 0, sizeof(*trans)); --=20 2.42.0 From nobody Wed Dec 17 19:00:28 2025 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 D60C7C27C40 for ; Wed, 22 Nov 2023 23:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344507AbjKVXvv (ORCPT ); Wed, 22 Nov 2023 18:51:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344503AbjKVXve (ORCPT ); Wed, 22 Nov 2023 18:51:34 -0500 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF7931B9 for ; Wed, 22 Nov 2023 15:51:28 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1700697087; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Myq1bmeGBQIlDgNEhC6NfEwTgajaz4KUdFS8x/+ovE0=; b=A6re6fRtOjUFuLPZzy5AdlBTwdRPq7aLxjX6JGSBeKgnLzPIC/GD5yVCd0FuncsK/NGqOp 7tuaaJJEUaw9FtVUiLOsADzufm1rX2U9EunUFQgJ1EW5LuRubvAKm9IXTo+TkZIcY5CZWA IiqZmoHO5PULFkkEhUpY6ZlHc4YKmEY= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org, peterz@infradead.org Cc: boqun.feng@gmail.com, longman@redhat.com, will@kernel.org, mingo@redhat.com, Kent Overstreet Subject: [PATCH 6/6] bcachefs: Switch to lockdep_set_no_check_recursion() Date: Wed, 22 Nov 2023 18:51:13 -0500 Message-ID: <20231122235113.180132-7-kent.overstreet@linux.dev> In-Reply-To: <20231122235113.180132-1-kent.overstreet@linux.dev> References: <20231122235113.180132-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_locking.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/bcachefs/btree_locking.c b/fs/bcachefs/btree_locking.c index ef84b0423deb..59c57c585a4c 100644 --- a/fs/bcachefs/btree_locking.c +++ b/fs/bcachefs/btree_locking.c @@ -10,7 +10,9 @@ void bch2_btree_lock_init(struct btree_bkey_cached_common= *b, enum six_lock_init_flags flags) { __six_lock_init(&b->lock, "b->c.lock", &bch2_btree_node_lock_key, flags); - lockdep_set_novalidate_class(&b->lock); +#ifdef CONFIG_DEBUG_LOCK_ALLOC + lockdep_set_no_check_recursion(&b->lock.dep_map); +#endif } =20 #ifdef CONFIG_LOCKDEP --=20 2.42.0