DEPT(DEPendency Tracker)
Subsystems (31)
v19 cover DEPT(DEPendency Tracker)
Hi Linus and folks,
DEPT(DEPendency Tracker) is a runtime deadlock detection framework that sees what lockdep cannot.
I'm thrilled to share that DEPT has moved beyond theory and is now catching real deadlocks in the wild:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/all/[email protected]/
I've added comprehensive documentation explaining DEPT's design and usage. Getting started is as simple as enabling CONFIG_DEPT and watching dmesg.
THE PROBLEM LOCKDEP CANNOT SOLVE
--------------------------------
Lockdep has been our trusted deadlock detector for two decades, but it has a fundamental blind spot: it tracks lock acquisition order, not the actual waits and events that cause deadlocks. This means lockdep misses:
* Deadlocks involving folio locks (not released within the context)
* Cross-context synchronization like wait_for_completion()/complete()
* DMA fence waits, RCU waits, and general waitqueue patterns
* Any synchronization primitive outside the classic lock/unlock model
Consider this real deadlock pattern that lockdep cannot detect:
context X context Y context Z
mutex_lock A
folio_lock B
folio_lock B <- DEADLOCK
mutex_lock A <- DEADLOCK folio_unlock B
folio_unlock B
mutex_unlock A
mutex_unlock A
Lockdep sees lock acquisitions. DEPT sees the actual dependency:
"mutex_unlock A in context Y cannot happen until folio_lock B is awakened by the owner's folio_unlock B, and vice versa in context Z."
It's a circular dependency that means deadlock.
THE DEPT APPROACH
-----------------
DEPT asks a simpler question: "What is this context waiting for, and what event will wake it up?"
Every deadlock is fundamentally about unreachable events. DEPT tracks:
[S] Where an event context begins (the code path that will trigger an event)
[W] Where a wait for another event apears between [S] and [E]
[E] Where the event for [S] occurs
By building a dependency graph of "[E] cannot occur until the event that
[W] waits for occurs", DEPT detects circular dependencies regardless of the underlying synchronization primitives involved.
WHAT DEPT BRINGS TO THE TABLE
-----------------------------
* Universal coverage: Works with any wait/event-based synchronization, not just locks
* Correct read-lock handling: No more blind spots for read-side dependencies
* Continuous operation: Unlike lockdep, DEPT keeps running after reports, catching multiple deadlocks in a single session
* Clean annotation API: Simple, intuitive interfaces for subsystem maintainers to refine detection
* Battle-tested: Already catching real deadlocks as the links above demonstrate
FALSE POSITIVES: THE HONEST CONVERSATION
----------------------------------------
Like any powerful detection tool, DEPT faces the false positive challenge. This is not unique to DEPT — lockdep spent years building its annotation infrastructure (lock classes, subclasses, lockdep_map) to separate real bugs from intentional patterns.
DEPT is on the same journey. We have:
* Event site recovery: Declare when an event has fallback paths
* Subclass-based classification: Distinguish per-CPU, per-device, and modality-specific waits
* Page usage tracking: Separate block device mappings from regular file mappings to avoid spurious reports (currently being worked on)
But comprehensive annotation requires subsystem maintainer expertise. This is where I need your help.
THE PATH TO MAINLINE
--------------------
DEPT is marked EXPERIMENTAL in Kconfig for a reason. Like lockdep, it will mature through collaboration:
1. Core framework: Stabilized and ready for review
2. Subsystem pilots: Working with maintainers to add annotations where they matter most (mm, block, drm, networking, ...)
3. Gradual enablement: DEPT and lockdep coexist; DEPT takes over dependency checking when ready
I am not proposing to replace lockdep. Lockdep's lock usage validation remains invaluable. The vision is:
LOCKDEP: Validates correct lock usage
|
vDEPT: Performs dependency checking with full wait/event coverage
WHY MERGE NOW?
--------------
Some might suggest: "Fix all false positives out-of-tree first." But the affected subsystems span the entire kernel. Like lockdep's two-decade annotation journey, DEPT needs mainline visibility for:
* Proper annotation placement (maintainers know their code best)
* Real-world testing across configurations and workloads
* Incremental improvement through community feedback
CONFIG_DEPT is opt-in. It won't affect your default kernel build. But for those debugging complex synchronization issues, DEPT is ready to help today.
ACKNOWLEDGMENTS
---------------
This work would not be possible without:
Harry Yoo <[email protected]>
Gwan-gyeong Mun <[email protected]>
Yunseong Kim <[email protected]>
Yeoreum Yun <[email protected]>
And the countless kernel developers whose lockdep annotations over two decades showed us the path forward.
FAQ
---
Q. Isn't this the cross-release feature that got reverted?
A. Cross-release (commit b09be676e0ff2) attempted to extend lockdep
with wait/event tracking. It found real bugs but introduced false positives that masked further issues. DEPT learns from that experience with a cleaner design and flexible reporting that makes false positives less disruptive.
Q. Why not build DEPT into lockdep?
A. Lockdep is stable, battle-tested code. I chose separation because
while DEPT borrows BFS and hashing ideas, the wait/event model requires rebuilding from scratch. Lockdep was designed for lock acquisition order — retrofitting it would risk its stability.
Q. Will DEPT replace lockdep?
A. No. Lockdep validates correct lock usage — that's not going away.
DEPT supersedes only the dependency-checking logic when mature.
Q. Should we merge DEPT now or wait for more annotations out-of-tree?
A. Now. The annotation journey requires mainline collaboration. Lockdep
didn't become useful overnight — it grew through maintainer contributions. DEPT needs the same path.
Q. What if I enable DEPT and get false positives?
A. That's the point — report them. Work with us to add annotations that
distinguish your intentional patterns from real deadlocks. This is how lockdep became indispensable, and it's how DEPT will too.
GETTING STARTED
---------------
1. Enable CONFIG_DEPT (EXPERIMENTAL)
2. Boot your kernel
3. Check dmesg for DEPT reports
4. Read Documentation/dev-tools/dept.rst for interpretation
DEPT is a tool for understanding your code's synchronization behavior. Even if you never see a deadlock report, the visibility it provides is invaluable.
I look forward to your feedback, patches, and collaboration. Let's make DEPT as indispensable to kernel developers as lockdep has been.
---
Changes from v18:
1. Rebase on v7.0.
2. Add 'Reviewed-by: Jeff Layton <[email protected]>' on 37th patch, 'SUNRPC: relocate struct rcu_head to the first field of struct rpc_xprt'. (thanks to Jeff Layton)
3. Refine and supplement dept documents and comments, and fix typos. (feedbacked by Bagas Sanjaya and Yunseong Kim)
4. Add __rust_helper to rust_helper_wait_for_completion(). (feedbacked by Dirk Behme)
5. Remove the part supporting recover events tracking - I will keep maintaining it out of tree tho - as it unnecessarily complicates the initial DEPT patchset and significantly increases the review burden.
6. Get rid of 'extern' keyword with function declarations. (feedbacked by Petr Pavlu)
Changes from v17:
1. Rebase on the mainline as of 2025 Dec 5.
2. Convert the documents' format from txt to rst. (feedbacked by Jonathan Corbet and Bagas Sanjaya)
3. Move the documents from 'Documentation/dependency' to 'Documentation/dev-tools'. (feedbakced by Jonathan Corbet)
4. Improve the documentation. (feedbacked by NeilBrown)
5. Use a common function, enter_from_user_mode(), instead of arch specific code, to notice context switch from user mode. (feedbacked by Dave Hansen, Mark Rutland, and Mark Brown)
6. Resolve the header dependency issue by using dept's internal header, instead of relocating 'struct llist_{head,node}' to another header. (feedbacked by Greg KH)
7. Improve page(or folio) usage type APIs.
8. Add rust helper for wait_for_completion(). (feedbacked by Guangbo Cui, Boqun Feng, and Danilo Krummrich)
9. Refine some commit messages.
Changes from v16:
1. Rebase on v6.17.
2. Fix a false positive from rcu (by Yunseong Kim)
3. Introduce APIs to set page's usage, dept_set_page_usage() and dept_reset_page_usage() to avoid false positives.
4. Consider lock_page() as a potential wait unconditionally.
5. Consider folio_lock_killable() as a potential wait unconditionally.
6. Add support for tracking PG_writeback waits and events.
7. Fix two build errors due to the additional debug information added by dept. (by Yunseong Kim)
Changes from v15:
1. Fix typo and improve comments and commit messages (feedbacked by ALOK TIWARI, Waiman Long, and kernel test robot).
2. Do not stop dept on detection of cicular dependency of recover event, allowing to keep reporting.
3. Add SK hynix to copyright.
4. Consider folio_lock() as a potential wait unconditionally.
5. Fix Kconfig dependency bug (feedbacked by kernel test rebot).
6. Do not suppress reports that involve classes even that have already involved in other reports, allowing to keep reporting.
Changes from v14:
1. Rebase on the current latest, v6.15-rc6.
2. Refactor dept code.
3. With multi event sites for a single wait, even if an event forms a circular dependency, the event can be recovered by other event(or wake up) paths. Even though informing the circular dependency is worthy but it should be suppressed once informing it, if it doesn't lead an actual deadlock. So introduce APIs to annotate the relationship between event site and recover site, that are, event_site() and dept_recover_event().
4. wait_for_completion() worked with dept map embedded in struct completion. However, it generates a few false positves since all the waits using the instance of struct completion, share the map and key. To avoid the false positves, make it not to share the map and key but each wait_for_completion() caller have its own key by default. Of course, external maps also can be used if needed.
5. Fix a bug about hardirq on/off tracing.
6. Implement basic unit test for dept.
7. Add more supports for dma fence synchronization.
8. Add emergency stop of dept e.g. on panic().
9. Fix false positives by mmu_notifier_invalidate_*().
10. Fix recursive call bug by DEPT_WARN_*() and DEPT_STOP().
11. Fix trivial bugs in DEPT_WARN_*() and DEPT_STOP().
12. Fix a bug that a spin lock, dept_pool_spin, is used in both contexts of irq disabled and enabled without irq disabled.
13. Suppress reports with classes, any of that already have been reported, even though they have different chains but being barely meaningful.
14. Print stacktrace of the wait that an event is now waking up, not only stacktrace of the event.
15. Make dept aware of lockdep_cmp_fn() that is used to avoid false positives in lockdep so that dept can also avoid them.
16. Do do_event() only if there are no ecxts have been delimited.
17. Fix a bug that was not synchronized for stage_m in struct dept_task, using a spin lock, dept_task()->stage_lock.
18. Fix a bug that dept didn't handle the case that multiple ttwus for a single waiter can be called at the same time e.i. a race issue.
19. Distinguish each kernel context from others, not only by system call but also by user oriented fault so that dept can work with more accuracy information about kernel context. That helps to avoid a few false positives.
20. Limit dept's working to x86_64 and arm64.
Changes from v13:
1. Rebase on the current latest version, v6.9-rc7.
2. Add 'dept' documentation describing dept APIs.
Changes from v12:
1. Refine the whole document for dept.
2. Add 'Interpret dept report' section in the document, using a deadlock report obtained in practice. Hope this version of document helps guys understand dept better.
https://lore.kernel.org/lkml/[email protected]/#t
https://lore.kernel.org/lkml/[email protected]/
Changes from v11:
1. Add 'dept' documentation describing the concept of dept.
2. Rewrite the commit messages of the following commits for using weaker lockdep annotation, for better description.
fs/jbd2: Use a weaker annotation in journal handling cpu/hotplug: Use a weaker annotation in AP thread
(feedbacked by Thomas Gleixner)
Changes from v10:
1. Fix noinstr warning when building kernel source.
2. dept has been reporting some false positives due to the folio lock's unfairness. Reflect it and make dept work based on dept annotaions instead of just wait and wake up primitives.
3. Remove the support for PG_writeback while working on 2. I will add the support later if needed.
4. dept didn't print stacktrace for [S] if the participant of a deadlock is not lock mechanism but general wait and event. However, it made hard to interpret the report in that case. So add support to print stacktrace of the requestor who asked the event context to run - usually a waiter of the event does it just before going to wait state.
5. Give up tracking raw_local_irq_{disable,enable}() since it totally messed up dept's irq tracking. So make it work in the same way as lockdep does. I will consider it once any false positives by those are observed again.
6. Change the manual rwsem_acquire_read(->j_trans_commit_map) annotation in fs/jbd2/transaction.c to the try version so that it works as much as it exactly needs.
7. Remove unnecessary 'inline' keyword in dept.c and add '__maybe_unused' to a needed place.
Changes from v9:
1. Fix a bug. SDT tracking didn't work well because of my big mistake that I should've used waiter's map to indentify its class but it had been working with waker's one. FYI, PG_locked and PG_writeback weren't affected. They still worked well. (reported by YoungJun)
Changes from v8:
1. Fix build error by adding EXPORT_SYMBOL(PG_locked_map) and EXPORT_SYMBOL(PG_writeback_map) for kernel module build - appologize for that. (reported by kernel test robot)
2. Fix build error by removing header file's circular dependency that was caused by "atomic.h", "kernel.h" and "irqflags.h", which I introduced - appolgize for that. (reported by kernel test robot)
Changes from v7:
1. Fix a bug that cannot track rwlock dependency properly, introduced in v7. (reported by Boqun and lockdep selftest)
2. Track wait/event of PG_{locked,writeback} more aggressively assuming that when a bit of PG_{locked,writeback} is cleared there might be waits on the bit. (reported by Linus, Hillf and syzbot)
3. Fix and clean bad style code e.i. unnecessarily introduced a randome pattern and so on. (pointed out by Linux)
4. Clean code for applying dept to wait_for_completion().
Changes from v6:
1. Tie to task scheduler code to track sleep and try_to_wake_up() assuming sleeps cause waits, try_to_wake_up()s would be the events that those are waiting for, of course with proper dept annotations, sdt_might_sleep_weak(), sdt_might_sleep_strong() and so on. For these cases, class is classified at sleep entrance rather than the synchronization initialization code. Which would extremely reduce false alarms.
2. Remove the dept associated instance in each page struct for tracking dependencies by PG_locked and PG_writeback thanks to the 1. work above.
3. Introduce CONFIG_dept_AGGRESIVE_TIMEOUT_WAIT to suppress reports that waits with timeout set are involved, for those who don't like verbose reporting.
4. Add a mechanism to refill the internal memory pools on running out so that dept could keep working as long as free memory is available in the system.
5. Re-enable tracking hashed-waitqueue wait. That's going to no longer generate false positives because class is classified at sleep entrance rather than the waitqueue initailization.
6. Refactor to make it easier to port onto each new version of the kernel.
7. Apply dept to dma fence.
8. Do trivial optimizaitions.
Changes from v5:
1. Use just pr_warn_once() rather than WARN_ONCE() on the lack of internal resources because WARN_*() printing stacktrace is too much for informing the lack. (feedback from Ted, Hyeonggon)
2. Fix trivial bugs like missing initializing a struct before using it.
3. Assign a different class per task when handling onstack variables for waitqueue or the like. Which makes dept distinguish between onstack variables of different tasks so as to prevent false positives. (reported by Hyeonggon)
4. Make dept aware of even raw_local_irq_*() to prevent false positives. (reported by Hyeonggon)
5. Don't consider dependencies between the events that might be triggered within __schedule() and the waits that requires __schedule(), real ones. (reported by Hyeonggon)
6. Unstage the staged wait that has prepare_to_wait_event()'ed *and* yet to get to __schedule(), if we encounter __schedule() in-between for another sleep, which is possible if e.g. a mutex_lock() exists in 'condition' of ___wait_event().
7. Turn on CONFIG_PROVE_LOCKING when CONFIG_DEPT is on, to rely on the hardirq and softirq entrance tracing to make dept more portable for now.
Changes from v4:
1. Fix some bugs that produce false alarms.
2. Distinguish each syscall context from another *for arm64*.
3. Make it not warn it but just print it in case dept ring buffer gets exhausted. (feedback from Hyeonggon)
4. Explicitely describe "EXPERIMENTAL" and "dept might produce false positive reports" in Kconfig. (feedback from Ted)
Changes from v3:
1. dept shouldn't create dependencies between different depths of a class that were indicated by *_lock_nested(). dept normally doesn't but it does once another lock class comes in. So fixed it. (feedback from Hyeonggon)
2. dept considered a wait as a real wait once getting to __schedule() even if it has been set to TASK_RUNNING by wake up sources in advance. Fixed it so that dept doesn't consider the case as a real wait. (feedback from Jan Kara)
3. Stop tracking dependencies with a map once the event associated with the map has been handled. dept will start to work with the map again, on the next sleep.
Changes from v2:
1. Disable dept on bit_wait_table[] in sched/wait_bit.c reporting a lot of false positives, which is my fault. Wait/event for bit_wait_table[] should've been tagged in a higher layer for better work, which is a future work. (feedback from Jan Kara)
2. Disable dept on crypto_larval's completion to prevent a false positive.
Changes from v1:
1. Fix coding style and typo. (feedback from Steven)
2. Distinguish each work context from another in workqueue.
3. Skip checking lock acquisition with nest_lock, which is about correct lock usage that should be checked by lockdep.
Changes from RFC(v0):
1. Prevent adding a wait tag at prepare_to_wait() but __schedule(). (feedback from Linus and Matthew)
2. Use try version at lockdep_acquire_cpus_lock() annotation.
3. Distinguish each syscall context from another.
Byungchul Park (39):
dept: implement DEPT(DEPendency Tracker)
dept: add single event dependency tracker APIs
dept: add lock dependency tracker APIs
dept: tie to lockdep and IRQ tracing
dept: add proc knobs to show stats and dependency graph
dept: distinguish each kernel context from another
dept: distinguish each work from another
dept: add a mechanism to refill the internal memory pools on running
out
dept: record the latest one out of consecutive waits of the same class
dept: apply sdt_might_sleep_{start,end}() to
wait_for_completion()/complete()
dept: apply sdt_might_sleep_{start,end}() to swait
dept: apply sdt_might_sleep_{start,end}() to waitqueue wait
dept: apply sdt_might_sleep_{start,end}() to hashed-waitqueue wait
dept: apply sdt_might_sleep_{start,end}() to dma fence
dept: track timeout waits separately with a new Kconfig
dept: apply timeout consideration to wait_for_completion()/complete()
dept: apply timeout consideration to swait
dept: apply timeout consideration to waitqueue wait
dept: apply timeout consideration to hashed-waitqueue wait
dept: apply timeout consideration to dma fence wait
dept: make dept able to work with an external wgen
dept: track PG_locked with dept
dept: print staged wait's stacktrace on report locking/lockdep: prevent various lockdep assertions when
lockdep_off()'ed
dept: add documents for dept
cpu/hotplug: use a weaker annotation in AP thread
dept: assign dept map to mmu notifier invalidation synchronization
dept: assign unique dept_key to each distinct dma fence caller
dept: make dept aware of lockdep_set_lock_cmp_fn() annotation
dept: make dept stop from working on debug_locks_off()
dept: assign unique dept_key to each distinct wait_for_completion()
caller
completion, dept: introduce init_completion_dmap() API
dept: call dept_hardirqs_off() in local_irq_*() regardless of irq
state
dept: introduce APIs to set page usage and use subclasses_evt for the
usage
dept: track PG_writeback with dept
SUNRPC: relocate struct rcu_head to the first field of struct rpc_xprt
mm: percpu: increase PERCPU_DYNAMIC_SIZE_SHIFT on DEPT and large
PAGE_SIZE
rust: completion: Add __rust_helper to
rust_helper_wait_for_completion()
dept: implement a basic unit test for dept
Yunseong Kim (1):
rcu/update: fix same dept key collision between various types of RCU
Documentation/dev-tools/dept.rst | 905 ++++++++ Documentation/dev-tools/dept_api.rst | 124 + Documentation/dev-tools/index.rst | 2 + drivers/dma-buf/dma-fence.c | 23 +- include/linux/completion.h | 124 +- include/linux/dept.h | 267 +++ include/linux/dept_ldt.h | 78 + include/linux/dept_sdt.h | 68 + include/linux/dept_unit_test.h | 61 + include/linux/dma-fence.h | 74 +- include/linux/hardirq.h | 3 + include/linux/irq-entry-common.h | 4 + include/linux/irqflags.h | 21 +- include/linux/local_lock_internal.h | 1 + include/linux/lockdep.h | 105 +- include/linux/lockdep_types.h | 3 + include/linux/mm_types.h | 4 + include/linux/mmu_notifier.h | 26 + include/linux/mutex.h | 1 + include/linux/page-flags.h | 217 +- include/linux/pagemap.h | 37 +- include/linux/percpu-rwsem.h | 2 +- include/linux/percpu.h | 4 + include/linux/rcupdate_wait.h | 13 +- include/linux/rtmutex.h | 1 + include/linux/rwlock_types.h | 1 + include/linux/rwsem.h | 1 + include/linux/sched.h | 111 + include/linux/seqlock.h | 2 +- include/linux/spinlock_types_raw.h | 3 + include/linux/srcu.h | 2 +- include/linux/sunrpc/xprt.h | 9 +- include/linux/swait.h | 3 + include/linux/wait.h | 3 + include/linux/wait_bit.h | 3 + init/init_task.c | 2 + init/main.c | 2 + kernel/Makefile | 1 + kernel/cpu.c | 2 +- kernel/dependency/Makefile | 5 + kernel/dependency/dept.c | 3222 ++++++++++++++++++++++++++ kernel/dependency/dept_hash.h | 10 + kernel/dependency/dept_internal.h | 314 +++ kernel/dependency/dept_object.h | 13 + kernel/dependency/dept_proc.c | 94 + kernel/dependency/dept_unit_test.c | 149 ++ kernel/exit.c | 1 + kernel/fork.c | 2 + kernel/locking/lockdep.c | 33 + kernel/module/main.c | 2 + kernel/rcu/rcu.h | 1 + kernel/rcu/update.c | 5 +- kernel/sched/completion.c | 62 +- kernel/sched/core.c | 9 + kernel/workqueue.c | 3 + lib/Kconfig.debug | 48 + lib/debug_locks.c | 2 + lib/locking-selftest.c | 2 + mm/filemap.c | 38 + mm/mm_init.c | 3 + mm/mmu_notifier.c | 31 +- rust/helpers/completion.c | 5 + 62 files changed, 6247 insertions(+), 120 deletions(-) create mode 100644 Documentation/dev-tools/dept.rst create mode 100644 Documentation/dev-tools/dept_api.rst create mode 100644 include/linux/dept.h create mode 100644 include/linux/dept_ldt.h create mode 100644 include/linux/dept_sdt.h create mode 100644 include/linux/dept_unit_test.h create mode 100644 kernel/dependency/Makefile create mode 100644 kernel/dependency/dept.c create mode 100644 kernel/dependency/dept_hash.h create mode 100644 kernel/dependency/dept_internal.h create mode 100644 kernel/dependency/dept_object.h create mode 100644 kernel/dependency/dept_proc.c create mode 100644 kernel/dependency/dept_unit_test.c
base-commit: 028ef9c96e96197026887c0f092424679298aae8
Signature · 1 line
2.17.1
PATCH v19 1/40 dept: implement DEPT(DEPendency Tracker)
Lockdep tracks lock acquisition order to identify potential deadlock conditions. Additionally, it monitors IRQ state changes (enable/disable) to detect cases where locks are inadvertently acquired during interrupt handling.
PROBLEM
-------
Waits and their corresponding events that never become reachable can eventually lead to deadlocks. However, since Lockdep focuses solely on lock acquisition order, it has inherent limitations when handling waits and events.
Moreover, by tracking only lock acquisition order, Lockdep cannot properly handle read locks or cross-event scenarios such as wait_for_completion() and complete(), making it increasingly inadequate as a general-purpose deadlock detection tool.
SOLUTION
--------
DEPT(DEPendency Tracker) addresses these limitations by focusing directly on waits and events. DEPT monitors wait operations and their corresponding events, reporting when any events become unreachable.
DEPT provides:
* Correct handling of read locks
* Support for general waits and events
* Continuous operation, even after multiple reports
* Simple, intuitive annotation APIs
FAQ
---
Q. Isn't this the cross-release feature that got reverted?
A. Cross-release (commit b09be676e0ff2) attempted to extend lockdep
with wait/event tracking. It found real bugs but introduced false positives that masked further issues. DEPT learns from that experience with a cleaner design and flexible reporting that makes false positives less disruptive.
Q. Why not build DEPT into lockdep?
A. Lockdep is stable, battle-tested code. I chose separation because
while DEPT borrows BFS and hashing ideas, the wait/event model requires rebuilding from scratch. Lockdep was designed for lock acquisition order — retrofitting it would risk its stability.
Q. Will DEPT replace lockdep?
A. No. Lockdep validates correct lock usage — that's not going away.
DEPT supersedes only the dependency-checking logic when mature.
Q. Should we merge DEPT now or wait for more annotations out-of-tree?
A. Now. The annotation journey requires mainline collaboration. Lockdep
didn't become useful overnight — it grew through maintainer contributions. DEPT needs the same path.
Q. What if I enable DEPT and get false positives?
A. That's the point — report them. Work with us to add annotations that
distinguish your intentional patterns from real deadlocks. This is how lockdep became indispensable, and it's how DEPT will too.
--- include/linux/dept.h | 208 ++ include/linux/hardirq.h | 3 + include/linux/sched.h | 107 ++ init/init_task.c | 2 + init/main.c | 2 + kernel/Makefile | 1 + kernel/dependency/Makefile | 3 + kernel/dependency/dept.c | 2977 +++++++++++++++++++++++++++++ kernel/dependency/dept_hash.h | 10 + kernel/dependency/dept_internal.h | 283 +++ kernel/dependency/dept_object.h | 13 + kernel/exit.c | 1 + kernel/fork.c | 2 + kernel/module/main.c | 2 + kernel/sched/core.c | 9 + lib/Kconfig.debug | 26 + lib/locking-selftest.c | 2 + 17 files changed, 3651 insertions(+) create mode 100644 include/linux/dept.h create mode 100644 kernel/dependency/Makefile create mode 100644 kernel/dependency/dept.c create mode 100644 kernel/dependency/dept_hash.h create mode 100644 kernel/dependency/dept_internal.h create mode 100644 kernel/dependency/dept_object.h
include/linux/dept.h new file +208 -0
@@ -0,0 +1,208 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* DEPT(DEPendency Tracker) - runtime dependency tracker +* +* Started by Byungchul Park <[email protected]>: +* +* Copyright (c) 2020 LG Electronics, Inc., Byungchul Park +* Copyright (c) 2024 SK hynix, Inc., Byungchul Park +*/ + +#ifndef __LINUX_DEPT_H +#define __LINUX_DEPT_H + +#ifdef CONFIG_DEPT + +struct task_struct ; + +#define DEPT_MAX_STACK_ENTRY 16 +#define DEPT_MAX_WAIT_HIST 64 +#define DEPT_MAX_ECXT_HELD 48 + +#define DEPT_MAX_SUBCLASSES 16 +#define DEPT_MAX_SUBCLASSES_EVT 2 +#define DEPT_MAX_SUBCLASSES_USR (DEPT_MAX_SUBCLASSES / DEPT_MAX_SUBCLASSES_EVT) +#define DEPT_MAX_SUBCLASSES_CACHE 2 + +#define DEPT_SIRQ 0 +#define DEPT_HIRQ 1 +#define DEPT_IRQS_NR 2 +#define DEPT_SIRQF (1UL << DEPT_SIRQ) +#define DEPT_HIRQF (1UL << DEPT_HIRQ) + +struct dept_key { +union { +/* +* Each byte-wise address will be used as its key. +*/ +char base[DEPT_MAX_SUBCLASSES ]; + +/* +* for caching the main class pointer +*/ +struct dept_class *classes[DEPT_MAX_SUBCLASSES_CACHE ]; + }; +}; + +struct dept_map { +const char *name; +struct dept_key *keys; + +/* +* subclass that can be set from user +*/ +int sub_u; + +/* +* It's local copy for fast access to the associated classes. +* Also used for dept_key for static maps. +*/ +struct dept_key map_key; + +/* +* wait timestamp associated to this map +*/ +unsigned int wgen; + +/* +* whether this map should be going to be checked or not +*/ +bool nocheck; +}; + +#define DEPT_MAP_INITIALIZER (n, k) \ +{ \ + .name = #n, \ + .keys = (struct dept_key *)(k), \ + .sub_u = 0, \ + .map_key = { .classes = { NULL, } }, \ + .wgen = 0U, \ + .nocheck = false, \ +} + +struct dept_ecxt_held { +/* +* associated event context +*/ +struct dept_ecxt *ecxt; + +/* +* unique key for this dept_ecxt_held +*/ +struct dept_map *map; + +/* +* class of the ecxt of this dept_ecxt_held +*/ +struct dept_class *class; + +/* +* the wgen when the event context started +*/ +unsigned int wgen; + +/* +* subclass that only works in the local context +*/ +int sub_l; +}; + +struct dept_wait_hist { +/* +* associated wait +*/ +struct dept_wait *wait; + +/* +* unique id of all waits system-wise until wrapped +*/ +unsigned int wgen; + +/* +* local context id to identify IRQ context +*/ +unsigned int ctxt_id; +}; + +void dept_on (void ); +void dept_off (void ); +void dept_init (void ); +void dept_task_init (struct task_struct *t); +void dept_task_exit (struct task_struct *t); +void dept_free_range (void *start,unsigned int sz); + +void dept_map_init (struct dept_map *m,struct dept_key *k,int sub_u,const char *n); +void dept_map_reinit (struct dept_map *m,struct dept_key *k,int sub_u,const char *n); +void dept_map_copy (struct dept_map *to,struct dept_map *from); +void dept_wait (struct dept_map *m,unsigned long w_f,unsigned long ip,const char *w_fn,int sub_l); +void dept_stage_wait (struct dept_map *m,struct dept_key *k,unsigned long ip,const char *w_fn); +void dept_request_event_wait_commit (void ); +void dept_clean_stage (void ); +void dept_ttwu_stage_wait (struct task_struct *t,unsigned long ip); +void dept_ecxt_enter (struct dept_map *m,unsigned long e_f,unsigned long ip,const char *c_fn,const char *e_fn,int sub_l); +bool dept_ecxt_holding (struct dept_map *m,unsigned long e_f); +void dept_request_event (struct dept_map *m); +void dept_event (struct dept_map *m,unsigned long e_f,unsigned long ip,const char *e_fn); +void dept_ecxt_exit (struct dept_map *m,unsigned long e_f,unsigned long ip); +void dept_sched_enter (void ); +void dept_sched_exit (void ); + +static inline void dept_ecxt_enter_nokeep (struct dept_map *m) +{ +dept_ecxt_enter (m,0UL ,0UL ,NULL ,NULL ,0 ); +} + +/* +* for users who want to manage external keys +*/ +void dept_key_init (struct dept_key *k); +void dept_key_destroy (struct dept_key *k); +void dept_map_ecxt_modify (struct dept_map *m,unsigned long e_f,struct dept_key *new_k,unsigned long new_e_f,unsigned long new_ip,const char *new_c_fn,const char *new_e_fn,int new_sub_l); + +void dept_softirq_enter (void ); +void dept_hardirq_enter (void ); +void dept_softirqs_on_ip (unsigned long ip); +void dept_hardirqs_on (void ); +void dept_softirqs_off (void ); +void dept_hardirqs_off (void ); +#else /* !CONFIG_DEPT */ +struct dept_key { }; +struct dept_map { }; + +#define DEPT_MAP_INITIALIZER (n, k) { } + +#define dept_on () do { } while (0) +#define dept_off () do { } while (0) +#define dept_init () do { } while (0) +#define dept_task_init (t) do { } while (0) +#define dept_task_exit (t) do { } while (0) +#define dept_free_range (s, sz) do { } while (0) + +#define dept_map_init (m, k, su, n) do { (void)(n); (void)(k); } while (0) +#define dept_map_reinit (m, k, su, n) do { (void)(n); (void)(k); } while (0) +#define dept_map_copy (t, f) do { } while (0) +#define dept_wait (m, w_f, ip, w_fn, sl) do { (void)(w_fn); } while (0) +#define dept_stage_wait (m, k, ip, w_fn) do { (void)(k); (void)(w_fn); } while (0) +#define dept_request_event_wait_commit () do { } while (0) +#define dept_clean_stage () do { } while (0) +#define dept_ttwu_stage_wait (t, ip) do { } while (0) +#define dept_ecxt_enter (m, e_f, ip, c_fn, e_fn, sl) do { (void)(c_fn); (void)(e_fn); } while (0) +#define dept_ecxt_holding (m, e_f) false +#define dept_request_event (m) do { } while (0) +#define dept_event (m, e_f, ip, e_fn) do { (void)(e_fn); } while (0) +#define dept_ecxt_exit (m, e_f, ip) do { } while (0) +#define dept_sched_enter () do { } while (0) +#define dept_sched_exit () do { } while (0) +#define dept_ecxt_enter_nokeep (m) do { } while (0) +#define dept_key_init (k) do { (void)(k); } while (0) +#define dept_key_destroy (k) do { (void)(k); } while (0) +#define dept_map_ecxt_modify (m, e_f, n_k, n_e_f, n_ip, n_c_fn, n_e_fn, n_sl) do { (void)(n_k); (void)(n_c_fn); (void)(n_e_fn); } while (0) + +#define dept_softirq_enter () do { } while (0) +#define dept_hardirq_enter () do { } while (0) +#define dept_softirqs_on_ip (ip) do { } while (0) +#define dept_hardirqs_on () do { } while (0) +#define dept_softirqs_off () do { } while (0) +#define dept_hardirqs_off () do { } while (0) +#endif +#endif /* __LINUX_DEPT_H */
include/linux/hardirq.h +3 -0
@@ -5,6 +5,7 @@#include <linux/context_tracking_state.h> #include <linux/preempt.h> #include <linux/lockdep.h> +#include <linux/dept.h> #include <linux/ftrace_irq.h> #include <linux/sched.h> #include <linux/vtime.h>
@@ -106,6 +107,7 @@ void irq_exit_rcu(void);*/ #define __nmi_enter () \ do { \ + dept_off(); \ lockdep_off(); \ arch_nmi_enter(); \ BUG_ON(in_nmi() == NMI_MASK); \
@@ -128,6 +130,7 @@ void irq_exit_rcu(void);__preempt_count_sub (NMI_OFFSET +HARDIRQ_OFFSET ); \arch_nmi_exit (); \lockdep_on (); \ +dept_on (); \ }while (0 ) #define nmi_exit() \
include/linux/sched.h +107 -0
125 lines not on this page · raw message
init/init_task.c +2 -0
@@ -14,6 +14,7 @@#include <linux/numa.h> #include <linux/scs.h> #include <linux/plist.h> +#include <linux/dept.h> #include <linux/uaccess.h>
@@ -230,6 +231,7 @@ struct task_struct init_task __aligned(L1_CACHE_BYTES) = { .curr_chain_key = INITIAL_CHAIN_KEY, .lockdep_recursion = 0, #endif + .dept_task =DEPT_TASK_INITIALIZER (init_task), #ifdef CONFIG_FUNCTION_GRAPH_TRACER .ret_stack =NULL , .tracing_graph_pause = ATOMIC_INIT(0),
init/main.c +2 -0
@@ -66,6 +66,7 @@#include <linux/debug_locks.h> #include <linux/debugobjects.h> #include <linux/lockdep.h> +#include <linux/dept.h> #include <linux/kmemleak.h> #include <linux/padata.h> #include <linux/pid_namespace.h>
@@ -1150,6 +1151,7 @@ void start_kernel(void) panic_param);lockdep_init (); +dept_init ();/* * Need to run this when irqs are enabled, because it wants
kernel/Makefile +1 -0
@@ -59,6 +59,7 @@ obj-y += dma/ obj-y += entry/ obj-y += unwind/ obj-$(CONFIG_MODULES) += module/ +obj-y += dependency/ obj-$(CONFIG_KCMP) += kcmp.o obj-$(CONFIG_FREEZER) += freezer.o
kernel/dependency/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_DEPT) += dept.o
kernel/dependency/dept.c new file +2977 -0
2,608 lines not on this page · raw message
kernel/dependency/dept_hash.h new file +10 -0
Lines of this file are not shown. View the raw message.
kernel/dependency/dept_internal.h new file +283 -0
283 lines not on this page · raw message
kernel/dependency/dept_object.h new file +13 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
[email protected]
AI reviewRe: [PATCH v19 01/40] dept: implement DEPT(DEPendency Tracker)
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Data race and Use-After-Clear on `dt->stage_m` between `dept_request_event_wait_commit()` and…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Data race and Use-After-Clear on dt->stage_m between dept_request_event_wait_commit() and dept_ttwu_stage_wait()
- [High] Use-after-free and RCU list corruption because dept_class objects are freed before the RCU grace period elapses
- [High] Deadlock on PREEMPT_RT due to local_irq_disable() being used with a raw spinlock (dept_pool_spin) --
commit 1fd2695b58a470d54e232dcaaf112ad8a807718e
Author: Byungchul Park <[email protected]>
dept: implement DEPT(DEPendency Tracker)
This commit implements DEPT (Dependency Tracker) to monitor waits and events for deadlock detection. It addresses Lockdep's limitations regarding read locks and cross-event scenarios.
Quoted 6 lines
kernel/dependency/dept.c new file +0
-0@@ -0,0 +1,2977 @@
[ ... ]
kernel/dependency/dept.c
Quoted 12 lines
kernel/dependency/dept.c new file +12
-0+static void dept_wq_work_fn (struct work_struct *work) +{ +int i; + +for (i =0 ; i <OBJECT_NR ; i++) { +struct dept_pool *p = dept_pool + i; +int sz = p->tot_nr * p->obj_sz; +void *rpool; +bool need; + +local_irq_disable (); +arch_spin_lock (&dept_pool_spin);
[Severity: High]
Is this locking pattern safe on PREEMPT_RT?
By using local_irq_disable() with a raw spinlock (dept_pool_spin), hardware interrupts aren't disabled on PREEMPT_RT. Since DEPT instruments hardirq paths via dept_enter(), could a hardware interrupt fire here, attempt to acquire the exact same lock in from_pool(), and cause a hard deadlock?
Should raw_local_irq_disable() or arch_local_irq_save() be used instead?
[ ... ]
Quoted 15 lines
kernel/dependency/dept.c new file +15
-0+list_for_each_entry_safe (c, n, &dept_classes, all_node) { +if (!within ((void *)c->key, start, sz) && + !within (c->name, start, sz)) +continue ; + +hash_del_class (c); +disconnect_class (c); +list_del (&c->all_node); +invalidate_class (c); + +/* +* Actual deletion will happen on the rcu callback +* that has been added in disconnect_class(). +*/ +del_class (c);
kernel/dependency/dept.c line 2142
Quoted 10 lines
kernel/dependency/dept.c new file +10
-0+ } +dept_unlock (); +dept_exit (flags); + +/* +* Wait until even lockless hash_lookup_class() for the class +* returns NULL. +*/ +might_sleep (); +synchronize_rcu ();
[Severity: High]
Does this sequence safely handle RCU lifetimes for the dept_class objects?
Although the comment states actual deletion happens in the RCU callback, disconnect_class() only queues callbacks for dept_dep objects, not the class itself. By calling del_class(c) directly before synchronize_rcu(), the object is pushed to the freelist synchronously via to_pool().
If a concurrent lockless RCU reader like hash_lookup_class() traverses the bucket and reads hash_node.next after the class is reallocated, wouldn't this result in list corruption or use-after-free crashes?
[ ... ]
Quoted 8 lines
kernel/dependency/dept.c new file +8
-0+void dept_request_event_wait_commit (void ) +{ +struct dept_task *dt =dept_task (); +unsigned long flags; +unsigned int wg; +unsigned long ip; +const char *w_fn; +bool sched_map;
[ ... ]
kernel/dependency/dept.c line 2422
Quoted 5 lines
kernel/dependency/dept.c new file +5
-0+ wg =next_wgen (); +WRITE_ONCE (dt->stage_m.wgen, wg); +arch_spin_unlock (&dt->stage_lock); + +__dept_wait (&dt->stage_m,1UL , ip, w_fn,0 , true, sched_map);
[Severity: High]
Can this sequence lead to a use-after-clear of dt->stage_m?
Once dt->stage_lock is dropped, a concurrent wakeup can execute dept_ttwu_stage_wait() which acquires the same stage_lock and calls __dept_clean_stage(), clearing the original stage_m using memset().
Since __dept_wait() is called here with a reference to &dt->stage_m after the lock is released, could it read memory that is actively being zeroed out, resulting in a NULL pointer dereference for fields like keys or name in check_new_class()?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v19 2/40 dept: add single event dependency tracker APIs
In reply to Byungchul ParkWrapped the base APIs for easier annotation on wait and event. Start with supporting waiters on each single event. More general support for multiple events is a future work. Do more when the need arises.
How to annotate:
1. Initaialize a map for the interesting wait.
/*
* Place along with the wait instance.
*/
struct dept_map my_wait;
/*
* Place in the initialization code.
*/
sdt_map_init(&my_wait);
2. Place the following at the wait code.
sdt_wait(&my_wait);
3. Place the following at the event code.
sdt_event(&my_wait);
That's it!
--- include/linux/dept_sdt.h | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 include/linux/dept_sdt.h
include/linux/dept_sdt.h new file +65 -0
@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Single-event Dependency Tracker +* +* Started by Byungchul Park <[email protected]>: +* +* Copyright (c) 2020 LG Electronics, Inc., Byungchul Park +* Copyright (c) 2024 SK hynix, Inc., Byungchul Park +*/ + +#ifndef __LINUX_DEPT_SDT_H +#define __LINUX_DEPT_SDT_H + +#include <linux/kernel.h> +#include <linux/dept.h> + +#ifdef CONFIG_DEPT +#define sdt_map_init (m) \ + do { \ + static struct dept_key __key; \ + dept_map_init(m, &__key, 0, #m); \ + } while (0) + +#define sdt_map_init_key (m, k) dept_map_init(m, k, 0, #m) + +#define sdt_wait (m) \ + do { \ + dept_request_event(m); \ + dept_wait(m, 1UL, _THIS_IP_, __func__, 0); \ + } while (0) + +/* +* sdt_might_sleep() and its family will be committed in __schedule() +* when it actually gets to __schedule(). Both dept_request_event() and +* dept_wait() will be performed on the commit. +*/ + +/* +* Use the code location as the class key if an explicit map is not used. +*/ +#define sdt_might_sleep_start (m) \ + do { \ + struct dept_map *__m = m; \ + static struct dept_key __key; \ + dept_stage_wait(__m, __m ? NULL : &__key, _THIS_IP_, __func__);\ + } while (0) + +#define sdt_might_sleep_end () dept_clean_stage() + +#define sdt_ecxt_enter (m) dept_ecxt_enter(m, 1UL, _THIS_IP_, "start", "event", 0) +#define sdt_event (m) dept_event(m, 1UL, _THIS_IP_, __func__) +#define sdt_ecxt_exit (m) dept_ecxt_exit(m, 1UL, _THIS_IP_) +#define sdt_request_event (m) dept_request_event(m) +#else /* !CONFIG_DEPT */ +#define sdt_map_init (m) do { } while (0) +#define sdt_map_init_key (m, k) do { (void)(k); } while (0) +#define sdt_wait (m) do { } while (0) +#define sdt_might_sleep_start (m) do { } while (0) +#define sdt_might_sleep_end () do { } while (0) +#define sdt_ecxt_enter (m) do { } while (0) +#define sdt_event (m) do { } while (0) +#define sdt_ecxt_exit (m) do { } while (0) +#define sdt_request_event (m) do { } while (0) +#endif +#endif /* __LINUX_DEPT_SDT_H */
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 02/40] dept: add single event dependency tracker APIs
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Critical] Unsafe macro conversion of functions causes double-evaluation of arguments, leading to logic…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Unsafe macro conversion of functions causes double-evaluation of arguments, leading to logic bugs and memory corruption. --
commit e5795ffb367b1b68ef8574b0a67f0bf3654baf77
Author: Byungchul Park <[email protected]>
dept: add single event dependency tracker APIs
Wrapped the base APIs for easier annotation on wait and event. Start with supporting waiters on each single event. More general support for multiple events is a future work. Do more when the need arises.
Quoted 5 lines
include/linux/dept_sdt.h new file +0
-0
[ ... ]
include/linux/dept_sdt.h line 30
Quoted 7 lines
include/linux/dept_sdt.h new file +7
-0+#define sdt_map_init_key (m, k) dept_map_init(m, k, 0, #m) + +#define sdt_wait (m) \ + do { \ + dept_request_event(m); \ + dept_wait(m, 1UL, _THIS_IP_, __func__, 0); \ + } while (0)
[Severity: Critical]
Can this macro evaluate its argument multiple times, causing a regression if the argument contains side effects?
Unlike sdt_might_sleep_start(m) later in this file which safely captures its argument in a local variable __m, sdt_wait(m) evaluates its argument twice.
If an expression with a post-increment is passed to a macro like this, the side effect will execute multiple times. This is especially risky if existing synchronization primitives like wait_for_completion(x) are converted into similar macros to integrate with the tracker.
For example, looking at drivers/vdpa/mlx5/core/resources.c:
mlx5_vdpa_add_res() {
...
while (completed < issued)
wait_for_completion(&cmds[completed++].cmd_done);
...
}If wait_for_completion() or a similar wrapper evaluates its argument twice, completed++ increments twice per loop iteration. This would skip completion entries and eventually access out-of-bounds memory past the end of the cmds array.
Could the argument be evaluated once and captured in a local variable within these macros to avoid this?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v19 3/40 dept: add lock dependency tracker APIs
In reply to Byungchul ParkWrap the base APIs for easier annotation on typical lock.
--- include/linux/dept_ldt.h | 78 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 include/linux/dept_ldt.h
include/linux/dept_ldt.h new file +78 -0
@@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Lock Dependency Tracker +* +* Started by Byungchul Park <[email protected]>: +* +* Copyright (c) 2020 LG Electronics, Inc., Byungchul Park +* Copyright (c) 2024 SK hynix, Inc., Byungchul Park +*/ + +#ifndef __LINUX_DEPT_LDT_H +#define __LINUX_DEPT_LDT_H + +#include <linux/dept.h> + +#ifdef CONFIG_DEPT +#define LDT_EVT_L 1UL +#define LDT_EVT_R 2UL +#define LDT_EVT_W 1UL +#define LDT_EVT_RW (LDT_EVT_R | LDT_EVT_W) +#define LDT_EVT_ALL (LDT_EVT_L | LDT_EVT_RW) + +#define ldt_init (m, k, su, n) dept_map_init(m, k, su, n) +#define ldt_lock (m, sl, t, n, i) \ + do { \ + if (n) \ + dept_ecxt_enter_nokeep(m); \ + else if (t) \ + dept_ecxt_enter(m, LDT_EVT_L, i, "trylock", "unlock", sl);\ + else { \ + dept_wait(m, LDT_EVT_L, i, "lock", sl); \ + dept_ecxt_enter(m, LDT_EVT_L, i, "lock", "unlock", sl);\ + } \ + } while (0) + +#define ldt_rlock (m, sl, t, n, i, q) \ + do { \ + if (n) \ + dept_ecxt_enter_nokeep(m); \ + else if (t) \ + dept_ecxt_enter(m, LDT_EVT_R, i, "read_trylock", "read_unlock", sl);\ + else { \ + dept_wait(m, q ? LDT_EVT_RW : LDT_EVT_W, i, "read_lock", sl);\ + dept_ecxt_enter(m, LDT_EVT_R, i, "read_lock", "read_unlock", sl);\ + } \ + } while (0) + +#define ldt_wlock (m, sl, t, n, i) \ + do { \ + if (n) \ + dept_ecxt_enter_nokeep(m); \ + else if (t) \ + dept_ecxt_enter(m, LDT_EVT_W, i, "write_trylock", "write_unlock", sl);\ + else { \ + dept_wait(m, LDT_EVT_RW, i, "write_lock", sl); \ + dept_ecxt_enter(m, LDT_EVT_W, i, "write_lock", "write_unlock", sl);\ + } \ + } while (0) + +#define ldt_unlock (m, i) dept_ecxt_exit(m, LDT_EVT_ALL, i) + +#define ldt_downgrade (m, i) \ + do { \ + if (dept_ecxt_holding(m, LDT_EVT_W)) \ + dept_map_ecxt_modify(m, LDT_EVT_W, NULL, LDT_EVT_R, i, "downgrade", "read_unlock", -1);\ + } while (0) + +#define ldt_set_class (m, n, k, sl, i) dept_map_ecxt_modify(m, LDT_EVT_ALL, k, 0UL, i, "lock_set_class", "(any)unlock", sl) +#else /* !CONFIG_DEPT */ +#define ldt_init (m, k, su, n) do { (void)(k); } while (0) +#define ldt_lock (m, sl, t, n, i) do { } while (0) +#define ldt_rlock (m, sl, t, n, i, q) do { } while (0) +#define ldt_wlock (m, sl, t, n, i) do { } while (0) +#define ldt_unlock (m, i) do { } while (0) +#define ldt_downgrade (m, i) do { } while (0) +#define ldt_set_class (m, n, k, sl, i) do { } while (0) +#endif +#endif /* __LINUX_DEPT_LDT_H */
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 03/40] dept: add lock dependency tracker APIs
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] `ldt_set_class` silently drops the lock name parameter, causing newly assigned lock classes to…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] ldt_set_class silently drops the lock name parameter, causing newly assigned lock classes to be registered in DEPT with the old lock name. --
commit ca6be2708025c25889ef609a2203d1465096983d
Author: Byungchul Park <[email protected]>
dept: add lock dependency tracker APIs
Wrap the base APIs for easier annotation on typical lock.
Quoted 5 lines
include/linux/dept_ldt.h new file +0
-0
[ ... ]
include/linux/dept_ldt.h line 68
Quoted 7 lines
include/linux/dept_ldt.h new file +7
-0+#define ldt_downgrade (m, i) \ + do { \ + if (dept_ecxt_holding(m, LDT_EVT_W)) \ + dept_map_ecxt_modify(m, LDT_EVT_W, NULL, LDT_EVT_R, i, "downgrade", "read_unlock", -1);\ + } while (0) + +#define ldt_set_class (m, n, k, sl, i) dept_map_ecxt_modify(m, LDT_EVT_ALL, k, 0UL, i, "lock_set_class", "(any)unlock", sl)
[Severity: Medium]
Does this code inadvertently drop the lock name parameter n?
When a caller invokes lock_set_class on a held lock, it passes the new name n. Because n is completely omitted from the replacement list here, dept_map_ecxt_modify won't receive the new name. This could cause newly assigned lock classes to be registered in DEPT with the old lock name, which might lead to incorrect lock names in dependency deadlock reports.
Inside dept_map_ecxt_modify(), dept_map_reinit() is called with NULL for the name, leaving m->name unchanged. check_new_class() is then called, which registers the new class key using the old m->name. Lockdep subsequently updates m->name via ldt_init, but it is too late as the DEPT class was already created with the old name.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v19 4/40 dept: tie to lockdep and IRQ tracing
In reply to Byungchul ParkHow to place dept this way looks so ugly. However, it's inevitable for now. The way should be enhanced gradually.
--- include/linux/irqflags.h | 7 +- include/linux/local_lock_internal.h | 1 + include/linux/lockdep.h | 102 ++++++++++++++++++++++------ include/linux/lockdep_types.h | 3 + include/linux/mutex.h | 1 + include/linux/percpu-rwsem.h | 2 +- include/linux/rtmutex.h | 1 + include/linux/rwlock_types.h | 1 + include/linux/rwsem.h | 1 + include/linux/seqlock.h | 2 +- include/linux/spinlock_types_raw.h | 3 + include/linux/srcu.h | 2 +- kernel/dependency/dept.c | 8 +-- kernel/locking/lockdep.c | 22 ++++++ 14 files changed, 127 insertions(+), 29 deletions(-)
include/linux/irqflags.h +6 -1
@@ -15,6 +15,7 @@#include <linux/irqflags_types.h> #include <linux/typecheck.h> #include <linux/cleanup.h> +#include <linux/dept.h> #include <asm/irqflags.h> #include <asm/percpu.h>
@@ -55,8 +56,10 @@ extern void trace_hardirqs_off(void);# define lockdep_softirqs_enabled (p) ((p)->softirqs_enabled)# define lockdep_hardirq_enter () \ do { \ - if (__this_cpu_inc_return(hardirq_context) == 1)\ + if (__this_cpu_inc_return(hardirq_context) == 1) { \ current->hardirq_threaded = 0; \ + dept_hardirq_enter(); \ + } \ } while (0)# define lockdep_hardirq_threaded () \ do { \
@@ -131,6 +134,8 @@ do { \# define lockdep_softirq_enter () \ do { \ current->softirq_context++; \ + if (current->softirq_context == 1) \ + dept_softirq_enter(); \ } while (0)# define lockdep_softirq_exit () \ do { \
include/linux/local_lock_internal.h +1 -0
@@ -35,6 +35,7 @@ typedef struct local_trylock local_trylock_t; .name = #lockname, \ .wait_type_inner = LD_WAIT_CONFIG, \ .lock_type = LD_LOCK_PERCPU, \ + .dmap = DEPT_MAP_INITIALIZER(lockname, NULL),\ }, \ .owner = NULL,
include/linux/lockdep.h +81 -21
133 lines not on this page · raw message
include/linux/lockdep_types.h +3 -0
@@ -11,6 +11,7 @@#define __LINUX_LOCKDEP_TYPES_H#include <linux/types.h> +#include <linux/dept.h> #define MAX_LOCKDEP_SUBCLASSES 8UL
@@ -77,6 +78,7 @@ struct lock_class_key {struct hlist_node hash_entry;struct lockdep_subclass_key subkeys[MAX_LOCKDEP_SUBCLASSES ]; }; +struct dept_key dkey; };extern struct lock_class_key __lockdep_no_validate__;
@@ -195,6 +197,7 @@ struct lockdep_map {int cpu;unsigned long ip;#endif +struct dept_map dmap; };struct pin_cookie {unsigned int val; };
include/linux/mutex.h +1 -0
@@ -29,6 +29,7 @@ struct device; , .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_SLEEP, \ + .dmap = DEPT_MAP_INITIALIZER(lockname, NULL),\ }#else # define __DEP_MAP_MUTEX_INITIALIZER (lockname)
include/linux/percpu-rwsem.h +1 -1
@@ -22,7 +22,7 @@ struct percpu_rw_semaphore { };#ifdef CONFIG_DEBUG_LOCK_ALLOC -#define __PERCPU_RWSEM_DEP_MAP_INIT (lockname) .dep_map = { .name = #lockname }, +#define __PERCPU_RWSEM_DEP_MAP_INIT (lockname) .dep_map = { .name = #lockname, .dmap = DEPT_MAP_INITIALIZER(lockname, NULL) },#else #define __PERCPU_RWSEM_DEP_MAP_INIT (lockname)#endif
include/linux/rtmutex.h +1 -0
@@ -91,6 +91,7 @@ do { \ .dep_map = { \ .name = #mutexname, \ .wait_type_inner = LD_WAIT_SLEEP, \ + .dmap = DEPT_MAP_INITIALIZER(mutexname, NULL),\ }#else #define __DEP_MAP_RT_MUTEX_INITIALIZER (mutexname)
include/linux/rwlock_types.h +1 -0
@@ -10,6 +10,7 @@ .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_CONFIG, \ + .dmap = DEPT_MAP_INITIALIZER(lockname, NULL), \ }#else # define RW_DEP_MAP_INIT (lockname)
include/linux/rwsem.h +1 -0
@@ -22,6 +22,7 @@ .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_SLEEP, \ + .dmap = DEPT_MAP_INITIALIZER(lockname, NULL),\ },#else # define __RWSEM_DEP_MAP_INIT (lockname)
include/linux/seqlock.h +1 -1
@@ -52,7 +52,7 @@ static inline void __seqcount_init(seqcount_t *s, const char *name,#ifdef CONFIG_DEBUG_LOCK_ALLOC # define SEQCOUNT_DEP_MAP_INIT (lockname) \ - .dep_map = { .name = #lockname } + .dep_map = { .name = #lockname, .dmap = DEPT_MAP_INITIALIZER(lockname, NULL) }/** * seqcount_init() - runtime initializer for seqcount_t
include/linux/spinlock_types_raw.h +3 -0
@@ -32,11 +32,13 @@ typedef struct raw_spinlock raw_spinlock_t; .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_SPIN, \ + .dmap = DEPT_MAP_INITIALIZER(lockname, NULL),\ }# define SPIN_DEP_MAP_INIT (lockname) \ .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_CONFIG, \ + .dmap = DEPT_MAP_INITIALIZER(lockname, NULL),\ }# define LOCAL_SPIN_DEP_MAP_INIT (lockname) \
@@ -44,6 +46,7 @@ typedef struct raw_spinlock raw_spinlock_t; .name = #lockname, \ .wait_type_inner = LD_WAIT_CONFIG, \ .lock_type = LD_LOCK_PERCPU, \ + .dmap = DEPT_MAP_INITIALIZER(lockname, NULL),\ }#else # define RAW_SPIN_DEP_MAP_INIT (lockname)
include/linux/srcu.h +1 -1
@@ -53,7 +53,7 @@ int __init_srcu_struct_fast_updown(struct srcu_struct *ssp, const char *name, __init_srcu_struct_fast_updown((ssp), #ssp, &__srcu_key); \ }) -#define __SRCU_DEP_MAP_INIT (srcu_name) .dep_map = { .name = #srcu_name }, +#define __SRCU_DEP_MAP_INIT (srcu_name) .dep_map = { .name = #srcu_name, .dmap = DEPT_MAP_INITIALIZER(srcu_name, NULL) },#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ int init_srcu_struct (struct srcu_struct *ssp);
kernel/dependency/dept.c +4 -4
@@ -250,10 +250,10 @@ static bool dept_working(void)* Even k == NULL is considered a valid key because it would use * &->map_key as the key in that case. */ -struct dept_key __dept_no_validate__; +extern struct lock_class_key __lockdep_no_validate__;static bool valid_key (struct dept_key *k) { -return &__dept_no_validate__ != k; +return &__lockdep_no_validate__.dkey != k; }/*
@@ -1921,7 +1921,7 @@ void dept_softirqs_off(void)dept_task ()->softirqs_enabled = false; } -void dept_hardirqs_off (void ) +void noinstr dept_hardirqs_off(void) {/* * Assumes that it's called with IRQ disabled so that accessing
@@ -1943,7 +1943,7 @@ void dept_softirq_enter(void)/* * Ensure it's the outmost hardirq context. */ -void dept_hardirq_enter (void ) +void noinstr dept_hardirq_enter(void) {struct dept_task *dt =dept_task ();
kernel/locking/lockdep.c +22 -0
@@ -1224,6 +1224,8 @@ void lockdep_register_key(struct lock_class_key *key)struct lock_class_key *k;unsigned long flags; +dept_key_init (&key->dkey); +if (WARN_ON_ONCE (static_obj (key)))return ; hash_head =keyhashentry (key);
@@ -4361,6 +4363,8 @@ static void __trace_hardirqs_on_caller(void)*/ void lockdep_hardirqs_on_prepare (void ) { +dept_hardirqs_on (); +if (unlikely (!debug_locks))return ;
@@ -4481,6 +4485,8 @@ EXPORT_SYMBOL_GPL(lockdep_hardirqs_on);*/ void noinstr lockdep_hardirqs_off(unsigned long ip) { +dept_hardirqs_off (); +if (unlikely (!debug_locks))return ;
@@ -4525,6 +4531,8 @@ void lockdep_softirqs_on(unsigned long ip) {struct irqtrace_events *trace = ¤t->irqtrace; +dept_softirqs_on_ip (ip); +if (unlikely (!lockdep_enabled ()))return ;
@@ -4563,6 +4571,8 @@ void lockdep_softirqs_on(unsigned long ip)*/ void lockdep_softirqs_off (unsigned long ip) { +dept_softirqs_off (); +if (unlikely (!lockdep_enabled ()))return ;
@@ -4940,6 +4950,8 @@ void lockdep_init_map_type(struct lockdep_map *lock, const char *name, {int i; +ldt_init (&lock->dmap, &key->dkey, subclass, name); +for (i =0 ; i <NR_LOCKDEP_CACHING_CLASSES ; i++) lock->class_cache[i] =NULL ;
@@ -5736,6 +5748,12 @@ void lock_set_class(struct lockdep_map *lock, const char *name, {unsigned long flags; +/* +* dept_map_(re)init() might be called twice redundantly. But +* there's no choice as long as Dept relies on Lockdep. +*/ +ldt_set_class (&lock->dmap, name, &key->dkey, subclass, ip); +if (unlikely (!lockdep_enabled ()))return ;
@@ -5753,6 +5771,8 @@ void lock_downgrade(struct lockdep_map *lock, unsigned long ip) {unsigned long flags; +ldt_downgrade (&lock->dmap, ip); +if (unlikely (!lockdep_enabled ()))return ;
@@ -6588,6 +6608,8 @@ void lockdep_unregister_key(struct lock_class_key *key)bool found = false;bool need_callback = false; +dept_key_destroy (&key->dkey); +might_sleep ();if (WARN_ON_ONCE (static_obj (key)))
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 04/40] dept: tie to lockdep and IRQ tracing
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [Critical] dept_key_destroy() synchronously recycles dept_class objects to the lockless pool before the…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [Critical] dept_key_destroy() synchronously recycles dept_class objects to the lockless pool before the RCU grace period completes, causing UAF and list traversal corruption for concurrent lockless readers.
- [High] rwsem_acquire_read and rwsem_acquire incorrectly use ldt_lock(), breaking reader-writer dependency tracking and causing false-positive deadlocks.
- [High] ldt_init() is called before the key parameter is validated, causing DEPT to dereference a garbage pointer if key is NULL.
- [Medium] dept_key_init() and dept_key_destroy() are called on static keys before validation, erroneously disabling DEPT or corrupting tracking state.
- [Low] STATIC_LOCKDEP_MAP_INIT creates double-quoted strings for map names due to #n stringification in DEPT_MAP_INITIALIZER.
--
commit 6c1a95ee3182a2a82a1d61196d75acd387d7f3e3
Author: Byungchul Park <[email protected]>
dept: tie to lockdep and IRQ tracing
This patch integrates DEPT (Dependency Tracker) into the lockdep framework and IRQ tracing paths. It modifies various locking primitives and lockdep interfaces to initialize and track DEPT maps alongside lockdep maps.
Quoted 4 lines
include/linux/lockdep.h +0
-0
[ ... ]
include/linux/lockdep.h enum xhlock_context_t { · line 435
Quoted 7 lines
include/linux/lockdep.h +2
-1@@ -428,7 +431,8 @@ enum xhlock_context_t {* Note that _name must not be NULL. */ #define STATIC_LOCKDEP_MAP_INIT (_name, _key) \ - { .name = (_name), .key = (void *)(_key), } + { .name = (_name), .key = (void *)(_key), \ + .dmap = DEPT_MAP_INITIALIZER(_name, _key) }
[Severity: Low]
Since _name is usually passed as a string literal to STATIC_LOCKDEP_MAP_INIT, does passing it to DEPT_MAP_INITIALIZER, which uses the stringification operator on its first argument, result in double-quoted strings for map names in DEPT's debug output?
[ ... ]
Quoted 4 lines
include/linux/lockdep.h +0
-4-#define rwsem_acquire (l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) -#define rwsem_acquire_nest (l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i) -#define rwsem_acquire_read (l, s, t, i) lock_acquire_shared(l, s, t, NULL, i) -#define rwsem_release (l, i) lock_release(l, i)
[ ... ]
Quoted 5 lines
include/linux/lockdep.h +5
-0+#define rwsem_acquire (l, s, t, i) \ +do { \ + ldt_lock(&(l)->dmap, s, t, NULL, i); \ + lock_acquire_exclusive(l, s, t, NULL, i); \ +} while (0)
include/linux/lockdep.h extern bool read_lock_is_recursive(void); · line 594
Quoted 10 lines
include/linux/lockdep.h +10
-0+#define rwsem_acquire_nest (l, s, t, n, i) \ +do { \ + ldt_lock(&(l)->dmap, s, t, n, i); \ + lock_acquire_exclusive(l, s, t, n, i); \ +} while (0) +#define rwsem_acquire_read (l, s, t, i) \ +do { \ + ldt_lock(&(l)->dmap, s, t, NULL, i); \ + lock_acquire_shared(l, s, t, NULL, i); \ +} while (0)
[Severity: High]
Is it intentional that rwsem_acquire_read() uses ldt_lock() instead of ldt_rlock(), and rwsem_acquire() uses ldt_lock() instead of ldt_wlock()?
This appears to mistakenly model a shared lock as an exclusive lock. Does this cause DEPT to incorrectly model concurrent read locks as mutually exclusive, leading to false-positive circular dependency (deadlock) reports when concurrent readers take an rwsem and interact with other locks?
kernel/locking/lockdep.c void lockdep_register_key(struct lock_class_key *key) · line 1231
Quoted 13 lines
kernel/locking/lockdep.c +2
-0@@ -1224,6 +1224,8 @@ void lockdep_register_key(struct lock_class_key *key)struct hlist_head *hash_head;struct lock_class_key *k;unsigned long flags; +dept_key_init (&key->dkey); +if (WARN_ON_ONCE (static_obj (key)))return ;
[Severity: Medium]
In lockdep_register_key(), dept_key_init() is called before the static_obj() check. If a static key is improperly passed, lockdep gracefully rejects it by warning and returning early.
However, processing a static key in dept_key_init() triggers a DEPT_STOP abort. Should the DEPT initialization occur after validating the key?
[ ... ]
kernel/locking/lockdep.c void lockdep_init_map_type(struct lockdep_map *lock, const char *name, · line 4956
Quoted 8 lines
kernel/locking/lockdep.c +2
-0@@ -4940,6 +4950,8 @@ void lockdep_init_map_type(struct lockdep_map *lock, const char *name, {int i; +ldt_init (&lock->dmap, &key->dkey, subclass, name); +for (i =0 ; i <NR_LOCKDEP_CACHING_CLASSES ; i++) lock->class_cache[i] =NULL ;
[Severity: High]
In lockdep_init_map_type(), ldt_init() is called before the parameter validation checks for a NULL key further down in the function.
If key is NULL, &key->dkey yields a non-NULL offset pointer. Does DEPT accept this garbage pointer in valid_key(), causing a kernel panic when check_new_class() dereferences it?
[ ... ]
Quoted 10 lines
kernel/locking/lockdep.c +2
-0@@ -6588,6 +6608,8 @@ void lockdep_unregister_key(struct lock_class_key *key)bool found = false;bool need_callback = false; +dept_key_destroy (&key->dkey); +might_sleep ();if (WARN_ON_ONCE (static_obj (key)))return;
[Severity: Medium]
Similarly to lockdep_register_key(), dept_key_destroy() is called here unconditionally before the static_obj() check. If a driver incorrectly calls dynamic lock destruction on a static key, it eagerly destroys its DEPT state while lockdep retains it. Should this also be moved after the static_obj() check?
[Severity: Critical]
Additionally, in dept_key_destroy() called here, the function removes a class from the RCU hash table and drops its refcount to 0 via del_class(). This recycles the object to the DEPT pool before synchronize_rcu() is called.
Can a concurrent lockless reader in hash_lookup_class() traversing the same bucket via hlist_for_each_entry_rcu() access this recycled object, leading to a use-after-free and hash list corruption?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v19 04/40] dept: tie to lockdep and IRQ tracing
Quoted 22 lines · On Tue, Jul 07, 2026 at 07:33:22AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [Critical]dept_key_destroy()synchronously recyclesdept_classobjects to the lockless pool before the RCU grace period completes, causing UAF and list traversal corruption for concurrent lockless readers.
- [High]rwsem_acquire_readandrwsem_acquireincorrectly useldt_lock(), breaking reader-writer dependency tracking and causing false-positive deadlocks.
- [High]ldt_init()is called before thekeyparameter is validated, causing DEPT to dereference a garbage pointer ifkeyis NULL.
- [Medium]dept_key_init()anddept_key_destroy()are called on static keys before validation, erroneously disabling DEPT or corrupting tracking state.
- [Low]STATIC_LOCKDEP_MAP_INITcreates double-quoted strings for map names due to#nstringification inDEPT_MAP_INITIALIZER.
--commit
6c1a95ee3182a2a82a1d61196d75acd387d7f3e3
Author: Byungchul Park <[email protected]>dept: tie to lockdep and IRQ tracing
This patch integrates DEPT (Dependency Tracker) into the lockdep framework and IRQ tracing paths. It modifies various locking primitives and lockdep interfaces to initialize and track DEPT maps alongside lockdep maps.
Quoted 4 lines
include/linux/lockdep.h +0
-0[ ... ]
Quoted 13 lines
include/linux/lockdep.h enum xhlock_context_t { · line 435
Quoted 7 lines
include/linux/lockdep.h +2
-1@@ -428,7 +431,8 @@ enum xhlock_context_t {* Note that _name must not be NULL. */ #define STATIC_LOCKDEP_MAP_INIT (_name, _key) \ - { .name = (_name), .key = (void *)(_key), } + { .name = (_name), .key = (void *)(_key), \ + .dmap = DEPT_MAP_INITIALIZER(_name, _key) }[Severity: Low]
Since_nameis usually passed as a string literal toSTATIC_LOCKDEP_MAP_INIT, does passing it toDEPT_MAP_INITIALIZER, which uses the stringification operator on its first argument, result in double-quoted strings for map names in DEPT's debug output?
I will check it. Thanks.
Quoted 17 lines
[ ... ]
Quoted 4 lines
include/linux/lockdep.h +0
-4-#define rwsem_acquire (l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) -#define rwsem_acquire_nest (l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i) -#define rwsem_acquire_read (l, s, t, i) lock_acquire_shared(l, s, t, NULL, i) -#define rwsem_release (l, i) lock_release(l, i)[ ... ]
Quoted 11 lines
include/linux/lockdep.h +11
-0+#define rwsem_acquire (l, s, t, i) \ +do { \ + ldt_lock(&(l)->dmap, s, t, NULL, i); \ + lock_acquire_exclusive(l, s, t, NULL, i); \ +} while (0) +#define rwsem_acquire_nest (l, s, t, n, i) \ +do { \ + ldt_lock(&(l)->dmap, s, t, n, i); \ + lock_acquire_exclusive(l, s, t, n, i); \ +} while (0) +#define rwsem_acquire_read (l, s, t, i) \
Quoted 8 lines
include/linux/lockdep.h extern bool read_lock_is_recursive(void); · line 594
Quoted 4 lines
include/linux/lockdep.h +4
-0+do { \ +ldt_lock (&(l)->dmap, s, t,NULL , i); \ +lock_acquire_shared (l, s, t,NULL , i); \ +}while (0 )[Severity: High]
Is it intentional thatrwsem_acquire_read()usesldt_lock()instead ofldt_rlock(), andrwsem_acquire()usesldt_lock()instead ofldt_wlock()?
It's intended. rwsem is a queued lock for fairness. So it should be considered as a normal lock to detect a potential deadlock.
Quoted 4 lines
This appears to mistakenly model a shared lock as an exclusive lock. Does this cause DEPT to incorrectly model concurrent read locks as mutually exclusive, leading to false-positive circular dependency (deadlock) reports when concurrent readers take an rwsem and interact with other locks?
As I told you, rwsem is a queued lock. So this is not true.
Quoted 19 lines
kernel/locking/lockdep.c void lockdep_register_key(struct lock_class_key *key) · line 1231
Quoted 13 lines
kernel/locking/lockdep.c +2
-0@@ -1224,6 +1224,8 @@ void lockdep_register_key(struct lock_class_key *key)struct hlist_head *hash_head;struct lock_class_key *k;unsigned long flags; +dept_key_init (&key->dkey); +if (WARN_ON_ONCE (static_obj (key)))return ;[Severity: Medium]
Inlockdep_register_key(),dept_key_init()is called before thestatic_obj()check. If a static key is improperly passed, lockdep gracefully rejects it by warning and returning early.
Quoted 2 lines
However, processing a static key in
dept_key_init()triggers aDEPT_STOPabort. Should the DEPT initialization occur after validating the key?
I will check it.
Quoted 14 lines
[ ... ]
kernel/locking/lockdep.c void lockdep_init_map_type(struct lockdep_map *lock, const char *name, · line 4956
Quoted 8 lines
kernel/locking/lockdep.c +2
-0@@ -4940,6 +4950,8 @@ void lockdep_init_map_type(struct lockdep_map *lock, const char *name, {int i; +ldt_init (&lock->dmap, &key->dkey, subclass, name); +for (i =0 ; i <NR_LOCKDEP_CACHING_CLASSES ; i++) lock->class_cache[i] =NULL ;[Severity: High]
Inlockdep_init_map_type(),ldt_init()is called before the parameter validation checks for a NULL key further down in the function.
Quoted 3 lines
If key is NULL,
&key->dkeyyields a non-NULL offset pointer. Does DEPT accept this garbage pointer invalid_key(), causing a kernel panic whencheck_new_class()dereferences it?
I will check it.
Quoted 9 lines
[ ... ]
Quoted 8 lines
kernel/locking/lockdep.c +2
-0@@ -6588,6 +6608,8 @@ void lockdep_unregister_key(struct lock_class_key *key)bool found = false;bool need_callback = false; +dept_key_destroy (&key->dkey); +might_sleep ();
Quoted 9 lines
Quoted 2 lines
kernel/locking/lockdep.c +0
-0if (WARN_ON_ONCE (static_obj (key)))return;[Severity: Medium]
Similarly tolockdep_register_key(),dept_key_destroy()is called here unconditionally before thestatic_obj()check. If a driver incorrectly calls dynamic lock destruction on a static key, it eagerly destroys its DEPT state while lockdep retains it. Should this also be moved after thestatic_obj()check?
Sure. I will.
Quoted 4 lines
[Severity: Critical]
Additionally, indept_key_destroy()called here, the function removes a class from the RCU hash table and drops its refcount to 0 viadel_class(). This recycles the object to the DEPT pool beforesynchronize_rcu()is called.
No.
del_class() never drops refcount to 0. That happens only through:
disconnect_class()->call_rcu(del_dep_rcu)
// after the grace period
del_dep_rcu()->del_dep()->put_ecxt()->put_class() del_dep_rcu()->del_dep()->put_wait()->put_class()
So it's safe.
Quoted 3 lines
Can a concurrent lockless reader in
hash_lookup_class()traversing the same bucket viahlist_for_each_entry_rcu()access this recycled object, leading to a use-after-free and hash list corruption?
No.
Byungchul
Quoted 3 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v19 5/40 dept: add proc knobs to show stats and dependency graph
In reply to Byungchul ParkIt'd be useful to show dept internal stats and dependency graph on runtime via proc for better information. Introduce the knobs.
--- kernel/dependency/Makefile | 1 + kernel/dependency/dept.c | 11 +--- kernel/dependency/dept_internal.h | 10 ++++ kernel/dependency/dept_proc.c | 96 +++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 kernel/dependency/dept_proc.c
kernel/dependency/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DEPT) += dept.o +obj-$(CONFIG_DEPT) += dept_proc.o
kernel/dependency/dept.c +2 -9
@@ -266,20 +266,13 @@ static bool valid_key(struct dept_key *k)* have been freed will be placed there. */ -enum object_t { -#define OBJECT(id, nr) OBJECT_##id, -#include "dept_object.h" -#undef OBJECT - OBJECT_NR, -}; -#define OBJECT (id, nr) \ static struct dept_##id spool_##id[nr]; \ static DEFINE_PER_CPU(struct llist_head, lpool_##id);#include "dept_object.h" #undef OBJECT -static struct dept_pool dept_pool[OBJECT_NR] = { +struct dept_pool dept_pool[OBJECT_NR] = { #define OBJECT(id, nr) { \ .name = #id, \ .obj_sz = sizeof(struct dept_##id), \
@@ -2083,7 +2076,7 @@ void dept_map_copy(struct dept_map *to, struct dept_map *from)clean_classes_cache (&to->map_key); } -static LIST_HEAD (dept_classes); +LIST_HEAD (dept_classes);static bool within (const void *addr,void *start,unsigned long size) {
kernel/dependency/dept_internal.h +10 -0
@@ -279,5 +279,15 @@ struct dept_hash {int bits; }; +enum object_t { +#define OBJECT(id, nr) OBJECT_##id, +#include "dept_object.h" +#undef OBJECT + OBJECT_NR, +}; + +extern struct list_head dept_classes; +extern struct dept_pool dept_pool[]; +#endif #endif /* __DEPT_INTERNAL_H */
kernel/dependency/dept_proc.c new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 05/40] dept: add proc knobs to show stats and dependency graph
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Lockless traversal of `dept_classes` and `fc->dep_head` in procfs read operations causes kernel…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Lockless traversal of dept_classes and fc->dep_head in procfs read operations causes kernel panic due to LIST_POISON pointer dereference and Use-After-Free. --
commit e2e753e7050a1aa0365bc001321fe4e79158b5b4
Author: Byungchul Park <[email protected]>
dept: add proc knobs to show stats and dependency graph
This commit introduces procfs knobs to expose internal stats and the dependency graph for the dependency tracker at runtime.
Quoted 5 lines
kernel/dependency/dept_proc.c new file +0
-0
[ ... ]
Quoted 7 lines
kernel/dependency/dept_proc.c new file +7
-0+static void *l_next (struct seq_file *m,void *v,loff_t *pos) +{ +/* +* XXX: Serialize list traversal if needed. The following might +* give a wrong information on contention. +*/ +return seq_list_next (v, &dept_classes, pos);
kernel/dependency/dept_proc.c line 31
Quoted 10 lines
kernel/dependency/dept_proc.c new file +10
-0+} + +static void *l_start (struct seq_file *m,loff_t *pos) +{ +/* +* XXX: Serialize list traversal if needed. The following might +* give a wrong information on contention. +*/ +return seq_list_start_head (&dept_classes, *pos); +}
[Severity: High]
Is it safe to traverse dept_classes without locks here?
If a concurrent module unload occurs, dept_free_range() calls list_del() on the class node:
kernel/dependency/dept.c:dept_free_range() {
...
list_del(&c->all_node);
...
}Because list_del() poisons the removed node's next pointer with LIST_POISON1, a concurrent lockless reader in seq_list_next() will dereference LIST_POISON1 and cause a kernel panic, rather than just returning wrong information.
Quoted 14 lines
kernel/dependency/dept_proc.c new file +14
-0+ +static void l_stop (struct seq_file *m,void *v) +{ +} + +static int l_show (struct seq_file *m,void *v) +{ + struct dept_class *fc = list_entry(v, struct dept_class, all_node); +struct dept_dep *d; +const char *prefix; + +if (v == &dept_classes) { +seq_puts (m,"All classes:\n\n" ); +return 0 ;
kernel/dependency/dept_proc.c line 55
Quoted 10 lines
kernel/dependency/dept_proc.c new file +10
-0+ } + + prefix = fc->sched_map ?"<sched> " :"" ; +seq_printf (m,"[%p] %s%s\n" , (void *)fc->key, prefix, fc->name); + +/* +* XXX: Serialize list traversal if needed. The following might +* give a wrong information on contention. +*/ +list_for_each_entry (d, &fc->dep_head, dep_node) {
[Severity: High]
Does traversing fc->dep_head without rcu_read_lock() risk a use-after-free?
Since the dependency objects in this list are RCU-managed, traversing them without holding rcu_read_lock() might allow the objects to be freed to the pool while they are still being iterated.
Quoted 9 lines
kernel/dependency/dept_proc.c new file +9
-0+struct dept_class *tc = d->wait->class; + + prefix = tc->sched_map ?"<sched> " :"" ; +seq_printf (m," -> [%p] %s%s\n" , (void *)tc->key, prefix, tc->name); + } +seq_puts (m,"\n" ); + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v19 6/40 dept: distinguish each kernel context from another
In reply to Byungchul ParkEach unique kernel context, in dept's point of view, should be identified on every entrance to kernel mode e.g. system call or user oriented fault. Otherwise, dept may track meaningless dependencies across different kernel context.
--- include/linux/dept.h | 17 +++++--- include/linux/irq-entry-common.h | 4 ++ include/linux/sched.h | 10 ++--- kernel/dependency/dept.c | 67 ++++++++++++++++--------------- kernel/dependency/dept_internal.h | 12 +++--- 5 files changed, 61 insertions(+), 49 deletions(-)
include/linux/dept.h +12 -5
@@ -24,11 +24,16 @@ struct task_struct;#define DEPT_MAX_SUBCLASSES_USR (DEPT_MAX_SUBCLASSES / DEPT_MAX_SUBCLASSES_EVT)#define DEPT_MAX_SUBCLASSES_CACHE 2 -#define DEPT_SIRQ 0 -#define DEPT_HIRQ 1 -#define DEPT_IRQS_NR 2 -#define DEPT_SIRQF (1UL << DEPT_SIRQ) -#define DEPT_HIRQF (1UL << DEPT_HIRQ) +enum { +DEPT_CXT_SIRQ =0 , +DEPT_CXT_HIRQ , +DEPT_CXT_IRQS_NR , +DEPT_CXT_PROCESS =DEPT_CXT_IRQS_NR , +DEPT_CXTS_NR +}; + +#define DEPT_SIRQF (1UL << DEPT_CXT_SIRQ) +#define DEPT_HIRQF (1UL << DEPT_CXT_HIRQ) struct dept_key { union {
@@ -146,6 +151,7 @@ void dept_event(struct dept_map *m, unsigned long e_f, unsigned long ip, const cvoid dept_ecxt_exit (struct dept_map *m,unsigned long e_f,unsigned long ip);void dept_sched_enter (void );void dept_sched_exit (void ); +void dept_update_cxt (void );static inline void dept_ecxt_enter_nokeep (struct dept_map *m) {
@@ -193,6 +199,7 @@ struct dept_map { };#define dept_ecxt_exit (m, e_f, ip) do { } while (0)#define dept_sched_enter () do { } while (0)#define dept_sched_exit () do { } while (0) +#define dept_update_cxt () do { } while (0)#define dept_ecxt_enter_nokeep (m) do { } while (0)#define dept_key_init (k) do { (void)(k); } while (0)#define dept_key_destroy (k) do { (void)(k); } while (0)
include/linux/irq-entry-common.h +4 -0
@@ -9,6 +9,7 @@#include <linux/syscalls.h> #include <linux/tick.h> #include <linux/unwind_deferred.h> +#include <linux/dept.h> #include <asm/entry-common.h>
@@ -88,6 +89,9 @@ static __always_inline bool arch_in_rcu_eqs(void) { return false; }*/ static __always_inline void enter_from_user_mode(struct pt_regs *regs) { +/* Make dept work with a new context. */ +dept_update_cxt (); +arch_enter_from_user_mode (regs);lockdep_hardirqs_off (CALLER_ADDR0 );
include/linux/sched.h +5 -5
@@ -833,19 +833,19 @@ struct dept_task {int wait_hist_pos;/* -* sequential id to identify each IRQ context +* sequential id to identify each context */ -unsigned int irq_id[DEPT_IRQS_NR ]; +unsigned int cxt_id[DEPT_CXTS_NR ];/* * for tracking IRQ-enabled points with cross-event */ -unsigned int wgen_enirq[DEPT_IRQS_NR ]; +unsigned int wgen_enirq[DEPT_CXT_IRQS_NR ];/* * for keeping up-to-date IRQ-enabled points */ -unsigned long enirq_ip[DEPT_IRQS_NR ]; +unsigned long enirq_ip[DEPT_CXT_IRQS_NR ];/* * for reserving a current stack instance at each operation
@@ -899,7 +899,7 @@ struct dept_task { .wait_hist = { { .wait = NULL, } }, \ .ecxt_held_pos = 0, \ .wait_hist_pos = 0, \ - .irq_id = { 0U }, \ + .cxt_id = { 0U }, \ .wgen_enirq = { 0U }, \ .enirq_ip = { 0UL }, \ .stack = NULL, \
kernel/dependency/dept.c +34 -33
197 lines not on this page · raw message
kernel/dependency/dept_internal.h +6 -6
@@ -106,8 +106,8 @@ struct dept_class {/* * for tracking IRQ dependencies */ -struct dept_iecxt iecxt[DEPT_IRQS_NR ]; -struct dept_iwait iwait[DEPT_IRQS_NR ]; +struct dept_iecxt iecxt[DEPT_CXT_IRQS_NR ]; +struct dept_iwait iwait[DEPT_CXT_IRQS_NR ];/* * classified by a map embedded in task_struct,
@@ -169,8 +169,8 @@ struct dept_ecxt {/* * where the IRQ-enabled happened */ -unsigned long enirq_ip[DEPT_IRQS_NR ]; -struct dept_stack *enirq_stack[DEPT_IRQS_NR ]; +unsigned long enirq_ip[DEPT_CXT_IRQS_NR ]; +struct dept_stack *enirq_stack[DEPT_CXT_IRQS_NR ];/* * where the event context started
@@ -214,8 +214,8 @@ struct dept_wait {/* * where the IRQ wait happened */ -unsigned long irq_ip[DEPT_IRQS_NR ]; -struct dept_stack *irq_stack[DEPT_IRQS_NR ]; +unsigned long irq_ip[DEPT_CXT_IRQS_NR ]; +struct dept_stack *irq_stack[DEPT_CXT_IRQS_NR ];/* * where the wait happened
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 06/40] dept: distinguish each kernel context from another
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] cur_cxt() incorrectly identifies a hardirq interrupting a softirq as a softirq context, mixing dependencies between unrelated execution contexts. --
commit 504ac1eb7d0a4081c645648037ec455b5ec741d7
Author: Byungchul Park <[email protected]>
dept: distinguish each kernel context from another
Each unique kernel context, in dept's point of view, should be identified on every entrance to kernel mode e.g. system call or user oriented fault. Otherwise, dept may track meaningless dependencies across different kernel context.
Quoted 4 lines
kernel/dependency/dept.c +0
-0
[ ... ]
kernel/dependency/dept.c static unsigned long cur_enirqf(void) · line 1810
Quoted 12 lines
kernel/dependency/dept.c +4
-4-static int cur_irq (void ) +static int cur_cxt (void ) {if (lockdep_softirq_context (current)) -return DEPT_SIRQ ; +return DEPT_CXT_SIRQ ;if (lockdep_hardirq_context ()) -return DEPT_HIRQ ; -return DEPT_IRQS_NR ; +return DEPT_CXT_HIRQ ; +return DEPT_CXT_PROCESS ; }
[Severity: High]
This is a pre-existing issue, but does cur_cxt() incorrectly prioritize softirq over hardirq context here?
If a softirq is executing and is interrupted by a hardirq, both lockdep_softirq_context(current) and lockdep_hardirq_context() evaluate to true. Because the softirq check comes first, cur_cxt() will return DEPT_CXT_SIRQ instead of DEPT_CXT_HIRQ.
Could this cause the waits and events triggered inside the interrupting hardirq to be erroneously attributed to the interrupted softirq's context, potentially mixing unrelated dependencies and leading to false positive circular dependency reports?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v19 7/40 dept: distinguish each work from another
In reply to Byungchul ParkWorkqueue already provides concurrency control. By that, any wait in a work doesn't prevents events in other works with the control enabled. Thus, each work would better be considered a different context.
So let dept assign a different context id to each work.
--- kernel/workqueue.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/workqueue.c +3 -0
@@ -55,6 +55,7 @@#include <linux/kvm_para.h> #include <linux/delay.h> #include <linux/irq_work.h> +#include <linux/dept.h> #include "workqueue_internal.h"
@@ -3204,6 +3205,8 @@ __acquires(&pool->lock)lockdep_copy_map (&lockdep_map, &work->lockdep_map);#endif +dept_update_cxt (); +/* ensure we're on the correct CPU */ WARN_ON_ONCE (!(pool->flags &POOL_DISASSOCIATED ) &&raw_smp_processor_id () != pool->cpu);
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 07/40] dept: distinguish each work from another
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] `dept_update_cxt()` hardcodes the process context ID, failing to track bottom-half (BH) work…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dept_update_cxt() hardcodes the process context ID, failing to track bottom-half (BH) work items in softirq context and corrupting the context of preempted tasks. --
commit b8dda7d95e5377770d28c6712cf8fe7fafa98ade
Author: Byungchul Park <[email protected]>
dept: distinguish each work from another
This commit updates DEPT to assign a different context ID to each work item. Since workqueues provide their own concurrency control, wait operations in a work item do not prevent events in other works from executing.
Quoted 4 lines
kernel/workqueue.c +0
-0
[ ... ]
kernel/workqueue.c __acquires(&pool->lock) · line 3209
Quoted 6 lines
kernel/workqueue.c +2
-0@@ -3204,6 +3205,8 @@ __acquires(&pool->lock)lockdep_copy_map (&lockdep_map, &work->lockdep_map);#endif +dept_update_cxt (); +
[Severity: Medium]
Will this unconditionally modify the process context ID, even when tracking bottom-half (BH) work items running in softirq context?
When a BH workqueue executes multiple work items in a single softirq batch, process_one_work() executes them and calls dept_update_cxt(). However, dept_update_cxt() is implemented as:
kernel/dependency/dept.c:dept_update_cxt() {
struct dept_task *dt = dept_task();
dt->cxt_id[DEPT_CXT_PROCESS] += 1UL << DEPT_CXTS_NR;
}This hardcodes the increment to DEPT_CXT_PROCESS rather than checking cur_cxt() to increment DEPT_CXT_SIRQ. Does this cause DEPT to fail in distinguishing sequential BH work items and falsely report dependencies?
Also, can this corrupt the continuous dependency tracking context of whatever task was preempted by the softirq?
Quoted 3 lines
kernel/workqueue.c +0
-0/* ensure we're on the correct CPU */ WARN_ON_ONCE (!(pool->flags &POOL_DISASSOCIATED ) &&raw_smp_processor_id () != pool->cpu);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Re: [PATCH v19 07/40] dept: distinguish each work from another
Quoted 20 lines · On Tue, Jul 07, 2026 at 07:33:33AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium]dept_update_cxt()hardcodes the process context ID, failing to track bottom-half (BH) work items in softirq context and corrupting the context of preempted tasks. --commit
b8dda7d95e5377770d28c6712cf8fe7fafa98ade
Author: Byungchul Park <[email protected]>dept: distinguish each work from another
This commit updates DEPT to assign a different context ID to each work item. Since workqueues provide their own concurrency control, wait operations in a work item do not prevent events in other works from executing.
Quoted 4 lines
kernel/workqueue.c +0
-0[ ... ]
Quoted 2 lines
kernel/workqueue.c +0
-0@@ -3204,6 +3205,8 @@ __acquires(&pool->lock)
Quoted 8 lines
kernel/workqueue.c __acquires(&pool->lock) · line 3209
Quoted 4 lines
kernel/workqueue.c +2
-0lockdep_copy_map (&lockdep_map, &work->lockdep_map);#endif +dept_update_cxt (); +[Severity: Medium]
Will this unconditionally modify the process context ID, even when tracking bottom-half (BH) work items running in softirq context?
Am I missing something? AFAIK, workqueue's workers run in process context, not softirq context.
Quoted 3 lines
When a BH workqueue executes multiple work items in a single softirq batch,
process_one_work()executes them and callsdept_update_cxt(). However,dept_update_cxt()is implemented as:
It's becasue its not racing with other contexts.
Quoted 8 lines
kernel/dependency/dept.c:dept_update_cxt() { struct dept_task *dt = dept_task(); dt->cxt_id[DEPT_CXT_PROCESS] += 1UL << DEPT_CXTS_NR; }This hardcodes the increment to
DEPT_CXT_PROCESSrather than checkingcur_cxt()to incrementDEPT_CXT_SIRQ. Does this cause DEPT to fail in distinguishing sequential BH work items and falsely report dependencies?
Are BH works running in softirq context? I will check it.
Quoted 2 lines
Also, can this corrupt the continuous dependency tracking context of whatever task was preempted by the softirq?
Process context's cxt_id is referred only in the process context, and irq context's cxt_id is referred only in the irq context. So no problem.
Byungchul
Quoted 6 lines
kernel/workqueue.c __acquires(&pool->lock) · line 3212
Quoted 3 lines
kernel/workqueue.c +0
-0/* ensure we're on the correct CPU */ WARN_ON_ONCE (!(pool->flags &POOL_DISASSOCIATED ) &&raw_smp_processor_id () != pool->cpu);--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
PATCH v19 8/40 dept: add a mechanism to refill the internal memory pools on running out
In reply to Byungchul Parkdept engine works in a constrained environment. For example, dept cannot make use of dynamic allocation e.g. kmalloc(). So dept has been using static pools to keep memory chunks dept uses.
However, dept would barely work once any of the pools gets run out. So implemented a mechanism for the refill on the lack, using irq work and workqueue that fits on the contrained environment.
--- kernel/dependency/dept.c | 108 +++++++++++++++++++++++++----- kernel/dependency/dept_internal.h | 19 ++++-- kernel/dependency/dept_object.h | 10 +-- kernel/dependency/dept_proc.c | 8 +-- 4 files changed, 116 insertions(+), 29 deletions(-)
kernel/dependency/dept.c +93 -15
@@ -75,6 +75,9 @@#include <linux/dept.h> #include <linux/utsname.h> #include <linux/kernel.h> +#include <linux/workqueue.h> +#include <linux/irq_work.h> +#include <linux/vmalloc.h> #include "dept_internal.h" static int dept_stop;
@@ -143,9 +146,11 @@ static inline struct dept_task *dept_task(void) } \ }) -#define DEPT_INFO_ONCE(s...) pr_warn_once("DEPT_INFO_ONCE: " s) +#define DEPT_INFO_ONCE(s...) pr_warn_once("DEPT_INFO_ONCE: " s) +#define DEPT_INFO(s...) pr_warn("DEPT_INFO: " s)static arch_spinlock_t dept_spin = (arch_spinlock_t )__ARCH_SPIN_LOCK_UNLOCKED; +static arch_spinlock_t dept_pool_spin = (arch_spinlock_t )__ARCH_SPIN_LOCK_UNLOCKED;/* * The DEPT internal engine should be cautious when using external functions
@@ -268,6 +273,7 @@ static bool valid_key(struct dept_key *k)#define OBJECT (id, nr) \ static struct dept_##id spool_##id[nr]; \ +static struct dept_##id rpool_##id[nr]; \ static DEFINE_PER_CPU(struct llist_head, lpool_##id);#include "dept_object.h" #undef OBJECT
@@ -276,14 +282,74 @@ struct dept_pool dept_pool[OBJECT_NR] = {#define OBJECT (id, nr) { \ .name = #id, \ .obj_sz = sizeof(struct dept_##id), \ - .obj_nr = ATOMIC_INIT(nr), \ + .obj_nr = nr, \ + .tot_nr = nr, \ + .acc_sz = ATOMIC_INIT(sizeof(spool_##id) + sizeof(rpool_##id)), \ .node_off = offsetof(struct dept_##id, pool_node), \ .spool = spool_##id, \ + .rpool = rpool_##id, \ .lpool = &lpool_##id, },#include "dept_object.h" #undef OBJECT }; +static void dept_wq_work_fn (struct work_struct *work) +{ +int i; + +for (i =0 ; i <OBJECT_NR ; i++) { +struct dept_pool *p = dept_pool + i; +int sz = p->tot_nr * p->obj_sz; +void *rpool; +bool need; + +local_irq_disable (); +arch_spin_lock (&dept_pool_spin); + need = !p->rpool; +arch_spin_unlock (&dept_pool_spin); +local_irq_enable (); + +if (!need) +continue ; + + rpool =vmalloc (sz); + +if (!rpool) { +DEPT_STOP ("Failed to extend internal resources.\n" ); +break ; + } + +local_irq_disable (); +arch_spin_lock (&dept_pool_spin); +if (!p->rpool) { + p->rpool = rpool; + rpool =NULL ; +atomic_add (sz, &p->acc_sz); + } +arch_spin_unlock (&dept_pool_spin); +local_irq_enable (); + +if (rpool) +vfree (rpool); +else +DEPT_INFO ("Dept object(%s) just got refilled successfully.\n" , p->name); + } +} + +static DECLARE_WORK(dept_wq_work, dept_wq_work_fn); + +static void dept_irq_work_fn (struct irq_work *w) +{ +schedule_work (&dept_wq_work); +} + +static DEFINE_IRQ_WORK(dept_irq_work, dept_irq_work_fn); + +static void request_rpool_refill (void ) +{ +irq_work_queue (&dept_irq_work); +} +/* * We can use llist regardless of whether CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG * is enabled, because NMI and other contexts on the same CPU never run
@@ -319,19 +385,31 @@ static void *from_pool(enum object_t t)/* * Try static pool. */ -if (atomic_read (&p->obj_nr) >0 ) { -int idx =atomic_dec_return (&p->obj_nr); +arch_spin_lock (&dept_pool_spin); + +if (!p->obj_nr) { + p->spool = p->rpool; + p->obj_nr = p->rpool ? p->tot_nr :0 ; + p->rpool =NULL ; +request_rpool_refill (); + } + +if (p->obj_nr) { +void *ret; + + p->obj_nr--; + ret = p->spool + (p->obj_nr * p->obj_sz); +arch_spin_unlock (&dept_pool_spin); -if (idx >=0 ) -return p->spool + (idx * p->obj_sz); +return ret; } +arch_spin_unlock (&dept_pool_spin); -DEPT_INFO_ONCE ("---------------------------------------------\n" -" Some of Dept internal resources are run out.\n" -" Dept might still work if the resources get freed.\n" -" However, the chances are Dept will suffer from\n" -" the lack from now. Needs to extend the internal\n" -" resource pools. Ask [email protected]\n" ); +DEPT_INFO ("------------------------------------------\n" +" Dept object(%s) is run out.\n" +" Dept is trying to refill the object.\n" +" Nevertheless, if it fails, Dept will stop.\n" , + p->name);return NULL ; }
@@ -2957,8 +3035,8 @@ void __init dept_init(void)pr_info ("... DEPT_MAX_ECXT_HELD : %d\n" ,DEPT_MAX_ECXT_HELD );pr_info ("... DEPT_MAX_SUBCLASSES : %d\n" ,DEPT_MAX_SUBCLASSES );#define OBJECT (id, nr) \ - pr_info("... memory used by %s: %zu KB\n", \ - #id, B2KB(sizeof(struct dept_##id) * nr)); + pr_info("... memory initially used by %s: %zu KB\n", \ + #id, B2KB(sizeof(spool_##id) + sizeof(rpool_##id)));#include "dept_object.h" #undef OBJECT#define HASH (id, bits) \
@@ -2966,6 +3044,6 @@ void __init dept_init(void)#id , B2KB(sizeof(struct hlist_head) * (1 << (bits))));#include "dept_hash.h" #undef HASH -pr_info ("... total memory used by objects and hashs: %zu KB\n" ,B2KB (mem_total)); +pr_info ("... total memory initially used by objects and hashs: %zu KB\n" ,B2KB (mem_total));pr_info ("... per task memory footprint: %zu bytes\n" ,sizeof (struct dept_task )); }
kernel/dependency/dept_internal.h +15 -4
@@ -26,9 +26,19 @@ struct dept_pool {size_t obj_sz;/* -* the number of the static array +* the remaining number of the object in spool */ -atomic_t obj_nr; +int obj_nr; + +/* +* the number of the object in spool +*/ +int tot_nr; + +/* +* accumulated amount of memory used by the object in byte +*/ +atomic_t acc_sz;/* * offset of ->pool_node
@@ -38,9 +48,10 @@ struct dept_pool {/* * pointer to the pool */ -void *spool; +void *spool;/* static pool */ +void *rpool;/* reserved pool */ struct llist_head boot_pool; -struct llist_head __percpu *lpool; +struct llist_head __percpu *lpool;/* local pool */ };struct dept_ecxt ;
kernel/dependency/dept_object.h +5 -5
@@ -6,8 +6,8 @@* nr: # of the object that should be kept in the pool. */ -OBJECT(dep, 1024 * 8) -OBJECT(class, 1024 * 8) -OBJECT(stack, 1024 * 32) -OBJECT(ecxt, 1024 * 16) -OBJECT (wait,1024 *32 ) +OBJECT(dep, 1024 * 4 * 2) +OBJECT(class, 1024 * 4) +OBJECT(stack, 1024 * 4 * 8) +OBJECT(ecxt, 1024 * 4 * 2) +OBJECT (wait,1024 *4 *4 )
kernel/dependency/dept_proc.c +3 -5
@@ -74,12 +74,10 @@ static int dept_stats_show(struct seq_file *m, void *v) {int r; -seq_puts (m,"Availability in the static pools:\n\n" ); +seq_puts (m,"Accumulated amount of memory used by pools:\n\n" );#define OBJECT (id, nr) \ - r = atomic_read(&dept_pool[OBJECT_##id].obj_nr); \ - if (r < 0) \ - r = 0; \ - seq_printf(m, "%s\t%d/%d(%d%%)\n", #id, r, nr, (r * 100) / (nr)); + r = atomic_read(&dept_pool[OBJECT_##id].acc_sz); \ + seq_printf(m, "%s\t%d KB\n", #id, r / 1024);#include "dept_object.h" #undef OBJECT
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 08/40] dept: add a mechanism to refill the internal memory pools on running out
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Per-CPU object pools (`lpool`) grow unboundedly because objects are never returned to the global…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Per-CPU object pools (lpool) grow unboundedly because objects are never returned to the global pool, leading to endless vmalloc() allocations and potential OOM.
- [High] Un-ratelimited printk in the pool exhaustion path causes console flooding and soft lockups.
--
(Note: The format of this report is altered to use a free-form summary rather than inline diff quotes due to recitation restrictions.)
commit 0f35ff40c325e46d2d4adab446907928b805d0e5
Author: Byungchul Park <[email protected]>
dept: add a mechanism to refill the internal memory pools on running out
This commit introduces a mechanism to dynamically refill internal memory pools for the DEPT engine using an IRQ work and workqueue. It adds per-CPU local pools and a vmalloc-based refill path when the static pools are exhausted.
[Severity: High]
Could the per-CPU local pools (lpool) grow without bounds under certain workloads?
Looking at to_pool() and from_pool() in kernel/dependency/dept.c, objects are unconditionally added to the per-CPU lpool without any upper bound check or reclaim logic. If a task allocates an object (like ecxt or wait) on CPU A, migrates to CPU B, and frees it, the object goes into CPU B's lpool.
Because objects are never returned to the global spool when the lpool grows large, the global pool will eventually drain. When from_pool() sees an empty global pool, it triggers request_rpool_refill(), which allocates new memory via vmalloc() in dept_wq_work_fn().
Will continuous cross-CPU allocation and freeing indefinitely leak memory into local pools and repeatedly trigger vmalloc allocations, potentially leading to an out-of-memory condition?
[Severity: High]
Is it safe to use an un-ratelimited printk in the pool exhaustion path?
In kernel/dependency/dept.c:from_pool(), when a pool is exhausted, the code calls DEPT_INFO() (which maps to pr_warn()) to notify the user. This happens with hardware interrupts disabled via dept_enter().
Because the pool refill in dept_wq_work_fn() happens asynchronously in a workqueue, the pool will remain empty until the workqueue runs. Every subsequent lock acquisition during this window will synchronously print a multi-line message to the console.
Could this flood the console and cause soft lockups or RCU stalls since thousands of locks might be acquired by a single thread while waiting for the async workqueue to execute?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH v19 9/40 dept: record the latest one out of consecutive waits of the same class
In reply to Byungchul ParkThe current code records all the waits for later use to track relation between waits and events within each context. However, since the same class is handled the same way, it'd be okay to record only one on behalf of the others if they all have the same class.
Even though it's the ideal to search the whole history buffer for that, since it'd cost too high, alternatively, let's keep the latest one when the same class'ed waits consecutively appear.
--- kernel/dependency/dept.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
kernel/dependency/dept.c +20 -1
@@ -1486,9 +1486,28 @@ static struct dept_wait_hist *new_hist(void)return wh; } +static struct dept_wait_hist *last_hist (void ) +{ +int pos_n =hist_pos_next (); +struct dept_wait_hist *wh_n =hist (pos_n); + +/* +* This is the first try. +*/ +if (!pos_n && !wh_n->wait) +return NULL ; + +return hist (pos_n +DEPT_MAX_WAIT_HIST -1 ); +} +static void add_hist (struct dept_wait *w,unsigned int wg,unsigned int ctxt_id) { -struct dept_wait_hist *wh =new_hist (); +struct dept_wait_hist *wh; + + wh =last_hist (); + +if (!wh || wh->wait->class != w->class || wh->ctxt_id != ctxt_id) + wh =new_hist ();if (likely (wh->wait))put_wait (wh->wait);
Signature · 1 line
2.17.1
PATCH v19 10/40 dept: apply sdt_might_sleep_{start,end}() to wait_for_completion()/complete()
In reply to Byungchul ParkMake dept able to track dependencies by wait_for_completion()/complete().
--- include/linux/completion.h | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
include/linux/completion.h +25 -5
@@ -10,6 +10,7 @@*/ #include <linux/swait.h> +#include <linux/dept_sdt.h> /* * struct completion - structure used to maintain state for a "completion"
@@ -26,14 +27,33 @@struct completion {unsigned int done;struct swait_queue_head wait; +struct dept_map dmap; }; +#define init_completion (x) \ +do { \ + sdt_map_init(&(x)->dmap); \ + __init_completion(x); \ +} while (0) + +/* +* XXX: No use cases for now. Fill the body when needed. +*/ #define init_completion_map (x, m) init_completion(x) -static inline void complete_acquire (struct completion *x) {} -static inline void complete_release (struct completion *x) {} + +static inline void complete_acquire (struct completion *x) +{ +sdt_might_sleep_start (&x->dmap); +} + +static inline void complete_release (struct completion *x) +{ +sdt_might_sleep_end (); +}#define COMPLETION_INITIALIZER (work) \ - { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait) } + { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait), \ + .dmap = DEPT_MAP_INITIALIZER(work, NULL), }#define COMPLETION_INITIALIZER_ONSTACK_MAP (work, map) \ (*({ init_completion_map(&(work), &(map)); &(work); }))
@@ -75,13 +95,13 @@ static inline void complete_release(struct completion *x) {}#endif /** -* init_completion - Initialize a dynamically allocated completion +* __init_completion - Initialize a dynamically allocated completion * @x: pointer to completion structure that is to be initialized * * This inline function will initialize a dynamically created completion * structure. */ -static inline void init_completion (struct completion *x) +static inline void __init_completion (struct completion *x) { x->done =0 ;init_swait_queue_head (&x->wait);
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 10/40] dept: apply sdt_might_sleep_{start, end}() to wait_for_completion()/complete()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The `init_completion_map()` macro ignores the provided lockdep map argument `m` and sets `dmap` to…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The init_completion_map() macro ignores the provided lockdep map argument m and sets dmap to NULL. This forces all generic wrappers like flush_work() to share a single, monolithic dependency class generated at the wait_for_completion macro call site. --
commit c25e7af1e00aa68cd5900db21d080eadb8fccd71
Author: Byungchul Park <[email protected]>
dept: apply sdt_might_sleep_{start,end}() to wait_for_completion()/complete()
This commit enables the DEPT (Dependency Tracker) to track dependencies introduced by wait_for_completion() and complete() calls. It adds a dept_map to the completion structure and applies the appropriate sleep start and end annotations.
Quoted 4 lines
include/linux/completion.h +0
-0
[ ... ]
Quoted 7 lines
include/linux/completion.h +1
-0@@ -26,14 +27,33 @@struct completion {unsigned int done;struct swait_queue_head wait; +struct dept_map dmap; };
include/linux/completion.h line 42
Quoted 10 lines
include/linux/completion.h +9
-0+#define init_completion (x) \ +do { \ + sdt_map_init(&(x)->dmap); \ + __init_completion(x); \ +} while (0) + +/* +* XXX: No use cases for now. Fill the body when needed. +*/ #define init_completion_map (x, m) init_completion(x)
[Severity: High]
Does this macro cause independent dependency graphs to merge? By ignoring the lockdep map argument m and calling init_completion(x) instead, it seems generic wrappers like flush_work() will be forced to share a single monolithic dependency class generated at the wait site.
Could this lead DEPT to report false-positive deadlocks during normal operations? For example, if Work A flushes Work B, and Work B flushes Work C, both use the same flush_work() completion class. DEPT might see Work B both waiting on and satisfying this global class, erroneously detecting a self-cycle.
Quoted 2 lines
include/linux/completion.h +0
-2-static inline void complete_acquire (struct completion *x) {} -static inline void complete_release (struct completion *x) {}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
PATCH v19 11/40 dept: apply sdt_might_sleep_{start,end}() to swait
In reply to Byungchul ParkMake dept able to track dependencies by swaits.
--- include/linux/swait.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/swait.h +3 -0
@@ -6,6 +6,7 @@#include <linux/stddef.h> #include <linux/spinlock.h> #include <linux/wait.h> +#include <linux/dept_sdt.h> #include <asm/current.h> /*
@@ -161,6 +162,7 @@ extern void finish_swait(struct swait_queue_head *q, struct swait_queue *wait);struct swait_queue __wait; \long __ret = ret; \ \ +sdt_might_sleep_start (NULL ); \INIT_LIST_HEAD (&__wait.task_list); \for (;;) { \long __int =prepare_to_swait_event (&wq, &__wait, state);\
@@ -176,6 +178,7 @@ extern void finish_swait(struct swait_queue_head *q, struct swait_queue *wait); cmd; \ } \finish_swait (&wq, &__wait); \ +sdt_might_sleep_end (); \ __out: __ret; \ })
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 11/40] dept: apply sdt_might_sleep_{start,end}() to swait
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The `___swait_event`, `___wait_event`, and `___wait_var_event` macros skip the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The ___swait_event, ___wait_event, and ___wait_var_event macros skip the sdt_might_sleep_end() cleanup call when returning early due to a pending signal, leading to persistent DEPT state corruption that permanently disables dependency tracking for the affected task. --
commit 7785a2fe54ced42e856f39ece5776f11bca47be8
Author: Byungchul Park <[email protected]>
dept: apply sdt_might_sleep_{start,end}() to swait
Make dept able to track dependencies by swaits.
Quoted 4 lines
include/linux/swait.h +0
-0
[ ... ]
Quoted 9 lines
include/linux/swait.h +1
-0@@ -161,6 +162,7 @@ extern void finish_swait(struct swait_queue_head *q, struct swait_queue *wait);struct swait_queue __wait; \long __ret = ret; \ \ +sdt_might_sleep_start (NULL ); \INIT_LIST_HEAD (&__wait.task_list); \for (;;) { \long __int =prepare_to_swait_event (&wq, &__wait, state);\
include/linux/swait.h extern void finish_swait(struct swait_queue_head *q, struct swait_queue *wait); · line 183
Quoted 6 lines
include/linux/swait.h +1
-0@@ -176,6 +178,7 @@ extern void finish_swait(struct swait_queue_head *q, struct swait_queue *wait); cmd; \ } \finish_swait (&wq, &__wait); \ +sdt_might_sleep_end (); \ __out: __ret; \ })
[Severity: High]
Does this code bypass the sdt_might_sleep_end() cleanup when returning early due to a pending signal?
Looking at ___swait_event(), if a task waiting interruptibly receives a signal, prepare_to_swait_event() returns a non-zero error code.
The wait loop evaluates ___wait_is_interruptible(state) && __int as true and executes a goto __out; which jumps completely over this new cleanup call.
If sdt_might_sleep_end() is skipped, does the task's dependency staging map remain persistently populated, effectively causing subsequent calls to dept_stage_wait() to silently exit early and disable DEPT tracking for that task?
It looks like this identical sequence might also occur in the generic waitqueue macros (___wait_event in include/linux/wait.h) and the hashed waitqueue macros (___wait_var_event in include/linux/wait_bit.h).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
PATCH v19 12/40 dept: apply sdt_might_sleep_{start,end}() to waitqueue wait
In reply to Byungchul ParkMake dept able to track dependencies by waitqueue waits.
--- include/linux/wait.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/wait.h +3 -0
@@ -7,6 +7,7 @@#include <linux/list.h> #include <linux/stddef.h> #include <linux/spinlock.h> +#include <linux/dept_sdt.h> #include <asm/current.h>
@@ -305,6 +306,7 @@ extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);struct wait_queue_entry __wq_entry; \long __ret = ret;/* explicit shadow */ \ \ +sdt_might_sleep_start (NULL ); \init_wait_entry (&__wq_entry, exclusive ?WQ_FLAG_EXCLUSIVE :0 ); \for (;;) { \long __int =prepare_to_wait_event (&wq_head, &__wq_entry, state);\
@@ -323,6 +325,7 @@ extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);break ; \ } \finish_wait (&wq_head, &__wq_entry); \ +sdt_might_sleep_end (); \ __out: __ret; \ })
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 12/40] dept: apply sdt_might_sleep_{start, end}() to waitqueue wait
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The `sdt_might_sleep_end()` cleanup macro is bypassed when wait loops (`___wait_event`…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The sdt_might_sleep_end() cleanup macro is bypassed when wait loops (___wait_event, ___swait_event) are interrupted by a signal, permanently leaking a DEPT dependency stage. --
commit 1300cac9c94eeb3955744b6d40ed8dce8cfc059f
Author: Byungchul Park <[email protected]>
dept: apply sdt_might_sleep_{start,end}() to waitqueue wait
Make dept able to track dependencies by waitqueue waits.
Quoted 4 lines
include/linux/wait.h +0
-0
[ ... ]
Quoted 9 lines
include/linux/wait.h +1
-0@@ -305,6 +306,7 @@ extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);struct wait_queue_entry __wq_entry; \long __ret = ret;/* explicit shadow */ \ \ +sdt_might_sleep_start (NULL ); \init_wait_entry (&__wq_entry, exclusive ?WQ_FLAG_EXCLUSIVE :0 ); \for (;;) { \long __int =prepare_to_wait_event (&wq_head, &__wq_entry, state);\
include/linux/wait.h extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags); · line 330
Quoted 6 lines
include/linux/wait.h +1
-0@@ -323,6 +325,7 @@ extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);break ; \ } \finish_wait (&wq_head, &__wq_entry); \ +sdt_might_sleep_end (); \ __out: __ret; \ })
[Severity: High]
Does this bypass sdt_might_sleep_end() when interrupted by a signal?
Looking at ___wait_event(), if ___wait_is_interruptible(state) and __int is set, it will take the goto __out path:
if (___wait_is_interruptible(state) && __int) { \
__ret = __int; \
goto __out; \
} \If that path is taken, sdt_might_sleep_end() is bypassed, which permanently leaks a DEPT dependency stage. A stale wait context remains in the task's dependency tracker state. When the task later sleeps for unrelated reasons, the scheduler might attribute the sleep to the leaked context, leading to false-positive lockup splats.
Also, does this same structural issue exist in ___swait_event() in include/linux/swait.h for simple waitqueues?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
PATCH v19 13/40 dept: apply sdt_might_sleep_{start,end}() to hashed-waitqueue wait
In reply to Byungchul ParkMake dept able to track dependencies by hashed-waitqueue waits.
--- include/linux/wait_bit.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/wait_bit.h +3 -0
@@ -6,6 +6,7 @@* Linux wait-bit related types and methods: */ #include <linux/wait.h> +#include <linux/dept_sdt.h> struct wait_bit_key {unsigned long *flags;
@@ -257,6 +258,7 @@ extern wait_queue_head_t *__var_waitqueue(void *p);struct wait_bit_queue_entry __wbq_entry; \long __ret = ret;/* explicit shadow */ \ \ +sdt_might_sleep_start (NULL ); \init_wait_var_entry (&__wbq_entry, var, \ exclusive ?WQ_FLAG_EXCLUSIVE :0 ); \for (;;) { \
@@ -274,6 +276,7 @@ extern wait_queue_head_t *__var_waitqueue(void *p); cmd; \ } \finish_wait (__wq_head, &__wbq_entry.wq_entry); \ +sdt_might_sleep_end (); \ __out: __ret; \ })
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 13/40] dept: apply sdt_might_sleep_{start, end}() to hashed-waitqueue wait
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The `sdt_might_sleep_end()` macro is bypassed when `___wait_var_event` is interrupted, leaving…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The sdt_might_sleep_end() macro is bypassed when ___wait_var_event is interrupted, leaving the DEPT tracker in an inconsistent state.
- [Medium] The sdt_might_sleep_end() macro is bypassed when ___wait_event is interrupted, leaving the DEPT tracker in an inconsistent state. --
commit 0bd2d42866fa6b852ee5317edcaf6890a90c3c65
Author: Byungchul Park <[email protected]>
dept: apply sdt_might_sleep_{start,end}() to hashed-waitqueue wait
Make dept able to track dependencies by hashed-waitqueue waits.
Quoted 4 lines
include/linux/wait_bit.h +0
-0
[ ... ]
Quoted 9 lines
include/linux/wait_bit.h +1
-0@@ -257,6 +258,7 @@ extern wait_queue_head_t *__var_waitqueue(void *p);struct wait_bit_queue_entry __wbq_entry; \long __ret = ret;/* explicit shadow */ \ \ +sdt_might_sleep_start (NULL ); \init_wait_var_entry (&__wbq_entry, var, \ exclusive ?WQ_FLAG_EXCLUSIVE :0 ); \for (;;) { \
include/linux/wait_bit.h extern wait_queue_head_t *__var_waitqueue(void *p); · line 281
Quoted 6 lines
include/linux/wait_bit.h +1
-0@@ -274,6 +276,7 @@ extern wait_queue_head_t *__var_waitqueue(void *p); cmd; \ } \finish_wait (__wq_head, &__wbq_entry.wq_entry); \ +sdt_might_sleep_end (); \ __out: __ret; \ })
[Severity: Medium]
If this wait is interrupted by a signal, the loop executes a goto __out which bypasses sdt_might_sleep_end(). Does this leave the dept tracker in an inconsistent state where the task's stage remains permanently armed?
This could cause false positive dependency tracking splats on subsequent waits, or fail to record new dependencies because the tracker is blinded by the stale stage.
I noticed the exact same issue is present in ___wait_event():
include/linux/wait.h:___wait_event() {
...
if (___wait_is_interruptible(state) && __int) {
__ret = __int;
goto __out;
}
...
sdt_might_sleep_end();__out: __ret;
})
[Severity: Medium]
Does ___wait_event() also skip sdt_might_sleep_end() when interrupted? By missing the paired cleanup call, the task's stage could remain permanently armed here as well.
Would it make sense to move the __out label above sdt_might_sleep_end(), or otherwise ensure the state is cleaned up on the interrupted paths for both of these macros?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
Re: [PATCH v19 13/40] dept: apply sdt_might_sleep_{start, end}() to hashed-waitqueue wait
Quoted 52 lines · On Tue, Jul 07, 2026 at 07:33:16AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Thesdt_might_sleep_end()macro is bypassed when___wait_var_eventis interrupted, leaving the DEPT tracker in an inconsistent state.
- [Medium] Thesdt_might_sleep_end()macro is bypassed when___wait_eventis interrupted, leaving the DEPT tracker in an inconsistent state. --commit
0bd2d42866fa6b852ee5317edcaf6890a90c3c65
Author: Byungchul Park <[email protected]>dept: apply sdt_might_sleep_{start,end}() to hashed-waitqueue wait
Make dept able to track dependencies by hashed-waitqueue waits.
Quoted 4 lines
include/linux/wait_bit.h +0
-0[ ... ]
Quoted 9 lines
include/linux/wait_bit.h +1
-0@@ -257,6 +258,7 @@ extern wait_queue_head_t *__var_waitqueue(void *p);struct wait_bit_queue_entry __wbq_entry; \long __ret = ret;/* explicit shadow */ \ \ +sdt_might_sleep_start (NULL ); \init_wait_var_entry (&__wbq_entry, var, \ exclusive ?WQ_FLAG_EXCLUSIVE :0 ); \for (;;) { \include/linux/wait_bit.h extern wait_queue_head_t *__var_waitqueue(void *p); · line 281
Quoted 6 lines
include/linux/wait_bit.h +1
-0@@ -274,6 +276,7 @@ extern wait_queue_head_t *__var_waitqueue(void *p); cmd; \ } \finish_wait (__wq_head, &__wbq_entry.wq_entry); \ +sdt_might_sleep_end (); \ __out: __ret; \ })[Severity: Medium]
If this wait is interrupted by a signal, the loop executes a goto__outwhich bypassessdt_might_sleep_end(). Does this leave the dept tracker in an inconsistent state where the task's stage remains permanently armed?This could cause false positive dependency tracking splats on subsequent waits, or fail to record new dependencies because the tracker is blinded by the stale stage.
I noticed the exact same issue is present in
___wait_event():include/linux/wait.h:___wait_event() { ... if (___wait_is_interruptible(state) && __int) { __ret = __int; goto __out; } ... sdt_might_sleep_end();
Quoted 2 lines
__out:__ret;
})
I will fix it.
Quoted 8 lines
[Severity: Medium]
Does___wait_event()also skipsdt_might_sleep_end()when interrupted? By missing the paired cleanup call, the task's stage could remain permanently armed here as well.Would it make sense to move the
__outlabel abovesdt_might_sleep_end(), or otherwise ensure the state is cleaned up on the interrupted paths for both of these macros?
Right. I will fix it.
Byungchul
Quoted 2 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
PATCH v19 14/40 dept: apply sdt_might_sleep_{start,end}() to dma fence
In reply to Byungchul ParkMake dept able to track dependencies by dma fence waits and signals.
--- drivers/dma-buf/dma-fence.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/dma-buf/dma-fence.c +5 -0
@@ -16,6 +16,7 @@#include <linux/dma-fence.h> #include <linux/sched/signal.h> #include <linux/seq_file.h> +#include <linux/dept_sdt.h> #define CREATE_TRACE_POINTS #include <trace/events/dma_fence.h>
@@ -822,6 +823,7 @@ dma_fence_default_wait(struct dma_fence *fence, bool intr, signed long timeout) cb.task = current;list_add (&cb.base.node, &fence->cb_list); +sdt_might_sleep_start (NULL );while (!dma_fence_test_signaled_flag (fence) && ret >0 ) {if (intr)__set_current_state (TASK_INTERRUPTIBLE );
@@ -835,6 +837,7 @@ dma_fence_default_wait(struct dma_fence *fence, bool intr, signed long timeout)if (ret >0 && intr &&signal_pending (current)) ret = -ERESTARTSYS ; } +sdt_might_sleep_end ();if (!list_empty (&cb.base.node))list_del (&cb.base.node);
@@ -924,6 +927,7 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, } } +sdt_might_sleep_start (NULL );while (ret >0 ) {if (intr)set_current_state (TASK_INTERRUPTIBLE );
@@ -938,6 +942,7 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,if (ret >0 && intr &&signal_pending (current)) ret = -ERESTARTSYS ; } +sdt_might_sleep_end ();__set_current_state (TASK_RUNNING );
Signature · 1 line
2.17.1
PATCH v19 15/40 dept: track timeout waits separately with a new Kconfig
In reply to Byungchul ParkWaits with valid timeouts don't actually cause deadlocks. However, dept has been reporting the cases as well because it's worth informing the circular dependency for some cases where, for example, timeout is used to avoid a deadlock.
However, yes, there are also a lot of, even more, cases where timeout is used for its clear purpose and meant to be expired.
Report these as an information rather than warning DEADLOCK. Plus, introduce CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT Kconfig to make it optional so that any reports involving waits with timeouts can be turned on/off depending on the purpose.
--- include/linux/dept.h | 8 ++-- include/linux/dept_ldt.h | 6 +-- include/linux/dept_sdt.h | 13 +++--- include/linux/sched.h | 2 + kernel/dependency/dept.c | 66 ++++++++++++++++++++++++++----- kernel/dependency/dept_internal.h | 5 +++ lib/Kconfig.debug | 10 +++++ 7 files changed, 89 insertions(+), 21 deletions(-)
include/linux/dept.h +4 -4
@@ -139,8 +139,8 @@ void dept_free_range(void *start, unsigned int sz);void dept_map_init (struct dept_map *m,struct dept_key *k,int sub_u,const char *n);void dept_map_reinit (struct dept_map *m,struct dept_key *k,int sub_u,const char *n);void dept_map_copy (struct dept_map *to,struct dept_map *from); -void dept_wait (struct dept_map *m,unsigned long w_f,unsigned long ip,const char *w_fn,int sub_l); -void dept_stage_wait (struct dept_map *m,struct dept_key *k,unsigned long ip,const char *w_fn); +void dept_wait (struct dept_map *m,unsigned long w_f,unsigned long ip,const char *w_fn,int sub_l,long timeout); +void dept_stage_wait (struct dept_map *m,struct dept_key *k,unsigned long ip,const char *w_fn,long timeout);void dept_request_event_wait_commit (void );void dept_clean_stage (void );void dept_ttwu_stage_wait (struct task_struct *t,unsigned long ip);
@@ -187,8 +187,8 @@ struct dept_map { };#define dept_map_init (m, k, su, n) do { (void)(n); (void)(k); } while (0)#define dept_map_reinit (m, k, su, n) do { (void)(n); (void)(k); } while (0)#define dept_map_copy (t, f) do { } while (0) -#define dept_wait (m, w_f, ip, w_fn, sl) do { (void)(w_fn); } while (0) -#define dept_stage_wait (m, k, ip, w_fn) do { (void)(k); (void)(w_fn); } while (0) +#define dept_wait (m, w_f, ip, w_fn, sl, t) do { (void)(w_fn); } while (0) +#define dept_stage_wait (m, k, ip, w_fn, t) do { (void)(k); (void)(w_fn); } while (0)#define dept_request_event_wait_commit () do { } while (0)#define dept_clean_stage () do { } while (0)#define dept_ttwu_stage_wait (t, ip) do { } while (0)
include/linux/dept_ldt.h +3 -3
@@ -28,7 +28,7 @@else if (t) \dept_ecxt_enter (m,LDT_EVT_L , i,"trylock" ,"unlock" , sl);\else { \ -dept_wait (m,LDT_EVT_L , i,"lock" , sl); \ +dept_wait (m,LDT_EVT_L , i,"lock" , sl, false); \dept_ecxt_enter (m,LDT_EVT_L , i,"lock" ,"unlock" , sl);\ } \ }while (0 )
@@ -40,7 +40,7 @@else if (t) \dept_ecxt_enter (m,LDT_EVT_R , i,"read_trylock" ,"read_unlock" , sl);\else { \ -dept_wait (m, q ?LDT_EVT_RW :LDT_EVT_W , i,"read_lock" , sl);\ +dept_wait (m, q ?LDT_EVT_RW :LDT_EVT_W , i,"read_lock" , sl, false);\dept_ecxt_enter (m,LDT_EVT_R , i,"read_lock" ,"read_unlock" , sl);\ } \ }while (0 )
@@ -52,7 +52,7 @@else if (t) \dept_ecxt_enter (m,LDT_EVT_W , i,"write_trylock" ,"write_unlock" , sl);\else { \ -dept_wait (m,LDT_EVT_RW , i,"write_lock" , sl); \ +dept_wait (m,LDT_EVT_RW , i,"write_lock" , sl, false);\dept_ecxt_enter (m,LDT_EVT_W , i,"write_lock" ,"write_unlock" , sl);\ } \ }while (0 )
include/linux/dept_sdt.h +8 -5
@@ -23,11 +23,12 @@#define sdt_map_init_key (m, k) dept_map_init(m, k, 0, #m) -#define sdt_wait (m) \ +#define sdt_wait_timeout (m, t) \ do { \ dept_request_event(m); \ - dept_wait(m, 1UL, _THIS_IP_, __func__, 0); \ + dept_wait(m, 1UL, _THIS_IP_, __func__, 0, t); \ } while (0) +#define sdt_wait (m) sdt_wait_timeout(m, -1L)/* * sdt_might_sleep() and its family will be committed in __schedule()
@@ -38,13 +39,13 @@/* * Use the code location as the class key if an explicit map is not used. */ -#define sdt_might_sleep_start (m) \ +#define sdt_might_sleep_start_timeout (m, t) \ do { \ struct dept_map *__m = m; \ static struct dept_key __key; \ - dept_stage_wait(__m, __m ? NULL : &__key, _THIS_IP_, __func__);\ + dept_stage_wait(__m, __m ? NULL : &__key, _THIS_IP_, __func__, t);\ } while (0) - +#define sdt_might_sleep_start (m) sdt_might_sleep_start_timeout(m, -1L)#define sdt_might_sleep_end () dept_clean_stage()#define sdt_ecxt_enter (m) dept_ecxt_enter(m, 1UL, _THIS_IP_, "start", "event", 0)
@@ -54,7 +55,9 @@#else /* !CONFIG_DEPT */ #define sdt_map_init (m) do { } while (0)#define sdt_map_init_key (m, k) do { (void)(k); } while (0) +#define sdt_wait_timeout (m, t) do { } while (0)#define sdt_wait (m) do { } while (0) +#define sdt_might_sleep_start_timeout (m, t) do { } while (0)#define sdt_might_sleep_start (m) do { } while (0)#define sdt_might_sleep_end () do { } while (0)#define sdt_ecxt_enter (m) do { } while (0)
include/linux/sched.h +2 -0
@@ -870,6 +870,7 @@ struct dept_task {bool stage_sched_map;const char *stage_w_fn;unsigned long stage_ip; +bool stage_timeout;arch_spinlock_t stage_lock;/*
@@ -910,6 +911,7 @@ struct dept_task { .stage_sched_map = false, \ .stage_w_fn = NULL, \ .stage_ip = 0UL, \ + .stage_timeout = false, \ .stage_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED,\ .missing_ecxt = 0, \ .hardirqs_enabled = false, \
kernel/dependency/dept.c +57 -9
171 lines not on this page · raw message
kernel/dependency/dept_internal.h +5 -0
@@ -238,6 +238,11 @@ struct dept_wait {* whether this wait is for commit in scheduler */ bool sched_sleep; + +/* +* whether a timeout is set +*/ +bool timeout; }; }; };
lib/Kconfig.debug +10 -0
@@ -1467,6 +1467,16 @@ config DEPT noting, to mitigate the impact by the false positives, multi reporting has been supported. +config DEPT_AGGRESSIVE_TIMEOUT_WAIT + bool "Aggressively track even timeout waits" + depends on DEPT + default n + help + Timeout wait doesn't contribute to a deadlock. However, + informing a circular dependency might be helpful for cases + that timeout is used to avoid a deadlock. Say N if you'd like + to avoid verbose reports. + config LOCK_DEBUGGING_SUPPORT bool depends on TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 15/40] dept: track timeout waits separately with a new Kconfig
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Semantic collision in the timeoutval argument causes 0-timeout try-waits to be incorrectly tracked…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Semantic collision in the timeoutval argument causes 0-timeout try-waits to be incorrectly tracked as hard blocking dependencies.
- [High] Enabling CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT masks real deadlocks because a timeout wait permanently poisons the dependency edge, causing subsequent strict (non-timeout) waits to be ignored. --
commit 1b06fc68b17e6c7948f8187e55952d1767e48762
Author: Byungchul Park <[email protected]>
dept: track timeout waits separately with a new Kconfig
This patch modifies DEPT to track timeout waits separately to avoid reporting false positive deadlocks for deliberate timeouts. It also introduces the CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT option to toggle this tracking behavior.
Quoted 4 lines
kernel/dependency/dept.c +0
-0
[ ... ]
Quoted 4 lines
kernel/dependency/dept.c +0
-0@@ -810,6 +812,24 @@ static void print_dep(struct dept_dep *d)static void save_current_stack (int skip);
kernel/dependency/dept.c static void print_dep(struct dept_dep *d) · line 824
Quoted 10 lines
kernel/dependency/dept.c +10
-0+static bool is_timeout_wait_circle (struct dept_class *c) +{ +struct dept_class *fc = c->bfs_parent; +struct dept_class *tc = c; + + do { + struct dept_dep *d = lookup_dep(fc, tc); + + if (d->wait->timeout) + return true;
[Severity: High]
If CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT is enabled, does this mask genuine deadlocks if a strict wait follows a timeout wait?
If a timeout wait between class A and class B occurs first, it creates a dependency edge with wait->timeout set to true. If a strict (non-timeout) wait subsequently occurs between the same classes, add_dep() finds the existing edge and returns early:
kernel/dependency/dept.c:add_dep() {
if (lookup_dep(fc, tc))
return;
...
}The edge is never upgraded to reflect the stricter dependency.
If a deadlock later happens involving this edge, would is_timeout_wait_circle() see the stale timeout flag and incorrectly report it as an intended circular dependency instead of a genuine deadlock?
Quoted 7 lines
kernel/dependency/dept.c +7
-0+ + tc = fc; + fc = fc->bfs_parent; + }while (tc != c); + +return false; +}
[ ... ]
Quoted 6 lines
kernel/dependency/dept.c +1
-1@@ -2355,14 +2381,23 @@ static void __dept_event(struct dept_map *m, struct dept_map *real_m, } void dept_wait(struct dept_map *m, unsigned long w_f, -unsigned long ip,const char *w_fn,int sub_l) + unsigned long ip, const char *w_fn, int sub_l,
kernel/dependency/dept.c static void __dept_event(struct dept_map *m, struct dept_map *real_m, · line 2394
Quoted 10 lines
kernel/dependency/dept.c +3
-0+ long timeoutval) {struct dept_task *dt =dept_task ();unsigned long flags; +bool timeout;if (unlikely (!dept_working ()))return ; + timeout = timeoutval >0 && timeoutval <MAX_SCHEDULE_TIMEOUT ;
[Severity: High]
Does this logic correctly handle try-waits or polling?
When a caller invokes a polling wait like wait_for_completion_timeout(x, 0), the timeoutval is 0. Because 0 > 0 evaluates to false, this sets timeout to false. DEPT then tracks this non-blocking poll as an indefinite hard wait.
Can this lead to false positive deadlock reports when no actual blocking occurs?
Quoted 9 lines
kernel/dependency/dept.c +6
-0+ +#if !defined(CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT ) +if (timeout) +return ; +#endif +if (dt->recursive)return ;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
PATCH v19 16/40 dept: apply timeout consideration to wait_for_completion()/complete()
In reply to Byungchul ParkNow that CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT was introduced, apply the consideration to wait_for_completion()/complete().
--- include/linux/completion.h | 4 ++-- kernel/sched/completion.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/completion.h +2 -2
@@ -41,9 +41,9 @@ do { \*/ #define init_completion_map (x, m) init_completion(x) -static inline void complete_acquire (struct completion *x) +static inline void complete_acquire (struct completion *x,long timeout) { -sdt_might_sleep_start (&x->dmap); +sdt_might_sleep_start_timeout (&x->dmap, timeout); }static inline void complete_release (struct completion *x)
kernel/sched/completion.c +1 -1
@@ -115,7 +115,7 @@ __wait_for_common(struct completion *x, {might_sleep (); -complete_acquire (x); +complete_acquire (x, timeout);raw_spin_lock_irq (&x->wait.lock); timeout =do_wait_for_common (x, action, timeout, state);
Signature · 1 line
2.17.1
PATCH v19 17/40 dept: apply timeout consideration to swait
In reply to Byungchul ParkNow that CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT was introduced, apply the consideration to swait, assuming an input 'ret' in ___swait_event() macro is used as a timeout value.
--- include/linux/swait.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/swait.h +1 -1
@@ -162,7 +162,7 @@ extern void finish_swait(struct swait_queue_head *q, struct swait_queue *wait);struct swait_queue __wait; \long __ret = ret; \ \ -sdt_might_sleep_start (NULL ); \ +sdt_might_sleep_start_timeout (NULL , __ret); \INIT_LIST_HEAD (&__wait.task_list); \for (;;) { \long __int =prepare_to_swait_event (&wq, &__wait, state);\
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 17/40] dept: apply timeout consideration to swait
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] When a wait event is interrupted by a signal, it bypasses sdt_might_sleep_end(), permanently…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] When a wait event is interrupted by a signal, it bypasses sdt_might_sleep_end(), permanently leaking the DEPT wait stage. --
commit 264d829a8f72641205caea8b130ee3c25557563a
Author: Byungchul Park <[email protected]>
dept: apply timeout consideration to swait
Now that CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT was introduced, apply the consideration to swait, assuming an input 'ret' in ___swait_event() macro is used as a timeout value.
include/linux/swait.h extern void finish_swait(struct swait_queue_head *q, struct swait_queue *wait); · line 165
Quoted 10 lines
include/linux/swait.h +1
-1@@ -162,7 +162,7 @@ extern void finish_swait(struct swait_queue_head *q, struct swait_queue *wait);struct swait_queue __wait; \long __ret = ret; \ \ -sdt_might_sleep_start (NULL ); \ +sdt_might_sleep_start_timeout (NULL , __ret); \
[Severity: High]
Is this a regression where a signal-interrupted wait event permanently leaks the dept wait stage tracking state?
Looking at ___swait_event(), if the task receives a signal while waiting, it evaluates ___wait_is_interruptible(state) && __int as true and takes the goto __out path:
if (___wait_is_interruptible(state) && __int) {
__ret = __int;
goto __out;
}This jumps completely over the cleanup call:
finish_swait(&wq, &__wait); sdt_might_sleep_end();
__out: __ret;
Without calling sdt_might_sleep_end() and its underlying dept_clean_stage(), the dept state isn't cleaned up for the current task. Subsequent waits by this task will fail to register new dependency maps and instead repeatedly commit the stale wait map during __schedule(). This irreversibly corrupts the lock dependency graph and triggers false deadlock reports.
The exact same bypass flaw appears to be present in ___wait_event() in include/linux/wait.h and ___wait_var_event() in include/linux/wait_bit.h.
Quoted 3 lines
include/linux/swait.h +0
-0INIT_LIST_HEAD (&__wait.task_list); \for (;;) { \long __int =prepare_to_swait_event (&wq, &__wait, state);\
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
PATCH v19 18/40 dept: apply timeout consideration to waitqueue wait
In reply to Byungchul ParkNow that CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT was introduced, apply the consideration to waitqueue wait, assuming an input 'ret' in ___wait_event() macro is used as a timeout value.
--- include/linux/wait.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/wait.h +1 -1
@@ -306,7 +306,7 @@ extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);struct wait_queue_entry __wq_entry; \long __ret = ret;/* explicit shadow */ \ \ -sdt_might_sleep_start (NULL ); \ +sdt_might_sleep_start_timeout (NULL , __ret); \init_wait_entry (&__wq_entry, exclusive ?WQ_FLAG_EXCLUSIVE :0 ); \for (;;) { \long __int =prepare_to_wait_event (&wq_head, &__wq_entry, state);\
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 18/40] dept: apply timeout consideration to waitqueue wait
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The timeout consideration logic fails for wait_event_hrtimeout(), hashed-waitqueues, and DMA…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The timeout consideration logic fails for wait_event_hrtimeout(), hashed-waitqueues, and DMA fences, causing them to be falsely treated as infinite waits.
- [Medium] The ___wait_event() and ___wait_var_event() macros skip the DEPT sleep end annotation on the signal interruption error path, leaking the DEPT tracking stage context. --
commit 25089e0217c82211740316928fec38c6d2b7e4fa
Author: Byungchul Park <[email protected]>
dept: apply timeout consideration to waitqueue wait
This commit applies timeout consideration to waitqueue waits by using the ret parameter in ___wait_event() as a timeout value for DEPT tracking. It leverages CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT to help reduce false positive deadlock reports for waits that are meant to expire.
include/linux/wait.h extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags); · line 309
Quoted 10 lines
include/linux/wait.h +1
-1@@ -306,7 +306,7 @@ extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);struct wait_queue_entry __wq_entry; \long __ret = ret;/* explicit shadow */ \ \ -sdt_might_sleep_start (NULL ); \ +sdt_might_sleep_start_timeout (NULL , __ret); \
[Severity: Medium]
Does this logic also need to be applied to __wait_event_hrtimeout(), hashed-waitqueues, and DMA fences?
For example, __wait_event_hrtimeout() passes 0 as the 'ret' parameter to ___wait_event(), causing sdt_might_sleep_start_timeout() to treat it as an infinite wait.
Additionally, hashed-waitqueues (in ___wait_var_event) and DMA fences (in dma_fence_default_wait and dma_fence_wait_any_timeout) still hardcode sdt_might_sleep_start(NULL) even when taking a timeout. This seems to cause DEPT to falsely report deadlocks for these bounded waits.
include/linux/wait.h extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags); · line 312
Quoted 3 lines
include/linux/wait.h +0
-0init_wait_entry (&__wq_entry, exclusive ?WQ_FLAG_EXCLUSIVE :0 ); \for (;;) { \long __int =prepare_to_wait_event (&wq_head, &__wq_entry, state);\
[Severity: Medium]
Can the DEPT sleep end annotation be skipped on the signal interruption error path?
Looking further down in the ___wait_event() macro, if the wait is interruptible and interrupted by a signal, it takes the goto __out branch:
if (___wait_is_interruptible(state) && __int) {
__ret = __int;
goto __out;
}
...
}
finish_wait(&wq_head, &__wq_entry);
sdt_might_sleep_end();__out: __ret;
This skips over sdt_might_sleep_end(), which leaks the DEPT wait stage context. As a result, DEPT will mistakenly treat subsequent wait events for this task as nested waits.
The same issue appears to exist in ___wait_var_event() for hashed-waitqueues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
PATCH v19 19/40 dept: apply timeout consideration to hashed-waitqueue wait
In reply to Byungchul ParkNow that CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT was introduced, apply the consideration to hashed-waitqueue wait, assuming an input 'ret' in ___wait_var_event() macro is used as a timeout value.
--- include/linux/wait_bit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/wait_bit.h +1 -1
@@ -258,7 +258,7 @@ extern wait_queue_head_t *__var_waitqueue(void *p);struct wait_bit_queue_entry __wbq_entry; \long __ret = ret;/* explicit shadow */ \ \ -sdt_might_sleep_start (NULL ); \ +sdt_might_sleep_start_timeout (NULL , __ret); \init_wait_var_entry (&__wbq_entry, var, \ exclusive ?WQ_FLAG_EXCLUSIVE :0 ); \for (;;) { \
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 19/40] dept: apply timeout consideration to hashed-waitqueue wait
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Missing `sdt_might_sleep_end()` cleanup in the error path of wait macros (e.g.…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing sdt_might_sleep_end() cleanup in the error path of wait macros (e.g., ___wait_var_event, ___wait_event, ___swait_event) bypasses dept_clean_stage(), leaking the staged wait event state and corrupting DEPT tracking. --
commit cf04720896ab037609320947c88e8faa57dbddd7
Author: Byungchul Park <[email protected]>
dept: apply timeout consideration to hashed-waitqueue wait
Now that CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT was introduced, apply the consideration to hashed-waitqueue wait, assuming an input 'ret' in ___wait_var_event() macro is used as a timeout value.
include/linux/wait_bit.h extern wait_queue_head_t *__var_waitqueue(void *p); · line 261
Quoted 10 lines
include/linux/wait_bit.h +1
-1@@ -258,7 +258,7 @@ extern wait_queue_head_t *__var_waitqueue(void *p);struct wait_bit_queue_entry __wbq_entry; \long __ret = ret;/* explicit shadow */ \ \ -sdt_might_sleep_start (NULL ); \ +sdt_might_sleep_start_timeout (NULL , __ret); \
[Severity: High]
Does this error path properly clean up the dept wait state?
Lower in the ___wait_var_event() macro, if a signal is received it jumps to __out:
if (___wait_is_interruptible(state) && __int) { \
__ret = __int; \
goto __out; \
} \
...
sdt_might_sleep_end(); \__out: __ret; \
Because the goto __out branch skips sdt_might_sleep_end(), does it leave a dangling stage context in the dept subsystem's tracking graph?
If the stage context remains populated, could a subsequent wait on the same task be incorrectly seen as a nested stage, potentially corrupting dept tracking or leading to false deadlock reports?
(Note: A similar goto __out pattern skipping sdt_might_sleep_end() also exists in ___wait_event() in include/linux/wait.h and ___swait_event() in include/linux/swait.h).
Quoted 3 lines
include/linux/wait_bit.h +0
-0init_wait_var_entry (&__wbq_entry, var, \ exclusive ?WQ_FLAG_EXCLUSIVE :0 ); \for (;;) { \
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
Re: [PATCH v19 19/40] dept: apply timeout consideration to hashed-waitqueue wait
Quoted 38 lines · On Tue, Jul 07, 2026 at 07:33:36AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missingsdt_might_sleep_end()cleanup in the error path of wait macros (e.g.,___wait_var_event,___wait_event,___swait_event) bypassesdept_clean_stage(), leaking the staged wait event state and corrupting DEPT tracking. --commit
cf04720896ab037609320947c88e8faa57dbddd7
Author: Byungchul Park <[email protected]>dept: apply timeout consideration to hashed-waitqueue wait
Now that
CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAITwas introduced, apply the consideration to hashed-waitqueue wait, assuming an input 'ret' in___wait_var_event()macro is used as a timeout value.include/linux/wait_bit.h extern wait_queue_head_t *__var_waitqueue(void *p); · line 261
Quoted 10 lines
include/linux/wait_bit.h +1
-1@@ -258,7 +258,7 @@ extern wait_queue_head_t *__var_waitqueue(void *p);struct wait_bit_queue_entry __wbq_entry; \long __ret = ret;/* explicit shadow */ \ \ -sdt_might_sleep_start (NULL ); \ +sdt_might_sleep_start_timeout (NULL , __ret); \[Severity: High]
Does this error path properly clean up the dept wait state?Lower in the
___wait_var_event()macro, if a signal is received it jumps to__out:if (___wait_is_interruptible(state) && __int) { \ __ret = __int; \ goto __out; \ } \... sdt_might_sleep_end(); \
Quoted 8 lines
__out:__ret; \Because the goto
__outbranch skipssdt_might_sleep_end(), does it leave a dangling stage context in the dept subsystem's tracking graph?If the stage context remains populated, could a subsequent wait on the same task be incorrectly seen as a nested stage, potentially corrupting dept tracking or leading to false deadlock reports?
I will fix it.
Quoted 3 lines
(Note: A similar goto
__outpattern skippingsdt_might_sleep_end()also exists in___wait_event()ininclude/linux/wait.hand___swait_event()ininclude/linux/swait.h).
I will fix it.
Byungchul
Quoted 7 lines
include/linux/wait_bit.h extern wait_queue_head_t *__var_waitqueue(void *p); · line 264
Quoted 4 lines
include/linux/wait_bit.h +0
-0init_wait_var_entry (&__wbq_entry, var, \ exclusive ?WQ_FLAG_EXCLUSIVE :0 ); \for (;;) { \--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
PATCH v19 20/40 dept: apply timeout consideration to dma fence wait
In reply to Byungchul ParkNow that CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT was introduced, apply the consideration to dma fence wait.
--- drivers/dma-buf/dma-fence.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma-buf/dma-fence.c +2 -2
@@ -823,7 +823,7 @@ dma_fence_default_wait(struct dma_fence *fence, bool intr, signed long timeout) cb.task = current;list_add (&cb.base.node, &fence->cb_list); -sdt_might_sleep_start (NULL ); +sdt_might_sleep_start_timeout (NULL , timeout);while (!dma_fence_test_signaled_flag (fence) && ret >0 ) {if (intr)__set_current_state (TASK_INTERRUPTIBLE );
@@ -927,7 +927,7 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, } } -sdt_might_sleep_start (NULL ); +sdt_might_sleep_start_timeout (NULL , timeout);while (ret >0 ) {if (intr)set_current_state (TASK_INTERRUPTIBLE );
Signature · 1 line
2.17.1
PATCH v19 21/40 dept: make dept able to work with an external wgen
In reply to Byungchul ParkThere is a case where the total map size of waits of a class is so large. For instance, PG_locked is the case if every struct page embeds its regular map for PG_locked. The total size for the maps will be 'the # of pages * sizeof(struct dept_map)', which is too big to accept.
Keep the minimum data in the case, timestamp called 'wgen', that dept uses. Make dept able to work with the wgen instead of whole regular map.
--- include/linux/dept.h | 18 ++++++++++++++---- include/linux/dept_sdt.h | 6 +++--- kernel/dependency/dept.c | 30 +++++++++++++++++++++--------- 3 files changed, 38 insertions(+), 16 deletions(-)
include/linux/dept.h +14 -4
@@ -129,6 +129,13 @@ struct dept_wait_hist {unsigned int ctxt_id; }; +/* +* for subsystems that requires compact use of memory e.g. struct page +*/ +struct dept_ext_wgen { +unsigned int wgen; +}; +void dept_on (void );void dept_off (void );void dept_init (void );
@@ -138,6 +145,7 @@ void dept_free_range(void *start, unsigned int sz);void dept_map_init (struct dept_map *m,struct dept_key *k,int sub_u,const char *n);void dept_map_reinit (struct dept_map *m,struct dept_key *k,int sub_u,const char *n); +void dept_ext_wgen_init (struct dept_ext_wgen *ewg);void dept_map_copy (struct dept_map *to,struct dept_map *from);void dept_wait (struct dept_map *m,unsigned long w_f,unsigned long ip,const char *w_fn,int sub_l,long timeout);void dept_stage_wait (struct dept_map *m,struct dept_key *k,unsigned long ip,const char *w_fn,long timeout);
@@ -146,8 +154,8 @@ void dept_clean_stage(void);void dept_ttwu_stage_wait (struct task_struct *t,unsigned long ip);void dept_ecxt_enter (struct dept_map *m,unsigned long e_f,unsigned long ip,const char *c_fn,const char *e_fn,int sub_l);bool dept_ecxt_holding (struct dept_map *m,unsigned long e_f); -void dept_request_event (struct dept_map *m); -void dept_event (struct dept_map *m,unsigned long e_f,unsigned long ip,const char *e_fn); +void dept_request_event (struct dept_map *m,struct dept_ext_wgen *ewg); +void dept_event (struct dept_map *m,unsigned long e_f,unsigned long ip,const char *e_fn,struct dept_ext_wgen *ewg);void dept_ecxt_exit (struct dept_map *m,unsigned long e_f,unsigned long ip);void dept_sched_enter (void );void dept_sched_exit (void );
@@ -174,6 +182,7 @@ void dept_hardirqs_off(void);#else /* !CONFIG_DEPT */ struct dept_key { };struct dept_map { }; +struct dept_ext_wgen { };#define DEPT_MAP_INITIALIZER (n, k) { }
@@ -186,6 +195,7 @@ struct dept_map { };#define dept_map_init (m, k, su, n) do { (void)(n); (void)(k); } while (0)#define dept_map_reinit (m, k, su, n) do { (void)(n); (void)(k); } while (0) +#define dept_ext_wgen_init (wg) do { } while (0)#define dept_map_copy (t, f) do { } while (0)#define dept_wait (m, w_f, ip, w_fn, sl, t) do { (void)(w_fn); } while (0)#define dept_stage_wait (m, k, ip, w_fn, t) do { (void)(k); (void)(w_fn); } while (0)
@@ -194,8 +204,8 @@ struct dept_map { };#define dept_ttwu_stage_wait (t, ip) do { } while (0)#define dept_ecxt_enter (m, e_f, ip, c_fn, e_fn, sl) do { (void)(c_fn); (void)(e_fn); } while (0)#define dept_ecxt_holding (m, e_f) false -#define dept_request_event (m) do { } while (0) -#define dept_event (m, e_f, ip, e_fn) do { (void)(e_fn); } while (0) +#define dept_request_event (m, wg) do { } while (0) +#define dept_event (m, e_f, ip, e_fn, wg) do { (void)(e_fn); } while (0)#define dept_ecxt_exit (m, e_f, ip) do { } while (0)#define dept_sched_enter () do { } while (0)#define dept_sched_exit () do { } while (0)
include/linux/dept_sdt.h +3 -3
@@ -25,7 +25,7 @@#define sdt_wait_timeout (m, t) \ do { \ - dept_request_event(m); \ + dept_request_event(m, NULL); \ dept_wait(m, 1UL, _THIS_IP_, __func__, 0, t); \ } while (0)#define sdt_wait (m) sdt_wait_timeout(m, -1L)
@@ -49,9 +49,9 @@#define sdt_might_sleep_end () dept_clean_stage()#define sdt_ecxt_enter (m) dept_ecxt_enter(m, 1UL, _THIS_IP_, "start", "event", 0) -#define sdt_event (m) dept_event(m, 1UL, _THIS_IP_, __func__) +#define sdt_event (m) dept_event(m, 1UL, _THIS_IP_, __func__, NULL)#define sdt_ecxt_exit (m) dept_ecxt_exit(m, 1UL, _THIS_IP_) -#define sdt_request_event (m) dept_request_event(m) +#define sdt_request_event (m) dept_request_event(m, NULL)#else /* !CONFIG_DEPT */ #define sdt_map_init (m) do { } while (0)#define sdt_map_init_key (m, k) do { (void)(k); } while (0)
kernel/dependency/dept.c +21 -9
@@ -2172,6 +2172,11 @@ void dept_map_reinit(struct dept_map *m, struct dept_key *k, int sub_u, }EXPORT_SYMBOL_GPL (dept_map_reinit); +void dept_ext_wgen_init (struct dept_ext_wgen *ewg) +{ + ewg->wgen =0U ; +} +void dept_map_copy (struct dept_map *to,struct dept_map *from) {if (unlikely (!dept_working ())) {
@@ -2355,7 +2360,7 @@ static void __dept_wait(struct dept_map *m, unsigned long w_f,*/ static void __dept_event (struct dept_map *m,struct dept_map *real_m,unsigned long e_f,unsigned long ip,const char *e_fn, -bool sched_map) +bool sched_map,unsigned int wg) {struct dept_class *c;struct dept_key *k;
@@ -2377,7 +2382,7 @@ static void __dept_event(struct dept_map *m, struct dept_map *real_m, c =check_new_class (&m->map_key, k,sub_id (m, e), m->name, sched_map);if (c) -do_event (m, real_m, c,READ_ONCE (m->wgen), ip, e_fn); +do_event (m, real_m, c, wg, ip, e_fn); } void dept_wait(struct dept_map *m, unsigned long w_f,
@@ -2602,7 +2607,7 @@ void dept_ttwu_stage_wait(struct task_struct *requestor, unsigned long ip)if (!m.keys) goto exit; -__dept_event (&m, real_m,1UL , ip,"try_to_wake_up" , sched_map); +__dept_event (&m, real_m,1UL , ip,"try_to_wake_up" , sched_map, m.wgen); exit:dept_exit (flags); }
@@ -2781,10 +2786,11 @@ bool dept_ecxt_holding(struct dept_map *m, unsigned long e_f) }EXPORT_SYMBOL_GPL (dept_ecxt_holding); -void dept_request_event (struct dept_map *m) +void dept_request_event (struct dept_map *m,struct dept_ext_wgen *ewg) {unsigned long flags;unsigned int wg; +unsigned int *wg_p;if (unlikely (!dept_working ()))return ;
@@ -2797,18 +2803,22 @@ void dept_request_event(struct dept_map *m)*/ flags =dept_enter_recursive (); + wg_p = ewg ? &ewg->wgen : &m->wgen; + wg =next_wgen (); -WRITE_ONCE (m->wgen, wg); +WRITE_ONCE (*wg_p, wg);dept_exit_recursive (flags); }EXPORT_SYMBOL_GPL (dept_request_event);void dept_event (struct dept_map *m,unsigned long e_f, -unsigned long ip,const char *e_fn) +unsigned long ip,const char *e_fn, +struct dept_ext_wgen *ewg) {struct dept_task *dt =dept_task ();unsigned long flags; +unsigned int *wg_p;if (unlikely (!dept_working ()))return ;
@@ -2816,24 +2826,26 @@ void dept_event(struct dept_map *m, unsigned long e_f,if (m->nocheck)return ; + wg_p = ewg ? &ewg->wgen : &m->wgen; +if (dt->recursive) {/* * Dept won't work with this even though an event * context has been asked. Don't make it confused at * handling the event. Disable it until the next. */ -WRITE_ONCE (m->wgen,0U ); +WRITE_ONCE (*wg_p,0U );return ; } flags =dept_enter (); -__dept_event (m, m, e_f, ip, e_fn, false); +__dept_event (m, m, e_f, ip, e_fn, false,READ_ONCE (*wg_p));/* * Keep the map diabled until the next sleep. */ -WRITE_ONCE (m->wgen,0U ); +WRITE_ONCE (*wg_p,0U );dept_exit (flags); }
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 21/40] dept: make dept able to work with an external wgen
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unconditional zeroing of wgen in dept_event creates a race condition that systematically loses dependencies for shared locks, blinding the deadlock detector. --
commit f7ae795e924d8a4b1154e57adaf0e878e810272c
Author: Byungchul Park <[email protected]>
dept: make dept able to work with an external wgen
This commit introduces an external wait generation structure, struct dept_ext_wgen, to allow subsystems with memory constraints to use DEPT without embedding a full struct dept_map. It modifies dept_request_event() and dept_event() to optionally accept and operate on this external wgen instead of the one embedded in struct dept_map.
Quoted 4 lines
kernel/dependency/dept.c +0
-0
[ ... ]
Quoted 17 lines
kernel/dependency/dept.c +3
-1@@ -2816,24 +2826,26 @@ void dept_event(struct dept_map *m, unsigned long e_f,if (m->nocheck)return ; + wg_p = ewg ? &ewg->wgen : &m->wgen; +if (dt->recursive) {/* * Dept won't work with this even though an event * context has been asked. Don't make it confused at * handling the event. Disable it until the next. */ -WRITE_ONCE (m->wgen,0U ); +WRITE_ONCE (*wg_p,0U );return ; }
kernel/dependency/dept.c void dept_event(struct dept_map *m, unsigned long e_f, · line 2848
Quoted 10 lines
kernel/dependency/dept.c +2
-2flags =dept_enter (); -__dept_event (m, m, e_f, ip, e_fn, false); +__dept_event (m, m, e_f, ip, e_fn, false,READ_ONCE (*wg_p));/* * Keep the map diabled until the next sleep. */ -WRITE_ONCE (m->wgen,0U ); +WRITE_ONCE (*wg_p,0U );
[Severity: High]
This is a pre-existing issue, but does unconditionally clearing the wgen here in dept_event() create a race condition that loses dependencies for shared locks?
When multiple threads hold a shared lock (e.g., a read-lock like rw_semaphore), and a writer begins waiting, the writer calls dept_request_event() which sets the lock's wgen. The first reader to unlock calls dept_event(), which reads the wgen, processes the wait dependency for its own context, and then unconditionally clears wgen to 0 here.
All subsequent readers unlocking will read 0 and fail to record the dependency between the writer's wait and their own read-side critical sections, which could blind the deadlock detector.
Since this issue affects the newly introduced ewg->wgen as well, could this be addressed to ensure dependencies aren't lost when multiple threads share the lock?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
PATCH v19 22/40 dept: track PG_locked with dept
In reply to Byungchul ParkMakes dept able to track PG_locked waits and events, which will be useful in practice. See the following link that shows dept worked with PG_locked and detected real issues in practice:
https://lore.kernel.org/lkml/[email protected]/
--- include/linux/mm_types.h | 2 + include/linux/page-flags.h | 125 +++++++++++++++++++++++++++++++++---- include/linux/pagemap.h | 37 ++++++++++- mm/filemap.c | 34 ++++++++++ mm/mm_init.c | 2 + 5 files changed, 187 insertions(+), 13 deletions(-)
include/linux/mm_types.h +2 -0
@@ -22,6 +22,7 @@#include <linux/types.h> #include <linux/rseq_types.h> #include <linux/bitmap.h> +#include <linux/dept.h> #include <asm/mmu.h>
@@ -219,6 +220,7 @@ struct page {struct page *kmsan_shadow;struct page *kmsan_origin;#endif +struct dept_ext_wgen pg_locked_wgen; } _struct_page_alignment;/*
include/linux/page-flags.h +113 -12
178 lines not on this page · raw message
include/linux/pagemap.h +36 -1
@@ -1119,7 +1119,12 @@ void folio_unlock(struct folio *folio);*/ static inline bool folio_trylock (struct folio *folio) { -return likely (!test_and_set_bit_lock (PG_locked,folio_flags (folio,0 ))); +bool ret = !test_and_set_bit_lock (PG_locked,folio_flags (folio,0 )); + +if (ret) +dept_page_set_bit (&folio->page, PG_locked); + +return likely (ret); }/*
@@ -1155,6 +1160,16 @@ static inline bool trylock_page(struct page *page)static inline void folio_lock (struct folio *folio) {might_sleep (); + +/* +* dept_page_wait_on_bit() will be called if __folio_lock() goes +* through a real wait path. However, for better job to detect +* *potential* deadlocks, let's assume that folio_lock() always +* goes through wait so that dept can take into account all the +* potential cases. +*/ +dept_page_wait_on_bit (&folio->page, PG_locked); +if (!folio_trylock (folio))__folio_lock (folio); }
@@ -1175,6 +1190,15 @@ static inline void lock_page(struct page *page)struct folio *folio;might_sleep (); +/* +* dept_page_wait_on_bit() will be called if __folio_lock() goes +* through a real wait path. However, for better job to detect +* *potential* deadlocks, let's assume that lock_page() always +* goes through wait so that dept can take into account all the +* potential cases. +*/ +dept_page_wait_on_bit (page, PG_locked); + folio =page_folio (page);if (!folio_trylock (folio))__folio_lock (folio);
@@ -1193,6 +1217,17 @@ static inline void lock_page(struct page *page)static inline int folio_lock_killable (struct folio *folio) {might_sleep (); + +/* +* dept_page_wait_on_bit() will be called if +* __folio_lock_killable() goes through a real wait path. +* However, for better job to detect *potential* deadlocks, +* let's assume that folio_lock_killable() always goes through +* wait so that dept can take into account all the potential +* cases. +*/ +dept_page_wait_on_bit (&folio->page, PG_locked); +if (!folio_trylock (folio))return __folio_lock_killable (folio);return 0 ;
mm/filemap.c +34 -0
@@ -49,6 +49,7 @@#include <linux/sched/mm.h> #include <linux/sysctl.h> #include <linux/pgalloc.h> +#include <linux/dept.h> #include <asm/tlbflush.h> #include "internal.h"
@@ -1151,6 +1152,7 @@ static int wake_page_function(wait_queue_entry_t *wait, unsigned mode, int sync,if (flags &WQ_FLAG_CUSTOM ) {if (test_and_set_bit (key->bit_nr, &key->folio->flags.f))return -1 ; +dept_page_set_bit (&key->folio->page, key->bit_nr); flags |=WQ_FLAG_DONE ; } }
@@ -1191,6 +1193,13 @@ static void folio_wake_bit(struct folio *folio, int bit_nr) key.bit_nr = bit_nr; key.page_match =0 ; +/* +* dept_page_clear_bit() being called multiple times is harmless. +* The worst case is to miss some dependencies but it's okay. +*/ +if (bit_nr == PG_locked) +dept_page_clear_bit (&folio->page, bit_nr); +spin_lock_irqsave (&q->lock, flags);__wake_up_locked_key (q,TASK_NORMAL , &key);
@@ -1234,6 +1243,7 @@ static inline bool folio_trylock_flag(struct folio *folio, int bit_nr,if (wait->flags &WQ_FLAG_EXCLUSIVE ) {if (test_and_set_bit (bit_nr, &folio->flags.f))return false; +dept_page_set_bit (&folio->page, bit_nr); }else if (test_bit (bit_nr, &folio->flags.f))return false;
@@ -1241,6 +1251,9 @@ static inline bool folio_trylock_flag(struct folio *folio, int bit_nr,return true; } +struct dept_map __maybe_unused pg_locked_map =DEPT_MAP_INITIALIZER (pg_locked_map,NULL ); +EXPORT_SYMBOL (pg_locked_map); +static inline int folio_wait_bit_common (struct folio *folio,int bit_nr,int state,enum behavior behavior) {
@@ -1252,6 +1265,8 @@ static inline int folio_wait_bit_common(struct folio *folio, int bit_nr,unsigned long pflags;bool in_thrashing; +dept_page_wait_on_bit (&folio->page, bit_nr); +if (bit_nr == PG_locked && !folio_test_uptodate (folio) &&folio_test_workingset (folio)) {delayacct_thrashing_start (&in_thrashing);
@@ -1345,6 +1360,23 @@ static inline int folio_wait_bit_common(struct folio *folio, int bit_nr,break ; } +/* +* dept_page_set_bit() might have been called already in +* folio_trylock_flag(), wake_page_function() or somewhere. +* However, call it again to reset the wgen of dept to ensure +* dept_page_wait_on_bit() is called prior to +* dept_page_set_bit(). +* +* Remind dept considers all the waits between +* dept_page_set_bit() and dept_page_clear_bit() as potential +* event disturbers. Ensure the correct sequence so that dept +* can make correct decisions: +* +* wait -> acquire(set bit) -> release(clear bit) +*/ +if (wait->flags &WQ_FLAG_DONE ) +dept_page_set_bit (&folio->page, bit_nr); +/* * If a signal happened, this 'finish_wait()' may remove the last * waiter from the wait-queues, but the folio waiters bit will remain
@@ -1507,6 +1539,7 @@ void folio_unlock(struct folio *folio)BUILD_BUG_ON (PG_waiters !=7 );BUILD_BUG_ON (PG_locked >7 );VM_BUG_ON_FOLIO (!folio_test_locked (folio), folio); +dept_page_clear_bit (&folio->page, PG_locked);if (folio_xor_flags_has_waiters (folio,1 << PG_locked))folio_wake_bit (folio, PG_locked); }
@@ -1537,6 +1570,7 @@ void folio_end_read(struct folio *folio, bool success)if (likely (success)) mask |=1 << PG_uptodate; +dept_page_clear_bit (&folio->page, PG_locked);if (folio_xor_flags_has_waiters (folio, mask))folio_wake_bit (folio, PG_locked); }
mm/mm_init.c +2 -0
@@ -32,6 +32,7 @@#include <linux/vmstat.h> #include <linux/kexec_handover.h> #include <linux/hugetlb.h> +#include <linux/dept.h> #include "internal.h" #include "slab.h" #include "shuffle.h"
@@ -587,6 +588,7 @@ void __meminit __init_single_page(struct page *page, unsigned long pfn,atomic_set (&page->_mapcount,-1 );page_cpupid_reset_last (page);page_kasan_tag_reset (page); +dept_ext_wgen_init (&page->pg_locked_wgen);INIT_LIST_HEAD (&page->lru);#ifdef WANT_PAGE_VIRTUAL
Signature · 1 line
2.17.1
Matthew Wilcox
maintainerRe: [PATCH v19 22/40] dept: track PG_locked with dept
include/linux/mm_types.h struct page { · line 224
Quoted 12 lines · Byungchul Park
Makes dept able to track
PG_lockedwaits and events, which will be useful in practice. See the following link that shows dept worked withPG_lockedand detected real issues in practice:https://lore.kernel.org/lkml/[email protected]/include/linux/mm_types.h +1
-0@@ -219,6 +220,7 @@ struct page {struct page *kmsan_shadow;struct page *kmsan_origin;#endif +struct dept_ext_wgen pg_locked_wgen; } _struct_page_alignment;
I may not understand this quite correctly, but I think that tracking PG_locked dependencies in the struct page has both false positive and false negative problems.
Imagine we have a file mapping M1 containing folio F1 at index 0 and F2 at index 1. It is correct locking order to lock F1 before locking F2 (for example when doing writeback). Later, M1 has its folios reclaimed and returned to the free pool. Then each is added to mapping M2, this time with folio F2 at index 8 and F1 at index 9. Now the correct order to lock these folios in the order F2 followed by F1.
I don't see a part of this patch where we clear pg_locked_wgen when the page is returned to the page allocator. Maybe I missed that.
I think we should be tracking PG_locked dependencies in the owner of the folio. For files, that would be in the struct address_space. For anon memory, I think that's in the anon_vma, but if somebody told me it was in some other structure, I wouldn't argue with them.
This requires slightly more complexity than lockdep currently has. We don't want to use a lockdep class for each folio, obviously. So we need something to say "I already have folio F1 locked, is it OK to lock folio F2?". Essentially figuring out how we can track all folios in a given mapping the same way, and making sure that we don't deadlock on folios in the same mapping.
If F1 and F2 are in different mappings, it's not a deadlock if F1 is in a filesystem mapping and F2 is in its backing dev. It's also not a deadlock if F1 and F2 are both filesystem folios and the inodes are both locked. See vfs_lock_two_folios() in fs/remap_range.c.
I have much less knowledge about anonymous memory locking order. Maybe it doesn't happen. Or about locking one anon and one file folio. For slab memory, we don't sleep on PG_locked (it's used as a spinlock bit). For other kinds of memory ... I don't know. Page migration is fun.
Re: [PATCH v19 22/40] dept: track PG_locked with dept
Quoted 18 lines · Matthew Wilcox
include/linux/mm_types.h struct page { · line 224
Quoted 12 lines · Byungchul Park
Makes dept able to track
PG_lockedwaits and events, which will be useful in practice. See the following link that shows dept worked withPG_lockedand detected real issues in practice:https://lore.kernel.org/lkml/[email protected]/include/linux/mm_types.h +1
-0@@ -219,6 +220,7 @@ struct page {struct page *kmsan_shadow;struct page *kmsan_origin;#endif +struct dept_ext_wgen pg_locked_wgen; } _struct_page_alignment;I may not understand this quite correctly, but I think that tracking
PG_lockeddependencies in the struct page has both false positive and false negative problems.
Quoted 6 lines
Imagine we have a file mapping M1 containing folio F1 at index 0 and F2 at index 1. It is correct locking order to lock F1 before locking F2 (for example when doing writeback). Later, M1 has its folios reclaimed and returned to the free pool. Then each is added to mapping M2, this time with folio F2 at index 8 and F1 at index 9. Now the correct order to lock these folios in the order F2 followed by F1.
First of all, I appreciate your feedback. Thanks!
That case doesn't generate any dependency unless any other waits are involved in. That should be handled in xxx_nested manner e.g. folio_lock_nested() that I need to introduce. The work is in progress.
Quoted 2 lines
I don't see a part of this patch where we clear
pg_locked_wgenwhen the page is returned to the page allocator. Maybe I missed that.
You are right. pg_locked_wgen doesn't get cleared. However, DEPT works this way:
folio_lock()
wait_for_pg_locked_cleared()
set_pg_locked() // (1) update pg_locked_wgen to the current wgen
... // there might be other waits
folio_unlock()
clear_pg_locked() // (2) check if there have been any waits since (1)
In other words, it's guranteed that pg_locked_wgen has been updated e.i.
(1) when DEPT refers to pg_locked_wgen e.i. (2). So I don't think it's a problem.
Quoted 4 lines
I think we should be tracking
PG_lockeddependencies in the owner of the folio. For files, that would be in the structaddress_space. For anon memory, I think that's in theanon_vma, but if somebody told me it was in some other structure, I wouldn't argue with them.
I think it's a good point but it's a classification issue. folios owned by struct address_space should be classified to e.g. address_space_class and ones owned by struct anon_vma should be classified to e.g. anon_vma_class. I will work on it to apply the insight you just gave but better do it as follow-up patches since the initial patchset is already too big to get reviewed.
Quoted 3 lines
This requires slightly more complexity than lockdep currently has. We don't want to use a lockdep class for each folio, obviously. So we need something to say "I already have folio F1 locked, is it OK to lock
From DEPT's perspective, folio_lock(F1) and folio_lock(F2) are waits and folio_unlock(F1) and folio_unlock(F2) are events. Since DEPT tracks dependencies with specified classes between waits and events, DEPT's interest in the following example is to detect a situation like:
< context X >
folio_lock(address_space_class'ed F1)
...
folio_lock(anon_vma_class'ed F2)
...
folio_unlock(anon_vma_class'ed F2)
...
folio_unlock(address_space_class'ed F1)
< context Y >
folio_lock(anon_vma_class'ed any folio)
...
folio_lock(address_space_class'ed any folio)
...
folio_unlock(address_space_class'ed any folio)
...
folio_unlock(anon_vma_class'ed any folio)
However, the following pattern should be manually annotated by developers like using folio_lock_nested() or something. DEPT cannot work with it automatically:
folio_lock(address_space_class'ed F1)
...
folio_lock(address_space_class'ed F2)
...
folio_unlock(address_space_class'ed F2)
...
folio_unlock(address_space_class'ed F1)
or
folio_lock(anon_vma_class'ed F1)
...
folio_lock(anon_vma_class'ed F2)
...
folio_unlock(anon_vma_class'ed F2)
...
folio_unlock(anon_vma_class'ed F1)
These should be explicitly annotated by developers if it's intended:
folio_lock(address_space_class'ed F1)
...
folio_lock_nested(address_space_class'ed F2)
...
folio_unlock(address_space_class'ed F2)
...
folio_unlock(address_space_class'ed F1)
or
folio_lock(anon_vma_class'ed F1)
...
folio_lock_nested(anon_vma_class'ed F2)
...
folio_unlock(anon_vma_class'ed F2)
...
folio_unlock(anon_vma_class'ed F1)
Quoted 3 lines
folio F2?". Essentially figuring out how we can track all folios in a given mapping the same way, and making sure that we don't deadlock on folios in the same mapping.
At the moment, as I told you, DEPT cannot work with dependencies between the same class'ed folios. However, it'd be much better if DEPT can work with even those cases. Could you provide a scenario where a deadlock happens between the same class'ed ones? Any idea how to detect for the cases?
Quoted 4 lines
If F1 and F2 are in different mappings, it's not a deadlock if F1 is in a filesystem mapping and F2 is in its backing dev. It's also not a deadlock if F1 and F2 are both filesystem folios and the inodes are both locked. See
vfs_lock_two_folios()infs/remap_range.c.
Yeah.. DEPT is a tracker to track dependencies between waits and events even across different contexts, but not a magic unfortunately. That lock ordering issue - with the same class'ed ones - should be resolved in the manual manner as vfs_lock_two_folios() does.
Quoted 4 lines
I have much less knowledge about anonymous memory locking order. Maybe it doesn't happen. Or about locking one anon and one file folio. For slab memory, we don't sleep on
PG_locked(it's used as a spinlock bit). For other kinds of memory ... I don't know. Page migration is fun.
Anyway, the sophisticated classification you mentioned is necessary for DEPT to be better especially for folio locking mechanism.
Thanks again!
Byungchul
[email protected]
AI reviewRe: [PATCH v19 22/40] dept: track PG_locked with dept
In reply to Byungchul ParkThank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [Critical] Unconditional `dept_page_set_bit` in `folio_wait_bit_common` causes Use-After-Free and lock…
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [Critical] Unconditional dept_page_set_bit in folio_wait_bit_common causes Use-After-Free and lock tracking leaks for non-exclusive waits.
- [High] Lock handoff in wake_page_function registers lock acquisition in the waker's context instead of the sleeper's.
- [High] A single lock acquisition incorrectly records two events in the thread's DEPT tracking stack on the fast path.
- [High] Generic page flag macros clear the lock bit before notifying the dependency tracker, creating a race condition.
- [High] Unconditional addition of struct dept_ext_wgen and struct dept_page_usage directly to struct page causes severe memory bloat.
- [Medium] Mismatched DEPT tracking on compound tail pages splits lock acquisition and wait events across different tracking contexts. --
Note: Due to system recitation restrictions, this review uses a free-form summary format instead of standard inline patch quoting.
Commit: 1b85b38be891fb326526f230171e29e8fb12a627
Author: Byungchul Park <[email protected]>
Subject: dept: track PG_locked with dept
Summary: This patch makes dept able to track PG_locked waits and events.
[Severity: High]
In include/linux/mm_types.h, the struct page definition is modified to add the pg_locked_wgen and pg_writeback_wgen fields. Are these structures being added unconditionally without CONFIG_DEPT guards?
Adding per-page metadata directly to struct page increases the size of the structure for every physical page, which wastes memory on large systems. Should this tracking metadata be moved to the dynamically allocated page_ext framework, or at least be strictly guarded by Kconfig checks?
[Severity: High]
In include/linux/page-flags.h, macros like FOLIO_CLEAR_FLAG clear the target bit using clear_bit() before notifying the tracker via dept_folio_clear_bit(). Could this out-of-order execution create a race condition?
If the lock bit is cleared first, another thread could immediately acquire the lock and call dept_page_set_bit() before the original thread finishes calling dept_folio_clear_bit(). This sequence would process the release after the subsequent acquisition, which might corrupt the tracker state.
[Severity: Medium]
In include/linux/pagemap.h within lock_page(), dept_page_wait_on_bit() is called on the raw page pointer before converting it to the head folio with page_folio(page).
If this is called on a tail page, won't the wait event be recorded on the tail page's tracking metadata, while the subsequent lock acquisition correctly records on the head page? Splitting the wait and acquisition tracking could break the dependency graph for large folios.
[Severity: Critical]
In mm/filemap.c within folio_wait_bit_common(), the code unconditionally calls dept_page_set_bit() if WQ_FLAG_DONE is set in wait->flags. Does this create a use-after-free for DROP waits?
For DROP waits, folio_put() is called before the wait loop. If the folio is concurrently freed, dereferencing the page pointer after the loop will cause a use-after-free.
Additionally, for SHARED non-exclusive waits, folio_trylock_flag() sets WQ_FLAG_DONE when the bit is clear. Does this cause the unconditional check in folio_wait_bit_common() to incorrectly register a lock acquisition for a thread that is merely waiting? This could permanently leak the lock tracking context.
[Severity: High]
Also in folio_wait_bit_common(), if the fast path successfully acquires the lock synchronously, folio_trylock_flag() sets the lock bit, calls dept_page_set_bit(), and sets WQ_FLAG_DONE.
When folio_wait_bit_common() checks WQ_FLAG_DONE at the end of the function, won't it call dept_page_set_bit() a second time? This appears to push a duplicate lock acquisition record to the tracker stack for a single lock operation.
[Severity: High]
In mm/filemap.c within wake_page_function(), during an exclusive lock handoff, the function sets the lock bit on behalf of the sleeper and calls dept_page_set_bit().
Since this function executes in the context of the waker thread, won't the tracker incorrectly record the lock acquisition in the waker's task structure rather than the sleeper's? This could leak the lock tracking state in the waker and break the dependency graph for the sleeper.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=22
PATCH v19 23/40 dept: print staged wait's stacktrace on report
In reply to Byungchul ParkCurrently, print nothing about what event wakes up in report. However, it makes hard to interpret dept's report.
Make it print wait's stacktrace that the event wakes up.
--- include/linux/sched.h | 2 ++ kernel/dependency/dept.c | 59 ++++++++++++++++++++++++++----- kernel/dependency/dept_internal.h | 5 +++ 3 files changed, 57 insertions(+), 9 deletions(-)
include/linux/sched.h +2 -0
@@ -871,6 +871,7 @@ struct dept_task {const char *stage_w_fn;unsigned long stage_ip;bool stage_timeout; +struct dept_stack *stage_wait_stack;arch_spinlock_t stage_lock;/*
@@ -912,6 +913,7 @@ struct dept_task { .stage_w_fn = NULL, \ .stage_ip = 0UL, \ .stage_timeout = false, \ + .stage_wait_stack = NULL, \ .stage_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED,\ .missing_ecxt = 0, \ .hardirqs_enabled = false, \
kernel/dependency/dept.c +50 -9
174 lines not on this page · raw message
kernel/dependency/dept_internal.h +5 -0
@@ -194,6 +194,11 @@ struct dept_ecxt {*/ unsigned long event_ip;struct dept_stack *event_stack; + +/* +* wait that this event ttwu +*/ +struct dept_stack *ewait_stack; }; }; };
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 23/40] dept: print staged wait's stacktrace on report
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Data race on dt->stage_m leading to zeroed class keys and kernel warnings. --
commit 02dbd1fb0ecda3493e1e312bcf532860fa1353de
Author: Byungchul Park <[email protected]>
dept: print staged wait's stacktrace on report
This commit modifies the dependency tracking (dept) system to capture and print the stacktrace of the wait that an event wakes up. This provides more context for interpreting dept's reports.
Quoted 4 lines
kernel/dependency/dept.c +0
-0
[ ... ]
Quoted 5 lines
kernel/dependency/dept.c +1
-0@@ -2561,6 +2580,14 @@ void dept_request_event_wait_commit(void) wg =next_wgen ();WRITE_ONCE (dt->stage_m.wgen, wg); +
kernel/dependency/dept.c void dept_request_event_wait_commit(void) · line 2593
Quoted 10 lines
kernel/dependency/dept.c +7
-0+/* +* __schedule() can be hit multiple times between +* dept_stage_wait() and dept_clean_stage(). In that case, +* keep the first stacktrace only. That's enough. +*/ +if (!dt->stage_wait_stack) + dt->stage_wait_stack =get_current_stack ();arch_spin_unlock (&dt->stage_lock);__dept_wait (&dt->stage_m,1UL , ip, w_fn,0 , true, sched_map, timeout);
[Severity: High]
This isn't a bug introduced by this patch, but does accessing dt->stage_m here, immediately after dropping the stage_lock, introduce a data race with a concurrent wakeup?
If a task begins scheduling out, it calls dept_request_event_wait_commit() from __schedule(). It acquires dt->stage_lock, updates fields, and unlocks it. Before it can call __dept_wait(&dt->stage_m, ...), an interrupt or another CPU could concurrently call try_to_wake_up() on the same task.
The waking CPU would acquire dt->stage_lock in dept_ttwu_stage_wait() and zero out dt->stage_m via __dept_clean_stage():
kernel/dependency/dept.c:__dept_clean_stage() {
memset(&dt->stage_m, 0x0, sizeof(struct dept_map));
...
}If __dept_wait(&dt->stage_m) executes concurrently on the original CPU, it reads the zeroed structure. This would cause it to look up a class with key 0 and trigger DEPT_WARN_ON(!valid_class(c)), breaking dependency tracking and potentially panicking the system if panic_on_warn is enabled.
Could this be prevented by either copying the required parts of dt->stage_m to local variables while the lock is still held, or expanding the lock coverage?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
PATCH v19 24/40 locking/lockdep: prevent various lockdep assertions when lockdep_off()'ed
In reply to Byungchul Parklockdep provides APIs for assertion only if lockdep is enabled at the moment asserting to avoid unnecessary confusion, using the following condition, debug_locks && !this_cpu_read(lockdep_recursion).
However, lockdep_{off,on}() are also used for disabling and enabling lockdep for a simular purpose. Add !lockdep_recursing(current) that is updated by lockdep_{off,on}() to the condition so that the assertions are aware of !__lockdep_enabled if lockdep_off()'ed.
--- include/linux/lockdep.h | 3 ++- kernel/locking/lockdep.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-)
include/linux/lockdep.h +2 -1
@@ -303,6 +303,7 @@ extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie); lockdep_assert_once(!current->lockdep_depth)#define lockdep_recursing (tsk) ((tsk)->lockdep_recursion) +extern bool lockdep_recursing_current (void );#define lockdep_pin_lock (l) lock_pin_lock(&(l)->dep_map)#define lockdep_repin_lock (l,c) lock_repin_lock(&(l)->dep_map, (c))
@@ -630,7 +631,7 @@ DECLARE_PER_CPU(int, hardirqs_enabled);DECLARE_PER_CPU (int, hardirq_context); DECLARE_PER_CPU(unsigned int, lockdep_recursion); -#define __lockdep_enabled (debug_locks && !this_cpu_read(lockdep_recursion)) +#define __lockdep_enabled (debug_locks && !this_cpu_read(lockdep_recursion) && !lockdep_recursing_current())#define lockdep_assert_irqs_enabled () \ do { \
kernel/locking/lockdep.c +10 -0
@@ -6900,3 +6900,13 @@ void lockdep_rcu_suspicious(const char *file, const int line, const char *s)warn_rcu_exit (rcu); }EXPORT_SYMBOL_GPL (lockdep_rcu_suspicious); + +/* +* For avoiding header dependency when using (struct task_struct *)current +* and lockdep_recursing() at the same time. +*/ +noinstr bool lockdep_recursing_current(void) +{ +return lockdep_recursing (current); +} +EXPORT_SYMBOL_GPL (lockdep_recursing_current);
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 24/40] locking/lockdep: prevent various lockdep assertions when lockdep_off()'ed
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch introduces a performance regression on fast paths when CONFIG_PROVE_LOCKING is enabled…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch introduces a performance regression on fast paths when CONFIG_PROVE_LOCKING is enabled by adding an out-of-line function call to a macro that is unconditionally evaluated before checking if the assertion actually fails. --
commit a2a5c1f9c5f68f19a3e991808b6e812dde3fa53a
Author: Byungchul Park <[email protected]>
locking/lockdep: prevent various lockdep assertions when lockdep_off()'ed
This commit adds a check for lockdep_recursing(current) to the __lockdep_enabled macro. To avoid header dependency issues, it introduces an out-of-line function lockdep_recursing_current().
Quoted 4 lines
include/linux/lockdep.h +0
-0
[ ... ]
include/linux/lockdep.h DECLARE_PER_CPU(int, hardirqs_enabled); · line 637
Quoted 9 lines
include/linux/lockdep.h +1
-1@@ -630,7 +631,7 @@ DECLARE_PER_CPU(int, hardirqs_enabled);DECLARE_PER_CPU (int, hardirq_context); DECLARE_PER_CPU(unsigned int, lockdep_recursion); -#define __lockdep_enabled (debug_locks && !this_cpu_read(lockdep_recursion)) +#define __lockdep_enabled (debug_locks && !this_cpu_read(lockdep_recursion) && !lockdep_recursing_current())#define lockdep_assert_irqs_enabled () \ do { \
[Severity: Medium]
Will this out-of-line call introduce measurable overhead on fast paths?
Since debug_locks and !this_cpu_read(lockdep_recursion) are almost always true in healthy systems, lockdep_recursing_current() will be evaluated every time __lockdep_enabled is checked.
For example, in lockdep_assert_irqs_enabled():
WARN_ON_ONCE(__lockdep_enabled && !this_cpu_read(hardirqs_enabled));
Because __lockdep_enabled is the first operand, the out-of-line call executes before checking if the assertion actually fails.
Could we move __lockdep_enabled to the end of the && chain in these assertions?
WARN_ON_ONCE(!this_cpu_read(hardirqs_enabled) && __lockdep_enabled);
Placing the failure condition first would ensure the out-of-line function is only evaluated on the slow path when the assertion is already failing, avoiding the function call overhead on hot paths entirely.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
PATCH v19 25/40 dept: add documents for dept
In reply to Byungchul ParkAdd documents describing the concept and APIs of dept.
--- Documentation/dev-tools/dept.rst | 905 +++++++++++++++++++++++++++ Documentation/dev-tools/dept_api.rst | 124 ++++ Documentation/dev-tools/index.rst | 2 + 3 files changed, 1031 insertions(+) create mode 100644 Documentation/dev-tools/dept.rst create mode 100644 Documentation/dev-tools/dept_api.rst
Documentation/dev-tools/dept.rst new file +905 -0
@@ -0,0 +1,905 @@ +DEPT(DEPendency Tracker) +======================== + +Started by Byungchul Park <[email protected]> + +How lockdep works +----------------- + +Lockdep detects deadlocks by checking lock acquisition order. For +example, a graph to track acquisition order built by lockdep might look +like: + +.. code-block:: + + A -> B - + \ + -> E + / + C -> D - + + where 'A -> B' means that acquisition A is prior to acquisition B + with A still held. + +Lockdep keeps adding each new acquisition order into the graph at +runtime. For example, 'E -> C' will be added when the two locks have +been acquired in the order E and then C. The graph will look like: + +.. code-block:: + + A -> B - + \ + -> E - + / \ + -> C -> D - \ + / / + \ / + ------------------ + + where 'A -> B' means that acquisition A is prior to acquisition B + with A still held. + +This graph contains a subgraph that demonstrates a loop like: + +.. code-block:: + + -> E - + / \ + -> C -> D - \ + / / + \ / + ------------------ + + where 'A -> B' means that acquisition A is prior to acquisition B + with A still held. + +Lockdep reports it as a deadlock on detection of a loop and stops +working. + +CONCLUSION + +Lockdep detects a deadlock by checking if a loop has been created after +adding a new acquisition order into the graph. + + +Limitation of lockdep +--------------------- + +Lockdep deals with deadlocks involving typical locks e.g. spinlock and +mutex, that are supposed to be released within the acquisition context. +However, when it comes to a deadlock involving folio lock that is not +supposed to be released within the acquisition context or other general +synchronization mechanisms, lockdep doesn't work. + +NOTE: In this document, 'context' refers to any type of unique context +e.g. irq context, normal process context, wq worker context, and so on. + +Can lockdep detect the following deadlock? + +.. code-block:: + + context X context Y context Z + + mutex_lock A + folio_lock B + folio_lock B <- DEADLOCK + mutex_lock A <- DEADLOCK + folio_unlock B + folio_unlock B + mutex_unlock A + mutex_unlock A + +No. What about the following? + +.. code-block:: + + context X context Y + + mutex_lock A + mutex_lock A <- DEADLOCK + wait_for_completion B <- DEADLOCK + complete B + mutex_unlock A + mutex_unlock A + +No. + +CONCLUSION + +Lockdep cannot detect a deadlock involving folio lock or other general +synchronization mechanisms. + + +What leads to a deadlock +------------------------ + +A deadlock occurs when one or more contexts are waiting for events that +will never happen. For example: + +.. code-block:: + + context X context Y context Z + + | | | + v | | + 1 wait for A v | + . 2 wait for C v + event C . 3 wait for B + event B . + event A + +Event C cannot be triggered because context X is stuck at 1, event B +cannot be triggered because context Y is stuck at 2, and event A cannot +be triggered because context Z is stuck at 3. All the contexts are stuck. +We call this **deadlock**. + +If an event occurrence to awaken its wait is a prerequisite to reaching +another event, we call it **dependency**. In this example: + + * Event A occurrence is a prerequisite to reaching event C. + * Event C occurrence is a prerequisite to reaching event B. + * Event B occurrence is a prerequisite to reaching event A. + +In terms of dependency: + + * Event C depends on event A. + * Event B depends on event C. + * Event A depends on event B. + +Dependency graph reflecting this example will look like: + +.. code-block:: + + -> C -> A -> B - + / \ + \ / + ---------------- + + where 'A -> B' means that event A depends on event B. + +A circular dependency exists. Such a circular dependency leads to a +deadlock since no waiters can have desired events triggered. + +CONCLUSION + +A circular dependency of events leads to a deadlock. + + +Introduce DEPT +-------------- + +DEPT(DEPendency Tracker) tracks wait and event instead of lock +acquisition order so as to recognize the following situation: + +.. code-block:: + + context X context Y context Z + + | | | + v | | + wait for A v | + . wait for C v + event C . wait for B + event B . + event A + +and builds up a dependency graph at runtime that is similar to lockdep. +The graph might look like: + +.. code-block:: + + -> C -> A -> B - + / \ + \ / + ---------------- + + where 'A -> B' means that event A depends on event B. + +DEPT keeps adding each new dependency into the graph at runtime. For +example, 'B -> D' will be added when event D occurrence is a +prerequisite to reaching event B like: + +.. code-block:: + + context W + + | + v + wait for D + . + event B + +After the addition, the graph will look like: + +.. code-block:: + + -> D + / + -> C -> A -> B - + / \ + \ / + ---------------- + + where 'A -> B' means that event A depends on event B. + +DEPT is going to report a deadlock on detection of a new loop. + +CONCLUSION + +DEPT works on wait and event so as to theoretically detect all potential +deadlocks. + + +How DEPT works +-------------- + +Let's take a look at how DEPT works with the 1st example in the section +'Limitation of lockdep'. + +.. code-block:: + + context X context Y context Z + + mutex_lock A + folio_lock B + folio_lock B <- DEADLOCK + mutex_lock A <- DEADLOCK + folio_unlock B + folio_unlock B + mutex_unlock A + mutex_unlock A + +NOTE: In this document, 'event context' refers to a portion within a +context where an interesting event is triggered in, between a point +where the context has started progressing toward the event, and the +event. + +Adding comments to describe DEPT's view in detail: + +.. code-block:: + + context X context Y context Z + + mutex_lock A + /* might wait for A */ + /* start to take into account event A's context */ + /* 1 */ + folio_lock B + /* might wait for B */ + /* start to take into account event B's context */ + /* 2 */ + + folio_lock B + /* might wait for B */ <- DEADLOCK + /* start to take into account event B's context */ + /* 3 */ + + mutex_lock A + /* might wait for A */ <- DEADLOCK + /* start to take into account + event A's context */ + /* 4 */ + + folio_unlock B + /* event B that has been valid since 2 */ + folio_unlock B + /* event B that has been valid since 3 */ + + mutex_unlock A + /* event A that has been valid since 1 */ + + mutex_unlock A + /* event A that has been valid since 4 */ + +Let's build up a dependency graph with this example. Firstly, context X: + +.. code-block:: + + context X + + folio_lock B + /* might wait for B */ + /* start to take into account event B's context */ + /* 2 */ + +There are no events to create dependency. Next, context Y: + +.. code-block:: + + context Y + + mutex_lock A + /* might wait for A */ + /* start to take into account event A's context */ + /* 1 */ + + folio_lock B + /* might wait for B */ + /* start to take into account event B's context */ + /* 3 */ + + folio_unlock B + /* event B that has been valid since 3 */ + + mutex_unlock A + /* event A that has been valid since 1 */ + +There are two events, folio_unlock B a.k.a. event B and mutex_unlock A +a.k.a. event A. For event B, since there are no waits between 3 and the +event, event B does not create any dependency. For event A, there is a +wait, folio_lock B a.k.a. wait B, between 1 and the event. Which means +event A cannot be triggered if wait B cannot be awakened by event B. +Therefore, we can say event A depends on event B, say, 'A -> B'. The +graph will look like after adding the dependency: + +.. code-block:: + + A -> B + + where 'A -> B' means that event A depends on event B. + +Lastly, context Z: + +.. code-block:: + + context Z + + mutex_lock A + /* might wait for A */ + /* start to take into account event A's context */ + /* 4 */ + + folio_unlock B + /* event B that has been valid since 2 */ + + mutex_unlock A + /* event A that has been valid since 4 */ + +There are also two events, folio_unlock B a.k.a. event B and +mutex_unlock A a.k.a. event A. For event B, there is a wait, mutex_lock +A a.k.a. wait A, between 2 and the event. Which means event B cannot be +triggered if wait A cannot be awakened by event A. Therefore, we can +say event B depends on event A, say, 'B -> A'. The graph will look like +after adding the dependency: + +.. code-block:: + + -> A -> B - + / \ + \ / + ----------- + + where 'A -> B' means that event A depends on event B. + +A new loop has been created. So DEPT can report it as a deadlock. For +event A, since there are no waits between 4 and the event, event A does +not create any dependency. That's it. + +Let's take a look at how DEPT works with the 2nd example in the section +'Limitation of lockdep'. + +.. code-block:: + + context X context Y + + mutex_lock A + mutex_lock A <- DEADLOCK + wait_for_completion B <- DEADLOCK + complete B + mutex_unlock A + mutex_unlock A + +Similarly adding comments to describe DEPT's view in detail: + +.. code-block:: + + context X context Y + + mutex_lock A + /* might wait for A */ + /* start to take into account event A's context */ + /* 1 */ + + request_something_and_complete_B + /* request to handle something via e.g. wq, daemon, + or any its own way, and finally do 'complete B' + a.k.a. event B */ + /* 2 */ + /* notice the request from 2 and handle it running toward event B */ + /* start to take into account event B's context */ + /* 3 */ + + mutex_lock A + /* might wait for A */ <- DEADLOCK + /* start to take into account event A's context */ + /* 4 */ + wait_for_completion B + /* wait for B */ <- DEADLOCK + /* 5 */ + complete B + /* event B that has been valid since 3 */ + mutex_unlock A + /* event A that has been valid since 1 */ + mutex_unlock A + /* event A that has been valid since 4 */ + +Let's build up a dependency graph with this example. Firstly, context X: + +.. code-block:: + + context X + + /* notice the request from 2 and handle it running toward event B */ + /* start to take into account event B's context */ + /* 3 */ + + mutex_lock A + /* might wait for A */ + /* start to take into account event A's context */ + /* 4 */ + + complete B + /* event B that has been valid since 3 */ + + mutex_unlock A + /* event A that has been valid since 4 */ + +There are two events, complete B a.k.a. event B and mutex_unlock A a.k.a. +event A. For event A, since there are no waits between between 4 and the +event, event A does not create any dependency. For event B, there is a +wait, mutex_lock A a.k.a. wait A, between 3 and the event. Which means +event B cannot be triggered if wait A cannot be awakened by event A. +Therefore, we can say event B depends on event A, say, 'B -> A'. The +graph will look like after adding the dependency: + +.. code-block:: + + B -> A + + where 'A -> B' means that event A depends on event B. + +If context X might notice the request after mutex_lock A, DEPT cannot +track this dependency, which results in missing a dependency. However, +that can be improved by adding proper DEPT annotations if needed. + +Next, context Y: + +.. code-block:: + + context Y + + mutex_lock A + /* might wait for A */ + /* start to take into account event A's context */ + /* 1 */ + + request_something_and_complete_B + /* request to handle something via e.g. wq, daemon, or any its own + way, and finally do 'complete B' a.k.a. event B */ + /* 2 */ + + wait_for_completion B + /* wait for B */ + /* 5 */ + + mutex_unlock A + /* event A that has been valid since 1 */ + +There is one event, mutex_unlock A a.k.a. event A. For event A, there is +a wait, wait_for_completion B a.k.a. wait B, between 1 and the event. +Which means event A cannot be triggered if wait B cannot be awakened by +event B. Therefore, we can say event A depends on event B, say, 'A -> B'. +The graph will look like after adding the dependency: + +.. code-block:: + + -> B -> A - + / \ + \ / + ----------- + + where 'A -> B' means that event A depends on event B. + +A new loop has been created. So DEPT can report it as a deadlock. + +CONCLUSION + +DEPT works well with any general synchronization mechanisms by focusing +on wait, event and its context. + + +Interpret DEPT report +--------------------- + +The following is the same example in the section 'How DEPT works'. + +.. code-block:: + + context X context Y context Z + + mutex_lock A + /* might wait for A */ + /* start to take into account event A's context */ + /* 1 */ + folio_lock B + /* might wait for B */ + /* start to take into account event B's context */ + /* 2 */ + + folio_lock B + /* might wait for B */ <- DEADLOCK + /* start to take into account event B's context */ + /* 3 */ + + mutex_lock A + /* might wait for A */ <- DEADLOCK + /* start to take into account + event A's context */ + /* 4 */ + + folio_unlock B + /* event B that has been valid since 2 */ + folio_unlock B + /* event B that has been valid since 3 */ + + mutex_unlock A + /* event A that has been valid since 1 */ + + mutex_unlock A + /* event A that has been valid since 4 */ + +We can simplify this by labeling each waiting point with [W], each point +where its event's context starts with [S] and each event with [E]. This +example will look like after the labeling: + +.. code-block:: + + context X context Y context Z + + [W][S] mutex_lock A + [W][S] folio_lock B + [W][S] folio_lock B <- DEADLOCK + + [W][S] mutex_lock A <- DEADLOCK + [E] folio_unlock B + [E] folio_unlock B + [E] mutex_unlock A + [E] mutex_unlock A + +DEPT uses the symbols [W], [S] and [E] in its report as described above. +The following is an example reported by DEPT for a real problem in +practice. + +.. code-block:: + + Link: https://lore.kernel.org/lkml/[email protected]/#t + Link: https://lore.kernel.org/lkml/[email protected]/ + + =================================================== + DEPT: Circular dependency has been detected. + 6.2.0-rc1-00025-gb0c20ebf51ac-dirty #28 Not tainted + --------------------------------------------------- + summary + --------------------------------------------------- + *** DEADLOCK *** + + context A + [S] lock(&ni->ni_lock:0) + [W] folio_wait_bit_common(PG_locked_map:0) + [E] unlock(&ni->ni_lock:0) + + context B + [S] (unknown)(PG_locked_map:0) + [W] lock(&ni->ni_lock:0) + [E] folio_unlock(PG_locked_map:0) + + [S]: start of the event context + [W]: the wait blocked + [E]: the event not reachable + --------------------------------------------------- + context A's detail + --------------------------------------------------- + context A + [S] lock(&ni->ni_lock:0) + [W] folio_wait_bit_common(PG_locked_map:0) + [E] unlock(&ni->ni_lock:0) + + [S] lock(&ni->ni_lock:0): + [<ffffffff82b396fb>] ntfs3_setattr+0x54b/0xd40 + stacktrace: + ntfs3_setattr+0x54b/0xd40 + notify_change+0xcb3/0x1430 + do_truncate+0x149/0x210 + path_openat+0x21a3/0x2a90 + do_filp_open+0x1ba/0x410 + do_sys_openat2+0x16d/0x4e0 + __x64_sys_creat+0xcd/0x120 + do_syscall_64+0x41/0xc0 + entry_SYSCALL_64_after_hwframe+0x63/0xcd + + [W] folio_wait_bit_common(PG_locked_map:0): + [<ffffffff81b228b0>] truncate_inode_pages_range+0x9b0/0xf20 + stacktrace: + folio_wait_bit_common+0x5e0/0xaf0 + truncate_inode_pages_range+0x9b0/0xf20 + truncate_pagecache+0x67/0x90 + ntfs3_setattr+0x55a/0xd40 + notify_change+0xcb3/0x1430 + do_truncate+0x149/0x210 + path_openat+0x21a3/0x2a90 + do_filp_open+0x1ba/0x410 + do_sys_openat2+0x16d/0x4e0 + __x64_sys_creat+0xcd/0x120 + do_syscall_64+0x41/0xc0 + entry_SYSCALL_64_after_hwframe+0x63/0xcd + + [E] unlock(&ni->ni_lock:0): + (N/A) + --------------------------------------------------- + context B's detail + --------------------------------------------------- + context B + [S] (unknown)(PG_locked_map:0) + [W] lock(&ni->ni_lock:0) + [E] folio_unlock(PG_locked_map:0) + + [S] (unknown)(PG_locked_map:0): + (N/A) + + [W] lock(&ni->ni_lock:0): + [<ffffffff82b009ec>] attr_data_get_block+0x32c/0x19f0 + stacktrace: + attr_data_get_block+0x32c/0x19f0 + ntfs_get_block_vbo+0x264/0x1330 + __block_write_begin_int+0x3bd/0x14b0 + block_write_begin+0xb9/0x4d0 + ntfs_write_begin+0x27e/0x480 + generic_perform_write+0x256/0x570 + __generic_file_write_iter+0x2ae/0x500 + ntfs_file_write_iter+0x66d/0x1d70 + do_iter_readv_writev+0x20b/0x3c0 + do_iter_write+0x188/0x710 + vfs_iter_write+0x74/0xa0 + iter_file_splice_write+0x745/0xc90 + direct_splice_actor+0x114/0x180 + splice_direct_to_actor+0x33b/0x8b0 + do_splice_direct+0x1b7/0x280 + do_sendfile+0xb49/0x1310 + + [E] folio_unlock(PG_locked_map:0): + [<ffffffff81f10222>] generic_write_end+0xf2/0x440 + stacktrace: + generic_write_end+0xf2/0x440 + ntfs_write_end+0x42e/0x980 + generic_perform_write+0x316/0x570 + __generic_file_write_iter+0x2ae/0x500 + ntfs_file_write_iter+0x66d/0x1d70 + do_iter_readv_writev+0x20b/0x3c0 + do_iter_write+0x188/0x710 + vfs_iter_write+0x74/0xa0 + iter_file_splice_write+0x745/0xc90 + direct_splice_actor+0x114/0x180 + splice_direct_to_actor+0x33b/0x8b0 + do_splice_direct+0x1b7/0x280 + do_sendfile+0xb49/0x1310 + __x64_sys_sendfile64+0x1d0/0x210 + do_syscall_64+0x41/0xc0 + entry_SYSCALL_64_after_hwframe+0x63/0xcd + --------------------------------------------------- + information that might be helpful + --------------------------------------------------- + CPU: 1 PID: 8060 Comm: a.out Not tainted + 6.2.0-rc1-00025-gb0c20ebf51ac-dirty #28 + Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), + BIOS Bochs 01/01/2011 + Call Trace: + <TASK> + dump_stack_lvl+0xf2/0x169 + print_circle.cold+0xca4/0xd28 + ? lookup_dep+0x240/0x240 + ? extend_queue+0x223/0x300 + cb_check_dl+0x1e7/0x260 + bfs+0x27b/0x610 + ? print_circle+0x240/0x240 + ? llist_add_batch+0x180/0x180 + ? extend_queue_rev+0x300/0x300 + ? __add_dep+0x60f/0x810 + add_dep+0x221/0x5b0 + ? __add_idep+0x310/0x310 + ? add_iecxt+0x1bc/0xa60 + ? add_iecxt+0x1bc/0xa60 + ? add_iecxt+0x1bc/0xa60 + ? add_iecxt+0x1bc/0xa60 + __dept_wait+0x600/0x1490 + ? add_iecxt+0x1bc/0xa60 + ? truncate_inode_pages_range+0x9b0/0xf20 + ? check_new_class+0x790/0x790 + ? dept_enirq_transition+0x519/0x9c0 + dept_wait+0x159/0x3b0 + ? truncate_inode_pages_range+0x9b0/0xf20 + folio_wait_bit_common+0x5e0/0xaf0 + ? filemap_get_folios_contig+0xa30/0xa30 + ? dept_enirq_transition+0x519/0x9c0 + ? lock_is_held_type+0x10e/0x160 + ? lock_is_held_type+0x11e/0x160 + truncate_inode_pages_range+0x9b0/0xf20 + ? truncate_inode_partial_folio+0xba0/0xba0 + ? setattr_prepare+0x142/0xc40 + truncate_pagecache+0x67/0x90 + ntfs3_setattr+0x55a/0xd40 + ? ktime_get_coarse_real_ts64+0x1e5/0x2f0 + ? ntfs_extend+0x5c0/0x5c0 + ? mode_strip_sgid+0x210/0x210 + ? ntfs_extend+0x5c0/0x5c0 + notify_change+0xcb3/0x1430 + ? do_truncate+0x149/0x210 + do_truncate+0x149/0x210 + ? file_open_root+0x430/0x430 + ? process_measurement+0x18c0/0x18c0 + ? ntfs_file_release+0x230/0x230 + path_openat+0x21a3/0x2a90 + ? path_lookupat+0x840/0x840 + ? dept_enirq_transition+0x519/0x9c0 + ? lock_is_held_type+0x10e/0x160 + do_filp_open+0x1ba/0x410 + ? may_open_dev+0xf0/0xf0 + ? find_held_lock+0x2d/0x110 + ? lock_release+0x43c/0x830 + ? dept_ecxt_exit+0x31a/0x590 + ? _raw_spin_unlock+0x3b/0x50 + ? alloc_fd+0x2de/0x6e0 + do_sys_openat2+0x16d/0x4e0 + ? __ia32_sys_get_robust_list+0x3b0/0x3b0 + ? build_open_flags+0x6f0/0x6f0 + ? dept_enirq_transition+0x519/0x9c0 + ? dept_enirq_transition+0x519/0x9c0 + ? lock_is_held_type+0x4e/0x160 + ? lock_is_held_type+0x4e/0x160 + __x64_sys_creat+0xcd/0x120 + ? __x64_compat_sys_openat+0x1f0/0x1f0 + do_syscall_64+0x41/0xc0 + entry_SYSCALL_64_after_hwframe+0x63/0xcd + RIP: 0033:0x7f8b9e4e4469 + Code: 00 f3 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 + 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> + 3d 01 f0 ff ff 73 01 c3 48 8b 0d ff 49 2b 00 f7 d8 64 89 01 48 + RSP: 002b:00007f8b9eea4ef8 EFLAGS: 00000202 ORIG_RAX: 0000000000000055 + RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f8b9e4e4469 + RDX: 0000000000737562 RSI: 0000000000000000 RDI: 0000000020000000 + RBP: 00007f8b9eea4f20 R08: 0000000000000000 R09: 0000000000000000 + R10: 0000000000000000 R11: 0000000000000202 R12: 00007fffa75511ee + R13: 00007fffa75511ef R14: 00007f8b9ee85000 R15: 0000000000000003 + </TASK> + +Let's take a look at the summary that is the most important part. + +.. code-block:: + + --------------------------------------------------- + summary + --------------------------------------------------- + *** DEADLOCK *** + + context A + [S] lock(&ni->ni_lock:0) + [W] folio_wait_bit_common(PG_locked_map:0) + [E] unlock(&ni->ni_lock:0) + + context B + [S] (unknown)(PG_locked_map:0) + [W] lock(&ni->ni_lock:0) + [E] folio_unlock(PG_locked_map:0) + + [S]: start of the event context + [W]: the wait blocked + [E]: the event not reachable + +The summary shows the following scenario: + +.. code-block:: + + context A context B context ?(unknown) + + [S] folio_lock(&f1) + [S] lock(&ni->ni_lock:0) + [W] folio_wait_bit_common(PG_locked_map:0) + + [W] lock(&ni->ni_lock:0) + [E] folio_unlock(&f1) + + [E] unlock(&ni->ni_lock:0) + +Adding comments to describe DEPT's view in detail: + +.. code-block:: + + context A context B context ?(unknown) + + [S] folio_lock(&f1) + /* start to take into account context + B heading for folio_unlock(&f1) */ + /* 1 */ + [S] lock(&ni->ni_lock:0) + /* start to take into account this context heading for + unlock(&ni->ni_lock:0) */ + /* 2 */ + + [W] folio_wait_bit_common(PG_locked_map:0) (= folio_lock(&f1)) + /* might wait for folio_unlock(&f1) */ + + [W] lock(&ni->ni_lock:0) + /* might wait for unlock(&ni->ni_lock:0) */ + + [E] folio_unlock(&f1) + /* event that has been valid since 1 */ + + [E] unlock(&ni->ni_lock:0) + /* event that has been valid since 2 */ + +Let's build up a dependency graph with this report. Firstly, context A: + +.. code-block:: + + context A + + [S] lock(&ni->ni_lock:0) + /* start to take into account this context heading for + unlock(&ni->ni_lock:0) */ + /* 2 */ + + [W] folio_wait_bit_common(PG_locked_map:0) (= folio_lock(&f1)) + /* might wait for folio_unlock(&f1) */ + + [E] unlock(&ni->ni_lock:0) + /* event that has been valid since 2 */ + +There is one event, unlock(&ni->ni_lock:0). There is a wait, +folio_lock(&f1), between 2 and the event. Which means +unlock(&ni->ni_lock:0) is not reachable if folio_lock(&f1) cannot be +awakened by the owner's folio_unlock(&f1). Therefore, we can say +unlock(&ni->ni_lock:0) depends on folio_unlock(&f1), say, +'unlock(&ni->ni_lock:0) -> folio_unlock(&f1)'. + +The graph will look like after adding the dependency: + +.. code-block:: + + unlock(&ni->ni_lock:0) -> folio_unlock(&f1) + + where 'A -> B' means that event A depends on event B. + +Secondly, context B: + +.. code-block:: + + context B + + [W] lock(&ni->ni_lock:0) + /* might wait for unlock(&ni->ni_lock:0) */ + + [E] folio_unlock(&f1) + /* event that has been valid since 1 */ + +There is also one event, folio_unlock(&f1). There is a wait, +lock(&ni->ni_lock:0), between 1 and the event. Which means +folio_unlock(&f1) is not reachable if lock(&ni->ni_lock:0) cannot be +awakened by the owner's unlock(&ni->ni_lock:0). Therefore, we can say +folio_unlock(&f1) depends on unlock(&ni->ni_lock:0), say, +'folio_unlock(&f1) -> unlock(&ni->ni_lock:0)'. + +The graph will look like after adding the dependency: + +.. code-block:: + + -> unlock(&ni->ni_lock:0) -> folio_unlock(&f1) - + / \ + \ / + ------------------------------------------------ + + where 'A -> B' means that event A depends on event B. + +A new loop has been created. So DEPT can report it as a deadlock! Cool! + +CONCLUSION + +DEPT works awesome!
Documentation/dev-tools/dept_api.rst new file +124 -0
124 lines not on this page · raw message
Documentation/dev-tools/index.rst +2 -0
@@ -23,6 +23,8 @@ Documentation/process/debugging/index.rst coccinelle context-analysis sparse + dept + dept_api kcov gcov kasan
Signature · 1 line
2.17.1
PATCH v19 26/40 cpu/hotplug: use a weaker annotation in AP thread
In reply to Byungchul Parkcb92173d1f0 ("locking/lockdep, cpu/hotplug: Annotate AP thread") was introduced to make lockdep_assert_cpus_held() work in AP thread.
However, the annotation is too strong for that purpose. We don't have to use more than try lock annotation for that.
rwsem_acquire() implies:
1. might be a waiter on contention of the lock.
2. enter to the critical section of the lock.
All we need in here is to act 2, not 1. So trylock version of annotation is sufficient for that purpose. Now that dept partially relies on lockdep annotaions, dept interpets rwsem_acquire() as a potential wait and might report a deadlock by the wait.
Replace it with trylock version of annotation.
--- kernel/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/cpu.c +1 -1
@@ -542,7 +542,7 @@ int lockdep_is_cpus_write_held(void)static void lockdep_acquire_cpus_lock (void ) { -rwsem_acquire (&cpu_hotplug_lock.dep_map,0 ,0 , _THIS_IP_); +rwsem_acquire (&cpu_hotplug_lock.dep_map,0 ,1 , _THIS_IP_); }static void lockdep_release_cpus_lock (void )
Signature · 1 line
2.17.1
PATCH v19 27/40 dept: assign dept map to mmu notifier invalidation synchronization
In reply to Byungchul ParkResolved the following false positive by introducing explicit dept map and annotations for dealing with this case:
*** DEADLOCK ***
context A
[S] (unknown)(<sched>:0)
[W] lock(&mm->mmap_lock:0)
[E] try_to_wake_up(<sched>:0)context B
[S] lock(&mm->mmap_lock:0)
[W] mmu_interval_read_begin(<sched>:0)
[E] unlock(&mm->mmap_lock:0) [S]: start of the event context
[W]: the wait blocked
[E]: the event not reachable
dept already tracks dependencies between scheduler sleep and ttwu based on internal timestamp called wgen. However, in case that more than one event contexts are overwrapped, dept has chance to wrongly guess the start of the event context like the following:
<before this patch>
context A: lock L
context A: mmu_notifier_invalidate_range_start()
context B: lock L'
context B: mmu_interval_read_begin() : wait <- here is the start of the event context of C. context B: unlock L'
context C: lock L''
context C: mmu_notifier_invalidate_range_start()
context A: mmu_notifier_invalidate_range_end()
context A: unlock L
context C: mmu_notifier_invalidate_range_end() : ttwu
<- here is the end of the event context of C. dept observes a wait,
lock L'' within the event context of C. Which causes a false positive dept report.
context C: unlock L''
By explicitly annotating the interesting event context range, make dept work with more precise information like:
<after this patch>
context A: lock L
context A: mmu_notifier_invalidate_range_start()
context B: lock L'
context B: mmu_interval_read_begin() : wait
context B: unlock L'
context C: lock L''
context C: mmu_notifier_invalidate_range_start() <- here is the start of the event context of C.
context A: mmu_notifier_invalidate_range_end()
context A: unlock L
context C: mmu_notifier_invalidate_range_end() : ttwu
<- here is the end of the event context of C. dept doesn't observe
the wait, lock L'' within the event context of C. context C is responsible only for the range delimited by mmu_notifier_invalidate_range_{start,end}().
context C: unlock L''
--- include/linux/mmu_notifier.h | 26 ++++++++++++++++++++++++++ mm/mmu_notifier.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-)
include/linux/mmu_notifier.h +26 -0
@@ -429,6 +429,14 @@ static inline int mmu_notifier_test_young(struct mm_struct *mm,return 0 ; } +#ifdef CONFIG_DEPT +void mmu_notifier_invalidate_dept_ecxt_start (struct mmu_notifier_range *range); +void mmu_notifier_invalidate_dept_ecxt_end (struct mmu_notifier_range *range); +#else +static inline void mmu_notifier_invalidate_dept_ecxt_start (struct mmu_notifier_range *range) {} +static inline void mmu_notifier_invalidate_dept_ecxt_end (struct mmu_notifier_range *range) {} +#endif +static inline void mmu_notifier_invalidate_range_start (struct mmu_notifier_range *range) {
@@ -440,6 +448,12 @@ mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range)__mmu_notifier_invalidate_range_start (range); }lock_map_release (&__mmu_notifier_invalidate_range_start_map); + +/* +* From now on, waiters could be there by this start until +* mmu_notifier_invalidate_range_end(). +*/ +mmu_notifier_invalidate_dept_ecxt_start (range); }/*
@@ -460,6 +474,12 @@ mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range) ret =__mmu_notifier_invalidate_range_start (range); }lock_map_release (&__mmu_notifier_invalidate_range_start_map); + +/* +* From now on, waiters could be there by this start until +* mmu_notifier_invalidate_range_end(). +*/ +mmu_notifier_invalidate_dept_ecxt_start (range);return ret; }
@@ -471,6 +491,12 @@ mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range)if (mm_has_notifiers (range->mm))__mmu_notifier_invalidate_range_end (range); + +/* +* The event context that has been started by +* mmu_notifier_invalidate_range_start() ends. +*/ +mmu_notifier_invalidate_dept_ecxt_end (range); } static inline void mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm,
mm/mmu_notifier.c +29 -2
@@ -46,6 +46,7 @@ struct mmu_notifier_subscriptions {unsigned long active_invalidate_ranges;struct rb_root_cached itree;wait_queue_head_t wq; +struct dept_map dmap;struct hlist_head deferred_list; };
@@ -165,6 +166,25 @@ static void mn_itree_inv_end(struct mmu_notifier_subscriptions *subscriptions)wake_up_all (&subscriptions->wq); } +#ifdef CONFIG_DEPT +void mmu_notifier_invalidate_dept_ecxt_start (struct mmu_notifier_range *range) +{ +struct mmu_notifier_subscriptions *subscriptions = + range->mm->notifier_subscriptions; + +if (subscriptions) +sdt_ecxt_enter (&subscriptions->dmap); +} +void mmu_notifier_invalidate_dept_ecxt_end (struct mmu_notifier_range *range) +{ +struct mmu_notifier_subscriptions *subscriptions = + range->mm->notifier_subscriptions; + +if (subscriptions) +sdt_ecxt_exit (&subscriptions->dmap); +} +#endif +/** * mmu_interval_read_begin - Begin a read side critical section against a VA * range
@@ -246,9 +266,12 @@ mmu_interval_read_begin(struct mmu_interval_notifier *interval_sub)*/ lock_map_acquire (&__mmu_notifier_invalidate_range_start_map);lock_map_release (&__mmu_notifier_invalidate_range_start_map); -if (is_invalidating) +if (is_invalidating) { +sdt_might_sleep_start (&subscriptions->dmap);wait_event (subscriptions->wq,READ_ONCE (subscriptions->invalidate_seq) != seq); +sdt_might_sleep_end (); + }/* * Notice that mmu_interval_read_retry() can already be true at this
@@ -624,6 +647,7 @@ int __mmu_notifier_register(struct mmu_notifier *subscription,INIT_HLIST_HEAD (&subscriptions->list);spin_lock_init (&subscriptions->lock); +sdt_map_init (&subscriptions->dmap); subscriptions->invalidate_seq =2 ; subscriptions->itree =RB_ROOT_CACHED ;init_waitqueue_head (&subscriptions->wq);
@@ -1069,9 +1093,12 @@ void mmu_interval_notifier_remove(struct mmu_interval_notifier *interval_sub)*/ lock_map_acquire (&__mmu_notifier_invalidate_range_start_map);lock_map_release (&__mmu_notifier_invalidate_range_start_map); -if (seq) +if (seq) { +sdt_might_sleep_start (&subscriptions->dmap);wait_event (subscriptions->wq,mmu_interval_seq_released (subscriptions, seq)); +sdt_might_sleep_end (); + }/* pairs with mmgrab in mmu_interval_notifier_insert() */ mmdrop (mm);
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 27/40] dept: assign dept map to mmu notifier invalidation synchronization
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Unbalanced DEPT tracking context leak in mmu_notifier_invalidate_range_start_nonblock() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Unbalanced DEPT tracking context leak in mmu_notifier_invalidate_range_start_nonblock() --
commit 10f75b8cdecfe9a5cbc6804a1d8ae1770fc9fe67
Author: Byungchul Park <[email protected]>
dept: assign dept map to mmu notifier invalidation synchronization
This commit introduces explicit DEPT tracking contexts to resolve false positive deadlock reports in mmu_notifier invalidation synchronization. It annotates the start and end of the event contexts delimited by mmu_notifier_invalidate_range_start() and _end().
Quoted 3 lines
include/linux/mmu_notifier.h +0
-0
[ ... ]
include/linux/mmu_notifier.h mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range) · line 484
Quoted 12 lines
include/linux/mmu_notifier.h +6
-0@@ -460,6 +474,12 @@ mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range) ret =__mmu_notifier_invalidate_range_start (range); }lock_map_release (&__mmu_notifier_invalidate_range_start_map); + +/* +* From now on, waiters could be there by this start until +* mmu_notifier_invalidate_range_end(). +*/ +mmu_notifier_invalidate_dept_ecxt_start (range);return ret; }
[Severity: Medium]
Does this unconditionally start the DEPT event context even if the non-blocking start fails?
If mmu_notifier_invalidate_range_start_nonblock() returns an error, callers typically abort and skip calling mmu_notifier_invalidate_range_end(). For example, in mm/oom_kill.c:__oom_reap_task_mm():
if (mmu_notifier_invalidate_range_start_nonblock(&range)) {
tlb_finish_mmu(&tlb);
ret = false;
continue;
}Could this lead to an unbalanced DEPT context being leaked, as the corresponding mmu_notifier_invalidate_dept_ecxt_end() will never be called on the error path?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=27
PATCH v19 28/40 dept: assign unique dept_key to each distinct dma fence caller
In reply to Byungchul Parkdma fence can be used at various points in the code and it's very hard to distinguish dma fences between different usages. Using a single dept_key for all the dma fences could trigger false positive reports.
Assign unique dept_key to each distinct dma fence wait to avoid false positive reports.
--- drivers/dma-buf/dma-fence.c | 18 ++++----- include/linux/dma-fence.h | 74 +++++++++++++++++++++++++++++-------- 2 files changed, 68 insertions(+), 24 deletions(-)
drivers/dma-buf/dma-fence.c +9 -9
@@ -503,7 +503,7 @@ void dma_fence_signal(struct dma_fence *fence)EXPORT_SYMBOL (dma_fence_signal);/** -* dma_fence_wait_timeout - sleep until the fence gets signaled +* __dma_fence_wait_timeout - sleep until the fence gets signaled * or until timeout elapses * @fence: the fence to wait on * @intr: if true, do an interruptible wait
@@ -521,7 +521,7 @@ EXPORT_SYMBOL(dma_fence_signal);* See also dma_fence_wait() and dma_fence_wait_any_timeout(). */ signed long -dma_fence_wait_timeout (struct dma_fence *fence,bool intr,signed long timeout) +__dma_fence_wait_timeout (struct dma_fence *fence,bool intr,signed long timeout) {signed long ret;
@@ -550,7 +550,7 @@ dma_fence_wait_timeout(struct dma_fence *fence, bool intr, signed long timeout) }return ret; } -EXPORT_SYMBOL (dma_fence_wait_timeout); +EXPORT_SYMBOL (__dma_fence_wait_timeout);/** * dma_fence_release - default release function for fences
@@ -786,7 +786,7 @@ dma_fence_default_wait_cb(struct dma_fence *fence, struct dma_fence_cb *cb) }/** -* dma_fence_default_wait - default sleep until the fence gets signaled +* __dma_fence_default_wait - default sleep until the fence gets signaled * or until timeout elapses * @fence: the fence to wait on * @intr: if true, do an interruptible wait
@@ -798,7 +798,7 @@ dma_fence_default_wait_cb(struct dma_fence *fence, struct dma_fence_cb *cb)* functions taking a jiffies timeout. */ signed long -dma_fence_default_wait (struct dma_fence *fence,bool intr,signed long timeout) +__dma_fence_default_wait (struct dma_fence *fence,bool intr,signed long timeout) {struct default_wait_cb cb;unsigned long flags;
@@ -847,7 +847,7 @@ dma_fence_default_wait(struct dma_fence *fence, bool intr, signed long timeout)spin_unlock_irqrestore (fence->lock, flags);return ret; } -EXPORT_SYMBOL (dma_fence_default_wait); +EXPORT_SYMBOL (__dma_fence_default_wait); static bool dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count,
@@ -867,7 +867,7 @@ dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count, }/** -* dma_fence_wait_any_timeout - sleep until any fence gets signaled +* __dma_fence_wait_any_timeout - sleep until any fence gets signaled * or until timeout elapses * @fences: array of fences to wait on * @count: number of fences to wait on
@@ -887,7 +887,7 @@ dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count,* See also dma_fence_wait() and dma_fence_wait_timeout(). */ signed long -dma_fence_wait_any_timeout (struct dma_fence **fences,uint32_t count, +__dma_fence_wait_any_timeout (struct dma_fence **fences,uint32_t count,bool intr,signed long timeout,uint32_t *idx) {struct default_wait_cb *cb;
@@ -955,7 +955,7 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,return ret; } -EXPORT_SYMBOL (dma_fence_wait_any_timeout); +EXPORT_SYMBOL (__dma_fence_wait_any_timeout);/** * DOC: deadline hints
include/linux/dma-fence.h +59 -15
98 lines not on this page · raw message
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 28/40] dept: assign unique dept_key to each distinct dma fence caller
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The newly introduced statement expression macros for DMA fence waiting evaluate their timeout…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The newly introduced statement expression macros for DMA fence waiting evaluate their timeout argument (t) multiple times.
- [Medium] Local variable shadowing in the statement expression macros due to the unhygienic __ret variable declaration. --
commit 4d4caad8d173eededcba1493c060f5ddecbd6b70
Author: Byungchul Park <[email protected]>
dept: assign unique dept_key to each distinct dma fence caller
dma fence can be used at various points in the code and it's very hard to distinguish dma fences between different usages. Using a single dept_key for all the dma fences could trigger false positive reports.
Quoted 4 lines
include/linux/dma-fence.h +0
-0
[ ... ]
Quoted 4 lines
include/linux/dma-fence.h +0
-0@@ -370,8 +370,22 @@ bool dma_fence_check_and_signal_locked(struct dma_fence *fence);void dma_fence_signal_locked (struct dma_fence *fence);void dma_fence_signal_timestamp (struct dma_fence *fence,ktime_t timestamp);void dma_fence_signal_timestamp_locked (struct dma_fence *fence,ktime_t timestamp);
include/linux/dma-fence.h bool dma_fence_check_and_signal_locked(struct dma_fence *fence); · line 381
Quoted 10 lines
include/linux/dma-fence.h +8
-1-signed long dma_fence_default_wait (struct dma_fence *fence, +signed long __dma_fence_default_wait (struct dma_fence *fence,bool intr,signed long timeout); + +/* +* Associate every caller with its own dept map. +*/ +#define dma_fence_default_wait (f, intr, t) \ +({ \ + signed long __ret; \
[Severity: Medium]
Could this local variable declaration lead to shadowing issues? If a caller passes arguments that reference a variable named __ret in their own scope, this uninitialized local variable will shadow the caller's variable, causing undefined behavior.
include/linux/dma-fence.h bool dma_fence_check_and_signal_locked(struct dma_fence *fence); · line 384
Quoted 3 lines
include/linux/dma-fence.h +3
-0+ \ +sdt_might_sleep_start_timeout (NULL , t); \ + __ret =__dma_fence_default_wait (f, intr, t); \
[Severity: Medium]
Is it safe to evaluate the timeout argument t multiple times here?
If a caller passes an expression with side effects, such as timeout--, it would be evaluated twice, which could lead to incorrect timeout logic.
Quoted 4 lines
include/linux/dma-fence.h +4
-0+sdt_might_sleep_end (); \ + __ret; \ +}) +
[ ... ]
Quoted 11 lines
include/linux/dma-fence.h +2
-2@@ -628,12 +642,37 @@ static inline ktime_t dma_fence_timestamp(struct dma_fence *fence)return fence->timestamp; } -signed long dma_fence_wait_timeout (struct dma_fence *, +signed long __dma_fence_wait_timeout (struct dma_fence *,bool intr,signed long timeout); -signed long dma_fence_wait_any_timeout(struct dma_fence **fences, +signed long __dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, bool intr, signed long timeout,
include/linux/dma-fence.h static inline ktime_t dma_fence_timestamp(struct dma_fence *fence) · line 659
Quoted 10 lines
include/linux/dma-fence.h +9
-0uint32_t *idx); +/* +* Associate every caller with its own dept map. +*/ +#define dma_fence_wait_timeout (f, intr, t) \ +({ \ + signed long __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, t); \ + __ret = __dma_fence_wait_timeout(f, intr, t); \
[Severity: Medium]
Does this code also suffer from the same macro hygiene issues with shadowing __ret and evaluating the t argument twice?
include/linux/dma-fence.h static inline ktime_t dma_fence_timestamp(struct dma_fence *fence) · line 672
Quoted 13 lines
include/linux/dma-fence.h +13
-0+sdt_might_sleep_end (); \ + __ret; \ +}) + +/* +* Associate every caller with its own dept map. +*/ +#define dma_fence_wait_any_timeout (fpp, count, intr, t, idx) \ +({ \ + signed long __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, t); \ + __ret = __dma_fence_wait_any_timeout(fpp, count, intr, t, idx); \
[Severity: Medium]
Would it be safer to use a more unique variable name instead of __ret, and evaluate t only once before passing it to sdt_might_sleep_start_timeout() and __dma_fence_wait_any_timeout(), similar to the other macros?
Quoted 3 lines
include/linux/dma-fence.h +3
-0+sdt_might_sleep_end (); \ + __ret; \ +})
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
Re: [PATCH v19 28/40] dept: assign unique dept_key to each distinct dma fence caller
Quoted 33 lines · On Tue, Jul 07, 2026 at 07:33:44AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The newly introduced statement expression macros for DMA fence waiting evaluate their timeout argument (t) multiple times.
- [Medium] Local variable shadowing in the statement expression macros due to the unhygienic__retvariable declaration. --commit
4d4caad8d173eededcba1493c060f5ddecbd6b70
Author: Byungchul Park <[email protected]>dept: assign unique
dept_keyto each distinct dma fence callerdma fence can be used at various points in the code and it's very hard to distinguish dma fences between different usages. Using a single
dept_keyfor all the dma fences could trigger false positive reports.Quoted 4 lines
include/linux/dma-fence.h +0
-0[ ... ]
Quoted 12 lines
include/linux/dma-fence.h +6
-1@@ -370,8 +370,22 @@ bool dma_fence_check_and_signal_locked(struct dma_fence *fence);void dma_fence_signal_locked (struct dma_fence *fence);void dma_fence_signal_timestamp (struct dma_fence *fence,ktime_t timestamp);void dma_fence_signal_timestamp_locked (struct dma_fence *fence,ktime_t timestamp); -signed long dma_fence_default_wait (struct dma_fence *fence, +signed long __dma_fence_default_wait (struct dma_fence *fence,bool intr,signed long timeout); + +/* +* Associate every caller with its own dept map. +*/ +#define dma_fence_default_wait (f, intr, t) \
Quoted 8 lines
include/linux/dma-fence.h bool dma_fence_check_and_signal_locked(struct dma_fence *fence); · line 381
Quoted 2 lines
include/linux/dma-fence.h +2
-0+({ \ + signed long __ret; \[Severity: Medium]
Could this local variable declaration lead to shadowing issues? If a caller passes arguments that reference a variable named__retin their own scope, this uninitialized local variable will shadow the caller's variable, causing undefined behavior.
I will fix it.
Quoted 9 lines
include/linux/dma-fence.h bool dma_fence_check_and_signal_locked(struct dma_fence *fence); · line 384
Quoted 3 lines
include/linux/dma-fence.h +3
-0+ \ +sdt_might_sleep_start_timeout (NULL , t); \ + __ret =__dma_fence_default_wait (f, intr, t); \[Severity: Medium]
Is it safe to evaluate the timeout argument t multiple times here?If a caller passes an expression with side effects, such as timeout--, it would be evaluated twice, which could lead to incorrect timeout logic.
Sure, I will fix it.
Quoted 24 lines
Quoted 4 lines
include/linux/dma-fence.h +4
-0+sdt_might_sleep_end (); \ + __ret; \ +}) +[ ... ]
Quoted 17 lines
include/linux/dma-fence.h +7
-2@@ -628,12 +642,37 @@ static inline ktime_t dma_fence_timestamp(struct dma_fence *fence)return fence->timestamp; } -signed long dma_fence_wait_timeout (struct dma_fence *, +signed long __dma_fence_wait_timeout (struct dma_fence *,bool intr,signed long timeout); -signed long dma_fence_wait_any_timeout (struct dma_fence **fences, +signed long __dma_fence_wait_any_timeout (struct dma_fence **fences,uint32_t count,bool intr,signed long timeout,uint32_t *idx); +/* +* Associate every caller with its own dept map. +*/ +#define dma_fence_wait_timeout (f, intr, t) \ +({ \
Quoted 8 lines
include/linux/dma-fence.h static inline ktime_t dma_fence_timestamp(struct dma_fence *fence) · line 659
Quoted 4 lines
include/linux/dma-fence.h +4
-0+signed long __ret; \ + \ +sdt_might_sleep_start_timeout (NULL , t); \ + __ret =__dma_fence_wait_timeout (f, intr, t); \[Severity: Medium]
Does this code also suffer from the same macro hygiene issues with shadowing__retand evaluating the t argument twice?
Okay, I will fix it.
Quoted 8 lines
Quoted 8 lines
include/linux/dma-fence.h +8
-0+sdt_might_sleep_end (); \ + __ret; \ +}) + +/* +* Associate every caller with its own dept map. +*/ +#define dma_fence_wait_any_timeout (fpp, count, intr, t, idx) \
Quoted 8 lines
include/linux/dma-fence.h static inline ktime_t dma_fence_timestamp(struct dma_fence *fence) · line 672
Quoted 5 lines
include/linux/dma-fence.h +5
-0+({ \ + signed long __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, t); \ + __ret = __dma_fence_wait_any_timeout(fpp, count, intr, t, idx); \[Severity: Medium]
Would it be safer to use a more unique variable name instead of__ret, and
Suggestion?
Quoted 2 lines
evaluate t only once before passing it to
sdt_might_sleep_start_timeout()and__dma_fence_wait_any_timeout(), similar to the other macros?
Sure.
Byungchul
Quoted 6 lines
include/linux/dma-fence.h bool dma_fence_check_and_signal_locked(struct dma_fence *fence); · line 387
Quoted 3 lines
include/linux/dma-fence.h +3
-0+sdt_might_sleep_end (); \ + __ret; \ +})--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
Re: [PATCH v19 28/40] dept: assign unique dept_key to each distinct dma fence caller
In reply to Byungchul ParkHi Nathan,
After reading your thoughtful comments, I tested the Clang build issue related to "indirect goto" on a v7.2 kernel with DEPT enabled:
$ clang -v Debian clang version 21.1.8 (10)
$ vng --arch arm64 --build LLVM=1 --configitem CONFIG_DEPT=y \
--configitem CONFIG_DRM_XE=m --configitem CONFIG_ARCH_QCOM=y \
--configitem CONFIG_DRM_MSM=mTested branch is here: https://github.com/yskzalloc/linux-dept/tree/dept19_v7.2
Since the update to the dma_fence_wait() usage in the 7.2 rc, Clang has no longer reported the "indirect goto" issue.
Quoted 13 lines · Byungchul Park
dma fence can be used at various points in the code and it's very hard to distinguish dma fences between different usages. Using a single
dept_keyfor all the dma fences could trigger false positive reports.Assign unique
dept_keyto each distinct dma fence wait to avoid false positive reports.Signed-off-by Byungchul Park <[email protected]>--- drivers/dma-buf/dma-fence.c | 18 ++++----- include/linux/dma-fence.h | 74 +++++++++++++++++++++++++++++-------- 2 files changed, 68 insertions(+), 24 deletions(-)
[snip...]
Quoted 92 lines
include/linux/dma-fence.h +49
-15@@ -370,8 +370,22 @@ bool dma_fence_check_and_signal_locked(struct dma_fence *fence);void dma_fence_signal_locked (struct dma_fence *fence);void dma_fence_signal_timestamp (struct dma_fence *fence,ktime_t timestamp);void dma_fence_signal_timestamp_locked (struct dma_fence *fence,ktime_t timestamp); -signed long dma_fence_default_wait (struct dma_fence *fence, +signed long __dma_fence_default_wait (struct dma_fence *fence,bool intr,signed long timeout); + +/* +* Associate every caller with its own dept map. +*/ +#define dma_fence_default_wait (f, intr, t) \ +({ \ + signed long __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, t); \ + __ret = __dma_fence_default_wait(f, intr, t); \ + sdt_might_sleep_end(); \ + __ret; \ +}) +int dma_fence_add_callback (struct dma_fence *fence,struct dma_fence_cb *cb,dma_fence_func_t func);@@ -628,12 +642,37 @@ static inline ktime_t dma_fence_timestamp(struct dma_fence *fence)return fence->timestamp; } -signed long dma_fence_wait_timeout (struct dma_fence *, +signed long __dma_fence_wait_timeout (struct dma_fence *,bool intr,signed long timeout); -signed long dma_fence_wait_any_timeout (struct dma_fence **fences, +signed long __dma_fence_wait_any_timeout (struct dma_fence **fences,uint32_t count,bool intr,signed long timeout,uint32_t *idx); +/* +* Associate every caller with its own dept map. +*/ +#define dma_fence_wait_timeout (f, intr, t) \ +({ \ + signed long __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, t); \ + __ret = __dma_fence_wait_timeout(f, intr, t); \ + sdt_might_sleep_end(); \ + __ret; \ +}) + +/* +* Associate every caller with its own dept map. +*/ +#define dma_fence_wait_any_timeout (fpp, count, intr, t, idx) \ +({ \ + signed long __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, t); \ + __ret = __dma_fence_wait_any_timeout(fpp, count, intr, t, idx); \ + sdt_might_sleep_end(); \ + __ret; \ +})/** * dma_fence_wait - sleep until the fence gets signaled @@ -649,19 +688,24 @@ signed long dma_fence_wait_any_timeout(struct dma_fence **fences,* fence might be freed before return, resulting in undefined behavior. * * See also dma_fence_wait_timeout() and dma_fence_wait_any_timeout(). +* +* Associate every caller with its own dept map. */ -static inline signed long dma_fence_wait (struct dma_fence *fence,bool intr) -{ -signed long ret; - -/* Since dma_fence_wait_timeout cannot timeout with -* MAX_SCHEDULE_TIMEOUT, only valid return values are -* -ERESTARTSYS and MAX_SCHEDULE_TIMEOUT. -*/ - ret =dma_fence_wait_timeout (fence, intr,MAX_SCHEDULE_TIMEOUT ); - -return ret <0 ? ret :0 ; -} +#define dma_fence_wait (f, intr) \ +({ \ + signed long __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, MAX_SCHEDULE_TIMEOUT); \
include/linux/dma-fence.h signed long dma_fence_wait_any_timeout(struct dma_fence **fences, · line 708
Quoted 10 lines
include/linux/dma-fence.h +10
-0+ __ret =__dma_fence_wait_timeout (f, intr,MAX_SCHEDULE_TIMEOUT );\ +sdt_might_sleep_end (); \ + \ +/* \ +* Since dma_fence_wait_timeout cannot timeout with \ +* MAX_SCHEDULE_TIMEOUT, only valid return values are \ +* -ERESTARTSYS and MAX_SCHEDULE_TIMEOUT. \ +*/ \ + __ret <0 ? __ret :0 ; \ +})
Thank you all! :)
Best regards,
Yunseong
PATCH v19 29/40 dept: make dept aware of lockdep_set_lock_cmp_fn() annotation
In reply to Byungchul Parkcommit 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.
--- include/linux/dept.h | 10 +++++++++ kernel/dependency/dept.c | 48 +++++++++++++++++++++++++++++++++++----- kernel/locking/lockdep.c | 1 + 3 files changed, 53 insertions(+), 6 deletions(-)
include/linux/dept.h +10 -0
@@ -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 */
kernel/dependency/dept.c +42 -6
72 lines not on this page · raw message
kernel/locking/lockdep.c +1 -0
@@ -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); }
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 29/40] dept: make dept aware of lockdep_set_lock_cmp_fn() annotation
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] DEPT falsely reports a deadlock when a task sequentially acquires three or more locks of the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] DEPT falsely reports a deadlock when a task sequentially acquires three or more locks of the same class (or interleaves them with other locks), because the lockdep_cmp_fn bypass is improperly restricted to only the immediately preceding lock. --
commit d03c5b926a945b89f5a90fd98986386e113df5af
Author: Byungchul Park <[email protected]>
dept: make dept aware of lockdep_set_lock_cmp_fn() annotation
This commit updates the DEPT (Dependency Tracker) subsystem to respect the lockdep_set_lock_cmp_fn() annotation. It allows DEPT to avoid false positive deadlock reports by using the custom comparison function when evaluating dependencies between locks of the same class.
Quoted 3 lines
kernel/dependency/dept.c +0
-0
[ ... ]
kernel/dependency/dept.c static void add_wait(struct dept_class *c, unsigned long ip, · line 1695
Quoted 11 lines
kernel/dependency/dept.c +5
-2@@ -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 ;
[Severity: Medium]
Will this condition incorrectly bypass the comparison for earlier locks in the chain?
By restricting the lockdep_cmp_fn() check to only the most recently acquired lock (i == dt->ecxt_held_pos - 1), it seems we might miss valid comparisons for older contexts.
For example, if a task acquires lock A1, then lock B, and then lock A2 (where A1 and A2 are the same class), the check against A1 will be skipped because A1 is no longer at dt->ecxt_held_pos - 1.
This would result in a call to add_dep(A1, A2), creating a self-referential class dependency that triggers a false positive deadlock report.
Should lockdep_cmp_fn() be allowed to evaluate against any previously held lock in the chain, rather than just the immediate predecessor?
Quoted 5 lines
kernel/dependency/dept.c +2
-0+ +add_dep (eh->ecxt, w); } wg =next_wgen ();
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
Re: [PATCH v19 29/40] dept: make dept aware of lockdep_set_lock_cmp_fn() annotation
Quoted 36 lines · On Tue, Jul 07, 2026 at 07:33:45AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] DEPT falsely reports a deadlock when a task sequentially acquires three or more locks of the same class (or interleaves them with other locks), because thelockdep_cmp_fnbypass is improperly restricted to only the immediately preceding lock. --commit
d03c5b926a945b89f5a90fd98986386e113df5af
Author: Byungchul Park <[email protected]>dept: make dept aware of
lockdep_set_lock_cmp_fn()annotationThis commit updates the DEPT (Dependency Tracker) subsystem to respect the
lockdep_set_lock_cmp_fn()annotation. It allows DEPT to avoid false positive deadlock reports by using the custom comparison function when evaluating dependencies between locks of the same class.Quoted 3 lines
kernel/dependency/dept.c +0
-0[ ... ]
kernel/dependency/dept.c static void add_wait(struct dept_class *c, unsigned long ip, · line 1695
Quoted 11 lines
kernel/dependency/dept.c +5
-2@@ -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 ;[Severity: Medium]
Will this condition incorrectly bypass the comparison for earlier locks in the chain?
Quoted 3 lines
By restricting the
lockdep_cmp_fn()check to only the most recently acquired lock (i ==dt->ecxt_held_pos- 1), it seems we might miss valid comparisons for older contexts.
No.
It's how lockdep works and it's intended by lockdep. The temporary code just follows the rule.
Quoted 7 lines
For example, if a task acquires lock A1, then lock B, and then lock A2 (where A1 and A2 are the same class), the check against A1 will be skipped because A1 is no longer at
dt->ecxt_held_pos- 1.This would result in a call to
add_dep(A1, A2), creating a self-referential class dependency that triggers a false positive deadlock report.
No.
It's a real deadlock.
Quoted 2 lines
Should
lockdep_cmp_fn()be allowed to evaluate against any previously held lock in the chain, rather than just the immediate predecessor?
No.
Check the lockdep code first. See check_deadlock() and check_prev_add().
Byungchul
Quoted 8 lines
kernel/dependency/dept.c static void add_wait(struct dept_class *c, unsigned long ip, · line 1700
Quoted 5 lines
kernel/dependency/dept.c +2
-0+ +add_dep (eh->ecxt, w); } wg =next_wgen ();--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
PATCH v19 30/40 dept: make dept stop from working on debug_locks_off()
In reply to Byungchul ParkFor many reasons, debug_locks_off() is called to stop lock debuging feature e.g. on panic(). dept should also stop it in the conditions.
--- include/linux/dept.h | 2 ++ kernel/dependency/dept.c | 6 ++++++ lib/debug_locks.c | 2 ++ 3 files changed, 10 insertions(+)
include/linux/dept.h +2 -0
@@ -142,6 +142,7 @@ struct dept_ext_wgen {unsigned int wgen; }; +void dept_stop_emerg (void );void dept_on (void );void dept_off (void );void dept_init (void );
@@ -194,6 +195,7 @@ struct dept_ext_wgen { };#define DEPT_MAP_INITIALIZER (n, k) { } +#define dept_stop_emerg () do { } while (0)#define dept_on () do { } while (0)#define dept_off () do { } while (0)#define dept_init () do { } while (0)
kernel/dependency/dept.c +6 -0
@@ -187,6 +187,12 @@ static void dept_unlock(void)arch_spin_unlock (&dept_spin); } +void dept_stop_emerg (void ) +{ +WRITE_ONCE (dept_stop,1 ); +} +EXPORT_SYMBOL_GPL (dept_stop_emerg); +enum bfs_ret {BFS_CONTINUE ,BFS_DONE ,
lib/debug_locks.c +2 -0
@@ -38,6 +38,8 @@ EXPORT_SYMBOL_GPL(debug_locks_silent);*/ int debug_locks_off (void ) { +dept_stop_emerg (); +if (debug_locks &&__debug_locks_off ()) {if (!debug_locks_silent) {console_verbose ();
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 30/40] dept: make dept stop from working on debug_locks_off()
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] DEPT fails to stop when lock debugging is globally disabled via kernel tainting. - [Low]…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] DEPT fails to stop when lock debugging is globally disabled via kernel tainting.
- [Low] dept_stop_emerg() is unnecessarily exported via EXPORT_SYMBOL_GPL despite having no module callers.
- [Low] Implicit reliance on transitive header inclusion for dept_stop_emerg().
--
commit 3772379470ad3a639343d641bfb17cbd105fc9a5
Author: Byungchul Park <[email protected]>
dept: make dept stop from working on debug_locks_off()
The commit adds a dept_stop_emerg() call inside debug_locks_off() to stop the DEPT feature when panic or other lock debugging suspensions occur.
Quoted 4 lines
kernel/dependency/dept.c +0
-0
[ ... ]
kernel/dependency/dept.c static void dept_unlock(void) · line 194
Quoted 9 lines
kernel/dependency/dept.c +5
-0@@ -187,6 +187,12 @@ static void dept_unlock(void)arch_spin_unlock (&dept_spin); } +void dept_stop_emerg (void ) +{ +WRITE_ONCE (dept_stop,1 ); +} +EXPORT_SYMBOL_GPL (dept_stop_emerg);
[Severity: Low]
Does this function need to be exported to loadable modules?
CONFIG_DEPT is a boolean configuration, so kernel/dependency/dept.c is always built-in. Its only caller in lib/debug_locks.c is also always built-in, making this export unnecessary.
Quoted 8 lines
kernel/dependency/dept.c +1
-0+enum bfs_ret {BFS_CONTINUE ,BFS_DONE ,lib/debug_locks.c +0
-0
[ ... ]
lib/debug_locks.c EXPORT_SYMBOL_GPL(debug_locks_silent); · line 41
Quoted 5 lines
lib/debug_locks.c +1
-0@@ -38,6 +38,8 @@ EXPORT_SYMBOL_GPL(debug_locks_silent);*/ int debug_locks_off (void ) { +dept_stop_emerg ();
[Severity: Low]
Is it possible to explicitly include <linux/dept.h> in lib/debug_locks.c?
Relying on implicit transitive header inclusion for dept_stop_emerg() could break the build if inner header structures like spinlock.h or lockdep.h change in the future.
lib/debug_locks.c EXPORT_SYMBOL_GPL(debug_locks_silent); · line 43
Quoted 2 lines
lib/debug_locks.c +1
-0+if (debug_locks &&__debug_locks_off ()) {
[Severity: Medium]
Will this miss DEPT shutdown when the system is tainted?
For example, when a system fault occurs, add_taint() disables lockdep via __debug_locks_off():
kernel/panic.c:add_taint() {
...
if (lockdep_ok == LOCKDEP_NOW_UNRELIABLE && __debug_locks_off())
pr_warn("Disabling lock debugging due to kernel taint\n");
...
}Because this bypasses debug_locks_off(), DEPT remains enabled when the system lock state is already unreliable, potentially leading to false positive dependency splats or further crashes.
Quoted 7 lines
lib/debug_locks.c +0
-0if (!debug_locks_silent) {console_verbose ();lib/debug_locks.c +0
-0return 1 ; } }return 0 ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=30
PATCH v19 31/40 dept: assign unique dept_key to each distinct wait_for_completion() caller
In reply to Byungchul Parkwait_for_completion() can be used at various points in the code and it's very hard to distinguish wait_for_completion()s between different usages. Using a single dept_key for all the wait_for_completion()s could trigger false positive reports.
Assign unique dept_key to each distinct wait_for_completion() caller to avoid false positive reports.
While at it, add a rust helper for wait_for_completion() to avoid build errors.
--- include/linux/completion.h | 100 +++++++++++++++++++++++++++++++------ kernel/sched/completion.c | 60 +++++++++++----------- rust/helpers/completion.c | 5 ++ 3 files changed, 120 insertions(+), 45 deletions(-)
include/linux/completion.h +85 -15
@@ -27,12 +27,10 @@struct completion {unsigned int done;struct swait_queue_head wait; -struct dept_map dmap; };#define init_completion (x) \ do { \ - sdt_map_init(&(x)->dmap); \ __init_completion(x); \ } while (0)
@@ -43,17 +41,14 @@ do { \static inline void complete_acquire (struct completion *x,long timeout) { -sdt_might_sleep_start_timeout (&x->dmap, timeout); }static inline void complete_release (struct completion *x) { -sdt_might_sleep_end (); }#define COMPLETION_INITIALIZER (work) \ - { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait), \ - .dmap = DEPT_MAP_INITIALIZER(work, NULL), } + { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait), }#define COMPLETION_INITIALIZER_ONSTACK_MAP (work, map) \ (*({ init_completion_map(&(work), &(map)); &(work); }))
@@ -119,18 +114,18 @@ static inline void reinit_completion(struct completion *x) x->done =0 ; } -extern void wait_for_completion (struct completion *); -extern void wait_for_completion_io (struct completion *); -extern int wait_for_completion_interruptible (struct completion *x); -extern int wait_for_completion_killable (struct completion *x); -extern int wait_for_completion_state (struct completion *x,unsigned int state); -extern unsigned long wait_for_completion_timeout (struct completion *x, +extern void __wait_for_completion (struct completion *); +extern void __wait_for_completion_io (struct completion *); +extern int __wait_for_completion_interruptible (struct completion *x); +extern int __wait_for_completion_killable (struct completion *x); +extern int __wait_for_completion_state (struct completion *x,unsigned int state); +extern unsigned long __wait_for_completion_timeout (struct completion *x,unsigned long timeout); -extern unsigned long wait_for_completion_io_timeout (struct completion *x, +extern unsigned long __wait_for_completion_io_timeout (struct completion *x,unsigned long timeout); -extern long wait_for_completion_interruptible_timeout ( +extern long __wait_for_completion_interruptible_timeout (struct completion *x,unsigned long timeout); -extern long wait_for_completion_killable_timeout ( +extern long __wait_for_completion_killable_timeout (struct completion *x,unsigned long timeout);extern bool try_wait_for_completion (struct completion *x);extern bool completion_done (struct completion *x);
@@ -139,4 +134,79 @@ extern void complete(struct completion *);extern void complete_on_current_cpu (struct completion *x);extern void complete_all (struct completion *); +#define wait_for_completion (x) \ +({ \ + sdt_might_sleep_start_timeout(NULL, -1L); \ + __wait_for_completion(x); \ + sdt_might_sleep_end(); \ +}) +#define wait_for_completion_io (x) \ +({ \ + sdt_might_sleep_start_timeout(NULL, -1L); \ + __wait_for_completion_io(x); \ + sdt_might_sleep_end(); \ +}) +#define wait_for_completion_interruptible (x) \ +({ \ + int __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, -1L); \ + __ret = __wait_for_completion_interruptible(x); \ + sdt_might_sleep_end(); \ + __ret; \ +}) +#define wait_for_completion_killable (x) \ +({ \ + int __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, -1L); \ + __ret = __wait_for_completion_killable(x); \ + sdt_might_sleep_end(); \ + __ret; \ +}) +#define wait_for_completion_state (x, s) \ +({ \ + int __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, -1L); \ + __ret = __wait_for_completion_state(x, s); \ + sdt_might_sleep_end(); \ + __ret; \ +}) +#define wait_for_completion_timeout (x, t) \ +({ \ + unsigned long __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, t); \ + __ret = __wait_for_completion_timeout(x, t); \ + sdt_might_sleep_end(); \ + __ret; \ +}) +#define wait_for_completion_io_timeout (x, t) \ +({ \ + unsigned long __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, t); \ + __ret = __wait_for_completion_io_timeout(x, t); \ + sdt_might_sleep_end(); \ + __ret; \ +}) +#define wait_for_completion_interruptible_timeout (x, t) \ +({ \ + long __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, t); \ + __ret = __wait_for_completion_interruptible_timeout(x, t); \ + sdt_might_sleep_end(); \ + __ret; \ +}) +#define wait_for_completion_killable_timeout (x, t) \ +({ \ + long __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, t); \ + __ret = __wait_for_completion_killable_timeout(x, t); \ + sdt_might_sleep_end(); \ + __ret; \ +})#endif
kernel/sched/completion.c +30 -30
186 lines not on this page · raw message
rust/helpers/completion.c +5 -0
@@ -6,3 +6,8 @@ __rust_helper void rust_helper_init_completion(struct completion *x) {init_completion (x); } + +void rust_helper_wait_for_completion (struct completion *x) +{ +wait_for_completion (x); +}
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 31/40] dept: assign unique dept_key to each distinct wait_for_completion() caller
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] The `wait_for_completion_*_timeout` macros evaluate their timeout argument `t` multiple times…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] The wait_for_completion_*_timeout macros evaluate their timeout argument t multiple times, creating a side-effect vulnerability.
- [High] The wait_for_completion_* wrapper macros declare local variables (__ret and __m) that shadow variables in the caller's scope, leading to uninitialized memory usage.
- [High] The wait_for_completion macros now implicitly depend on GPL-only exported symbols, breaking non-GPL module compilation when CONFIG_DEPT is enabled.
- [Medium] The C helper function rust_helper_wait_for_completion defeats the primary goal of the patch for the Rust subsystem by mapping all Rust callers to a single dept_key. --
commit 18fd6796eb79fb0d0201e71c6791aa80955604b2
Author: Byungchul Park <[email protected]>
dept: assign unique dept_key to each distinct wait_for_completion() caller
This patch assigns a unique dept_key to each distinct wait_for_completion() caller to avoid false positive reports from DEPT. It also adds a C helper for the Rust subsystem to avoid build errors.
Quoted 3 lines
include/linux/completion.h +0
-0
[ ... ]
include/linux/completion.h extern void complete(struct completion *); · line 142
Quoted 6 lines
include/linux/completion.h +6
-0+#define wait_for_completion (x) \ +({ \ + sdt_might_sleep_start_timeout(NULL, -1L); \ + __wait_for_completion(x); \ + sdt_might_sleep_end(); \ +})
[Severity: High]
Will these macros implicitly depend on GPL-only exported symbols, breaking non-GPL module compilation when CONFIG_DEPT is enabled?
The original wait_for_completion() functions are exported via EXPORT_SYMBOL, making them available to non-GPL modules.
The new macros wrap these primitives with calls to dept_stage_wait() and dept_clean_stage() via sdt_might_sleep_start_timeout().
Since those tracker functions are exported via EXPORT_SYMBOL_GPL, could this cause linkage failures for non-GPL modules using the macro?
[ ... ]
include/linux/completion.h extern void complete(struct completion *); · line 184
Quoted 9 lines
include/linux/completion.h +9
-0+#define wait_for_completion_timeout (x, t) \ +({ \ + unsigned long __ret; \ + \ + sdt_might_sleep_start_timeout(NULL, t); \ + __ret = __wait_for_completion_timeout(x, t); \ + sdt_might_sleep_end(); \ + __ret; \ +})
[Severity: High]
Does this macro evaluate the timeout argument t twice?
If a caller passes an expression with side effects (like a stateful function call or a pre/post-increment) as the timeout argument, the expression will be executed multiple times.
Would this lead to incorrect timeouts or potential kernel crashes if the expression modifies sensitive state?
[Severity: High]
Could the internal __ret variable shadow a variable in the caller's scope?
If a caller passes an expression for the timeout t or the completion x that relies on a variable named __ret in their own scope, the macro's inner uninitialized __ret might shadow the caller's variable.
Would this result in the underlying wait functions receiving uninitialized stack memory instead of the intended parameter?
[ ... ]
Quoted 3 lines
rust/helpers/completion.c +0
-0
[ ... ]
rust/helpers/completion.c __rust_helper void rust_helper_init_completion(struct completion *x) · line 13
Quoted 4 lines
rust/helpers/completion.c +4
-0+void rust_helper_wait_for_completion (struct completion *x) +{ +wait_for_completion (x); +}
[Severity: Medium]
Does this C helper function defeat the primary goal of the patch for the Rust subsystem?
The patch explicitly changes wait_for_completion() to a macro so that a unique static dept_key is instantiated at each distinct call site, avoiding false positive dependency reports.
However, by wrapping the macro into a single out-of-line C function, wouldn't all Rust callers of completions share the exact same dept_key, reintroducing the false positive reports?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=31
Gary Guo
reviewerRe: [PATCH v19 31/40] dept: assign unique dept_key to each distinct wait_for_completion() caller
In reply to Byungchul ParkQuoted 10 lines · Byungchul Park
wait_for_completion()can be used at various points in the code and it's very hard to distinguish wait_for_completion()s between different usages. Using a singledept_keyfor all the wait_for_completion()s could trigger false positive reports.Assign unique
dept_keyto each distinctwait_for_completion()caller to avoid false positive reports.While at it, add a rust helper for
wait_for_completion()to avoid build errors.
This will cause Rust code to share the same dept_key, so it will have all the false positives that the change is trying to avoid.
In general it is easy to create Rust bindings for static inline C functions because it'll be just some computation, while creating bindings for C function-like macros that define additional statics can be challenging.
Is dept_key similar to lock_class_key, where only the address matters? If so, the approach that I use in
https://lore.kernel.org/rust-for-linux/[email protected]
could be used for dept_key as well, then we can keep Rust wait_for_completion still a function; otherwise we have to turn it into a macro too on the Rust side to create such statics, which isn't ideal.
Best,
Gary
Quoted 7 lines
Signed-off-by Byungchul Park <[email protected]>--- include/linux/completion.h | 100 +++++++++++++++++++++++++++++++------ kernel/sched/completion.c | 60 +++++++++++----------- rust/helpers/completion.c | 5 ++ 3 files changed, 120 insertions(+), 45 deletions(-)
Re: [PATCH v19 31/40] dept: assign unique dept_key to each distinct wait_for_completion() caller
Quoted 6 lines · Gary Guo
Quoted 5 lines · Byungchul Park
wait_for_completion()can be used at various points in the code and it's very hard to distinguish wait_for_completion()s between different usages. Using a singledept_keyfor all the wait_for_completion()s could trigger false positive reports.
Quoted 8 lines
Quoted 5 lines
Assign unique
dept_keyto each distinctwait_for_completion()caller to avoid false positive reports.While at it, add a rust helper for
wait_for_completion()to avoid build errors.This will cause Rust code to share the same
dept_key, so it will have all the false positives that the change is trying to avoid.
Thank you for the input.
Quoted 7 lines
In general it is easy to create Rust bindings for static inline C functions because it'll be just some computation, while creating bindings for C function-like macros that define additional statics can be challenging.
Is
dept_keysimilar tolock_class_key, where only the address matters? If so, the approach that I use in
https://lore.kernel.org/rust-for-linux/[email protected]
Yes, dept_key is similar to lock_class_key. IIUC, the way you tried for lock_class_key can be applied to DEPT too. I will do:
1) add 'key' parameter to sdt_might_sleep_start_timeout()
2) introduce init_completion_dkey() to allow custom keys
3) remove init_completion_dmap() and adjust the existing users
Just in case, it's worth noting that the custom keys must be well-managed using e.g. dept_key_destroy() when the key gets freed.
Byungchul
Quoted 14 lines
could be used for
dept_keyas well, then we can keep Rustwait_for_completionstill a function; otherwise we have to turn it into a macro too on the Rust side to create such statics, which isn't ideal.Best,
GaryQuoted 7 lines
Signed-off-by Byungchul Park <[email protected]>--- include/linux/completion.h | 100 +++++++++++++++++++++++++++++++------ kernel/sched/completion.c | 60 +++++++++++----------- rust/helpers/completion.c | 5 ++ 3 files changed, 120 insertions(+), 45 deletions(-)
PATCH v19 32/40 completion, dept: introduce init_completion_dmap() API
In reply to Byungchul ParkCurrently, dept uses dept's map embedded in task_struct to track dependencies related to wait_for_completion() and its family. So it doesn't need an explicit map basically.
However, for those who want to set the maps with customized class or key, introduce a new API to use external maps.
--- include/linux/completion.h | 40 +++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-)
include/linux/completion.h +22 -18
@@ -27,17 +27,15 @@struct completion {unsigned int done;struct swait_queue_head wait; +struct dept_map *dmap; }; -#define init_completion (x) \ -do { \ - __init_completion(x); \ -} while (0) +#define init_completion (x) init_completion_dmap(x, NULL)/* -* XXX: No use cases for now. Fill the body when needed. +* XXX: This usage using lockdep's map should be deprecated. */ -#define init_completion_map (x, m) init_completion(x) +#define init_completion_map (x, m) init_completion_dmap(x, NULL)static inline void complete_acquire (struct completion *x,long timeout) {
@@ -48,8 +46,11 @@ static inline void complete_release(struct completion *x) }#define COMPLETION_INITIALIZER (work) \ - { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait), } + { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait), .dmap = NULL, } +/* +* XXX: This usage using lockdep's map should be deprecated. +*/ #define COMPLETION_INITIALIZER_ONSTACK_MAP (work, map) \ (*({ init_completion_map(&(work), &(map)); &(work); }))
@@ -90,15 +91,18 @@ static inline void complete_release(struct completion *x)#endif /** -* __init_completion - Initialize a dynamically allocated completion +* init_completion_dmap - Initialize a dynamically allocated completion * @x: pointer to completion structure that is to be initialized +* @dmap: pointer to external dept's map to be used as a separated map * * This inline function will initialize a dynamically created completion * structure. */ -static inline void __init_completion (struct completion *x) +static inline void init_completion_dmap (struct completion *x, +struct dept_map *dmap) { x->done =0 ; + x->dmap = dmap;init_swait_queue_head (&x->wait); }
@@ -136,13 +140,13 @@ extern void complete_all(struct completion *);#define wait_for_completion (x) \ ({ \ - sdt_might_sleep_start_timeout(NULL, -1L); \ + sdt_might_sleep_start_timeout((x)->dmap, -1L); \ __wait_for_completion(x); \ sdt_might_sleep_end(); \ })#define wait_for_completion_io (x) \ ({ \ - sdt_might_sleep_start_timeout(NULL, -1L); \ + sdt_might_sleep_start_timeout((x)->dmap, -1L); \ __wait_for_completion_io(x); \ sdt_might_sleep_end(); \ })
@@ -150,7 +154,7 @@ extern void complete_all(struct completion *); ({ \ int __ret; \ \ - sdt_might_sleep_start_timeout(NULL, -1L); \ + sdt_might_sleep_start_timeout((x)->dmap, -1L); \ __ret = __wait_for_completion_interruptible(x); \ sdt_might_sleep_end(); \ __ret; \
@@ -159,7 +163,7 @@ extern void complete_all(struct completion *); ({ \ int __ret; \ \ - sdt_might_sleep_start_timeout(NULL, -1L); \ + sdt_might_sleep_start_timeout((x)->dmap, -1L); \ __ret = __wait_for_completion_killable(x); \ sdt_might_sleep_end(); \ __ret; \
@@ -168,7 +172,7 @@ extern void complete_all(struct completion *); ({ \ int __ret; \ \ - sdt_might_sleep_start_timeout(NULL, -1L); \ + sdt_might_sleep_start_timeout((x)->dmap, -1L); \ __ret = __wait_for_completion_state(x, s); \ sdt_might_sleep_end(); \ __ret; \
@@ -177,7 +181,7 @@ extern void complete_all(struct completion *); ({ \ unsigned long __ret; \ \ - sdt_might_sleep_start_timeout(NULL, t); \ + sdt_might_sleep_start_timeout((x)->dmap, t); \ __ret = __wait_for_completion_timeout(x, t); \ sdt_might_sleep_end(); \ __ret; \
@@ -186,7 +190,7 @@ extern void complete_all(struct completion *); ({ \ unsigned long __ret; \ \ - sdt_might_sleep_start_timeout(NULL, t); \ + sdt_might_sleep_start_timeout((x)->dmap, t); \ __ret = __wait_for_completion_io_timeout(x, t); \ sdt_might_sleep_end(); \ __ret; \
@@ -195,7 +199,7 @@ extern void complete_all(struct completion *); ({ \ long __ret; \ \ - sdt_might_sleep_start_timeout(NULL, t); \ + sdt_might_sleep_start_timeout((x)->dmap, t); \ __ret = __wait_for_completion_interruptible_timeout(x, t); \ sdt_might_sleep_end(); \ __ret; \
@@ -204,7 +208,7 @@ extern void complete_all(struct completion *); ({ \ long __ret; \ \ - sdt_might_sleep_start_timeout(NULL, t); \ + sdt_might_sleep_start_timeout((x)->dmap, t); \ __ret = __wait_for_completion_killable_timeout(x, t); \ sdt_might_sleep_end(); \ __ret; \
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 32/40] completion, dept: introduce init_completion_dmap() API
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Double evaluation of arguments in wait_for_completion macros leads to skipped array indices and…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Double evaluation of arguments in wait_for_completion macros leads to skipped array indices and memory corruption.
- [Medium] Unconditional struct growth of a widely used primitive for a debug feature.
- [Medium] Wait event macros skip calling sdt_might_sleep_end() on signal interruptions, leaking DEPT tracking state and stacks. --
commit 5b626a37ee940081b6d37187cde51c2f272e370c
Author: Byungchul Park <[email protected]>
completion, dept: introduce init_completion_dmap() API
Currently, dept uses dept's map embedded in task_struct to track dependencies related to wait_for_completion() and its family. So it doesn't need an explicit map basically.
However, for those who want to set the maps with customized class or key, introduce a new API to use external maps.
include/linux/completion.h line 31
Quoted 10 lines
include/linux/completion.h +1
-0@@ -27,17 +27,15 @@struct completion {unsigned int done;struct swait_queue_head wait; +struct dept_map *dmap; };
[Severity: Medium]
Since struct completion is heavily embedded in many kernel data structures, does unconditionally adding the dmap pointer increase the global memory footprint even on production non-debug kernels? Should this new field be guarded by an #ifdef?
[ ... ]
include/linux/completion.h extern void complete_all(struct completion *); · line 146
Quoted 9 lines
include/linux/completion.h +1
-1@@ -136,13 +140,13 @@ extern void complete_all(struct completion *);#define wait_for_completion (x) \ ({ \ - sdt_might_sleep_start_timeout(NULL, -1L); \ + sdt_might_sleep_start_timeout((x)->dmap, -1L); \ __wait_for_completion(x); \ sdt_might_sleep_end(); \ })
[Severity: High]
Does evaluating the argument x multiple times in this macro lead to issues if callers pass an expression with side effects?
For example, if a caller like mlx5_vdpa_exec_async_cmds() does:
while (completed < issued) wait_for_completion(&cmds[completed++].cmd_done);
Would completed++ be executed twice per iteration, skipping array elements and potentially causing out-of-bounds memory accesses?
[ ... ]
[Severity: Medium]
Do wait event macros such as ___wait_event() in include/linux/wait.h skip calling sdt_might_sleep_end() when interrupted by a signal?
In include/linux/wait.h:___wait_event():
if (___wait_is_interruptible(state) && __int) { \
__ret = __int; \
goto __out; \
}
...
sdt_might_sleep_end(); \__out: __ret; \
})
If the wait is interrupted by a signal, it escapes via goto __out. Because __out is placed after sdt_might_sleep_end(), it seems the cleanup is skipped.
Does this permanently leak the tracking state and its underlying stack objects?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=32
Re: [PATCH v19 32/40] completion, dept: introduce init_completion_dmap() API
Quoted 18 lines · On Tue, Jul 07, 2026 at 07:33:49AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Double evaluation of arguments inwait_for_completionmacros leads to skipped array indices and memory corruption.
- [Medium] Unconditional struct growth of a widely used primitive for a debug feature.
- [Medium] Wait event macros skip callingsdt_might_sleep_end()on signal interruptions, leaking DEPT tracking state and stacks. --commit
5b626a37ee940081b6d37187cde51c2f272e370c
Author: Byungchul Park <[email protected]>completion, dept: introduce
init_completion_dmap()APICurrently, dept uses dept's map embedded in
task_structto track dependencies related towait_for_completion()and its family. So it doesn't need an explicit map basically.However, for those who want to set the maps with customized class or key, introduce a new API to use external maps.
Quoted 16 lines
include/linux/completion.h line 31
Quoted 10 lines
include/linux/completion.h +1
-0@@ -27,17 +27,15 @@struct completion {unsigned int done;struct swait_queue_head wait; +struct dept_map *dmap; };[Severity: Medium]
Since struct completion is heavily embedded in many kernel data structures, does unconditionally adding the dmap pointer increase the global memory footprint even on production non-debug kernels? Should this new field be guarded by an #ifdef?
Good point. I will fix it, but with dkey. It will look like:
+ struct dept_key_ptr dkey_ptr;
Quoted 16 lines
[ ... ]
include/linux/completion.h extern void complete_all(struct completion *); · line 146
Quoted 9 lines
include/linux/completion.h +1
-1@@ -136,13 +140,13 @@ extern void complete_all(struct completion *);#define wait_for_completion (x) \ ({ \ - sdt_might_sleep_start_timeout(NULL, -1L); \ + sdt_might_sleep_start_timeout((x)->dmap, -1L); \ __wait_for_completion(x); \ sdt_might_sleep_end(); \ })[Severity: High]
Does evaluating the argument x multiple times in this macro lead to issues if callers pass an expression with side effects?
Quoted 7 lines
For example, if a caller like
mlx5_vdpa_exec_async_cmds()does:while (completed < issued)
wait_for_completion(&cmds[completed++].cmd_done);Would completed++ be executed twice per iteration, skipping array elements and potentially causing out-of-bounds memory accesses?
Sure. I will fix it.
Quoted 17 lines
[ ... ]
[Severity: Medium]
Do wait event macros such as___wait_event()ininclude/linux/wait.hskip callingsdt_might_sleep_end()when interrupted by a signal?In include/linux/wait.h:___wait_event():
if (___wait_is_interruptible(state) && __int) { \ __ret = __int; \ goto __out; \ } ... sdt_might_sleep_end(); \
__out:__ret; \
})
Quoted 6 lines
If the wait is interrupted by a signal, it escapes via goto
__out. Because__outis placed aftersdt_might_sleep_end(), it seems the cleanup is skipped.Does this permanently leak the tracking state and its underlying stack objects?
I will fix it.
Byungchul
Quoted 2 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=32
PATCH v19 33/40 dept: call dept_hardirqs_off() in local_irq_*() regardless of irq state
In reply to Byungchul ParkFor dept to function properly, dept_task()->hardirqs_enabled must be set correctly. If it fails to set this value to false, for example, dept may mistakenly think irq is still enabled even when it's not.
Do dept_hardirqs_off() regardless of irq state not to miss any unexpected cases by any chance e.g. changes of the state by asm code.
--- include/linux/irqflags.h | 14 ++++++++++++++ kernel/dependency/dept.c | 1 + 2 files changed, 15 insertions(+)
include/linux/irqflags.h +14 -0
@@ -214,6 +214,13 @@ extern void warn_bogus_irq_restore(void);raw_local_irq_disable (); \if (!was_disabled) \trace_hardirqs_off (); \ +/* \ +* Just in case that C code has missed \ +* trace_hardirqs_off() at the first \ +* place e.g. disabling irq at asm code.\ +*/ \ +else \ +dept_hardirqs_off (); \ }while (0 ) #define local_irq_save(flags) \
@@ -221,6 +228,13 @@ extern void warn_bogus_irq_restore(void);raw_local_irq_save (flags); \if (!raw_irqs_disabled_flags (flags)) \trace_hardirqs_off (); \ +/* \ +* Just in case that C code has missed \ +* trace_hardirqs_off() at the first \ +* place e.g. disabling irq at asm code.\ +*/ \ +else \ +dept_hardirqs_off (); \ }while (0 ) #define local_irq_restore(flags) \
kernel/dependency/dept.c +1 -0
@@ -2095,6 +2095,7 @@ void noinstr dept_hardirqs_off(void)*/ dept_task ()->hardirqs_enabled = false; } +EXPORT_SYMBOL_GPL (dept_hardirqs_off); void noinstr dept_update_cxt(void) {
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 33/40] dept: call dept_hardirqs_off() in local_irq_*() regardless of irq state
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Hides missing assembly trace annotations, causing DEPT and Lockdep states to diverge and allowing…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Hides missing assembly trace annotations, causing DEPT and Lockdep states to diverge and allowing NMIs to silently revert the workaround.
- [Medium] Exporting dept_hardirqs_off as GPL-only breaks the build/loading of non-GPL modules that use local_irq_save() or local_irq_disable(). --
commit 3f12c8d53e9de3037ef421690b95c2ca6667e3a1
Author: Byungchul Park <[email protected]>
dept: call dept_hardirqs_off() in local_irq_*() regardless of irq state
For dept to function properly, dept_task()->hardirqs_enabled must be set correctly. If it fails to set this value to false, for example, dept may mistakenly think irq is still enabled even when it's not.
Quoted 6 lines
include/linux/irqflags.h +0
-0@@ -214,6 +214,13 @@ extern void warn_bogus_irq_restore(void);raw_local_irq_disable (); \
include/linux/irqflags.h extern void warn_bogus_irq_restore(void); · line 224
Quoted 10 lines
include/linux/irqflags.h +7
-0if (!was_disabled) \trace_hardirqs_off (); \ +/* \ +* Just in case that C code has missed \ +* trace_hardirqs_off() at the first \ +* place e.g. disabling irq at asm code.\ +*/ \ +else \ +dept_hardirqs_off (); \ }while (0 )
[Severity: High]
Can NMIs silently revert this workaround?
If assembly code disables IRQs but misses the trace_hardirqs_off() annotation, and then C code calls local_irq_disable(), this skips trace_hardirqs_off() but executes the new dept_hardirqs_off() branch. Lockdep still thinks IRQs are enabled, while DEPT thinks they are disabled.
If an NMI occurs while in this state, irqentry_nmi_enter() saves the Lockdep state (which is incorrectly 'enabled'). Upon NMI exit, irqentry_nmi_exit() restores the saved Lockdep state by calling lockdep_hardirqs_on(), which unconditionally calls dept_hardirqs_on().
Will this force DEPT back into an incorrect 'enabled' state while hardware IRQs are actually disabled, potentially leading to false-positive circular dependency reports?
[ ... ]
kernel/dependency/dept.c void noinstr dept_hardirqs_off(void) · line 2098
Quoted 9 lines
kernel/dependency/dept.c +1
-0@@ -2095,6 +2095,7 @@ void noinstr dept_hardirqs_off(void)*/ dept_task ()->hardirqs_enabled = false; } +EXPORT_SYMBOL_GPL (dept_hardirqs_off);
[Severity: Medium]
Will this break the build or loading of non-GPL modules?
Because dept_hardirqs_off() is now called directly from universal inline macros like local_irq_disable() and local_irq_save(), any out-of-tree module marked with a non-GPL license that invokes these macros will fail to link or load when CONFIG_DEPT is enabled.
Standard trace_hardirqs_off() avoids this issue by being exported via EXPORT_SYMBOL.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=33
PATCH v19 34/40 rcu/update: fix same dept key collision between various types of RCU
In reply to Byungchul ParkFrom: Yunseong Kim <[email protected]>
The current implementation shares the same dept key for multiple synchronization points, which can lead to false positive reports in dependency tracking and potential confusion in debugging. For example, both normal RCU and tasks trace RCU synchronization points use the same dept key. Specifically:
1. synchronize_rcu() uses a dept key embedded in __wait_rcu_gp():
synchronize_rcu()
synchronize_rcu_normal()
_wait_rcu_gp()
__wait_rcu_gp() <- the key as static variable
2. synchronize_rcu_tasks_trace() uses the dept key, too:
synchronize_rcu_tasks_trace()
synchronize_rcu_tasks_generic()
_wait_rcu_gp()
__wait_rcu_gp() <- the key as static variable
Since the both rely on the same dept key, dept may report false positive circular dependency. To resolve this, separate dept keys and maps should be assigned to each struct rcu_synchronize.
===================================================
DEPT: Circular dependency has been detected.
6.15.0-rc6-00042-ged94bafc6405 #2 Not tainted
---------------------------------------------------
summary
---------------------------------------------------
*** DEADLOCK ***
context A
[S] lock(cpu_hotplug_lock:0)
[W] __wait_rcu_gp(<sched>:0)
[E] unlock(cpu_hotplug_lock:0)context B
[S] (unknown)(<sched>:0)
[W] lock(cpu_hotplug_lock:0)
[E] try_to_wake_up(<sched>:0) [S]: start of the event context
[W]: the wait blocked
[E]: the event not reachable
---------------------------------------------------
context A's detail
---------------------------------------------------
context A
[S] lock(cpu_hotplug_lock:0)
[W] __wait_rcu_gp(<sched>:0)
[E] unlock(cpu_hotplug_lock:0) [S] lock(cpu_hotplug_lock:0):
[<ffff8000802ce964>] cpus_read_lock+0x14/0x20
stacktrace:
percpu_down_read.constprop.0+0x88/0x2ec
cpus_read_lock+0x14/0x20
cgroup_procs_write_start+0x164/0x634
__cgroup_procs_write+0xdc/0x4d0
cgroup_procs_write+0x34/0x74
cgroup_file_write+0x25c/0x670
kernfs_fop_write_iter+0x2ec/0x498
vfs_write+0x574/0xc30
ksys_write+0x124/0x244
__arm64_sys_write+0x70/0xa4
invoke_syscall+0x88/0x2e0
el0_svc_common.constprop.0+0xe8/0x2e0
do_el0_svc+0x44/0x60
el0_svc+0x50/0x188
el0t_64_sync_handler+0x10c/0x140
el0t_64_sync+0x198/0x19c [W] __wait_rcu_gp(<sched>:0):
[<ffff8000804ce88c>] __wait_rcu_gp+0x324/0x498
stacktrace:
schedule+0xcc/0x348
schedule_timeout+0x1a4/0x268
__wait_for_common+0x1c4/0x3f0
__wait_for_completion_state+0x20/0x38
__wait_rcu_gp+0x35c/0x498
synchronize_rcu_normal+0x200/0x218
synchronize_rcu+0x234/0x2a0
rcu_sync_enter+0x11c/0x300
percpu_down_write+0xb4/0x3e0
cgroup_procs_write_start+0x174/0x634
__cgroup_procs_write+0xdc/0x4d0
cgroup_procs_write+0x34/0x74
cgroup_file_write+0x25c/0x670
kernfs_fop_write_iter+0x2ec/0x498
vfs_write+0x574/0xc30
ksys_write+0x124/0x244 [E] unlock(cpu_hotplug_lock:0):
(N/A)
---------------------------------------------------
context B's detail
---------------------------------------------------
context B
[S] (unknown)(<sched>:0)
[W] lock(cpu_hotplug_lock:0)
[E] try_to_wake_up(<sched>:0) [S] (unknown)(<sched>:0):
(N/A)
[W] lock(cpu_hotplug_lock:0):
[<ffff8000802ce964>] cpus_read_lock+0x14/0x20
stacktrace:
percpu_down_read.constprop.0+0x6c/0x2ec
cpus_read_lock+0x14/0x20
check_all_holdout_tasks_trace+0x90/0xa30
rcu_tasks_wait_gp+0x47c/0x938
rcu_tasks_one_gp+0x75c/0xef8
rcu_tasks_kthread+0x180/0x1dc
kthread+0x3ac/0x74c
ret_from_fork+0x10/0x20 [E] try_to_wake_up(<sched>:0):
[<ffff8000804233b8>] complete+0xb8/0x1e8
stacktrace:
try_to_wake_up+0x374/0x1164
complete+0xb8/0x1e8
wakeme_after_rcu+0x14/0x20
rcu_tasks_invoke_cbs+0x218/0xaa8
rcu_tasks_one_gp+0x834/0xef8
rcu_tasks_kthread+0x180/0x1dc
kthread+0x3ac/0x74c
ret_from_fork+0x10/0x20
(wait to wake up)
stacktrace:
__schedule+0xf64/0x3614
schedule+0xcc/0x348
schedule_timeout+0x1a4/0x268
__wait_for_common+0x1c4/0x3f0
__wait_for_completion_state+0x20/0x38
__wait_rcu_gp+0x35c/0x498
synchronize_rcu_tasks_generic+0x14c/0x220
synchronize_rcu_tasks_trace+0x24/0x8c
rcu_init_tasks_generic+0x168/0x194
do_one_initcall+0x174/0xa00
kernel_init_freeable+0x744/0x7dc
kernel_init+0x78/0x220
ret_from_fork+0x10/0x20Separating the dept key and map for each of struct rcu_synchronize, ensuring proper tracking for each execution context.
--- include/linux/rcupdate_wait.h | 13 ++++++++----- kernel/rcu/rcu.h | 1 + kernel/rcu/update.c | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-)
include/linux/rcupdate_wait.h +8 -5
@@ -19,17 +19,20 @@ struct rcu_synchronize {/* This is for debugging. */ struct rcu_gp_oldstate oldstate; +struct dept_map dmap; +struct dept_key dkey; };void wakeme_after_rcu (struct rcu_head *head);void __wait_rcu_gp (bool checktiny,unsigned int state,int n,call_rcu_func_t *crcu_array, -struct rcu_synchronize *rs_array); +struct rcu_synchronize *rs_array,struct dept_key *dkey);#define _wait_rcu_gp (checktiny, state, ...) \ -do { \ - call_rcu_func_t __crcu_array[] = { __VA_ARGS__ }; \ - struct rcu_synchronize __rs_array[ARRAY_SIZE(__crcu_array)]; \ - __wait_rcu_gp(checktiny, state, ARRAY_SIZE(__crcu_array), __crcu_array, __rs_array); \ +do { \ + call_rcu_func_t __crcu_array[] = { __VA_ARGS__ }; \ + static struct dept_key __key; \ + struct rcu_synchronize __rs_array[ARRAY_SIZE(__crcu_array)]; \ + __wait_rcu_gp(checktiny, state, ARRAY_SIZE(__crcu_array), __crcu_array, __rs_array, &__key); \ } while (0)#define wait_rcu_gp (...) _wait_rcu_gp(false, TASK_UNINTERRUPTIBLE, __VA_ARGS__)
kernel/rcu/rcu.h +1 -0
@@ -12,6 +12,7 @@#include <linux/slab.h> #include <trace/events/rcu.h> +#include <linux/dept_sdt.h> /* * Grace-period counter management.
kernel/rcu/update.c +3 -2
@@ -409,7 +409,7 @@ void wakeme_after_rcu(struct rcu_head *head)EXPORT_SYMBOL_GPL (wakeme_after_rcu);void __wait_rcu_gp (bool checktiny,unsigned int state,int n,call_rcu_func_t *crcu_array, -struct rcu_synchronize *rs_array) +struct rcu_synchronize *rs_array,struct dept_key *dkey) {int i;int j;
@@ -426,7 +426,8 @@ void __wait_rcu_gp(bool checktiny, unsigned int state, int n, call_rcu_func_t *cbreak ;if (j == i) {init_rcu_head_on_stack (&rs_array[i].head); -init_completion (&rs_array[i].completion); +sdt_map_init_key (&rs_array[i].dmap, dkey); +init_completion_dmap (&rs_array[i].completion, &rs_array[i].dmap); (crcu_array[i])(&rs_array[i].head, wakeme_after_rcu); } }
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 34/40] rcu/update: fix same dept key collision between various types of RCU
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Unused struct member `dkey` inflates stack footprint --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Unused struct member dkey inflates stack footprint
--
commit de6aa9797881496b4a8d7d66626b1bfd19cfdd54
Author: Yunseong Kim <[email protected]>
rcu/update: fix same dept key collision between various types of RCU
This commit addresses a false positive circular dependency report in dept by assigning separate dept keys and maps to each struct rcu_synchronize execution context.
include/linux/rcupdate_wait.h struct rcu_synchronize { · line 23
Quoted 9 lines
include/linux/rcupdate_wait.h +2
-0@@ -19,17 +19,20 @@ struct rcu_synchronize {/* This is for debugging. */ struct rcu_gp_oldstate oldstate; +struct dept_map dmap; +struct dept_key dkey;
[Severity: Low]
Does this code ever use the dkey member of struct rcu_synchronize?
The _wait_rcu_gp() macro defines its own static struct dept_key __key, which it passes as an argument to __wait_rcu_gp(). This leaves the dkey member of struct rcu_synchronize completely unused and uninitialized, while needlessly increasing the stack footprint of the rs_array allocated in the macro.
Quoted 18 lines
include/linux/rcupdate_wait.h +6
-5};void wakeme_after_rcu (struct rcu_head *head);void __wait_rcu_gp (bool checktiny,unsigned int state,int n,call_rcu_func_t *crcu_array, -struct rcu_synchronize *rs_array); +struct rcu_synchronize *rs_array,struct dept_key *dkey);#define _wait_rcu_gp (checktiny, state, ...) \ -do { \ - call_rcu_func_t __crcu_array[] = { __VA_ARGS__ }; \ - struct rcu_synchronize __rs_array[ARRAY_SIZE(__crcu_array)]; \ - __wait_rcu_gp(checktiny, state, ARRAY_SIZE(__crcu_array), __crcu_array, __rs_array); \ +do { \ + call_rcu_func_t __crcu_array[] = { __VA_ARGS__ }; \ + static struct dept_key __key; \ + struct rcu_synchronize __rs_array[ARRAY_SIZE(__crcu_array)]; \ + __wait_rcu_gp(checktiny, state, ARRAY_SIZE(__crcu_array), __crcu_array, __rs_array, &__key); \ } while (0)
[ ... ]
Quoted 3 lines
kernel/rcu/update.c +0
-0
[ ... ]
Quoted 10 lines
kernel/rcu/update.c +2
-1@@ -426,7 +426,8 @@ void __wait_rcu_gp(bool checktiny, unsigned int state, int n, call_rcu_func_t *cbreak ;if (j == i) {init_rcu_head_on_stack (&rs_array[i].head); -init_completion (&rs_array[i].completion); +sdt_map_init_key (&rs_array[i].dmap, dkey); +init_completion_dmap (&rs_array[i].completion, &rs_array[i].dmap); (crcu_array[i])(&rs_array[i].head, wakeme_after_rcu); } }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=34
Re: [PATCH v19 34/40] rcu/update: fix same dept key collision between various types of RCU
Quoted 26 lines · On Tue, Jul 07, 2026 at 07:33:52AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Unused struct memberdkeyinflates stack footprint
--commit
de6aa9797881496b4a8d7d66626b1bfd19cfdd54
Author: Yunseong Kim <[email protected]>rcu/update: fix same dept key collision between various types of RCU
This commit addresses a false positive circular dependency report in dept by assigning separate dept keys and maps to each struct
rcu_synchronizeexecution context.include/linux/rcupdate_wait.h struct rcu_synchronize { · line 23
Quoted 9 lines
include/linux/rcupdate_wait.h +2
-0@@ -19,17 +19,20 @@ struct rcu_synchronize {/* This is for debugging. */ struct rcu_gp_oldstate oldstate; +struct dept_map dmap; +struct dept_key dkey;[Severity: Low]
Does this code ever use the dkey member of structrcu_synchronize?
Quoted 5 lines
The
_wait_rcu_gp()macro defines its own static structdept_key__key, which it passes as an argument to__wait_rcu_gp(). This leaves the dkey member of structrcu_synchronizecompletely unused and uninitialized, while needlessly increasing the stack footprint of thers_arrayallocated in the macro.
I will fix it.
Byungchul
Quoted 40 lines
Quoted 18 lines
include/linux/rcupdate_wait.h +6
-5};void wakeme_after_rcu (struct rcu_head *head);void __wait_rcu_gp (bool checktiny,unsigned int state,int n,call_rcu_func_t *crcu_array, -struct rcu_synchronize *rs_array); +struct rcu_synchronize *rs_array,struct dept_key *dkey);#define _wait_rcu_gp (checktiny, state, ...) \ -do { \ - call_rcu_func_t __crcu_array[] = { __VA_ARGS__ }; \ - struct rcu_synchronize __rs_array[ARRAY_SIZE(__crcu_array)]; \ - __wait_rcu_gp(checktiny, state, ARRAY_SIZE(__crcu_array), __crcu_array, __rs_array); \ +do { \ + call_rcu_func_t __crcu_array[] = { __VA_ARGS__ }; \ + static struct dept_key __key; \ + struct rcu_synchronize __rs_array[ARRAY_SIZE(__crcu_array)]; \ + __wait_rcu_gp(checktiny, state, ARRAY_SIZE(__crcu_array), __crcu_array, __rs_array, &__key); \ } while (0)[ ... ]
Quoted 3 lines
kernel/rcu/update.c +0
-0[ ... ]
kernel/rcu/update.c void __wait_rcu_gp(bool checktiny, unsigned int state, int n, call_rcu_func_t *c · line 433
Quoted 10 lines
kernel/rcu/update.c +2
-1@@ -426,7 +426,8 @@ void __wait_rcu_gp(bool checktiny, unsigned int state, int n, call_rcu_func_t *cbreak ;if (j == i) {init_rcu_head_on_stack (&rs_array[i].head); -init_completion (&rs_array[i].completion); +sdt_map_init_key (&rs_array[i].dmap, dkey); +init_completion_dmap (&rs_array[i].completion, &rs_array[i].dmap); (crcu_array[i])(&rs_array[i].head, wakeme_after_rcu); } }--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=34
PATCH v19 35/40 dept: introduce APIs to set page usage and use subclasses_evt for the usage
In reply to Byungchul ParkFalse positive reports have been observed since dept assumes that all the pages have the same dept class, but the class should be split since the call paths are different depending on what the page is used for.
At least, ones for block device and ones for regular file have exclusively different usages.
Define usage candidates like:
DEPT_PAGE_REGFILE_CACHE /* page in regular file's address_space */
DEPT_PAGE_BDEV_CACHE /* page in block device's address_space */
DEPT_PAGE_DEFAULT /* the others */
Introduce APIs to set each page usage properly and make sure not to interact between DEPT_PAGE_REGFILE_CACHE and DEPT_PAGE_BDEV_CACHE. Besides that, it allows the other cases:
interaction between DEPT_PAGE_DEFAULT and DEPT_PAGE_REGFILE_CACHE, interaction between DEPT_PAGE_DEFAULT and DEPT_PAGE_BDEV_CACHE, interaction between DEPT_PAGE_DEFAULT and DEPT_PAGE_DEFAULT.
--- include/linux/dept.h | 34 ++++++++++++++- include/linux/mm_types.h | 1 + include/linux/page-flags.h | 89 +++++++++++++++++++++++++++++++++++++- 3 files changed, 120 insertions(+), 4 deletions(-)
include/linux/dept.h +32 -2
@@ -19,8 +19,8 @@ struct task_struct;#define DEPT_MAX_WAIT_HIST 64#define DEPT_MAX_ECXT_HELD 48 -#define DEPT_MAX_SUBCLASSES 16 -#define DEPT_MAX_SUBCLASSES_EVT 2 +#define DEPT_MAX_SUBCLASSES 24 +#define DEPT_MAX_SUBCLASSES_EVT 3#define DEPT_MAX_SUBCLASSES_USR (DEPT_MAX_SUBCLASSES / DEPT_MAX_SUBCLASSES_EVT)#define DEPT_MAX_SUBCLASSES_CACHE 2
@@ -142,6 +142,35 @@ struct dept_ext_wgen {unsigned int wgen; }; +enum { +DEPT_PAGE_DEFAULT =0 , +DEPT_PAGE_REGFILE_CACHE ,/* regular file page cache */ +DEPT_PAGE_BDEV_CACHE ,/* block device cache */ +DEPT_PAGE_USAGE_NR ,/* nr of usages options */ +}; + +#define DEPT_PAGE_USAGE_SHIFT 16 +#define DEPT_PAGE_USAGE_MASK ((1U << DEPT_PAGE_USAGE_SHIFT) - 1) +#define DEPT_PAGE_USAGE_PENDING_MASK (DEPT_PAGE_USAGE_MASK << DEPT_PAGE_USAGE_SHIFT) + +/* +* Identify each page's usage type +*/ +struct dept_page_usage { +/* +* low 16 bits : the current usage type +* high 16 bits : usage type requested to be set +* +* Do not apply usage type on request immediately but postpone +* it until the next use of PG flags. For example, if the page +* is already within a PG_locked critical section, regard it as +* DEPT_PAGE_DEFAULT temporarily at least until the section ends +* e.g. folio_unlock() since it's still unclear which usage type +* the page acts within the section. +*/ +atomic_t type;/* Update and read atomically */ +}; +void dept_stop_emerg (void );void dept_on (void );void dept_off (void );
@@ -192,6 +221,7 @@ void dept_hardirqs_off(void);struct dept_key { };struct dept_map { };struct dept_ext_wgen { }; +struct dept_page_usage { };#define DEPT_MAP_INITIALIZER (n, k) { }
include/linux/mm_types.h +1 -0
@@ -220,6 +220,7 @@ struct page {struct page *kmsan_shadow;struct page *kmsan_origin;#endif +struct dept_page_usage usage;struct dept_ext_wgen pg_locked_wgen; } _struct_page_alignment;
include/linux/page-flags.h +87 -2
119 lines not on this page · raw message
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 35/40] dept: introduce APIs to set page usage and use subclasses_evt for the usage
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [High] Page usage state (`usage.type`) is not cleared upon page free, leaking stale DEPT classes.…
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Page usage state (usage.type) is not cleared upon page free, leaking stale DEPT classes.
- [High] Premature usage type update in waiters breaks the DEPT_PAGE_DEFAULT fallback mechanism.
- [Medium] The newly introduced APIs for setting page usage are never called.
- [Low] Passing unsigned int* to atomic_try_cmpxchg violates pointer compatibility.
- [Low] Redundant bitwise operations in dept_set_page_usage.
- [Low] Missing dummy implementations for dept_set_folio_usage and dept_reset_folio_usage. --
commit ded2d968cb8933d3c60792b69d4f3c8618c64ffa
Author: Byungchul Park <[email protected]>
dept: introduce APIs to set page usage and use subclasses_evt for the usage
False positive reports have been observed since dept assumes that all the pages have the same dept class, but the class should be split since the call paths are different depending on what the page is used for. This commit introduces APIs to track these usages via struct page to avoid false positive DEPT reports.
include/linux/mm_types.h struct page { · line 223
Quoted 9 lines
include/linux/mm_types.h +1
-0@@ -220,6 +220,7 @@ struct page {struct page *kmsan_shadow;struct page *kmsan_origin;#endif +struct dept_page_usage usage;
[Severity: High]
Does this leak stale DEPT classes when pages are freed and reallocated?
The new usage field is added to struct page, but it doesn't appear to be cleared during page free. If a page with a specific usage type is freed and later reallocated for a different purpose, it might retain the old usage type, leading to graph pollution and false positives.
Should this state be scrubbed in mm/page_alloc.c:__free_pages_prepare()?
Quoted 8 lines
include/linux/mm_types.h +0
-0struct dept_ext_wgen pg_locked_wgen; } _struct_page_alignment;include/linux/page-flags.h +0
-0
[ ... ]
include/linux/page-flags.h enum pageflags { · line 209
Quoted 7 lines
include/linux/page-flags.h +3
-0@@ -204,6 +204,80 @@ enum pageflags {extern struct dept_map pg_locked_map; +static inline void dept_set_page_usage (struct page *p, +unsigned int new_type) +{
[Severity: Medium]
This isn't a bug, but are there missing callers for these newly introduced APIs?
The commit message mentions splitting usages for block and file caches, but dept_set_page_usage() and dept_set_folio_usage() do not seem to be invoked anywhere in this patch.
include/linux/page-flags.h enum pageflags { · line 220
Quoted 11 lines
include/linux/page-flags.h +11
-0+/* +* Consider the page as DEPT_PAGE_DEFAULT until the next use of +* PG flags e.g. folio_lock(). +*/ +unsigned int type =DEPT_PAGE_DEFAULT ; + +if (WARN_ON_ONCE (new_type >=DEPT_PAGE_USAGE_NR )) +return ; + + new_type <<=DEPT_PAGE_USAGE_SHIFT ; + new_type |= type &DEPT_PAGE_USAGE_MASK ;
[Severity: Low]
Does this bitwise OR operation have any effect?
Since type is unconditionally initialized to DEPT_PAGE_DEFAULT (which is 0) just above, masking and ORing it with new_type seems redundant.
Quoted 2 lines
include/linux/page-flags.h +2
-0+atomic_set (&p->usage.type, new_type); +}
[ ... ]
Quoted 7 lines
include/linux/page-flags.h +7
-0+static inline void dept_update_page_usage (struct page *p) +{ +unsigned int type =atomic_read (&p->usage.type); +unsigned int new_type; + +retry: + new_type = type &DEPT_PAGE_USAGE_PENDING_MASK ;
include/linux/page-flags.h enum pageflags { · line 256
Quoted 10 lines
include/linux/page-flags.h +10
-0+ new_type >>=DEPT_PAGE_USAGE_SHIFT ; + new_type |= type &DEPT_PAGE_USAGE_PENDING_MASK ; + +/* +* Already updated by others. +*/ +if (type == new_type) +return ; + +if (!atomic_try_cmpxchg (&p->usage.type, &type, new_type))
[Severity: Low]
Can this trigger a -Wpointer-sign build warning?
The type variable is declared as unsigned int, but atomic_try_cmpxchg() expects an int * for its second argument.
Quoted 2 lines
include/linux/page-flags.h +2
-0+ goto retry; +}
[ ... ]
Quoted 7 lines
static inline void
dept_page_set_bit(struct page *p, int bit_nr){include/linux/page-flags.h +2
-0+dept_update_page_usage (p); +if (bit_nr == PG_locked)dept_request_event (&pg_locked_map, &p->pg_locked_wgen); }
[ ... ]
include/linux/page-flags.h extern struct dept_map pg_locked_map; · line 309
Quoted 5 lines
static inline void
dept_page_wait_on_bit(struct page *p, int bit_nr){include/linux/page-flags.h +3
-0+unsigned long evt_f; + +dept_update_page_usage (p);
[Severity: High]
Does calling dept_update_page_usage() in these flag update/wait functions prematurely overwrite the page usage, breaking the DEPT_PAGE_DEFAULT fallback mechanism?
If waiters or setters trigger dept_update_page_usage() unconditionally, they could clobber the current state with the pending state before the lock is released. When the lock is subsequently released, it might emit the wrong event type, which could cause early DEFAULT waiters to hang indefinitely and trigger false positive reports.
Quoted 6 lines
include/linux/page-flags.h +3
-1+ evt_f =dept_event_flags (p, true); +if (bit_nr == PG_locked) -dept_wait (&pg_locked_map,1UL , _RET_IP_, __func__,0 ,-1L ); +dept_wait (&pg_locked_map, evt_f, _RET_IP_, __func__,0 ,-1L ); }
[ ... ]
include/linux/page-flags.h static inline void dept_folio_wait_on_bit(struct folio *f, int bit_nr) · line 332
Quoted 6 lines
include/linux/page-flags.h +2
-0@@ -245,6 +328,8 @@ static inline void dept_folio_wait_on_bit(struct folio *f, int bit_nr) dept_page_wait_on_bit(&f->page, bit_nr); }#else +#define dept_set_page_usage (p, t) do { } while (0) +#define dept_reset_page_usage (p) do { } while (0)
[Severity: Low]
Will this break the build for users of dept_set_folio_usage() and dept_reset_folio_usage() when CONFIG_DEPT is disabled?
The #else block provides dummy macros for page variants, but seems to be missing the folio equivalents.
Quoted 3 lines
include/linux/page-flags.h +0
-0#define dept_page_set_bit (p, bit_nr) do { } while (0)#define dept_page_clear_bit (p, bit_nr) do { } while (0)#define dept_page_wait_on_bit (p, bit_nr) do { } while (0)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=35
PATCH v19 36/40 dept: track PG_writeback with dept
In reply to Byungchul ParkMakes dept able to track PG_writeback waits and events, which will be useful in practice.
--- include/linux/mm_types.h | 1 + include/linux/page-flags.h | 7 +++++++ mm/filemap.c | 6 +++++- mm/mm_init.c | 1 + 4 files changed, 14 insertions(+), 1 deletion(-)
include/linux/mm_types.h +1 -0
@@ -222,6 +222,7 @@ struct page {#endif struct dept_page_usage usage;struct dept_ext_wgen pg_locked_wgen; +struct dept_ext_wgen pg_writeback_wgen; } _struct_page_alignment;/*
include/linux/page-flags.h +7 -0
@@ -203,6 +203,7 @@ enum pageflags {#include <linux/dept.h> extern struct dept_map pg_locked_map; +extern struct dept_map pg_writeback_map;static inline void dept_set_page_usage (struct page *p,unsigned int new_type)
@@ -292,6 +293,8 @@ static inline void dept_page_set_bit(struct page *p, int bit_nr)if (bit_nr == PG_locked)dept_request_event (&pg_locked_map, &p->pg_locked_wgen); +else if (bit_nr == PG_writeback) +dept_request_event (&pg_writeback_map, &p->pg_writeback_wgen); }static inline void dept_page_clear_bit (struct page *p,int bit_nr)
@@ -300,6 +303,8 @@ static inline void dept_page_clear_bit(struct page *p, int bit_nr)if (bit_nr == PG_locked)dept_event (&pg_locked_map, evt_f, _RET_IP_, __func__, &p->pg_locked_wgen); +else if (bit_nr == PG_writeback) +dept_event (&pg_writeback_map, evt_f, _RET_IP_, __func__, &p->pg_writeback_wgen); }static inline void dept_page_wait_on_bit (struct page *p,int bit_nr)
@@ -311,6 +316,8 @@ static inline void dept_page_wait_on_bit(struct page *p, int bit_nr)if (bit_nr == PG_locked)dept_wait (&pg_locked_map, evt_f, _RET_IP_, __func__,0 ,-1L ); +else if (bit_nr == PG_writeback) +dept_wait (&pg_writeback_map, evt_f, _RET_IP_, __func__,0 ,-1L ); }static inline void dept_folio_set_bit (struct folio *f,int bit_nr)
mm/filemap.c +5 -1
@@ -1197,7 +1197,7 @@ static void folio_wake_bit(struct folio *folio, int bit_nr)* dept_page_clear_bit() being called multiple times is harmless. * The worst case is to miss some dependencies but it's okay. */ -if (bit_nr == PG_locked) +if (bit_nr == PG_locked || bit_nr == PG_writeback)dept_page_clear_bit (&folio->page, bit_nr);spin_lock_irqsave (&q->lock, flags);
@@ -1254,6 +1254,9 @@ static inline bool folio_trylock_flag(struct folio *folio, int bit_nr,struct dept_map __maybe_unused pg_locked_map =DEPT_MAP_INITIALIZER (pg_locked_map,NULL );EXPORT_SYMBOL (pg_locked_map); +struct dept_map __maybe_unused pg_writeback_map =DEPT_MAP_INITIALIZER (pg_writeback_map,NULL ); +EXPORT_SYMBOL (pg_writeback_map); +static inline int folio_wait_bit_common (struct folio *folio,int bit_nr,int state,enum behavior behavior) {
@@ -1697,6 +1700,7 @@ void folio_end_writeback_no_dropbehind(struct folio *folio)folio_rotate_reclaimable (folio); } +dept_page_clear_bit (&folio->page, PG_writeback);if (__folio_end_writeback (folio))folio_wake_bit (folio, PG_writeback);
mm/mm_init.c +1 -0
@@ -589,6 +589,7 @@ void __meminit __init_single_page(struct page *page, unsigned long pfn,page_cpupid_reset_last (page);page_kasan_tag_reset (page);dept_ext_wgen_init (&page->pg_locked_wgen); +dept_ext_wgen_init (&page->pg_writeback_wgen);INIT_LIST_HEAD (&page->lru);#ifdef WANT_PAGE_VIRTUAL
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 36/40] dept: track PG_writeback with dept
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] False lock acquisition registered in DEPT for SHARED waits on PG_writeback, permanently corrupting…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] False lock acquisition registered in DEPT for SHARED waits on PG_writeback, permanently corrupting the task's dependency graph. --
commit 9dc48dc95eded487307805ef6bce49ac459667ad
Author: Byungchul Park <[email protected]>
dept: track PG_writeback with dept
This commit adds DEPT tracking for PG_writeback to track writeback waits and events. It extends the existing page bit tracking machinery to cover PG_writeback in addition to PG_locked.
Quoted 4 lines
include/linux/page-flags.h +0
-0
[ ... ]
include/linux/page-flags.h static inline void dept_page_set_bit(struct page *p, int bit_nr) · line 297
Quoted 6 lines
include/linux/page-flags.h +2
-0@@ -292,6 +293,8 @@ static inline void dept_page_set_bit(struct page *p, int bit_nr)if (bit_nr == PG_locked)dept_request_event (&pg_locked_map, &p->pg_locked_wgen); +else if (bit_nr == PG_writeback) +dept_request_event (&pg_writeback_map, &p->pg_writeback_wgen);
[Severity: High]
Does wiring PG_writeback into this tracking logic cause false lock acquisitions for shared waits?
In the wait queue logic, tasks can wait for writeback to complete without actually acquiring the bit (a SHARED wait). However, when a task waits on PG_writeback and the bit is already clear on the fast path, folio_trylock_flag() sets WQ_FLAG_DONE:
mm/filemap.c:folio_trylock_flag() {
...
} else if (test_bit(bit_nr, &folio->flags.f))
return false;
wait->flags |= WQ_FLAG_WOKEN | WQ_FLAG_DONE;
return true;
}Then in folio_wait_bit_common(), it unconditionally registers an acquisition if WQ_FLAG_DONE is set:
mm/filemap.c:folio_wait_bit_common() {
...
if (wait->flags & WQ_FLAG_DONE)
dept_page_set_bit(&folio->page, bit_nr);
...
}Because the task never actually acquired the bit, it will never clear it, leaving DEPT recording the lock as permanently held. Could this cause DEPT resource leaks and false positive deadlock reports?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=36
PATCH v19 37/40 SUNRPC: relocate struct rcu_head to the first field of struct rpc_xprt
In reply to Byungchul ParkWhile compiling Linux kernel with DEPT on, the following error was observed:
./include/linux/rcupdate.h:1084:17: note: in expansion of macro ‘BUILD_BUG_ON’
1084 | BUILD_BUG_ON(offsetof(typeof(*(ptr)), rhf) >= 4096); \
| ^~~~~~~~~~~~
./include/linux/rcupdate.h:1047:29: note: in expansion of macro
'kvfree_rcu_arg_2'
1047 | #define kfree_rcu(ptr, rhf) kvfree_rcu_arg_2(ptr, rhf)
| ^~~~~~~~~~~~~~~~
net/sunrpc/xprt.c:1856:9: note: in expansion of macro 'kfree_rcu'
1856 | kfree_rcu(xprt, rcu);
| ^~~~~~~~~
CC net/kcm/kcmproc.o make[4]: *** [scripts/Makefile.build:203: net/sunrpc/xprt.o] Error 1
Since kfree_rcu() assumes 'offset of struct rcu_head in a rcu-managed struct < 4096', the offest of struct rcu_head in struct rpc_xprt should not exceed 4096 but does, due to the debug information added by DEPT.
Relocate struct rcu_head to the first field of struct rpc_xprt from an arbitrary location to avoid the issue and meet the assumption.
--- include/linux/sunrpc/xprt.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
include/linux/sunrpc/xprt.h +8 -1
@@ -211,6 +211,14 @@ enum xprt_transports {struct rpc_sysfs_xprt ;struct rpc_xprt { +/* +* Place struct rcu_head within the first 4096 bytes of struct +* rpc_xprt if sizeof(struct rpc_xprt) > 4096, so that +* kfree_rcu() can simply work assuming that. See the comment +* in kfree_rcu(). +*/ +struct rcu_head rcu; +struct kref kref;/* Reference count */ const struct rpc_xprt_ops *ops;/* transport methods */ unsigned int id;/* transport id */
@@ -317,7 +325,6 @@ struct rpc_xprt {#if IS_ENABLED (CONFIG_SUNRPC_DEBUG )struct dentry *debugfs;/* debugfs directory */ #endif -struct rcu_head rcu;const struct xprt_class *xprt_class;struct rpc_sysfs_xprt *xprt_sysfs;bool main;/*mark if this is the 1st transport */
Signature · 1 line
2.17.1
PATCH v19 38/40 mm: percpu: increase PERCPU_DYNAMIC_SIZE_SHIFT on DEPT and large PAGE_SIZE
In reply to Byungchul ParkYunseong reported a build failure due to the BUILD_BUG_ON() statement in alloc_kmem_cache_cpus(). In the following test:
PERCPU_DYNAMIC_EARLY_SIZE < NR_KMALLOC_TYPES * KMALLOC_SHIFT_HIGH * sizeof(struct kmem_cache_cpu)
The following factors increase the right side of the equation:
1. PAGE_SIZE > 4KiB increases KMALLOC_SHIFT_HIGH.
2. DEPT increases the size of the local_lock_t in kmem_cache_cpu.
Increase PERCPU_DYNAMIC_SIZE_SHIFT to 11 on configs with PAGE_SIZE larger than 4KiB and DEPT enabled.
--- include/linux/percpu.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/percpu.h +4 -0
@@ -43,7 +43,11 @@# define PERCPU_DYNAMIC_SIZE_SHIFT 12#endif /* LOCKDEP and PAGE_SIZE > 4KiB */ #else +#if defined(CONFIG_DEPT ) && !defined(CONFIG_PAGE_SIZE_4KB ) +#define PERCPU_DYNAMIC_SIZE_SHIFT 11 +#else #define PERCPU_DYNAMIC_SIZE_SHIFT 10 +#endif /* DEPT and PAGE_SIZE > 4KiB */ #endif /*
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 38/40] mm: percpu: increase PERCPU_DYNAMIC_SIZE_SHIFT on DEPT and large PAGE_SIZE
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch addresses a compile-time BUILD_BUG_ON failure that no longer exists, referencing a…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch addresses a compile-time BUILD_BUG_ON failure that no longer exists, referencing a deleted structure (struct kmem_cache_cpu) and function (alloc_kmem_cache_cpus()). Both have been removed from the upstream kernel. The only remaining BUILD_BUG_ON checking PERCPU_DYNAMIC_EARLY_SIZE in SLUB is in alloc_kmem_cache_stats(), which evaluates sizeof(struct kmem_cache_stats). Because struct kmem_cache_stats consists solely of an integer array, its size is entirely unaffected by CONFIG_DEPT or local_lock_t. Thus, this patch needlessly increases the dynamically reserved per-CPU memory based on an obsolete and misleading justification. --
commit 279fb8fb2919a407c18ab625ec67d2a3430b7b4d
Author: Byungchul Park <[email protected]>
mm: percpu: increase PERCPU_DYNAMIC_SIZE_SHIFT on DEPT and large PAGE_SIZE
This commit increases PERCPU_DYNAMIC_SIZE_SHIFT to 11 when both CONFIG_DEPT and a PAGE_SIZE larger than 4KiB are enabled. It aims to prevent a build failure related to the size of struct kmem_cache_cpu.
Quoted 4 lines
Yunseong reported a build failure due to the
BUILD_BUG_ON()statement inalloc_kmem_cache_cpus(). In the following test:
PERCPU_DYNAMIC_EARLY_SIZE<NR_KMALLOC_TYPES*KMALLOC_SHIFT_HIGH*sizeof(struct kmem_cache_cpu)
[Severity: Medium]
Are we referencing structures and functions that have been removed from the upstream kernel?
Both alloc_kmem_cache_cpus() and struct kmem_cache_cpu no longer exist upstream. The only remaining BUILD_BUG_ON() checking PERCPU_DYNAMIC_EARLY_SIZE in SLUB is in alloc_kmem_cache_stats():
mm/slub.c:alloc_kmem_cache_stats() {
BUILD_BUG_ON(PERCPU_DYNAMIC_EARLY_SIZE <
NR_KMALLOC_TYPES * KMALLOC_SHIFT_HIGH *
sizeof(struct kmem_cache_stats));
}Since struct kmem_cache_stats consists solely of an integer array, its size is entirely unaffected by CONFIG_DEPT or local_lock_t. Does this mean the increase in dynamically reserved per-CPU memory is no longer needed?
Quoted 14 lines
include/linux/percpu.h +4
-0@@ -43,7 +43,11 @@# define PERCPU_DYNAMIC_SIZE_SHIFT 12#endif /* LOCKDEP and PAGE_SIZE > 4KiB */ #else +#if defined(CONFIG_DEPT ) && !defined(CONFIG_PAGE_SIZE_4KB ) +#define PERCPU_DYNAMIC_SIZE_SHIFT 11 +#else #define PERCPU_DYNAMIC_SIZE_SHIFT 10 +#endif /* DEPT and PAGE_SIZE > 4KiB */ #endif
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=38
Re: [PATCH v19 38/40] mm: percpu: increase PERCPU_DYNAMIC_SIZE_SHIFT on DEPT and large PAGE_SIZE
Quoted 32 lines · On Tue, Jul 07, 2026 at 07:33:56AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch addresses a compile-timeBUILD_BUG_ONfailure that no longer exists, referencing a deleted structure (struct kmem_cache_cpu) and function (alloc_kmem_cache_cpus()). Both have been removed from the upstream kernel. The only remainingBUILD_BUG_ONcheckingPERCPU_DYNAMIC_EARLY_SIZEin SLUB is inalloc_kmem_cache_stats(), which evaluatessizeof(struct kmem_cache_stats). Becausestruct kmem_cache_statsconsists solely of an integer array, its size is entirely unaffected byCONFIG_DEPTorlocal_lock_t. Thus, this patch needlessly increases the dynamically reserved per-CPU memory based on an obsolete and misleading justification. --commit
279fb8fb2919a407c18ab625ec67d2a3430b7b4d
Author: Byungchul Park <[email protected]>mm: percpu: increase
PERCPU_DYNAMIC_SIZE_SHIFTon DEPT and largePAGE_SIZEThis commit increases
PERCPU_DYNAMIC_SIZE_SHIFTto 11 when bothCONFIG_DEPTand aPAGE_SIZElarger than 4KiB are enabled. It aims to prevent a build failure related to the size of structkmem_cache_cpu.Quoted 4 lines
Yunseong reported a build failure due to the
BUILD_BUG_ON()statement inalloc_kmem_cache_cpus(). In the following test:
PERCPU_DYNAMIC_EARLY_SIZE<NR_KMALLOC_TYPES*KMALLOC_SHIFT_HIGH*sizeof(struct kmem_cache_cpu)[Severity: Medium]
Are we referencing structures and functions that have been removed from the upstream kernel?Both
alloc_kmem_cache_cpus()and structkmem_cache_cpuno longer exist upstream. The only remainingBUILD_BUG_ON()checkingPERCPU_DYNAMIC_EARLY_SIZEin SLUB is inalloc_kmem_cache_stats():mm/slub.c:alloc_kmem_cache_stats() {
BUILD_BUG_ON(PERCPU_DYNAMIC_EARLY_SIZE <
NR_KMALLOC_TYPES*KMALLOC_SHIFT_HIGH*sizeof(struct kmem_cache_stats));
}
Quoted 3 lines
Since struct
kmem_cache_statsconsists solely of an integer array, its size is entirely unaffected byCONFIG_DEPTorlocal_lock_t. Does this mean the increase in dynamically reserved per-CPU memory is no longer needed?
Agree. It seems no longer needed. I will fix it.
Byungchul
Quoted 17 lines
Quoted 5 lines
include/linux/percpu.h +0
-0include/linux/percpu.h line 51
Quoted 9 lines
include/linux/percpu.h +4
-0@@ -43,7 +43,11 @@# define PERCPU_DYNAMIC_SIZE_SHIFT 12#endif /* LOCKDEP and PAGE_SIZE > 4KiB */ #else +#if defined(CONFIG_DEPT ) && !defined(CONFIG_PAGE_SIZE_4KB ) +#define PERCPU_DYNAMIC_SIZE_SHIFT 11 +#else #define PERCPU_DYNAMIC_SIZE_SHIFT 10 +#endif /* DEPT and PAGE_SIZE > 4KiB */ #endif --
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=38
PATCH v19 39/40 rust: completion: Add __rust_helper to rust_helper_wait_for_completion()
In reply to Byungchul ParkThis is needed to inline these helpers into Rust code, which is required for DEPT to play with wait_for_completion().
--- rust/helpers/completion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/helpers/completion.c +1 -1
@@ -7,7 +7,7 @@ __rust_helper void rust_helper_init_completion(struct completion *x)init_completion (x); } -void rust_helper_wait_for_completion (struct completion *x) +__rust_helper void rust_helper_wait_for_completion(struct completion *x) {wait_for_completion (x); }
Signature · 1 line
2.17.1
Re: [PATCH v19 39/40] rust: completion: Add __rust_helper to rust_helper_wait_for_completion()
Quoted 5 lines · Byungchul Park
This is needed to inline these helpers into Rust code, which is required for DEPT to play with
wait_for_completion().Signed-off-by Byungchul Park <[email protected]>
Apart from what Gary said -- why did you need to do this in a separate patch in the same series?
Cheers,
Miguel
Re: [PATCH v19 39/40] rust: completion: Add __rust_helper to rust_helper_wait_for_completion()
Quoted 9 lines · Miguel Ojeda
Quoted 5 lines · Byungchul Park
This is needed to inline these helpers into Rust code, which is required for DEPT to play with
wait_for_completion().Signed-off-by Byungchul Park <[email protected]>Apart from what Gary said -- why did you need to do this in a separate patch in the same series?
Not necessary. I will make them into one patch. Thanks.
Byungchul
Quoted 3 lines
Cheers,
Miguel
PATCH v19 40/40 dept: implement a basic unit test for dept
In reply to Byungchul ParkImplement CONFIG_DEPT_UNIT_TEST introducing a kernel module that runs basic unit test for dept.
--- include/linux/dept_unit_test.h | 61 ++++++++++++ kernel/dependency/Makefile | 1 + kernel/dependency/dept.c | 10 ++ kernel/dependency/dept_unit_test.c | 149 +++++++++++++++++++++++++++++ lib/Kconfig.debug | 12 +++ 5 files changed, 233 insertions(+) create mode 100644 include/linux/dept_unit_test.h create mode 100644 kernel/dependency/dept_unit_test.c
include/linux/dept_unit_test.h new file +61 -0
@@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* DEPT unit test +* +* Started by Byungchul Park <[email protected]>: +* +* Copyright (c) 2025 SK hynix, Inc., Byungchul Park +*/ + +#ifndef __LINUX_DEPT_UNIT_TEST_H +#define __LINUX_DEPT_UNIT_TEST_H + +#if defined(CONFIG_DEPT_UNIT_TEST ) || defined(CONFIG_DEPT_UNIT_TEST_MODULE ) +struct dept_ut { +bool circle_detected; + +int ecxt_stack_total_cnt; +int wait_stack_total_cnt; +int evnt_stack_total_cnt; +int ecxt_stack_valid_cnt; +int wait_stack_valid_cnt; +int evnt_stack_valid_cnt; +}; + +extern struct dept_ut dept_ut_results; + +static inline void dept_ut_circle_detect (void ) +{ + dept_ut_results.circle_detected = true; +} +static inline void dept_ut_ecxt_stack_account (bool valid) +{ + dept_ut_results.ecxt_stack_total_cnt++; + +if (valid) + dept_ut_results.ecxt_stack_valid_cnt++; +} +static inline void dept_ut_wait_stack_account (bool valid) +{ + dept_ut_results.wait_stack_total_cnt++; + +if (valid) + dept_ut_results.wait_stack_valid_cnt++; +} +static inline void dept_ut_evnt_stack_account (bool valid) +{ + dept_ut_results.evnt_stack_total_cnt++; + +if (valid) + dept_ut_results.evnt_stack_valid_cnt++; +} +#else +struct dept_ut {}; + +#define dept_ut_circle_detect () do { } while (0) +#define dept_ut_ecxt_stack_account (v) do { } while (0) +#define dept_ut_wait_stack_account (v) do { } while (0) +#define dept_ut_evnt_stack_account (v) do { } while (0) + +#endif +#endif /* __LINUX_DEPT_UNIT_TEST_H */
kernel/dependency/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_DEPT) += dept.o obj-$(CONFIG_DEPT) += dept_proc.o +obj-$(CONFIG_DEPT_UNIT_TEST) += dept_unit_test.o
kernel/dependency/dept.c +10 -0
@@ -78,8 +78,12 @@#include <linux/workqueue.h> #include <linux/irq_work.h> #include <linux/vmalloc.h> +#include <linux/dept_unit_test.h> #include "dept_internal.h" +struct dept_ut dept_ut_results; +EXPORT_SYMBOL_GPL (dept_ut_results); +static int dept_stop;static int dept_per_cpu_ready;
@@ -826,6 +830,10 @@ static void print_dep(struct dept_dep *d)pr_warn ("(wait to wake up)\n" );print_ip_stack (0 , e->ewait_stack); } + +dept_ut_ecxt_stack_account (valid_stack (e->ecxt_stack)); +dept_ut_wait_stack_account (valid_stack (w->wait_stack)); +dept_ut_evnt_stack_account (valid_stack (e->event_stack)); } }
@@ -920,6 +928,8 @@ static void print_circle(struct dept_class *c)dump_stack ();dept_outworld_exit (); + +dept_ut_circle_detect (); }/*
kernel/dependency/dept_unit_test.c new file +149 -0
149 lines not on this page · raw message
lib/Kconfig.debug +12 -0
@@ -1477,6 +1477,18 @@ config DEPT_AGGRESSIVE_TIMEOUT_WAIT that timeout is used to avoid a deadlock. Say N if you'd like to avoid verbose reports. +config DEPT_UNIT_TEST + tristate "unit test for DEPT" + depends on DEBUG_KERNEL && DEPT + default n + help + This option provides a kernel module that runs unit test for + DEPT. + + Say Y if you want DEPT unit test to be built into the kernel. + Say M if you want DEPT unit test to build as a module. + Say N if you are unsure. + config LOCK_DEBUGGING_SUPPORT bool depends on TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [PATCH v19 40/40] dept: implement a basic unit test for dept
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Data race on lockless global `dept_ut_results` test counters. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Data race on lockless global dept_ut_results test counters.
--
commit ed16879949bb8cfa840ac89b2502567868a42cfe
Author: Byungchul Park <[email protected]>
dept: implement a basic unit test for dept
This commit introduces CONFIG_DEPT_UNIT_TEST and a corresponding kernel module that runs basic unit tests for the Dependency Tracker (DEPT).
Quoted 5 lines
include/linux/dept_unit_test.h new file +0
-0
[ ... ]
include/linux/dept_unit_test.h line 33
Quoted 3 lines
include/linux/dept_unit_test.h new file +3
-0+static inline void dept_ut_ecxt_stack_account (bool valid) +{ + dept_ut_results.ecxt_stack_total_cnt++;
[Severity: Medium]
Since this global counter is incremented non-atomically, can it race with concurrent DEPT evaluations (e.g., from print_dep()) on other CPUs? A standard data race here might lead to corrupted test counters or trigger KCSAN warnings.
[ ... ]
Quoted 5 lines
kernel/dependency/dept_unit_test.c new file +0
-0
[ ... ]
kernel/dependency/dept_unit_test.c line 30
Quoted 5 lines
kernel/dependency/dept_unit_test.c new file +5
-0+static DEFINE_SPINLOCK (s1); +static DEFINE_SPINLOCK (s2); +static bool test_spin_lock_deadlock (void ) +{ + dept_ut_results.circle_detected = false;
[Severity: Medium]
Is it safe to reset this flag without protection? If a genuine dependency issue triggers DEPT on another CPU and calls print_circle() concurrently, could it set circle_detected to true and interfere with this test's result?
[ ... ]
kernel/dependency/dept_unit_test.c line 111
Quoted 12 lines
kernel/dependency/dept_unit_test.c new file +12
-0+static int __init dept_ut_init (void ) +{ +int i; + +lockdep_off (); + + dept_ut_results.ecxt_stack_valid_cnt =0 ; + dept_ut_results.ecxt_stack_total_cnt =0 ; + dept_ut_results.wait_stack_valid_cnt =0 ; + dept_ut_results.wait_stack_total_cnt =0 ; + dept_ut_results.evnt_stack_valid_cnt =0 ; + dept_ut_results.evnt_stack_total_cnt =0 ;
[Severity: Medium]
Could resetting these global counters locklessly and without accessors like WRITE_ONCE cause issues? It appears this setup could race with concurrent DEPT reports modifying them simultaneously in print_dep().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=40
syzbot ci has tested the following series
syzbot ci has tested the following series
[v19] DEPT(DEPendency Tracker)
https://lore.kernel.org/all/[email protected]
* [PATCH v19 01/40] dept: implement DEPT(DEPendency Tracker)
* [PATCH v19 02/40] dept: add single event dependency tracker APIs
* [PATCH v19 03/40] dept: add lock dependency tracker APIs
* [PATCH v19 04/40] dept: tie to lockdep and IRQ tracing
* [PATCH v19 05/40] dept: add proc knobs to show stats and dependency graph
* [PATCH v19 06/40] dept: distinguish each kernel context from another
* [PATCH v19 07/40] dept: distinguish each work from another
* [PATCH v19 08/40] dept: add a mechanism to refill the internal memory pools on running out
* [PATCH v19 09/40] dept: record the latest one out of consecutive waits of the same class
* [PATCH v19 10/40] dept: apply sdt_might_sleep_{start,end}() to wait_for_completion()/complete()
* [PATCH v19 11/40] dept: apply sdt_might_sleep_{start,end}() to swait
* [PATCH v19 12/40] dept: apply sdt_might_sleep_{start,end}() to waitqueue wait
* [PATCH v19 13/40] dept: apply sdt_might_sleep_{start,end}() to hashed-waitqueue wait
* [PATCH v19 14/40] dept: apply sdt_might_sleep_{start,end}() to dma fence
* [PATCH v19 15/40] dept: track timeout waits separately with a new Kconfig
* [PATCH v19 16/40] dept: apply timeout consideration to wait_for_completion()/complete()
* [PATCH v19 17/40] dept: apply timeout consideration to swait
* [PATCH v19 18/40] dept: apply timeout consideration to waitqueue wait
* [PATCH v19 19/40] dept: apply timeout consideration to hashed-waitqueue wait
* [PATCH v19 20/40] dept: apply timeout consideration to dma fence wait
* [PATCH v19 21/40] dept: make dept able to work with an external wgen
* [PATCH v19 22/40] dept: track PG_locked with dept
* [PATCH v19 23/40] dept: print staged wait's stacktrace on report
* [PATCH v19 24/40] locking/lockdep: prevent various lockdep assertions when lockdep_off()'ed
* [PATCH v19 25/40] dept: add documents for dept
* [PATCH v19 26/40] cpu/hotplug: use a weaker annotation in AP thread
* [PATCH v19 27/40] dept: assign dept map to mmu notifier invalidation synchronization
* [PATCH v19 28/40] dept: assign unique dept_key to each distinct dma fence caller
* [PATCH v19 29/40] dept: make dept aware of lockdep_set_lock_cmp_fn() annotation
* [PATCH v19 30/40] dept: make dept stop from working on debug_locks_off()
* [PATCH v19 31/40] dept: assign unique dept_key to each distinct wait_for_completion() caller
* [PATCH v19 32/40] completion, dept: introduce init_completion_dmap() API
* [PATCH v19 33/40] dept: call dept_hardirqs_off() in local_irq_*() regardless of irq state
* [PATCH v19 34/40] rcu/update: fix same dept key collision between various types of RCU
* [PATCH v19 35/40] dept: introduce APIs to set page usage and use subclasses_evt for the usage
* [PATCH v19 36/40] dept: track PG_writeback with dept
* [PATCH v19 37/40] SUNRPC: relocate struct rcu_head to the first field of struct rpc_xprt
* [PATCH v19 38/40] mm: percpu: increase PERCPU_DYNAMIC_SIZE_SHIFT on DEPT and large PAGE_SIZE
* [PATCH v19 39/40] rust: completion: Add __rust_helper to rust_helper_wait_for_completion()
* [PATCH v19 40/40] dept: implement a basic unit test for dept
and found the following issue:
KASAN: slab-use-after-free Read in __dept_wait
Full report is available here:
https://ci.syzbot.org/series/bad70fd4-71dd-485d-92ef-f266796152e3
***
KASAN: slab-use-after-free Read in __dept_wait
tree: bpf-next URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/bpf/bpf-next.git base: 028ef9c96e96197026887c0f092424679298aae8 arch: amd64 compiler: Debian clang version 22.1.6 (++20260514074242+fc4aad7b5db3-1~exp1~20260514074407.73), Debian LLD 22.1.6 config: https://ci.syzbot.org/builds/e0007242-bbfe-42b9-ad3e-e15fe3f29261/config syz repro: https://ci.syzbot.org/findings/1c2fe55b-5fa6-4b20-a73c-b9bbc70528f7/syz_repro
==================================================================
BUG: KASAN: slab-use-after-free in lockdep_cmp_fn kernel/dependency/dept.c:1647 [inline] BUG: KASAN: slab-use-after-free in add_wait kernel/dependency/dept.c:1710 [inline] BUG: KASAN: slab-use-after-free in __dept_wait+0xe66/0x1b70 kernel/dependency/dept.c:2422 Read of size 8 at addr ffff8881a7a30190 by task syz.1.18/5874 CPU: 1 UID: 0 PID: 5874 Comm: syz.1.18 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <IRQ> dump_stack_lvl+0xed/0x160 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0xbe/0x230 mm/kasan/report.c:482 kasan_report+0x117/0x150 mm/kasan/report.c:595 lockdep_cmp_fn kernel/dependency/dept.c:1647 [inline] add_wait kernel/dependency/dept.c:1710 [inline] __dept_wait+0xe66/0x1b70 kernel/dependency/dept.c:2422 dept_wait+0x135/0x1a0 kernel/dependency/dept.c:2483 __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:132 [inline] _raw_spin_lock_irqsave+0x5b/0xc0 kernel/locking/spinlock.c:162 debug_object_active_state+0x77/0x390 lib/debugobjects.c:1063 debug_rcu_head_unqueue kernel/rcu/rcu.h:246 [inline] rcu_do_batch kernel/rcu/tree.c:2609 [inline] rcu_core+0x6f9/0xff0 kernel/rcu/tree.c:2869 handle_softirqs+0x231/0x890 kernel/softirq.c:622 __do_softirq kernel/softirq.c:656 [inline] invoke_softirq kernel/softirq.c:496 [inline] __irq_exit_rcu+0x66/0x150 kernel/softirq.c:723 irq_exit_rcu+0x9/0x30 kernel/softirq.c:739 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1056 [inline] sysvec_apic_timer_interrupt+0xa6/0xc0 arch/x86/kernel/apic/apic.c:1056 </IRQ> <TASK> asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:697 RIP: 0010:lock_acquire+0x20b/0x2e0 kernel/locking/lockdep.c:5893 Code: e9 30 ff ff ff e8 c5 62 fd 09 f7 c3 00 02 00 00 0f 84 38 ff ff ff 65 48 8b 05 d1 2e 84 11 48 3b 44 24 30 75 33 fb 48 83 c4 38 <5b> 41 5c 41 5d 41 5e 41 5f 5d c3 cc cc cc cc cc 48 8d 3d 6e 8d 82 RSP: 0018:ffffc900041e74a8 EFLAGS: 00000282 RAX: e0efb026e1546b00 RBX: 0000000000000246 RCX: 0000000000000046 RDX: 00000000279c9488 RSI: ffffffff8e150025 RDI: ffffffff8c281c40 RBP: 0000000000000000 R08: ffffffff81764955 R09: 0000000000000000 R10: 0000000000000000 R11: ffffffff8e7da2a0 R12: 0000000000000002 R13: ffffffff8e7da2a0 R14: 0000000000000000 R15: 0000000000000000 rcu_lock_acquire include/linux/rcupdate.h:312 [inline] rcu_read_lock include/linux/rcupdate.h:850 [inline] class_rcu_constructor include/linux/rcupdate.h:1193 [inline] unwind_next_frame+0xb2/0x2380 arch/x86/kernel/unwind_orc.c:495 __unwind_start+0x4f2/0x640 arch/x86/kernel/unwind_orc.c:773 unwind_start arch/x86/include/asm/unwind.h:64 [inline] arch_stack_walk+0xe3/0x150 arch/x86/kernel/stacktrace.c:24 stack_trace_save+0xa9/0x100 kernel/stacktrace.c:122 kasan_save_stack mm/kasan/common.c:57 [inline] kasan_save_track+0x3e/0x80 mm/kasan/common.c:78 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:584 poison_slab_object mm/kasan/common.c:253 [inline] __kasan_slab_free+0x5c/0x80 mm/kasan/common.c:285 kasan_slab_free include/linux/kasan.h:235 [inline] slab_free_hook mm/slub.c:2685 [inline] slab_free mm/slub.c:6165 [inline] kfree+0x1c5/0x640 mm/slub.c:6483 xfs_mountfs+0x1458/0x2350 fs/xfs/xfs_mount.c:1280 xfs_fs_fill_super+0x11a2/0x15f0 fs/xfs/xfs_super.c:1938 get_tree_bdev_flags+0x430/0x4f0 fs/super.c:1694 vfs_get_tree+0x92/0x2a0 fs/super.c:1754 fc_mount fs/namespace.c:1193 [inline] do_new_mount_fc fs/namespace.c:3763 [inline] do_new_mount+0x319/0xdd0 fs/namespace.c:3839 do_mount fs/namespace.c:4172 [inline] __do_sys_mount fs/namespace.c:4361 [inline] __se_sys_mount+0x31d/0x420 fs/namespace.c:4338 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x175/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f6977f9e0ca Code: 48 c7 c2 e8 ff ff ff f7 d8 64 89 02 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f6978ec5e58 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5 RAX: ffffffffffffffda RBX: 00007f6978ec5ee0 RCX: 00007f6977f9e0ca RDX: 0000200000000040 RSI: 00002000000000c0 RDI: 00007f6978ec5ea0 RBP: 0000200000000040 R08: 00007f6978ec5ee0 R09: 0000000000000001 R10: 0000000000000001 R11: 0000000000000246 R12: 00002000000000c0 R13: 00007f6978ec5ea0 R14: 0000000000009888 R15: 0000200000000080 </TASK> Allocated by task 5874: kasan_save_stack mm/kasan/common.c:57 [inline] kasan_save_track+0x3e/0x80 mm/kasan/common.c:78 unpoison_slab_object mm/kasan/common.c:340 [inline] __kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:366 kasan_slab_alloc include/linux/kasan.h:253 [inline] slab_post_alloc_hook mm/slub.c:4538 [inline] slab_alloc_node mm/slub.c:4866 [inline] kmem_cache_alloc_lru_noprof+0x2b4/0x640 mm/slub.c:4885 xfs_inode_alloc+0x7e/0x710 fs/xfs/xfs_icache.c:97 xfs_iget_cache_miss fs/xfs/xfs_icache.c:637 [inline] xfs_iget+0xa6b/0x2ef0 fs/xfs/xfs_icache.c:808 xfs_mountfs+0x1165/0x2350 fs/xfs/xfs_mount.c:1073 xfs_fs_fill_super+0x11a2/0x15f0 fs/xfs/xfs_super.c:1938 get_tree_bdev_flags+0x430/0x4f0 fs/super.c:1694 vfs_get_tree+0x92/0x2a0 fs/super.c:1754 fc_mount fs/namespace.c:1193 [inline] do_new_mount_fc fs/namespace.c:3763 [inline] do_new_mount+0x319/0xdd0 fs/namespace.c:3839 do_mount fs/namespace.c:4172 [inline] __do_sys_mount fs/namespace.c:4361 [inline] __se_sys_mount+0x31d/0x420 fs/namespace.c:4338 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x175/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 5874: kasan_save_stack mm/kasan/common.c:57 [inline] kasan_save_track+0x3e/0x80 mm/kasan/common.c:78 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:584 poison_slab_object mm/kasan/common.c:253 [inline] __kasan_slab_free+0x5c/0x80 mm/kasan/common.c:285 kasan_slab_free include/linux/kasan.h:235 [inline] slab_free_hook mm/slub.c:2685 [inline] slab_free mm/slub.c:6165 [inline] kmem_cache_free+0x18c/0x630 mm/slub.c:6295 rcu_do_batch kernel/rcu/tree.c:2617 [inline] rcu_core+0x794/0xff0 kernel/rcu/tree.c:2869 handle_softirqs+0x231/0x890 kernel/softirq.c:622 __do_softirq kernel/softirq.c:656 [inline] invoke_softirq kernel/softirq.c:496 [inline] __irq_exit_rcu+0x66/0x150 kernel/softirq.c:723 irq_exit_rcu+0x9/0x30 kernel/softirq.c:739 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1056 [inline] sysvec_apic_timer_interrupt+0xa6/0xc0 arch/x86/kernel/apic/apic.c:1056 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:697 Last potentially related work creation: kasan_save_stack+0x3e/0x60 mm/kasan/common.c:57 kasan_record_aux_stack+0xcb/0xe0 mm/kasan/generic.c:556 __call_rcu_common kernel/rcu/tree.c:3131 [inline] call_rcu+0xf7/0x890 kernel/rcu/tree.c:3251 xfs_reclaim_inode fs/xfs/xfs_icache.c:1049 [inline] xfs_icwalk_process_inode fs/xfs/xfs_icache.c:1736 [inline] xfs_icwalk_ag+0x1204/0x18c0 fs/xfs/xfs_icache.c:1818 xfs_icwalk fs/xfs/xfs_icache.c:1866 [inline] xfs_reclaim_inodes+0x1b6/0x2b0 fs/xfs/xfs_icache.c:1082 xfs_unmount_flush_inodes+0xb1/0xd0 fs/xfs/xfs_mount.c:628 xfs_mountfs+0x1325/0x2350 fs/xfs/xfs_mount.c:1267 xfs_fs_fill_super+0x11a2/0x15f0 fs/xfs/xfs_super.c:1938 get_tree_bdev_flags+0x430/0x4f0 fs/super.c:1694 vfs_get_tree+0x92/0x2a0 fs/super.c:1754 fc_mount fs/namespace.c:1193 [inline] do_new_mount_fc fs/namespace.c:3763 [inline] do_new_mount+0x319/0xdd0 fs/namespace.c:3839 do_mount fs/namespace.c:4172 [inline] __do_sys_mount fs/namespace.c:4361 [inline] __se_sys_mount+0x31d/0x420 fs/namespace.c:4338 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x175/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the object at ffff8881a7a30000 which belongs to the cache xfs_inode of size 2672
The buggy address is located 400 bytes inside of
freed 2672-byte region [ffff8881a7a30000, ffff8881a7a30a70)
The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff8881a7a30b00 pfn:0x1a7a30
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 memcg:ffff8881a7a37901
flags: 0x57ff00000000240(workingset|head|node=1|zone=2|lastcpupid=0x7ff)page_type: f5(slab)
raw: 057ff00000000240 ffff8881604168c0 ffff888163eabc88 ffff888163eabc88 raw: ffff8881a7a30b00 00000008000b0001 00000000f5000000 ffff8881a7a37901 raw: 0000000000000000 0000000000000000
head: 057ff00000000240 ffff8881604168c0 ffff888163eabc88 ffff888163eabc88
head: ffff8881a7a30b00 00000008000b0001 00000000f5000000 ffff8881a7a37901
head: 0000000000000000 0000000000000000 057ff00000000003 ffffea0008462f01
head: 00000000ffffffff 00000000ffffffff ffffffffffffffff 0000000000000000
head: 00000000ffffffff 0000000000000008 0000000000000000 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Reclaimable, gfp_mask 0xd20d0(__GFP_RECLAIMABLE|__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 5874, tgid 5873 (syz.1.18), ts 154889839111, free_ts 140490269358
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x239/0x290 mm/page_alloc.c:1889
prep_new_page mm/page_alloc.c:1897 [inline]
get_page_from_freelist+0x2541/0x25e0 mm/page_alloc.c:3962
__alloc_frozen_pages_noprof+0x18d/0x380 mm/page_alloc.c:5250
alloc_slab_page mm/slub.c:3292 [inline]
allocate_slab+0x77/0x6a0 mm/slub.c:3481
new_slab mm/slub.c:3539 [inline]
refill_objects+0x331/0x3c0 mm/slub.c:7175
refill_sheaf mm/slub.c:2812 [inline]
alloc_full_sheaf mm/slub.c:2834 [inline]
__pcs_replace_empty_main+0x428/0x760 mm/slub.c:4626
alloc_from_pcs mm/slub.c:4717 [inline]
slab_alloc_node mm/slub.c:4851 [inline]
kmem_cache_alloc_lru_noprof+0x372/0x640 mm/slub.c:4885
xfs_inode_alloc+0x7e/0x710 fs/xfs/xfs_icache.c:97
xfs_iget_cache_miss fs/xfs/xfs_icache.c:637 [inline]
xfs_iget+0xa6b/0x2ef0 fs/xfs/xfs_icache.c:808
xfs_mountfs+0x1165/0x2350 fs/xfs/xfs_mount.c:1073
xfs_fs_fill_super+0x11a2/0x15f0 fs/xfs/xfs_super.c:1938
get_tree_bdev_flags+0x430/0x4f0 fs/super.c:1694
vfs_get_tree+0x92/0x2a0 fs/super.c:1754
fc_mount fs/namespace.c:1193 [inline]
do_new_mount_fc fs/namespace.c:3763 [inline]
do_new_mount+0x319/0xdd0 fs/namespace.c:3839
do_mount fs/namespace.c:4172 [inline]
__do_sys_mount fs/namespace.c:4361 [inline]
__se_sys_mount+0x31d/0x420 fs/namespace.c:4338
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x175/0xf80 arch/x86/entry/syscall_64.c:94
page last free pid 5668 tgid 5668 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
__free_pages_prepare mm/page_alloc.c:1433 [inline]
__free_frozen_pages+0xc81/0xe10 mm/page_alloc.c:2978
vfree+0x25b/0x400 mm/vmalloc.c:3479
kcov_put kernel/kcov.c:444 [inline]
kcov_close+0x2e/0x60 kernel/kcov.c:543
__fput+0x440/0xa80 fs/file_table.c:469
task_work_run+0x1d9/0x270 kernel/task_work.c:233
exit_task_work include/linux/task_work.h:40 [inline]
do_exit+0x73a/0x2470 kernel/exit.c:976
do_group_exit+0x22d/0x2f0 kernel/exit.c:1119
get_signal+0x121b/0x12c0 kernel/signal.c:3034
arch_do_signal_or_restart+0xbb/0x810 arch/x86/kernel/signal.c:337
__exit_to_user_mode_loop kernel/entry/common.c:64 [inline]
exit_to_user_mode_loop+0xa8/0x5f0 kernel/entry/common.c:98
__exit_to_user_mode_prepare include/linux/irq-entry-common.h:230 [inline]
syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:260 [inline]
syscall_exit_to_user_mode include/linux/entry-common.h:325 [inline]
do_syscall_64+0x37e/0xf80 arch/x86/entry/syscall_64.c:100
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff8881a7a30080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8881a7a30100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8881a7a30180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8881a7a30200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8881a7a30280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
----------------
Code disassembly (best guess):
0: e9 30 ff ff ff jmp 0xffffff35
5: e8 c5 62 fd 09 call 0x9fd62cf
a: f7 c3 00 02 00 00 test $0x200,%ebx
10: 0f 84 38 ff ff ff je 0xffffff4e
16: 65 48 8b 05 d1 2e 84 mov %gs:0x11842ed1(%rip),%rax # 0x11842eef
1d: 11
1e: 48 3b 44 24 30 cmp 0x30(%rsp),%rax
23: 75 33 jne 0x58
25: fb sti
26: 48 83 c4 38 add $0x38,%rsp
* 2a: 5b pop %rbx <-- trapping instruction
2b: 41 5c pop %r12
2d: 41 5d pop %r13
2f: 41 5e pop %r14
31: 41 5f pop %r15
33: 5d pop %rbp
34: c3 ret
35: cc int3
36: cc int3
37: cc int3
38: cc int3
39: cc int3
3a: 48 rex.W
3b: 8d .byte 0x8d
3c: 3d .byte 0x3d
3d: 6e outsb %ds:(%rsi),(%dx)
3e: 8d .byte 0x8d
3f: 82 .byte 0x82***
If these findings have caused you to resend the series or submit a separate fix, please add the following tag to your commit message:
---
This report is generated by a bot. It may contain errors. syzbot ci engineers can be reached at [email protected].
To test a patch for this bug, please reply with #syz test (should be on a separate line).
The patch should be attached to the email.
Note: arguments like custom git repos and branches are not supported.
David Hildenbrand (Arm)
maintainerQuoted 1 line · Byungchul Park
Hi Linus and folks,
Hi,
I think there was plenty of feedback from locking maintainers in the past. One question and a comment below.
Quoted 30 lines
DEPT(DEPendency Tracker) is a runtime deadlock detection framework that sees what lockdep cannot.
I'm thrilled to share that DEPT has moved beyond theory and is now catching real deadlocks in the wild:
https://lore.kernel.org/lkml/[email protected]/ https://lore.kernel.org/lkml/[email protected]/ https://lore.kernel.org/all/[email protected]/I've added comprehensive documentation explaining DEPT's design and usage. Getting started is as simple as enabling
CONFIG_DEPTand watching dmesg.THE PROBLEM LOCKDEP CANNOT SOLVE
--------------------------------Lockdep has been our trusted deadlock detector for two decades, but it has a fundamental blind spot: it tracks lock acquisition order, not the actual waits and events that cause deadlocks. This means lockdep misses:
* Deadlocks involving folio locks (not released within the context)
* Cross-context synchronization like wait_for_completion()/complete()
* DMA fence waits, RCU waits, and general waitqueue patterns
* Any synchronization primitive outside the classic lock/unlock modelConsider this real deadlock pattern that lockdep cannot detect:
context X context Y context Z
Quoted 8 lines
mutex_lockA
folio_lockB
folio_lockB <- DEADLOCK
mutex_lockA <- DEADLOCKfolio_unlockB
folio_unlockB
mutex_unlockA
mutex_unlockA
But that really just boils down to folio lock being implemented as a PG_lock + some advanced wait mechanism. And we must do that because of lack of bits in struct page.
Willy mentioned in a previous version [1]: "I don't think it makes sense to track lock state in the page (nor folio). Partly because there's just so many of them, but also because the locking rules don't really apply to individual folios so much as they do to the mappings (or anon_vmas) that contain folios."
Given that lockdep is a debug feature, and we will at some point allocate struct folio separately, I assume we could just squeeze a "struct lockdep_map" in there in such debug configs and the world would not collapse.
Doing that today (one "struct lockdep_map" in each "struct page") wouldn't work as mm_zero_struct_page() would not expect such large "struct page". But conceptually, for a debug kernel with a special CONFIG_LOCKDEP_PAGE_LOCK, maybe that would already be ok and we could just do that (and optimize it as we allocate folios separately).
Not that it's ideal, but for a debug feature to at least check PG_lock, probably an easier way to achieve it than some completely new infrastructure.
Now, Willy said "locking rules don't really apply to individual folios", I wonder if that could just help to also let lockdep check PG_lock with less metadata? (didn't fully wrap my head around the implications)
[1]
https://lore.kernel.org/all/[email protected]/?utm_source=chatgpt.com
It's your guiding example, that's why I mention it. You do mention other wait cases here, I don't know anything about them, but for folios it's really just "we used a single bit so far" AFAIKs.
[...]
Quoted 7 lines
Q. Why not build DEPT into lockdep?
A. Lockdep is stable, battle-tested code. I chose separation because
while DEPT borrows BFS and hashing ideas, the wait/event model requires rebuilding from scratch. Lockdep was designed for lock acquisition order — retrofitting it would risk its stability.
Why can't this just be some configurable extension to lockdep (CONFIG_LOCKDEP_XYZ) until the feature is stable and can unconditionally be enabled along with it?
I don't quite buy the "would risk its stability" argument. A lot of stuff we do "risks stability", every day :)
Is there another good reason (incompatible with X, dangerous with Y, cinfusing
Z) why this really must be a separate thing?
Quoted 5 lines
Q. Will DEPT replace lockdep?
A. No. Lockdep validates correct lock usage — that's not going away.
DEPT supersedes only the dependency-checking logic when mature.
It's quite unfortunate that we'd end up with another similar-but-different mechanism, that will just end up confusing people.
But I am not a locking maintainer. I think there was plenty of discussion in the past, so I might just be raising points that were already discussed in the past, but I really just read some random pieces of earlier discussions. (ideally previous discussions would be summarized here)
Long story short: we are now in v19 and I think there was pushback in the past. Did the opinion of locking maintainers change, or is there a way forward to integrate this in a way that would make locking maintainers accept this?
Signature · 3 lines
Cheers, David
Matthew Wilcox
maintainerQuoted 35 lines · David Hildenbrand (Arm)
Quoted 4 lines
Consider this real deadlock pattern that lockdep cannot detect:
context X context Y context Z
Quoted 8 lines
mutex_lockA
folio_lockB
folio_lockB <- DEADLOCK
mutex_lockA <- DEADLOCKfolio_unlockB
folio_unlockB
mutex_unlockA
mutex_unlockABut that really just boils down to folio lock being implemented as a
PG_lock+ some advanced wait mechanism. And we must do that because of lack of bits in struct page.Willy mentioned in a previous version [1]: "I don't think it makes sense to track lock state in the page (nor folio). Partly because there's just so many of them, but also because the locking rules don't really apply to individual folios so much as they do to the mappings (or
anon_vmas) that contain folios."Given that lockdep is a debug feature, and we will at some point allocate struct folio separately, I assume we could just squeeze a "struct
lockdep_map" in there in such debug configs and the world would not collapse.Doing that today (one "struct
lockdep_map" in each "struct page") wouldn't work asmm_zero_struct_page()would not expect such large "struct page". But conceptually, for a debug kernel with a specialCONFIG_LOCKDEP_PAGE_LOCK, maybe that would already be ok and we could just do that (and optimize it as we allocate folios separately).Not that it's ideal, but for a debug feature to at least check
PG_lock, probably an easier way to achieve it than some completely new infrastructure.
Quoted 6 lines
Now, Willy said "locking rules don't really apply to individual folios", I wonder if that could just help to also let lockdep check
PG_lockwith less metadata? (didn't fully wrap my head around the implications)[1]
https://lore.kernel.org/all/[email protected]/?utm_source=chatgpt.com
There are a few things going on that make PG_lock special. Let me try to explain again, only better this time.
1. The current lifetime of a struct page is the lifetime of the system. But the semantics of its PG_lock bit change each time it is freed and allocated.
2. The position of PG_lock in the locking hierarchy only depend on what the folio is currently being used for. That is, all folios in a given xfs inode behave exactly the same from a locking perspective. There's no need to build up state about how each PG_lock is used; they can all share. Arguably all xfs file inodes are the same as each other (directory inodes might be different from file inodes), so we might want to go further than telling DEPT that "this folio belongs to this inode" and go to "this folio belongs to this xfs file inode".
3. PG_lock can be taken in task context then released in interrupt context. For full points, we need to mark the exact point at which we submit the folio for read. Otherwise we can get into the situation alluded to by f2c817bed58d and better discussed at
https://lore.kernel.org/linux-mm/[email protected]/
where we have the folio locked but haven't yet submitted it for I/O so it doesn't matter how long we wait, it will never come unlocked.
Quoted 43 lines · Matthew Wilcox
Quoted 35 lines · David Hildenbrand (Arm)
Quoted 4 lines
Consider this real deadlock pattern that lockdep cannot detect:
context X context Y context Z
Quoted 8 lines
mutex_lockA
folio_lockB
folio_lockB <- DEADLOCK
mutex_lockA <- DEADLOCKfolio_unlockB
folio_unlockB
mutex_unlockA
mutex_unlockABut that really just boils down to folio lock being implemented as a
PG_lock+ some advanced wait mechanism. And we must do that because of lack of bits in struct page.Willy mentioned in a previous version [1]: "I don't think it makes sense to track lock state in the page (nor folio). Partly because there's just so many of them, but also because the locking rules don't really apply to individual folios so much as they do to the mappings (or
anon_vmas) that contain folios."Given that lockdep is a debug feature, and we will at some point allocate struct folio separately, I assume we could just squeeze a "struct
lockdep_map" in there in such debug configs and the world would not collapse.Doing that today (one "struct
lockdep_map" in each "struct page") wouldn't work asmm_zero_struct_page()would not expect such large "struct page". But conceptually, for a debug kernel with a specialCONFIG_LOCKDEP_PAGE_LOCK, maybe that would already be ok and we could just do that (and optimize it as we allocate folios separately).Not that it's ideal, but for a debug feature to at least check
PG_lock, probably an easier way to achieve it than some completely new infrastructure.Quoted 6 lines
Now, Willy said "locking rules don't really apply to individual folios", I wonder if that could just help to also let lockdep check
PG_lockwith less metadata? (didn't fully wrap my head around the implications)[1]
https://lore.kernel.org/all/[email protected]/?utm_source=chatgpt.com
Quoted 6 lines
There are a few things going on that make
PG_lockspecial. Let me try to explain again, only better this time.1. The current lifetime of a struct page is the lifetime of the system. But the semantics of its
PG_lockbit change each time it is freed and allocated.
Yes, it's a classification issue that is very important.
Quoted 3 lines
2. The position of
PG_lockin the locking hierarchy only depend on what the folio is currently being used for. That is, all folios in a given xfs inode behave exactly the same from a locking perspective.
You are exactly explaining what the classification means. Perfect.
Quoted 2 lines
There's no need to build up state about how each
PG_lockis used; they can all share. Arguably all xfs file inodes are the same as
Right. That's why DEPT doesn't use a full map in each page but just uses a timestamp in each. For the classification, DEPT uses a few classes for folio, using global maps:
1. folios in mm paths
2. folios in block device buffer (meta data)
3. folios in regular file cache
However, yes. I bet you could be a big help when classifying folios more presicely according to its usage. But the current classification is still a good start I think.
Quoted 4 lines
each other (directory inodes might be different from file inodes), so we might want to go further than telling DEPT that "this folio belongs to this inode" and go to "this folio belongs to this xfs file inode".
Totally agree.
Quoted 7 lines
3.
PG_lockcan be taken in task context then released in interrupt context. For full points, we need to mark the exact point at which we submit the folio for read. Otherwise we can get into the situation alluded to byf2c817bed58dand better discussed at
https://lore.kernel.org/linux-mm/[email protected]/
where we have the folio locked but haven't yet submitted it for I/O so it doesn't matter how long we wait, it will never come unlocked.
Interesting.
The following abstraction might make DEPT work with it. For example:
Annotate the point submitting IO as an event for the folio_lock() to be released. That way, the issue above can be detected by DEPT.
Again, DEPT can do every thing we need w.r.t. deadlock.
Byungchul
David Hildenbrand (Arm)
maintainerQuoted 40 lines · Matthew Wilcox
Quoted 39 lines · David Hildenbrand (Arm)
Quoted 4 lines
Consider this real deadlock pattern that lockdep cannot detect:
context X context Y context Z
Quoted 8 lines
mutex_lockA
folio_lockB
folio_lockB <- DEADLOCK
mutex_lockA <- DEADLOCKfolio_unlockB
folio_unlockB
mutex_unlockA
mutex_unlockABut that really just boils down to folio lock being implemented as a
PG_lock+ some advanced wait mechanism. And we must do that because of lack of bits in struct page.Willy mentioned in a previous version [1]: "I don't think it makes sense to track lock state in the page (nor folio). Partly because there's just so many of them, but also because the locking rules don't really apply to individual folios so much as they do to the mappings (or
anon_vmas) that contain folios."Given that lockdep is a debug feature, and we will at some point allocate struct folio separately, I assume we could just squeeze a "struct
lockdep_map" in there in such debug configs and the world would not collapse.Doing that today (one "struct
lockdep_map" in each "struct page") wouldn't work asmm_zero_struct_page()would not expect such large "struct page". But conceptually, for a debug kernel with a specialCONFIG_LOCKDEP_PAGE_LOCK, maybe that would already be ok and we could just do that (and optimize it as we allocate folios separately).Not that it's ideal, but for a debug feature to at least check
PG_lock, probably an easier way to achieve it than some completely new infrastructure.Now, Willy said "locking rules don't really apply to individual folios", I wonder if that could just help to also let lockdep check
PG_lockwith less metadata? (didn't fully wrap my head around the implications)
Quoted 6 lines
There are a few things going on that make
PG_lockspecial. Let me try to explain again, only better this time.
Thanks for that information :)
Quoted 3 lines
1. The current lifetime of a struct page is the lifetime of the system. But the semantics of its
PG_lockbit change each time it is freed and allocated.
Well, yeah, but that will effectively change once we dynamically allocate struct folio.
Until then, don't we have the following two events:
(a) Allocator handing out a page
(b) Page getting returned to page allocator
And while in the allocator, the PG_locked is essentially unused/unusable (and so would be lockdep data)?
I'd argue there is a well defined lifetime for PG_locked and any additional lockdep metadata. At least theoretically ;)
Quoted 10 lines
2. The position of
PG_lockin the locking hierarchy only depend on what the folio is currently being used for. That is, all folios in a given xfs inode behave exactly the same from a locking perspective. There's no need to build up state about how eachPG_lockis used; they can all share. Arguably all xfs file inodes are the same as each other (directory inodes might be different from file inodes), so we might want to go further than telling DEPT that "this folio belongs to this inode" and go to "this folio belongs to this xfs file inode".
"There is no need", I am not entirely sure when it comes to anonymous folios.
Even if there is actually no need, given that we are talking about debugging mechanisms, I am not sure if optimizing for less memory consumption is our highest priority. Debug kernels already consume plenty of memory on other things (page_ext, for example), so consuming some more to support the folio lock with lockdep does not sound too crazy for me.
(maybe lockdep data could even life in page_ext)
I understand that Dept applies to more things than just PG_locked, though.
Quoted 8 lines
3.
PG_lockcan be taken in task context then released in interrupt context. For full points, we need to mark the exact point at which we submit the folio for read. Otherwise we can get into the situation alluded to byf2c817bed58dand better discussed at
https://lore.kernel.org/linux-mm/[email protected]/
where we have the folio locked but haven't yet submitted it for I/O so it doesn't matter how long we wait, it will never come unlocked.
Yeah, it seems hard to squeeze different locking contexts into existing lockdep. I cannot tell whether lockdep could be adjusted to allow for that, or how much work it would involve.
So yeah, Dept might be a more natural fit for this scenario.
Signature · 3 lines
Cheers, David
Quoted 4 lines · David Hildenbrand (Arm)
Quoted 1 line · Byungchul Park
Hi Linus and folks,
Hi,
Hi,
Quoted 42 lines
I think there was plenty of feedback from locking maintainers in the past. One question and a comment below.
Quoted 30 lines
DEPT(DEPendency Tracker) is a runtime deadlock detection framework that sees what lockdep cannot.
I'm thrilled to share that DEPT has moved beyond theory and is now catching real deadlocks in the wild:
https://lore.kernel.org/lkml/[email protected]/ https://lore.kernel.org/lkml/[email protected]/ https://lore.kernel.org/all/[email protected]/I've added comprehensive documentation explaining DEPT's design and usage. Getting started is as simple as enabling
CONFIG_DEPTand watching dmesg.THE PROBLEM LOCKDEP CANNOT SOLVE
--------------------------------Lockdep has been our trusted deadlock detector for two decades, but it has a fundamental blind spot: it tracks lock acquisition order, not the actual waits and events that cause deadlocks. This means lockdep misses:
* Deadlocks involving folio locks (not released within the context)
* Cross-context synchronization like wait_for_completion()/complete()
* DMA fence waits, RCU waits, and general waitqueue patterns
* Any synchronization primitive outside the classic lock/unlock modelConsider this real deadlock pattern that lockdep cannot detect:
context X context Y context Z
Quoted 8 lines
mutex_lockA
folio_lockB
folio_lockB <- DEADLOCK
mutex_lockA <- DEADLOCKfolio_unlockB
folio_unlockB
mutex_unlockA
mutex_unlockA
Quoted 8 lines
But that really just boils down to folio lock being implemented as a
PG_lock+ some advanced wait mechanism. And we must do that because of lack of bits in struct page.Willy mentioned in a previous version [1]: "I don't think it makes sense to track lock state in the page (nor folio). Partly because there's just so many of them, but also because the locking rules don't really apply to individual folios so much as they do to the mappings (or
anon_vmas) that contain folios."
Exactly. That's why we use classification e.g. lock class - DEPT also makes use of the concept.
DEPT doesn't use a full map in each page but uses a minimum space for a timestamp in each to track when each starts to wait so as to use the recorded timestamp when the event occurs e.g. folio_unlock().
Quoted 3 lines
Given that lockdep is a debug feature, and we will at some point allocate struct folio separately, I assume we could just squeeze a "struct
lockdep_map" in there in such debug configs and the world would not collapse.
That's a good news for lockdep. (And even for DEPT :)
Quoted 5 lines
Doing that today (one "struct
lockdep_map" in each "struct page") wouldn't work asmm_zero_struct_page()would not expect such large "struct page". But conceptually, for a debug kernel with a specialCONFIG_LOCKDEP_PAGE_LOCK, maybe that would already be ok and we could just do that (and optimize it as we allocate folios separately).
Sounds great.
Quoted 2 lines
Not that it's ideal, but for a debug feature to at least check
PG_lock, probably an easier way to achieve it than some completely new infrastructure.
I understand what you are going to tell.
However, it's worth noting that lockdep tracks dependencies basically based on **lock acqusition orders** in the system. To make it track even rwlock and general synchronization mechanism as well, lockdep has no choice but to get more complicated.
Focusing on only the dependency checking, the most parts of lockdep are for the tricky things, so the reusable parts are not that big.
Quoted 3 lines
Now, Willy said "locking rules don't really apply to individual folios", I wonder if that could just help to also let lockdep check
PG_lockwith less metadata? (didn't fully wrap my head around the implications)
That's what DEPT did and what brought external wgen introduced in DEPT. I was considering the exactly same thing :)
Again, lockdep that tracks lock acquisition orders can't do that.
Quoted 7 lines
[1]
https://lore.kernel.org/all/[email protected]/?utm_source=chatgpt.comIt's your guiding example, that's why I mention it. You do mention other wait cases here, I don't know anything about them, but for folios it's really just "we used a single bit so far" AFAIKs.
It doesn't matter whether it's implemented using bit or not. folio lock is quite special since it's allowed to be released other than the acquisition context that makes lockdep impossible to track them.
Quoted 5 lines
[...]
Quoted 3 lines
Q. Why not build DEPT into lockdep?
Quoted 8 lines
Quoted 4 lines
A. Lockdep is stable, battle-tested code. I chose separation because
while DEPT borrows BFS and hashing ideas, the wait/event model requires rebuilding from scratch. Lockdep was designed for lock acquisition order — retrofitting it would risk its stability.Why can't this just be some configurable extension to lockdep (
CONFIG_LOCKDEP_XYZ) until the feature is stable and can unconditionally be enabled along with it?
Answered?
Quoted 2 lines
I don't quite buy the "would risk its stability" argument. A lot of stuff we do "risks stability", every day :)
That's awsome anyway :)
Quoted 2 lines
Is there another good reason (incompatible with X, dangerous with Y, cinfusing
Z) why this really must be a separate thing?
Roughly:
1. Similar or less effort is needed for the new one - retrofitting lockdep is not easy and big changes are required since the reusable parts are not that big.
2. Even though you didn't agree, retrofitting it would risk its stability.
Quoted 8 lines
Quoted 5 lines
Q. Will DEPT replace lockdep?
A. No. Lockdep validates correct lock usage — that's not going away.
DEPT supersedes only the dependency-checking logic when mature.It's quite unfortunate that we'd end up with another similar-but-different mechanism, that will just end up confusing people.
I meant, at least dependency checking engine should be altered, but you make sense. Worth thinking it more.
Quoted 8 lines
But I am not a locking maintainer. I think there was plenty of discussion in the past, so I might just be raising points that were already discussed in the past, but I really just read some random pieces of earlier discussions. (ideally previous discussions would be summarized here)
Long story short: we are now in v19 and I think there was pushback in the past. Did the opinion of locking maintainers change, or is there a way forward to integrate this in a way that would make locking maintainers accept this?
One of locking maintainers who I met in an LPC told me that he agrees with the direction of DEPT and supports DEPT, not officially tho.
What he and other people are concerning w.r.t DEPT the most is, false positives, which is the most important issue for now.
At the same time, I think the most important thing is to make DEPT useful in practice especially with folio locks involved. Actually, I'm planning to share DEPT's true reports periodically to LKML and work with people who believe DEPT can make things better.
Any advices will be welcome. Thanks for your opinions.
Byungchul
Quoted 4 lines
--
Cheers,David
David Hildenbrand (Arm)
maintainer[...]
Quoted 6 lines
Exactly. That's why we use classification e.g. lock class - DEPT also makes use of the concept.
DEPT doesn't use a full map in each page but uses a minimum space for a timestamp in each to track when each starts to wait so as to use the recorded timestamp when the event occurs e.g.
folio_unlock().
Thanks for that information!
Quoted 6 lines
Quoted 4 lines
Given that lockdep is a debug feature, and we will at some point allocate struct folio separately, I assume we could just squeeze a "struct
lockdep_map" in there in such debug configs and the world would not collapse.That's a good news for lockdep. (And even for DEPT :)
He :) Where do you currently store the additional per-page information?
Quoted 12 lines
Quoted 6 lines
Doing that today (one "struct
lockdep_map" in each "struct page") wouldn't work asmm_zero_struct_page()would not expect such large "struct page". But conceptually, for a debug kernel with a specialCONFIG_LOCKDEP_PAGE_LOCK, maybe that would already be ok and we could just do that (and optimize it as we allocate folios separately).Sounds great.
Quoted 2 lines
Not that it's ideal, but for a debug feature to at least check
PG_lock, probably an easier way to achieve it than some completely new infrastructure.
Quoted 6 lines
I understand what you are going to tell.
However, it's worth noting that lockdep tracks dependencies basically based on **lock acqusition orders** in the system. To make it track even rwlock and general synchronization mechanism as well, lockdep has no choice but to get more complicated.
Well, yes, sure :)
Quoted 17 lines
Focusing on only the dependency checking, the most parts of lockdep are for the tricky things, so the reusable parts are not that big.
Quoted 3 lines
Now, Willy said "locking rules don't really apply to individual folios", I wonder if that could just help to also let lockdep check
PG_lockwith less metadata? (didn't fully wrap my head around the implications)That's what DEPT did and what brought external wgen introduced in DEPT. I was considering the exactly same thing :)
Again, lockdep that tracks lock acquisition orders can't do that.
Quoted 7 lines
Quoted 3 lines
It's your guiding example, that's why I mention it. You do mention other wait cases here, I don't know anything about them, but for folios it's really just "we used a single bit so far" AFAIKs.
It doesn't matter whether it's implemented using bit or not. folio lock is quite special since it's allowed to be released other than the acquisition context that makes lockdep impossible to track them.
Does that really make lockdep *impossible* to track them? IOW, there is no way to extend lockdep to support lock release in different context?
I guess there is a way, but the question is at which price (I seriously have no idea, maybe this was already discussed and people have a pointer for me).
Quoted 11 lines
Quoted 11 lines
[...]
Quoted 7 lines
Q. Why not build DEPT into lockdep?
A. Lockdep is stable, battle-tested code. I chose separation because
while DEPT borrows BFS and hashing ideas, the wait/event model requires rebuilding from scratch. Lockdep was designed for lock acquisition order — retrofitting it would risk its stability.
Quoted 5 lines
Quoted 3 lines
Why can't this just be some configurable extension to lockdep (
CONFIG_LOCKDEP_XYZ) until the feature is stable and can unconditionally be enabled along with it?Answered?
Not quite. I don't understand why this must be a completely separate machinery, even if, conceptually, it would do more than traditional lockdep.
Is it either DEPT or LOCKDEP in current configurations? Can both run at the same time?
Quoted 9 lines
Quoted 3 lines
I don't quite buy the "would risk its stability" argument. A lot of stuff we do "risks stability", every day :)
That's awsome anyway :)
Quoted 2 lines
Is there another good reason (incompatible with X, dangerous with Y, cinfusing
Z) why this really must be a separate thing?
Quoted 8 lines
Roughly:
1. Similar or less effort is needed for the new one - retrofitting lockdep is not easy and big changes are required since the reusable parts are not that big.
2. Even though you didn't agree, retrofitting it would risk its stability.
Well, I don't buy the stability argument, really :)
Retrofitting effort for lockdep is an interesting point, though. Lockdep maintainers would have to make the call here regarding direction and feasibility.
[...]
Quoted 11 lines
Quoted 8 lines
But I am not a locking maintainer. I think there was plenty of discussion in the past, so I might just be raising points that were already discussed in the past, but I really just read some random pieces of earlier discussions. (ideally previous discussions would be summarized here)
Long story short: we are now in v19 and I think there was pushback in the past. Did the opinion of locking maintainers change, or is there a way forward to integrate this in a way that would make locking maintainers accept this?
One of locking maintainers who I met in an LPC told me that he agrees with the direction of DEPT and supports DEPT, not officially tho.
Hm.
Quoted 3 lines
What he and other people are concerning w.r.t DEPT the most is, false positives, which is the most important issue for now.
Thanks for highlighting that. What's the main reason for false positives? Is it something conceptual that is mostly impossible to solve, or rather just implementation work to cover all edge cases?
Quoted 7 lines
At the same time, I think the most important thing is to make DEPT useful in practice especially with folio locks involved. Actually, I'm planning to share DEPT's true reports periodically to LKML and work with people who believe DEPT can make things better.
Any advices will be welcome. Thanks for your opinions.
I think we must come to some conclusion on how to proceed with DEPT. I see the following options:
(1) Don't merge it and carry it OOT. Shame if it delivers real value.
(2) Merge it (after proper review and acks from relevant maintainers ;) ), keeping it entirely separate from lockdep.
(3) Integrate it with lockdep on a high level, giving us a single locking dependency checker, but mostly letting dept have a separate implementation. Look into possible merging afterwards.
(4) Retrofit and extend lockdep to really have one mechanism.
As the saying goes, it's hard to teach old dogs new tricks, but in the end taking care of two dogs is likely harder than only a single dog? :)
I tend to favor (4) (or 3 with possible future work to achieve 4), but I am not a locking maintainer, so really they have to voice what to do.
I do see value in DEPT (even if the folio lock might be handled differently).
Signature · 3 lines
Cheers, David
Quoted 12 lines · David Hildenbrand (Arm)
[...]
Quoted 6 lines
Exactly. That's why we use classification e.g. lock class - DEPT also makes use of the concept.
DEPT doesn't use a full map in each page but uses a minimum space for a timestamp in each to track when each starts to wait so as to use the recorded timestamp when the event occurs e.g.
folio_unlock().Thanks for that information!
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Given that lockdep is a debug feature, and we will at some point allocate struct folio separately, I assume we could just squeeze a "struct
lockdep_map" in there in such debug configs and the world would not collapse.That's a good news for lockdep. (And even for DEPT :)
He :) Where do you currently store the additional per-page information?
lockdep doesn't need to store per-page information. Possibly DEPT doesn't either.
lockdep needs one lockdep_map for each lock class. It would make sense for all folio locks to use the same global lockdep_map.
Each specific lock is known to lockdep as a task which holds the lock, a lockdep_map which represents the class of locks, and subclass number which allows a given task to hold multiple locks of the same class providing it declare (e.g. with spin_lock_nested() etc).
Quoted 43 lines
Quoted 13 lines
Quoted 7 lines
Doing that today (one "struct
lockdep_map" in each "struct page") wouldn't work asmm_zero_struct_page()would not expect such large "struct page". But conceptually, for a debug kernel with a specialCONFIG_LOCKDEP_PAGE_LOCK, maybe that would already be ok and we could just do that (and optimize it as we allocate folios separately).Sounds great.
Quoted 2 lines
Not that it's ideal, but for a debug feature to at least check
PG_lock, probably an easier way to achieve it than some completely new infrastructure.Quoted 6 lines
I understand what you are going to tell.
However, it's worth noting that lockdep tracks dependencies basically based on **lock acqusition orders** in the system. To make it track even rwlock and general synchronization mechanism as well, lockdep has no choice but to get more complicated.
Well, yes, sure :)
Quoted 21 lines
Focusing on only the dependency checking, the most parts of lockdep are for the tricky things, so the reusable parts are not that big.
Quoted 3 lines
Now, Willy said "locking rules don't really apply to individual folios", I wonder if that could just help to also let lockdep check
PG_lockwith less metadata? (didn't fully wrap my head around the implications)That's what DEPT did and what brought external wgen introduced in DEPT. I was considering the exactly same thing :)
Again, lockdep that tracks lock acquisition orders can't do that.
Quoted 7 lines
[1]
https://lore.kernel.org/all/[email protected]/?utm_source=chatgpt.comIt's your guiding example, that's why I mention it. You do mention other wait cases here, I don't know anything about them, but for folios it's really just "we used a single bit so far" AFAIKs.
Quoted 6 lines
Quoted 3 lines
It doesn't matter whether it's implemented using bit or not. folio lock is quite special since it's allowed to be released other than the acquisition context that makes lockdep impossible to track them.
Does that really make lockdep *impossible* to track them? IOW, there is no way to extend lockdep to support lock release in different context?
Yes and no....
lockdep has no knowledge of control flows moving across threads in the way that I assume DEPT does. But it should be possible to tell it.
If you have some code that takes a lock and then hands it off to another thread, at the hand-off point you call
lock_map_release(&the_lock_map)
This says "no task owns this lock any more".
maybe you put the folio which is locked on a queue or an lru or whatever.
There is no way to say "that queue owns this lock". Maybe that could usefully be added - assuming coherent semantics can be designed.
Somewhere else some other task takes responsibility for that folio and the lock. maybe it dequeues a page, or maybe an lru callback gives the locked page to some code.
That code then calls
lock_map_acquire_try(&the_lock_map)
This says "this task is now holding this lock" (or more accurately "now holding a lock of this class").
Note the "_try" - that says that the task didn't have to wait for the lock, it just got it for free, which in fact it did.
Now if that task takes some other lock, lockdep will see a dependency between the page lock and the new lock, and will accept or reject it as you would expect.
So you definitely *can* send lock dependency information between tasks with lockdep. I have only tried it in extremely simple cases where a single object is being locked by one task and unlocked by another - no queues or lists.
There may be - and probably are - more complexities involved with locking folios and passing them around. Maybe it is so complex that you need all the support that DEPT provides. But I'd like to see a coherent explanation of how the functionality offered by DEPT is clearly better.
NeilBrown
Quoted 109 lines
I guess there is a way, but the question is at which price (I seriously have no idea, maybe this was already discussed and people have a pointer for me).
Quoted 11 lines
Quoted 11 lines
[...]
Quoted 7 lines
Q. Why not build DEPT into lockdep?
A. Lockdep is stable, battle-tested code. I chose separation because
while DEPT borrows BFS and hashing ideas, the wait/event model requires rebuilding from scratch. Lockdep was designed for lock acquisition order — retrofitting it would risk its stability.Quoted 5 lines
Quoted 3 lines
Why can't this just be some configurable extension to lockdep (
CONFIG_LOCKDEP_XYZ) until the feature is stable and can unconditionally be enabled along with it?Answered?
Not quite. I don't understand why this must be a completely separate machinery, even if, conceptually, it would do more than traditional lockdep.
Is it either DEPT or LOCKDEP in current configurations? Can both run at the same time?
Quoted 9 lines
Quoted 3 lines
I don't quite buy the "would risk its stability" argument. A lot of stuff we do "risks stability", every day :)
That's awsome anyway :)
Quoted 2 lines
Is there another good reason (incompatible with X, dangerous with Y, cinfusing
Z) why this really must be a separate thing?Quoted 8 lines
Roughly:
1. Similar or less effort is needed for the new one - retrofitting lockdep is not easy and big changes are required since the reusable parts are not that big.
2. Even though you didn't agree, retrofitting it would risk its stability.
Well, I don't buy the stability argument, really :)
Retrofitting effort for lockdep is an interesting point, though. Lockdep maintainers would have to make the call here regarding direction and feasibility.
[...]
Quoted 11 lines
Quoted 8 lines
But I am not a locking maintainer. I think there was plenty of discussion in the past, so I might just be raising points that were already discussed in the past, but I really just read some random pieces of earlier discussions. (ideally previous discussions would be summarized here)
Long story short: we are now in v19 and I think there was pushback in the past. Did the opinion of locking maintainers change, or is there a way forward to integrate this in a way that would make locking maintainers accept this?
One of locking maintainers who I met in an LPC told me that he agrees with the direction of DEPT and supports DEPT, not officially tho.
Hm.
Quoted 3 lines
What he and other people are concerning w.r.t DEPT the most is, false positives, which is the most important issue for now.
Thanks for highlighting that. What's the main reason for false positives? Is it something conceptual that is mostly impossible to solve, or rather just implementation work to cover all edge cases?
Quoted 7 lines
At the same time, I think the most important thing is to make DEPT useful in practice especially with folio locks involved. Actually, I'm planning to share DEPT's true reports periodically to LKML and work with people who believe DEPT can make things better.
Any advices will be welcome. Thanks for your opinions.
I think we must come to some conclusion on how to proceed with DEPT. I see the following options:
(1) Don't merge it and carry it OOT. Shame if it delivers real value.
(2) Merge it (after proper review and acks from relevant maintainers ;) ), keeping it entirely separate from lockdep.
(3) Integrate it with lockdep on a high level, giving us a single locking dependency checker, but mostly letting dept have a separate implementation. Look into possible merging afterwards.
(4) Retrofit and extend lockdep to really have one mechanism.
As the saying goes, it's hard to teach old dogs new tricks, but in the end taking care of two dogs is likely harder than only a single dog? :)
I tend to favor (4) (or 3 with possible future work to achieve 4), but I am not a locking maintainer, so really they have to voice what to do.
I do see value in DEPT (even if the folio lock might be handled differently).
Signature · 3 lines
Cheers, David
David Hildenbrand (Arm)
maintainerHi!
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
That's a good news for lockdep. (And even for DEPT :)
He :) Where do you currently store the additional per-page information?
lockdep doesn't need to store per-page information. Possibly DEPT doesn't either.
That would be even better.
[...]
Quoted 3 lines
maybe you put the folio which is locked on a queue or an lru or whatever.
For readahead, I think that queues / lru are not involved. We submit the I/O, and once the I/O is done, we unlock the folio from interrupt context.
end_buffer_async_read() / iomap_finish_folio_read() end up calling folio_end_read(), where we do the magic
folio_wake_bit(folio, PG_locked);
It's interesting, that for writeback we never unlock the folio on the I/O path, but instead have the dedicated page flag to tell us when writeback is complete.
Quoted 9 lines
There is no way to say "that queue owns this lock". Maybe that could usefully be added - assuming coherent semantics can be designed.
Somewhere else some other task takes responsibility for that folio and the lock. maybe it dequeues a page, or maybe an lru callback gives the locked page to some code.
That code then calls
lock_map_acquire_try(&the_lock_map)
I'd assume that's what the unlock path would do from interrupt context.
Quoted 9 lines
This says "this task is now holding this lock" (or more accurately "now holding a lock of this class").
Note the "_try" - that says that the task didn't have to wait for the lock, it just got it for free, which in fact it did.Now if that task takes some other lock, lockdep will see a dependency between the page lock and the new lock, and will accept or reject it as you would expect.
I guess on the interrupt path, we primarily unlock the folio lock only. But we might take some other spinlocks temporarily indeed, like iomap_finish_folio_read() does.
Quoted 2 lines
But I'd like to see a coherent
explanation of how the functionality offered by DEPT is clearly better.
Yes, that's also what I am missing.
Stating that lockdep is stable and should not be destabilized is not really a good argument.
Signature · 3 lines
Cheers, David
Quoted 11 lines · David Hildenbrand (Arm)
Hi!
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
That's a good news for lockdep. (And even for DEPT :)
He :) Where do you currently store the additional per-page information?
lockdep doesn't need to store per-page information. Possibly DEPT doesn't either.
That would be even better.
A little bit more on this:
lockdep *does* store per-lock information - a "struct lockdep_map". I don't fully understand how it is used, but it seems to be mostly for convenience and performance.
When you lock something, lockdep need to know what class the lock belongs to. The lockdep_map maps from the lock to the class so the caller doesn't have to explicitly identify the class every time. The lockdep_map also contains a "name" and some wait_types which I *think* are only used for more descriptive error messages. There is also a "class_cache" which makes it easier (faster) for lockdep to find the target class for different subclasses.
rhashtables "bucket_table" is an existence proof there there doesn't need to be a lockdep_map for each lock. Every bucket has its own bit-spin-lock, but there is only one lockdep_map that they all shared.
You could conceivably put a lockdep_map in each "struct address_space" for folio locks (assuming all lockable folios still belong to some address_space).
Quoted 9 lines
[...]
Quoted 3 lines
maybe you put the folio which is locked on a queue or an lru or whatever.
For readahead, I think that queues / lru are not involved. We submit the I/O, and once the I/O is done, we unlock the folio from interrupt context.
"submit the I/O" means "attach the page to a "struct bio" (or similar) and attach the struct bio to a transmit queue for the device (or similar). So there really is a queue.
Quoted 5 lines
end_buffer_async_read()/iomap_finish_folio_read()end up callingfolio_end_read(), where we do the magicfolio_wake_bit(folio, PG_locked);
Exactly where the lock ownership should be reclaimed is not immediately clear to me. bio_endio() might be early enough but there are probably better points.
A small difficulty here is that a bio has multiple folios and they are all locked. I cannot see that lockdep has a concept of holding an arbitrarily large set of related locks.
We could just tell lockdep
"I have some folios locked"
or maybe enhance lockdep to allow
"I have N folios locked"
or even
"I have N folios in address-space A with the highest offset being O".
This would allow lockdep to check the validity of locking another folio
- only allowed if the address space is the same and the offset is larger than the previous largest.
Quoted 3 lines
It's interesting, that for writeback we never unlock the folio on the I/O path, but instead have the dedicated page flag to tell us when writeback is complete.
PG_locked and PG_writeback are two different lock-bits with two different meanings.
When a folio is PG_locked the content is invalid and shouldn't be accessed. When a folio is in PG_writeback its data is not safe even though PG_dirty has been cleared (if I remember correctly).
So these are two separate, though related, lock bits that would both need to be tracked. lockdep would detect how they are related.
Quoted 5 lines
Quoted 5 lines
There is no way to say "that queue owns this lock". Maybe that could usefully be added - assuming coherent semantics can be designed.
Quoted 7 lines
Quoted 5 lines
Somewhere else some other task takes responsibility for that folio and the lock. maybe it dequeues a page, or maybe an lru callback gives the locked page to some code.
That code then calls
lock_map_acquire_try(&the_lock_map)I'd assume that's what the unlock path would do from interrupt context.
exactly.
Quoted 7 lines
Quoted 7 lines
This says "this task is now holding this lock" (or more accurately "now holding a lock of this class").
Note the "_try" - that says that the task didn't have to wait for the lock, it just got it for free, which in fact it did.
Quoted 7 lines
Quoted 3 lines
Now if that task takes some other lock, lockdep will see a dependency between the page lock and the new lock, and will accept or reject it as you would expect.
I guess on the interrupt path, we primarily unlock the folio lock only. But we might take some other spinlocks temporarily indeed, like
iomap_finish_folio_read()does.
Yes. It is hard to see there being locking problems in interrupt handlers as the folio locks are sleeping locks and an interrupt handler can only take atomic locks, so getting the ordering wrong is likely impossible.
You would be more likely to see problems in a workqueue which takes the completely IO and does something with it, maybe verify a checksum or whatever (it is a long time since I've worked in the block layer).
Quoted 9 lines
Quoted 4 lines
But I'd like to see a coherent
explanation of how the functionality offered by DEPT is clearly better.Yes, that's also what I am missing.
Stating that lockdep is stable and should not be destabilized is not really a good argument.
No it is not. We change "stable" things all the time. Replacing one big thing with another big thing is almost always rejected. Incremental development is the preferred approach.
So developing something like DEPT to explore and learn and demonstrate a cool idea is great. Making it completely separate can give a developer freedom to innovate.
But the path from there to upstream acceptance is to take the lessons learned and to apply them one by one to the existing tools. Yes, that takes longer. Yes it can be frustrating. Yes you need to be able to work with people - not just code - to bring the community along with you.
But the result is generally much better.
Thanks,
NeilBrown
Quoted 6 lines
Signature · 4 lines
-- Cheers, David
Matthew Wilcox
maintainerQuoted 27 lines · NeilBrown
Quoted 2 lines
For readahead, I think that queues / lru are not involved. We submit the I/O, and once the I/O is done, we unlock the folio from interrupt context.
"submit the I/O" means "attach the page to a "struct bio" (or similar) and attach the struct bio to a transmit queue for the device (or similar). So there really is a queue.
Quoted 5 lines
end_buffer_async_read()/iomap_finish_folio_read()end up callingfolio_end_read(), where we do the magicfolio_wake_bit(folio, PG_locked);Exactly where the lock ownership should be reclaimed is not immediately clear to me.
bio_endio()might be early enough but there are probably better points.A small difficulty here is that a bio has multiple folios and they are all locked. I cannot see that lockdep has a concept of holding an arbitrarily large set of related locks.
We could just tell lockdep
"I have some folios locked"
or maybe enhance lockdep to allow
"I have N folios locked"
or even
"I have N folios in address-space A with the highest offset being O".
Quoted 3 lines
This would allow lockdep to check the validity of locking another folio
- only allowed if the address space is the same and the offset is larger than the previous largest.
It's more complex than that; see my other emails on the subject.
I think we need the ability for lockdep to call a function which says "I hold this lock, is that lock OK to acquire". But the devil is in the details.
Quoted 4 lines
Quoted 3 lines
It's interesting, that for writeback we never unlock the folio on the I/O path, but instead have the dedicated page flag to tell us when writeback is complete.
Quoted 8 lines
PG_lockedandPG_writebackare two different lock-bits with two different meanings.
When a folio isPG_lockedthe content is invalid and shouldn't be accessed. When a folio is inPG_writebackits data is not safe even thoughPG_dirtyhas been cleared (if I remember correctly).So these are two separate, though related, lock bits that would both need to be tracked. lockdep would detect how they are related.
Some history ... before we had PG_writeback, we held PG_locked throughout the writeback process. People argued convincingly that it was fine to map a page into a process's address space (which requires PG_locked) while it was being written back. And so PG_locked was split. Now we take PG_locked at the beginning of the writeback process and downgrade to PG_writeback at some point.
Quoted 28 lines · Matthew Wilcox
Quoted 27 lines · NeilBrown
Quoted 2 lines
For readahead, I think that queues / lru are not involved. We submit the I/O, and once the I/O is done, we unlock the folio from interrupt context.
"submit the I/O" means "attach the page to a "struct bio" (or similar) and attach the struct bio to a transmit queue for the device (or similar). So there really is a queue.
Quoted 5 lines
end_buffer_async_read()/iomap_finish_folio_read()end up callingfolio_end_read(), where we do the magicfolio_wake_bit(folio, PG_locked);Exactly where the lock ownership should be reclaimed is not immediately clear to me.
bio_endio()might be early enough but there are probably better points.A small difficulty here is that a bio has multiple folios and they are all locked. I cannot see that lockdep has a concept of holding an arbitrarily large set of related locks.
We could just tell lockdep
"I have some folios locked"
or maybe enhance lockdep to allow
"I have N folios locked"
or even
"I have N folios in address-space A with the highest offset being O".
Quoted 5 lines
Quoted 3 lines
This would allow lockdep to check the validity of locking another folio
- only allowed if the address space is the same and the offset is larger than the previous largest.It's more complex than that; see my other emails on the subject.
It always is more complex that you think, isn't it...
though I found
https://lore.kernel.org/all/[email protected]/
and think that you are saying the same thing as me, though I'm probably not saying it as clearly.
To say what I think you were saying, but with possibly different words:
We don't want to tell lockdep that we are locking a "folio". The particular folio is irrelevant. Rather we want to tell lockdep that we are locking something at a particular offset of some array of folios.
The vfs_lock_two_folios example is much like lock_two_nondirectories(). We use the subclass mechanism to tell lockdep "trust me, this is OK".
Quoted 4 lines
I think we need the ability for lockdep to call a function which says "I hold this lock, is that lock OK to acquire". But the devil is in the details.
I doubt we need arbitrary callbacks. lockdep doesn't try to prove the locking is correct, it just tries to prove that the information we have given it is consistent. So if you say:
spin_lock(some_lock); spin_lock_nested(other_lock, 1);
and later say
spin_lock(other_lock); spin_lock_nested(some_lock, 1);
lockdep will say "fine, that look good", while you or I would say "hang on, that looks weird".
Similarly for folios we just need to decide what information we want to give lockdep, and how it should manipulate that information.
I think that locks on ranges of an address-space is the sort of abstraction that would be most useful. But if you thought a different abstraction would be more useful I would certainly be open to that.
As an aside, d_walk() needs to lock a dentry, then lock a child while holding the parent lock, then drop the original lock and move down the tree. i.e. it wants an arbitrarily lock sequence of overlapping locks. lockdep doesn't have any direct way to express this. It has subclasses so that it is OK to lock the child while holding a lock on the parent, but there is a smallish limit to the number of subclasses. So d_walk() tells lockdep it is dropping the subclass lock on a dentry, then taking (try_lock) a primary lock on the same dentry. This is a "white lie" that leaves lockdep with almost full knowledge but without confusing it.
This example highlights the idea that lockdep doesn't need to know exactly what is going on, it just needs to know about the stuff we want it to check.
Thanks,
NeilBrown
David Hildenbrand (Arm)
maintainerQuoted 12 lines
Quoted 11 lines
Quoted 2 lines
It's interesting, that for writeback we never unlock the folio on the I/O path, but instead have the dedicated page flag to tell us when writeback is complete.
PG_lockedandPG_writebackare two different lock-bits with two different meanings.
When a folio isPG_lockedthe content is invalid and shouldn't be accessed. When a folio is inPG_writebackits data is not safe even thoughPG_dirtyhas been cleared (if I remember correctly).So these are two separate, though related, lock bits that would both need to be tracked. lockdep would detect how they are related.
Quoted 6 lines
Some history ... before we had
PG_writeback, we heldPG_lockedthroughout the writeback process. People argued convincingly that it was fine to map a page into a process's address space (which requiresPG_locked) while it was being written back. And soPG_lockedwas split. Now we takePG_lockedat the beginning of the writeback process and downgrade toPG_writebackat some point.
Right, conceptually I would have thought we could do something similar on the readahead path. PG_uptodate is likely not what we want I suspect.
Not that such a change would be easy, or that we should do it; just one thing that came to mind.
Signature · 3 lines
Cheers, David
David Hildenbrand (Arm)
maintainerQuoted 9 lines
Quoted 8 lines
Quoted 3 lines
But I'd like to see a coherent
explanation of how the functionality offered by DEPT is clearly better.Yes, that's also what I am missing.
Stating that lockdep is stable and should not be destabilized is not really a good argument.
Quoted 12 lines
No it is not. We change "stable" things all the time. Replacing one big thing with another big thing is almost always rejected. Incremental development is the preferred approach.
So developing something like DEPT to explore and learn and demonstrate a cool idea is great. Making it completely separate can give a developer freedom to innovate.
But the path from there to upstream acceptance is to take the lessons learned and to apply them one by one to the existing tools. Yes, that takes longer. Yes it can be frustrating. Yes you need to be able to work with people - not just code - to bring the community along with you.
But the result is generally much better.
I mean, I agree, and that's likely the direction DEPT should take.
... unless there is something so fundamental different that it cannot possibly be integrated into lockdep ... or can but overcomplicates things such that it really must stay separate.
Signature · 3 lines
Cheers, David
Quoted 17 lines · NeilBrown
Quoted 16 lines · David Hildenbrand (Arm)
[...]
Quoted 6 lines
Exactly. That's why we use classification e.g. lock class - DEPT also makes use of the concept.
DEPT doesn't use a full map in each page but uses a minimum space for a timestamp in each to track when each starts to wait so as to use the recorded timestamp when the event occurs e.g.
folio_unlock().Thanks for that information!
Quoted 5 lines
Quoted 4 lines
Given that lockdep is a debug feature, and we will at some point allocate struct folio separately, I assume we could just squeeze a "struct
lockdep_map" in there in such debug configs and the world would not collapse.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
That's a good news for lockdep. (And even for DEPT :)
He :) Where do you currently store the additional per-page information?
lockdep doesn't need to store per-page information. Possibly DEPT doesn't either.
Class can be stored in global map, but DEPT needs to keep a timestamp in each page to track when a potential-wait e.g. folio_lock() has been started and to refer to the information on its event e.g. folio_unlock().
Quoted 2 lines
lockdep needs one
lockdep_mapfor each lock class. It would make sense for all folio locks to use the same globallockdep_map.
Exactly. Only considering classes, you are right.
Quoted 4 lines
Each specific lock is known to lockdep as a task which holds the lock, a
lockdep_mapwhich represents the class of locks, and subclass number which allows a given task to hold multiple locks of the same class providing it declare (e.g. withspin_lock_nested()etc).
Right, lockdep works that way.
Quoted 57 lines
Quoted 41 lines
Quoted 11 lines
Quoted 5 lines
Doing that today (one "struct
lockdep_map" in each "struct page") wouldn't work asmm_zero_struct_page()would not expect such large "struct page". But conceptually, for a debug kernel with a specialCONFIG_LOCKDEP_PAGE_LOCK, maybe that would already be ok and we could just do that (and optimize it as we allocate folios separately).Sounds great.
Quoted 2 lines
Not that it's ideal, but for a debug feature to at least check
PG_lock, probably an easier way to achieve it than some completely new infrastructure.Quoted 6 lines
I understand what you are going to tell.
However, it's worth noting that lockdep tracks dependencies basically based on **lock acqusition orders** in the system. To make it track even rwlock and general synchronization mechanism as well, lockdep has no choice but to get more complicated.
Well, yes, sure :)
Quoted 21 lines
Focusing on only the dependency checking, the most parts of lockdep are for the tricky things, so the reusable parts are not that big.
Quoted 3 lines
Now, Willy said "locking rules don't really apply to individual folios", I wonder if that could just help to also let lockdep check
PG_lockwith less metadata? (didn't fully wrap my head around the implications)That's what DEPT did and what brought external wgen introduced in DEPT. I was considering the exactly same thing :)
Again, lockdep that tracks lock acquisition orders can't do that.
Quoted 7 lines
[1]
https://lore.kernel.org/all/[email protected]/?utm_source=chatgpt.comIt's your guiding example, that's why I mention it. You do mention other wait cases here, I don't know anything about them, but for folios it's really just "we used a single bit so far" AFAIKs.
Quoted 6 lines
Quoted 3 lines
It doesn't matter whether it's implemented using bit or not. folio lock is quite special since it's allowed to be released other than the acquisition context that makes lockdep impossible to track them.
Does that really make lockdep *impossible* to track them? IOW, there is no way to extend lockdep to support lock release in different context?
Yes and no....
lockdep has no knowledge of control flows moving across threads in the way that I assume DEPT does. But it should be possible to tell it.
If you have some code that takes a lock and then hands it off to another thread, at the hand-off point you call
lock_map_release(&the_lock_map)
Quoted 7 lines
This says "no task owns this lock any more".
maybe you put the folio which is locked on a queue or an lru or whatever.
There is no way to say "that queue owns this lock". Maybe that could usefully be added - assuming coherent semantics can be designed.
It's certainly useful to track who owns the lock, but the essence, when it comes to deadlock detection, lies elsewhere. DEPT is based on the essence, that is, a deadlock comes from waits that are never awakened.
Quoted 6 lines
Somewhere else some other task takes responsibility for that folio and the lock. maybe it dequeues a page, or maybe an lru callback gives the locked page to some code.
That code then calls
lock_map_acquire_try(&the_lock_map)
Quoted 8 lines
This says "this task is now holding this lock" (or more accurately "now holding a lock of this class").
Note the "_try" - that says that the task didn't have to wait for the lock, it just got it for free, which in fact it did.Now if that task takes some other lock, lockdep will see a dependency between the page lock and the new lock, and will accept or reject it as you would expect.
It's an interesting approach if your goal is to track the owenership, but if the goal is for tracking dependencies.. well.. I'm not sure.
Byungchul
Quoted 121 lines
So you definitely *can* send lock dependency information between tasks with lockdep. I have only tried it in extremely simple cases where a single object is being locked by one task and unlocked by another - no queues or lists.
There may be - and probably are - more complexities involved with locking folios and passing them around. Maybe it is so complex that you need all the support that DEPT provides. But I'd like to see a coherent explanation of how the functionality offered by DEPT is clearly better.NeilBrown
Quoted 109 lines
I guess there is a way, but the question is at which price (I seriously have no idea, maybe this was already discussed and people have a pointer for me).
Quoted 11 lines
Quoted 11 lines
[...]
Quoted 7 lines
Q. Why not build DEPT into lockdep?
A. Lockdep is stable, battle-tested code. I chose separation because
while DEPT borrows BFS and hashing ideas, the wait/event model requires rebuilding from scratch. Lockdep was designed for lock acquisition order — retrofitting it would risk its stability.Quoted 5 lines
Quoted 3 lines
Why can't this just be some configurable extension to lockdep (
CONFIG_LOCKDEP_XYZ) until the feature is stable and can unconditionally be enabled along with it?Answered?
Not quite. I don't understand why this must be a completely separate machinery, even if, conceptually, it would do more than traditional lockdep.
Is it either DEPT or LOCKDEP in current configurations? Can both run at the same time?
Quoted 9 lines
Quoted 3 lines
I don't quite buy the "would risk its stability" argument. A lot of stuff we do "risks stability", every day :)
That's awsome anyway :)
Quoted 2 lines
Is there another good reason (incompatible with X, dangerous with Y, cinfusing
Z) why this really must be a separate thing?Quoted 8 lines
Roughly:
1. Similar or less effort is needed for the new one - retrofitting lockdep is not easy and big changes are required since the reusable parts are not that big.
2. Even though you didn't agree, retrofitting it would risk its stability.
Well, I don't buy the stability argument, really :)
Retrofitting effort for lockdep is an interesting point, though. Lockdep maintainers would have to make the call here regarding direction and feasibility.
[...]
Quoted 11 lines
Quoted 8 lines
But I am not a locking maintainer. I think there was plenty of discussion in the past, so I might just be raising points that were already discussed in the past, but I really just read some random pieces of earlier discussions. (ideally previous discussions would be summarized here)
Long story short: we are now in v19 and I think there was pushback in the past. Did the opinion of locking maintainers change, or is there a way forward to integrate this in a way that would make locking maintainers accept this?
One of locking maintainers who I met in an LPC told me that he agrees with the direction of DEPT and supports DEPT, not officially tho.
Hm.
Quoted 3 lines
What he and other people are concerning w.r.t DEPT the most is, false positives, which is the most important issue for now.
Thanks for highlighting that. What's the main reason for false positives? Is it something conceptual that is mostly impossible to solve, or rather just implementation work to cover all edge cases?
Quoted 7 lines
At the same time, I think the most important thing is to make DEPT useful in practice especially with folio locks involved. Actually, I'm planning to share DEPT's true reports periodically to LKML and work with people who believe DEPT can make things better.
Any advices will be welcome. Thanks for your opinions.
I think we must come to some conclusion on how to proceed with DEPT. I see the following options:
(1) Don't merge it and carry it OOT. Shame if it delivers real value.
(2) Merge it (after proper review and acks from relevant maintainers ;) ), keeping it entirely separate from lockdep.
(3) Integrate it with lockdep on a high level, giving us a single locking dependency checker, but mostly letting dept have a separate implementation. Look into possible merging afterwards.
(4) Retrofit and extend lockdep to really have one mechanism.
As the saying goes, it's hard to teach old dogs new tricks, but in the end taking care of two dogs is likely harder than only a single dog? :)
I tend to favor (4) (or 3 with possible future work to achieve 4), but I am not a locking maintainer, so really they have to voice what to do.
I do see value in DEPT (even if the folio lock might be handled differently).
--
Cheers,David
Quoted 20 lines · Byungchul Park
Quoted 19 lines · NeilBrown
Quoted 18 lines · David Hildenbrand (Arm)
[...]
Quoted 6 lines
Exactly. That's why we use classification e.g. lock class - DEPT also makes use of the concept.
DEPT doesn't use a full map in each page but uses a minimum space for a timestamp in each to track when each starts to wait so as to use the recorded timestamp when the event occurs e.g.
folio_unlock().Thanks for that information!
Quoted 6 lines
Quoted 4 lines
Given that lockdep is a debug feature, and we will at some point allocate struct folio separately, I assume we could just squeeze a "struct
lockdep_map" in there in such debug configs and the world would not collapse.That's a good news for lockdep. (And even for DEPT :)
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
He :) Where do you currently store the additional per-page information?
lockdep doesn't need to store per-page information. Possibly DEPT doesn't either.
Class can be stored in global map, but DEPT needs to keep a timestamp in each page to track when a potential-wait e.g.
folio_lock()has been started and to refer to the information on its event e.g.folio_unlock().
A timestamp? What does that do?
There is a lot of detail in your cover letter, but I think there is a lot missing too. I would like to understand how DEPT works, but I don't want to dig too hard. The document in patch 25/40 helps a bit, but it is still a bit vague.
Where is the document which would explain at a level that would help me understand this timestamp?
Quoted 75 lines
Quoted 3 lines
lockdep needs one
lockdep_mapfor each lock class. It would make sense for all folio locks to use the same globallockdep_map.Exactly. Only considering classes, you are right.
Quoted 4 lines
Each specific lock is known to lockdep as a task which holds the lock, a
lockdep_mapwhich represents the class of locks, and subclass number which allows a given task to hold multiple locks of the same class providing it declare (e.g. withspin_lock_nested()etc).Right, lockdep works that way.
Quoted 62 lines
Quoted 41 lines
Quoted 11 lines
Quoted 5 lines
Doing that today (one "struct
lockdep_map" in each "struct page") wouldn't work asmm_zero_struct_page()would not expect such large "struct page". But conceptually, for a debug kernel with a specialCONFIG_LOCKDEP_PAGE_LOCK, maybe that would already be ok and we could just do that (and optimize it as we allocate folios separately).Sounds great.
Quoted 2 lines
Not that it's ideal, but for a debug feature to at least check
PG_lock, probably an easier way to achieve it than some completely new infrastructure.Quoted 6 lines
I understand what you are going to tell.
However, it's worth noting that lockdep tracks dependencies basically based on **lock acqusition orders** in the system. To make it track even rwlock and general synchronization mechanism as well, lockdep has no choice but to get more complicated.
Well, yes, sure :)
Quoted 21 lines
Focusing on only the dependency checking, the most parts of lockdep are for the tricky things, so the reusable parts are not that big.
Quoted 3 lines
Now, Willy said "locking rules don't really apply to individual folios", I wonder if that could just help to also let lockdep check
PG_lockwith less metadata? (didn't fully wrap my head around the implications)That's what DEPT did and what brought external wgen introduced in DEPT. I was considering the exactly same thing :)
Again, lockdep that tracks lock acquisition orders can't do that.
Quoted 7 lines
[1]
https://lore.kernel.org/all/[email protected]/?utm_source=chatgpt.comIt's your guiding example, that's why I mention it. You do mention other wait cases here, I don't know anything about them, but for folios it's really just "we used a single bit so far" AFAIKs.
Quoted 6 lines
Quoted 3 lines
It doesn't matter whether it's implemented using bit or not. folio lock is quite special since it's allowed to be released other than the acquisition context that makes lockdep impossible to track them.
Does that really make lockdep *impossible* to track them? IOW, there is no way to extend lockdep to support lock release in different context?
Yes and no....
lockdep has no knowledge of control flows moving across threads in the way that I assume DEPT does. But it should be possible to tell it.
If you have some code that takes a lock and then hands it off to another thread, at the hand-off point you call
lock_map_release(&the_lock_map)This says "no task owns this lock any more".
maybe you put the folio which is locked on a queue or an lru or whatever.
Quoted 6 lines
Quoted 2 lines
There is no way to say "that queue owns this lock". Maybe that could usefully be added - assuming coherent semantics can be designed.
It's certainly useful to track who owns the lock, but the essence, when it comes to deadlock detection, lies elsewhere. DEPT is based on the essence, that is, a deadlock comes from waits that are never awakened.
I disagree.
The "essence" of deadlock detection involves the interplay of ownership and waiting.
In your cover letter "THE DEPT APPROACH" talks about [S] where and event context begins, and [E] where the even occurs. This S-E section is exactly ownership. During that time something "owns" the event. Maybe the terminology is different, but the concept is the same.
Quoted 12 lines
Quoted 12 lines
Somewhere else some other task takes responsibility for that folio and the lock. maybe it dequeues a page, or maybe an lru callback gives the locked page to some code.
That code then calls
lock_map_acquire_try(&the_lock_map)This says "this task is now holding this lock" (or more accurately "now holding a lock of this class").
Note the "_try" - that says that the task didn't have to wait for the lock, it just got it for free, which in fact it did.
Quoted 6 lines
Quoted 3 lines
Now if that task takes some other lock, lockdep will see a dependency between the page lock and the new lock, and will accept or reject it as you would expect.
It's an interesting approach if your goal is to track the owenership, but if the goal is for tracking dependencies.. well.. I'm not sure.
I am sure. Dependencies are between waiters and owners.
A strong theme in your cover letter is the need to add comprehensive annotation for DEPT to work.
My position is that most of what we need for LOCKDEP to be able to detect exactly the same things is appropriate annotation.
We need to annotate when ownership is handed off to another thread, and when the other thread takes on ownership.
So what does your scheme provide that is clearly better? Is the annotation easier? Is some of it automatic? Does if give better error reports?
I had a look through dept.rst and it seems that if a lock is released by a different thread than the one which took the lock, then DEPT can detect that and do something useful. That might be interesting. But how does it know when it first took ownership of that lock? Or you use your terminology: how does it know when that lock first entered the context in that thread?
Maybe when you see an "unlock", you assume the lock has been owned since the last time the context didn't hold hold any locks. Would that be right?
Surely it wouldn't the too hard to teach lockdep about that. i.e. when a lock, which is allowed to migrate across threads, is released though it wasn't held - insert this lock at the top of the current context and re-assess all the wait points.
How do you decide that a lock that was taken is no longer part of the current context?
NeilBrown
On Fri, Aug 21, 2026 at 09:56:05AM +0200, David Hildenbrand (Arm) wrote:
[...]
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Q. Why not build DEPT into lockdep?
A. Lockdep is stable, battle-tested code. I chose separation because
while DEPT borrows BFS and hashing ideas, the wait/event model requires rebuilding from scratch. Lockdep was designed for lock acquisition order — retrofitting it would risk its stability.Why can't this just be some configurable extension to lockdep (
CONFIG_LOCKDEP_XYZ) until the feature is stable and can unconditionally be enabled along with it?
Quoted 7 lines
Quoted 1 line
Answered?
Not quite. I don't understand why this must be a completely separate machinery, even if, conceptually, it would do more than traditional lockdep.
Is it either DEPT or LOCKDEP in current configurations? Can both run at the same time?
Yes.
Quoted 40 lines
Quoted 9 lines
Quoted 3 lines
I don't quite buy the "would risk its stability" argument. A lot of stuff we do "risks stability", every day :)
That's awsome anyway :)
Quoted 2 lines
Is there another good reason (incompatible with X, dangerous with Y, cinfusing
Z) why this really must be a separate thing?Quoted 8 lines
Roughly:
1. Similar or less effort is needed for the new one - retrofitting lockdep is not easy and big changes are required since the reusable parts are not that big.
2. Even though you didn't agree, retrofitting it would risk its stability.
Well, I don't buy the stability argument, really :)
Retrofitting effort for lockdep is an interesting point, though. Lockdep maintainers would have to make the call here regarding direction and feasibility.
[...]
Quoted 11 lines
Quoted 8 lines
But I am not a locking maintainer. I think there was plenty of discussion in the past, so I might just be raising points that were already discussed in the past, but I really just read some random pieces of earlier discussions. (ideally previous discussions would be summarized here)
Long story short: we are now in v19 and I think there was pushback in the past. Did the opinion of locking maintainers change, or is there a way forward to integrate this in a way that would make locking maintainers accept this?
One of locking maintainers who I met in an LPC told me that he agrees with the direction of DEPT and supports DEPT, not officially tho.
Hm.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
What he and other people are concerning w.r.t DEPT the most is, false positives, which is the most important issue for now.
Thanks for highlighting that. What's the main reason for false positives? Is it something conceptual that is mostly impossible to solve, or rather just implementation work to cover all edge cases?
It's because of lack of annotations for proper classification. As Willy mentioned, different call paths for various usages should be annotated with different classes throughout the kernel.
Quoted 15 lines
Quoted 6 lines
At the same time, I think the most important thing is to make DEPT useful in practice especially with folio locks involved. Actually, I'm planning to share DEPT's true reports periodically to LKML and work with people who believe DEPT can make things better.
Any advices will be welcome. Thanks for your opinions.
I think we must come to some conclusion on how to proceed with DEPT. I see the following options:
(1) Don't merge it and carry it OOT. Shame if it delivers real value.
(2) Merge it (after proper review and acks from relevant maintainers ;) ), keeping it entirely separate from lockdep.
Quoted 8 lines
(3) Integrate it with lockdep on a high level, giving us a single locking dependency checker, but mostly letting dept have a separate implementation. Look into possible merging afterwards.
(4) Retrofit and extend lockdep to really have one mechanism.
As the saying goes, it's hard to teach old dogs new tricks, but in the end taking care of two dogs is likely harder than only a single dog? :)
Or it's better to train a unmatured hunting dog than to teach a pet dog, how to hunt, for better hunting, even though the pet dog might eventually become able to.
Quoted 2 lines
I tend to favor (4) (or 3 with possible future work to achieve 4), but I am not a locking maintainer, so really they have to voice what to do.
Right. However, thanks for your opinion.
Quoted 1 line
I do see value in DEPT (even if the folio lock might be handled differently).
Thanks!
Byungchul
Quoted 5 lines
--
Cheers,David
David Hildenbrand (Arm)
maintainerQuoted 7 lines
Quoted 3 lines
As the saying goes, it's hard to teach old dogs new tricks, but in the end taking care of two dogs is likely harder than only a single dog? :)
Or it's better to train a unmatured hunting dog than to teach a pet dog, how to hunt, for better hunting, even though the pet dog might eventually become able to.
I'm not sure whether "pet dog" is the right analogy to lockdep in that scenario, though ;)
Signature · 3 lines
Cheers, David
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 6 lines
Quoted 2 lines
As the saying goes, it's hard to teach old dogs new tricks, but in the end taking care of two dogs is likely harder than only a single dog? :)
Or it's better to train a unmatured hunting dog than to teach a pet dog, how to hunt, for better hunting, even though the pet dog might eventually become able to.
I'm not sure whether "pet dog" is the right analogy to lockdep in that scenario, though ;)
Ah. Okay. I will be careful in using terms.
I wanted to tell DEPT has its strength, lockdep has its own, and they are different.
Byungchul
Quoted 5 lines
--
Cheers,David