From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A68973E8346; Mon, 6 Jul 2026 06:21:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.125.252.92 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783318889; cv=none; b=o88Cw9cnEuU6XiXNH8TOtgxASx82d3iTHuH/u6C4C5FQcXxuhSfcxylqEeHBBV2qmrokVIQcHJDSswUsodQdY4HyM7WaPrPEHeEvzZGnqfqazvHzqyu1eeuVp54f/ewyMyGePNUWAFSmCqquDykgCpo0DSCbtTYcjKy//v6NEp8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783318889; c=relaxed/simple; bh=3ChC4SyDlXiXdXOWVfnb/g6ALQ0lSSP8kJq96KetFjs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=HiXwv6TFGltutjBQ7sjESmXAr5+jGKDmXDsomJbVkvTx3j07s7EdHMAEkDxFstnk5vMeoL6l6nTN4JmVgB+Xx6ZmwWcGrW7H+F0yMPFALbDnmTzArj6BcnfrlAdhUBVFxbMYuBbovFHVBNbCYBGrcp97mZDf8/ZrQZKacvu6F/s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sk.com; spf=pass smtp.mailfrom=sk.com; arc=none smtp.client-ip=166.125.252.92 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sk.com X-AuditID: a67dfc5b-c2dff70000001609-b4-6a4b4904580f From: Byungchul Park To: linux-kernel@vger.kernel.org Cc: max.byungchul.park@gmail.com, kernel_team@skhynix.com, torvalds@linux-foundation.org, damien.lemoal@opensource.wdc.com, linux-ide@vger.kernel.org, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, will@kernel.org, tglx@linutronix.de, rostedt@goodmis.org, joel@joelfernandes.org, sashal@kernel.org, daniel.vetter@ffwll.ch, duyuyang@gmail.com, johannes.berg@intel.com, tj@kernel.org, tytso@mit.edu, willy@infradead.org, david@fromorbit.com, amir73il@gmail.com, gregkh@linuxfoundation.org, kernel-team@lge.com, linux-mm@kvack.org, akpm@linux-foundation.org, mhocko@kernel.org, minchan@kernel.org, hannes@cmpxchg.org, vdavydov.dev@gmail.com, sj@kernel.org, jglisse@redhat.com, dennis@kernel.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, vbabka@suse.cz, ngupta@vflare.org, linux-block@vger.kernel.org, josef@toxicpanda.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, jlayton@kernel.org, dan.j.williams@intel.com, hch@infradead.org, djwong@kernel.org, dri-devel@lists.freedesktop.org, rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, hamohammed.sa@gmail.com, harry.yoo@oracle.com, chris.p.wilson@intel.com, gwan-gyeong.mun@intel.com, boqun.feng@gmail.com, longman@redhat.com, yunseong.kim@ericsson.com, ysk@kzalloc.com, yeoreum.yun@arm.com, netdev@vger.kernel.org, matthew.brost@intel.com, her0gyugyu@gmail.com, corbet@lwn.net, catalin.marinas@arm.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, luto@kernel.org, sumit.semwal@linaro.org, gustavo@padovan.org, christian.koenig@amd.com, andi.shyti@kernel.org, arnd@arndb.de, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, rppt@kernel.org, surenb@google.com, mcgrof@kernel.org, petr.pavlu@suse.com, da.gomez@kernel.org, samitolvanen@google.com, paulmck@kernel.org, frederic@kernel.org, neeraj.upadhyay@kernel.org, joelagnelf@nvidia.com, josh@joshtriplett.org, urezki@gmail.com, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, qiang.zhang@linux.dev, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, chuck.lever@oracle.com, neil@brown.name, okorniev@redhat.com, Dai.Ngo@oracle.com, tom@talpey.com, trondmy@kernel.org, anna@kernel.org, kees@kernel.org, bigeasy@linutronix.de, clrkwllms@kernel.org, mark.rutland@arm.com, ada.coupriediaz@arm.com, kristina.martsenko@arm.com, wangkefeng.wang@huawei.com, broonie@kernel.org, kevin.brodsky@arm.com, dwmw@amazon.co.uk, shakeel.butt@linux.dev, ast@kernel.org, ziy@nvidia.com, yuzhao@google.com, baolin.wang@linux.alibaba.com, usamaarif642@gmail.com, joel.granados@kernel.org, richard.weiyang@gmail.com, geert+renesas@glider.be, tim.c.chen@linux.intel.com, linux@treblig.org, alexander.shishkin@linux.intel.com, lillian@star-ark.net, chenhuacai@kernel.org, francesco@valla.it, guoweikang.kernel@gmail.com, link@vivo.com, jpoimboe@kernel.org, masahiroy@kernel.org, brauner@kernel.org, thomas.weissschuh@linutronix.de, oleg@redhat.com, mjguzik@gmail.com, andrii@kernel.org, wangfushuai@baidu.com, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-i2c@vger.kernel.org, linux-arch@vger.kernel.org, linux-modules@vger.kernel.org, rcu@vger.kernel.org, linux-nfs@vger.kernel.org, linux-rt-devel@lists.linux.dev, 2407018371@qq.com, dakr@kernel.org, miguel.ojeda.sandonis@gmail.com, neilb@ownmail.net, bagasdotme@gmail.com, wsa+renesas@sang-engineering.com, dave.hansen@intel.com, geert@linux-m68k.org, ojeda@kernel.org, alex.gaynor@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, rust-for-linux@vger.kernel.org Subject: [PATCH v19 29/40] dept: make dept aware of lockdep_set_lock_cmp_fn() annotation Date: Mon, 6 Jul 2026 15:19:17 +0900 Message-Id: <20260706061928.66713-30-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260706061928.66713-1-byungchul@sk.com> References: <20260706061928.66713-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWSbUxTZxTHfe597ks7G28q0Tt0wzUR0cQyNjBnyaJEk3mFkZD4xYwPoxlX KQKSggyWbOKkikWapoTiFLTdpAotpamwAoovIIhkYUy25Iqi7TZRlLcUqgIVLBC//XL+5//L +XBYUilRkaw2t0DU5WqyVbQcy8dX27ZT+5KzPv3DGA9l+mNQ0+SkYcDlQKBvW8Tw1tzDwMzs QwYWO3oQWP4ykyAN3CRh2r1Aw8uuAIJzI+fD6fAzAuz/LxDw1nIYXlqmaAiM+hA8NbWQcK+q nIYJNw0jQx0EWGo9GNp87Qw4PCnwxD6CoXqUhvPVJwioarxGwKy9gQF7yWYI+ePANf4nBd4S HwO2k5cwXO+4h2GwvYaGx85FCpqeSQT4fRIFkukpgsaJX2l4UD0WrgcnGbh/y0pAj3UdtNzU I6ibmSDhRpmPgDtNXgLqroxT0BUcI6DyvpWGueFWCvrm+gj41zjOQFWoLHzScSOCcr0FQ+mj BDD274U37v8oqJ2JgxlHQzjvfswkJgqv9UYsOC84kTA/Z0ZC19gkKbSdG2aE0htDjGD1HBV+ uz5KCLZAkBI8DadpwRMwM4Jt/jkpTPT3M0Lv2XksdHaVIaHN/0Xqx9/Iv8wQs7WFoi52Z7o8 88wDL5U3F11Ud+00LkE/RxmQjOW5eP5UuYN4z8NVF5eZ5rbwkjRLLnEEt4m/WjFCGZCcJbnB KP6MvQIbEMuu5Q7wTS2xSzuY28xbXlTSS6zgdvCLwUvkijOKd7hvLbMsPHeFapf9Si6Bfzh5 Fy85ec4h4483NjMrhQ/521ckbEIKK1rVgJTa3MIcjTY7Xp1ZnKstUn93JMeDwv9m/zGU1ooC A/s7Ecci1WoFJCZlKSlNYX5xTifiWVIVoYiOSc5SKjI0xT+IuiPf6o5mi/mdaAOLVesVn736 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S6hHHIPlMKazdlCqTKDK1+rR6xDOk PFo6f8HmVJl0r0J/VNQc2K05rBa19SiWwfI50k07xGQZt19xSFSJYoao+X9KMFExWcjSsLhT FU6tIWdkGT/H599Xzx2x6ra1qupikxrXXI1t31By0KAfowKMacsd57zVGXovvy50/5wOxWgV U41LY5K17c89H7p86z9KvxTWsrrzCa6t233O3u/0gyvsiGfXfyczRxZee5vXui3uYH38w4L9 ucf2zaTZx8HtQx5Pu9svx9oUxZI/SY1W8RNXjqH7SgMAAA== X-CFilter-Loop: Reflected Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: commit eb1cfd09f788e ("lockdep: Add lock_set_cmp_fn() annotation") has been added to address the issue that lockdep was not able to detect a true deadlock like the following: https://lore.kernel.org/lkml/20220510232633.GA18445@X58A-UD3R/ The approach is only for lockdep but dept should work being aware of it because the new annotation is already used to avoid false positive of lockdep in the code. Make dept aware of the new lockdep annotation. Signed-off-by: Byungchul Park --- include/linux/dept.h | 10 +++++++++ kernel/dependency/dept.c | 48 +++++++++++++++++++++++++++++++++++----- kernel/locking/lockdep.c | 1 + 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/include/linux/dept.h b/include/linux/dept.h index 827ccc1890d1..f3cc7566ddf2 100644 --- a/include/linux/dept.h +++ b/include/linux/dept.h @@ -53,6 +53,11 @@ struct dept_map { const char *name; struct dept_key *keys; + /* + * keep lockdep map to handle lockdep_set_lock_cmp_fn(). + */ + void *lockdep_map; + /* * subclass that can be set from user */ @@ -79,6 +84,7 @@ struct dept_map { { \ .name = #n, \ .keys = (struct dept_key *)(k), \ + .lockdep_map = NULL, \ .sub_u = 0, \ .map_key = { .classes = { NULL, } }, \ .wgen = 0U, \ @@ -179,6 +185,8 @@ void dept_softirqs_on_ip(unsigned long ip); void dept_hardirqs_on(void); void dept_softirqs_off(void); void dept_hardirqs_off(void); + +#define dept_set_lockdep_map(m, lockdep_m) ({ (m)->lockdep_map = lockdep_m; }) #else /* !CONFIG_DEPT */ struct dept_key { }; struct dept_map { }; @@ -221,5 +229,7 @@ struct dept_ext_wgen { }; #define dept_hardirqs_on() do { } while (0) #define dept_softirqs_off() do { } while (0) #define dept_hardirqs_off() do { } while (0) + +#define dept_set_lockdep_map(m, lockdep_m) do { } while (0) #endif #endif /* __LINUX_DEPT_H */ diff --git a/kernel/dependency/dept.c b/kernel/dependency/dept.c index 5bf32633e1fb..048348ea64d2 100644 --- a/kernel/dependency/dept.c +++ b/kernel/dependency/dept.c @@ -1615,9 +1615,39 @@ static int next_wgen(void) return atomic_inc_return(&wgen) ?: atomic_inc_return(&wgen); } -static void add_wait(struct dept_class *c, unsigned long ip, - const char *w_fn, int sub_l, bool sched_sleep, - bool timeout) +/* + * XXX: This is a temporary patch needed until lockdep stops tracking + * dependency in wrong way. lockdep has added an annotation to specify + * a callback to determin whether the given lock aquisition order is + * okay or not in its own way. Even though dept is already working + * correctly with sub class on that issue, it needs to be aware of the + * annotation anyway. + */ +static bool lockdep_cmp_fn(struct dept_map *prev, struct dept_map *next) +{ + /* + * Assumes the cmp_fn thing comes from struct lockdep_map. + */ + struct lockdep_map *p_lock = (struct lockdep_map *)prev->lockdep_map; + struct lockdep_map *n_lock = (struct lockdep_map *)next->lockdep_map; + struct lock_class *p_class = p_lock ? p_lock->class_cache[0] : NULL; + struct lock_class *n_class = n_lock ? n_lock->class_cache[0] : NULL; + + if (!p_class || !n_class) + return false; + + if (p_class != n_class) + return false; + + if (!p_class->cmp_fn) + return false; + + return p_class->cmp_fn(p_lock, n_lock) < 0; +} + +static void add_wait(struct dept_map *m, struct dept_class *c, + unsigned long ip, const char *w_fn, int sub_l, + bool sched_sleep, bool timeout) { struct dept_task *dt = dept_task(); struct dept_wait *w; @@ -1658,8 +1688,13 @@ static void add_wait(struct dept_class *c, unsigned long ip, if (!eh->ecxt) continue; - if (eh->ecxt->class != c || eh->sub_l == sub_l) - add_dep(eh->ecxt, w); + if (eh->ecxt->class == c && eh->sub_l != sub_l) + continue; + + if (i == dt->ecxt_held_pos - 1 && lockdep_cmp_fn(eh->map, m)) + continue; + + add_dep(eh->ecxt, w); } wg = next_wgen(); @@ -2145,6 +2180,7 @@ void dept_map_init(struct dept_map *m, struct dept_key *k, int sub_u, m->name = n; m->wgen = 0U; m->nocheck = !valid_key(k); + m->lockdep_map = NULL; dept_exit_recursive(flags); } @@ -2366,7 +2402,7 @@ static void __dept_wait(struct dept_map *m, unsigned long w_f, if (!c) continue; - add_wait(c, ip, w_fn, sub_l, sched_sleep, timeout); + add_wait(m, c, ip, w_fn, sub_l, sched_sleep, timeout); } } diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 39b9e3e27c0b..c99f91f7a54d 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -5035,6 +5035,7 @@ void lockdep_set_lock_cmp_fn(struct lockdep_map *lock, lock_cmp_fn cmp_fn, class->print_fn = print_fn; } + dept_set_lockdep_map(&lock->dmap, lock); lockdep_recursion_finish(); raw_local_irq_restore(flags); } -- 2.17.1