From nobody Fri Dec 19 17:20:13 2025 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B775A27F16F; Mon, 19 May 2025 09:19:00 +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=1747646344; cv=none; b=gZxJE5JaBNGI878e0XBsLcXsCuVZR8G1690Vo9jmcZ2+OVgInDNVrM1TZih3jX9ZiZqUEAsPynmvAEUA7Asd3mJBk6KcGKuYYxoA7n60cDSpB8ztUa/z/nQ/5dD3vJjShSbfI4sOvm4A67k2PjNbCOVCGzh1isAB6T1l+59ALPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747646344; c=relaxed/simple; bh=96XOFp5m0WCi1dCnE/wsAjz4TPWG2W3rMJRjru4SmyI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=kpE/U/tEedGiUnIvc/XzZlI9JOZLtyqWrbzdL+zC2ZvvbnZVmFjxG+StiS+byrfBEAgTa0NwgWAdQUbe6SiPAD5z5MdepZPGt6eOK6EcKUS5HcysWzI7w8W0TW5iQC+S1cbOQFjhV760exPj9qFgxhKVPvN8yXqIY78BelmXQ2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=none (p=none dis=none) header.from=sk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sk.com X-AuditID: a67dfc5b-681ff7000002311f-d8-682af770b4b4 From: Byungchul Park To: linux-kernel@vger.kernel.org Cc: 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, max.byungchul.park@gmail.com, boqun.feng@gmail.com, longman@redhat.com, yskelg@gmail.com, yunseong.kim@ericsson.com, yeoreum.yun@arm.com, netdev@vger.kernel.org, matthew.brost@intel.com, her0gyugyu@gmail.com Subject: [PATCH v16 33/42] dept: make dept aware of lockdep_set_lock_cmp_fn() annotation Date: Mon, 19 May 2025 18:18:17 +0900 Message-Id: <20250519091826.19752-34-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20250519091826.19752-1-byungchul@sk.com> References: <20250519091826.19752-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWSW0xTaRDH/c7lO4dqzdku6lE3izZhVTZeMGImUdl9Mftll41GJTH6oFVO bCM3C3IxMaGC2i2CrHJbBCzFHLFUxZYooiVAFUSDVoWCpKISY8SCJGirSNUtGF8mv8zM/zcv w9OqTnYBr0tOl/TJmkQ1VjCK0Vk1y1M/RGlXl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HRHSVyZf5699ryf5/X88zC45CY5h1HExAnK GFmUlBIRop0B6uWxP3zlq7QFHDhHtAQUVpooaK4oQ2C6nYLBwKMgeO0aQvCr6TkOeTnNCEr6 enC4be9FYDWcpaDl/QxodQ5T0JiTToH6WiUFLwbHMejOzcagzLwD3ugdBDy9WIpB3gAFBXlq zF0+YjCqN9KgT/aGfsMVGsb7/KCxt40EW1EjCdbOpXC5uJuCGmsjAfbqfgxa7hdS0Gv6Q8JT +2MCXJlzoTkrg4TyL6UUDLr0OOidwzS8rNNhYNfNgqpUt/Xc9wkSGjLqMDh3/RYGrR0PENRq 32JgNrVRYHMOYWAx5+AwduMRgv7MzzRoLozSUJCSiSBdk0tAarc//Prpvlw04gcpV6sIKP/d hjYF8qZiE+JtQ8M4n2o5yY85X1G81aUj+CelHH/vSg/Np9Z20rzOfIK3GHz5azUDGF/yzUny ZuN5ijd/y6b5tM+tGP/l2TM6bF64aH2kEKWIF5QrAyNE8vxeNRmb75NQZLRRyahwfhryZDh2 NdcweIGeZIr14drbR/FJ9mIXcJYMB5mGRAzOtk3jXhd1oMlgJruPqy59NcUE681datK6FxhG zK7hHt8N/eecz5VV1U15PN3tznTb1LiE9eday4qJi0ikQx5G5KWIiY+WKaL8V6iOyhNjFAkr Dh+LNiP3A+nPjGdVo5GWoHrEMkg6XVxlXSKXkLJ4VWJ0PeIYXOolNloWyyXiSFniKUF57JDy RJSgqkdzGUI6W7x9rxAhYY/I4oSjghArKP+nGOM5JxkFb/bY5VO3hzFpsiO8A+4z9gPH54k6 dnSpFzmR77Kur8MVW2rbsXfrloX+mdjY44i0ZHW81YwlPUxezR5vyWlgTksfnG33qOgqNGTu 3+C/7YDLGhdcc4qmtUGVCzUGmTYpLMw+IdrtsJeEircOhNjupHxtcoSs/bDHue2gsS/8k5RQ yWV+vrhSJfsLLmraaTwDAAA= X-CFilter-Loop: Reflected Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 b6dc4ff19537..8b4d97fc4627 100644 --- a/include/linux/dept.h +++ b/include/linux/dept.h @@ -130,6 +130,11 @@ struct dept_map { const char *name; struct dept_key *keys; =20 + /* + * keep lockdep map to handle lockdep_set_lock_cmp_fn(). + */ + void *lockdep_map; + /* * subclass that can be set from user */ @@ -156,6 +161,7 @@ struct dept_map { { \ .name =3D #n, \ .keys =3D (struct dept_key *)(k), \ + .lockdep_map =3D NULL, \ .sub_u =3D 0, \ .map_key =3D { .classes =3D { NULL, } }, \ .wgen =3D 0U, \ @@ -427,6 +433,8 @@ extern void dept_softirqs_on_ip(unsigned long ip); extern void dept_hardirqs_on(void); extern void dept_softirqs_off(void); extern void dept_hardirqs_off(void); + +#define dept_set_lockdep_map(m, lockdep_m) ({ (m)->lockdep_map =3D lockdep= _m; }) #else /* !CONFIG_DEPT */ struct dept_key { }; struct dept_map { }; @@ -469,5 +477,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 dc3effabfab4..b154c1bb4ee5 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); } =20 -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 =3D (struct lockdep_map *)prev->lockdep_map; + struct lockdep_map *n_lock =3D (struct lockdep_map *)next->lockdep_map; + struct lock_class *p_class =3D p_lock ? p_lock->class_cache[0] : NULL; + struct lock_class *n_class =3D n_lock ? n_lock->class_cache[0] : NULL; + + if (!p_class || !n_class) + return false; + + if (p_class !=3D 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 =3D 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; =20 - if (eh->ecxt->class !=3D c || eh->sub_l =3D=3D sub_l) - add_dep(eh->ecxt, w); + if (eh->ecxt->class =3D=3D c && eh->sub_l !=3D sub_l) + continue; + + if (i =3D=3D dt->ecxt_held_pos - 1 && lockdep_cmp_fn(eh->map, m)) + continue; + + add_dep(eh->ecxt, w); } =20 wg =3D next_wgen(); @@ -2145,6 +2180,7 @@ void dept_map_init(struct dept_map *m, struct dept_ke= y *k, int sub_u, m->name =3D n; m->wgen =3D 0U; m->nocheck =3D !valid_key(k); + m->lockdep_map =3D NULL; =20 dept_exit_recursive(flags); } @@ -2366,7 +2402,7 @@ static void __dept_wait(struct dept_map *m, unsigned = long w_f, if (!c) continue; =20 - add_wait(c, ip, w_fn, sub_l, sched_sleep, timeout); + add_wait(m, c, ip, w_fn, sub_l, sched_sleep, timeout); } } =20 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index d2805ce250cb..acab023eb015 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -5036,6 +5036,7 @@ void lockdep_set_lock_cmp_fn(struct lockdep_map *lock= , lock_cmp_fn cmp_fn, class->print_fn =3D print_fn; } =20 + dept_set_lockdep_map(&lock->dmap, lock); lockdep_recursion_finish(); raw_local_irq_restore(flags); } --=20 2.17.1