[PATCH v17 18/47] dept: track timeout waits separately with a new Kconfig

Byungchul Park
2025-10-02T08:13:41Z

Waits 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.

Signed-off-by: Byungchul Park <byungchul@sk.com>
---
include/linux/dept.h | 13 +++++---
include/linux/dept_ldt.h | 6 ++--
include/linux/dept_sdt.h | 13 +++++---
include/linux/sched.h | 2 ++
kernel/dependency/dept.c | 66 ++++++++++++++++++++++++++++++++++------
lib/Kconfig.debug | 10 ++++++
6 files changed, 89 insertions(+), 21 deletions(-)

diff --git a/include/linux/dept.h b/include/linux/dept.h
index cb1b1beea077..49f457390521 100644
--- a/include/linux/dept.h
+++ b/include/linux/dept.h
@@ -271,6 +271,11 @@ struct dept_wait {
* whether this wait is for commit in scheduler
*/
bool sched_sleep;
+
+ /*
+ * whether a timeout is set
+ */
+ bool timeout;
};
};
};
@@ -377,8 +382,8 @@ extern void dept_free_range(void *start, unsigned int sz);
extern void dept_map_init(struct dept_map *m, struct dept_key *k, int sub_u, const char *n);
extern void dept_map_reinit(struct dept_map *m, struct dept_key *k, int sub_u, const char *n);
extern void dept_map_copy(struct dept_map *to, struct dept_map *from);
-extern void dept_wait(struct dept_map *m, unsigned long w_f, unsigned long ip, const char *w_fn, int sub_l);
-extern void dept_stage_wait(struct dept_map *m, struct dept_key *k, unsigned long ip, const char *w_fn);
+extern void dept_wait(struct dept_map *m, unsigned long w_f, unsigned long ip, const char *w_fn, int sub_l, long timeout);
+extern void dept_stage_wait(struct dept_map *m, struct dept_key *k, unsigned long ip, const char *w_fn, long timeout);
extern void dept_request_event_wait_commit(void);
extern void dept_clean_stage(void);
extern void dept_ttwu_stage_wait(struct task_struct *t, unsigned long ip);
@@ -425,8 +430,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)
diff --git a/include/linux/dept_ldt.h b/include/linux/dept_ldt.h
index 8047d0a531f1..730af2517ecd 100644
--- a/include/linux/dept_ldt.h
+++ b/include/linux/dept_ldt.h
@@ -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)
diff --git a/include/linux/dept_sdt.h b/include/linux/dept_sdt.h
index 0535f763b21b..14917df0cc30 100644
--- a/include/linux/dept_sdt.h
+++ b/include/linux/dept_sdt.h
@@ -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)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 05c3f8a45405..95b1450f22fa 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -867,6 +867,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;

/*
@@ -907,6 +908,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, \
diff --git a/kernel/dependency/dept.c b/kernel/dependency/dept.c
index f4c08758f8db..519b2151403e 100644
--- a/kernel/dependency/dept.c
+++ b/kernel/dependency/dept.c
@@ -757,6 +757,8 @@ static void print_diagram(struct dept_dep *d)
if (!irqf) {
print_spc(spc, "[S] %s(%s:%d)\n", c_fn, fc_n, fc->sub_id);
print_spc(spc, "[W] %s(%s:%d)\n", w_fn, tc_n, tc->sub_id);
+ if (w->timeout)
+ print_spc(spc, "--------------- >8 timeout ---------------\n");
print_spc(spc, "[E] %s(%s:%d)\n", e_fn, fc_n, fc->sub_id);
}
}
@@ -810,6 +812,24 @@ static void print_dep(struct dept_dep *d)

static void save_current_stack(int skip);

+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;
+
+ tc = fc;
+ fc = fc->bfs_parent;
+ } while (tc != c);
+
+ return false;
+}
+
/*
* Print all classes in a circle.
*/
@@ -832,10 +852,14 @@ static void print_circle(struct dept_class *c)
pr_warn("summary\n");
pr_warn("---------------------------------------------------\n");

- if (fc == tc)
+ if (is_timeout_wait_circle(c)) {
+ pr_warn("NOT A DEADLOCK BUT A CIRCULAR DEPENDENCY\n");
+ pr_warn("CHECK IF THE TIMEOUT IS INTENDED\n\n");
+ } else if (fc == tc) {
pr_warn("*** AA DEADLOCK ***\n\n");
- else
+ } else {
pr_warn("*** DEADLOCK ***\n\n");
+ }

i = 0;
do {
@@ -1579,7 +1603,8 @@ static int next_wgen(void)
}

static void add_wait(struct dept_class *c, unsigned long ip,
- const char *w_fn, int sub_l, bool sched_sleep)
+ const char *w_fn, int sub_l, bool sched_sleep,
+ bool timeout)
{
struct dept_task *dt = dept_task();
struct dept_wait *w;
@@ -1599,6 +1624,7 @@ static void add_wait(struct dept_class *c, unsigned long ip,
w->wait_fn = w_fn;
w->wait_stack = get_current_stack();
w->sched_sleep = sched_sleep;
+ w->timeout = timeout;

cxt = cur_cxt();
if (cxt == DEPT_CXT_HIRQ || cxt == DEPT_CXT_SIRQ)
@@ -2297,7 +2323,7 @@ static struct dept_class *check_new_class(struct dept_key *local,
*/
static void __dept_wait(struct dept_map *m, unsigned long w_f,
unsigned long ip, const char *w_fn, int sub_l,
- bool sched_sleep, bool sched_map)
+ bool sched_sleep, bool sched_map, bool timeout)
{
int e;

@@ -2320,7 +2346,7 @@ static void __dept_wait(struct dept_map *m, unsigned long w_f,
if (!c)
continue;

- add_wait(c, ip, w_fn, sub_l, sched_sleep);
+ add_wait(c, ip, w_fn, sub_l, sched_sleep, timeout);
}
}

@@ -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,
+ 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;
+
+#if !defined(CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT)
+ if (timeout)
+ return;
+#endif
+
if (dt->recursive)
return;

@@ -2371,21 +2406,30 @@ void dept_wait(struct dept_map *m, unsigned long w_f,

flags = dept_enter();

- __dept_wait(m, w_f, ip, w_fn, sub_l, false, false);
+ __dept_wait(m, w_f, ip, w_fn, sub_l, false, false, timeout);

dept_exit(flags);
}
EXPORT_SYMBOL_GPL(dept_wait);

void dept_stage_wait(struct dept_map *m, struct dept_key *k,
- unsigned long ip, const char *w_fn)
+ unsigned long ip, const char *w_fn,
+ 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;
+
+#if !defined(CONFIG_DEPT_AGGRESSIVE_TIMEOUT_WAIT)
+ if (timeout)
+ return;
+#endif
+
if (m && m->nocheck)
return;

@@ -2434,6 +2478,7 @@ void dept_stage_wait(struct dept_map *m, struct dept_key *k,

dt->stage_w_fn = w_fn;
dt->stage_ip = ip;
+ dt->stage_timeout = timeout;
arch_spin_unlock(&dt->stage_lock);
exit:
dept_exit_recursive(flags);
@@ -2447,6 +2492,7 @@ static void __dept_clean_stage(struct dept_task *dt)
dt->stage_sched_map = false;
dt->stage_w_fn = NULL;
dt->stage_ip = 0UL;
+ dt->stage_timeout = false;
}

void dept_clean_stage(void)
@@ -2479,6 +2525,7 @@ void dept_request_event_wait_commit(void)
unsigned long ip;
const char *w_fn;
bool sched_map;
+ bool timeout;

if (unlikely(!dept_working()))
return;
@@ -2505,12 +2552,13 @@ void dept_request_event_wait_commit(void)
w_fn = dt->stage_w_fn;
ip = dt->stage_ip;
sched_map = dt->stage_sched_map;
+ timeout = dt->stage_timeout;

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);
+ __dept_wait(&dt->stage_m, 1UL, ip, w_fn, 0, true, sched_map, timeout);
exit:
dept_exit(flags);
}
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 3669b069337b..290563fa8b58 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1394,6 +1394,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
--
2.17.1