[PATCH v2 12/18] mm/ksw: add self-debug functions for kstackwatch watch

Jinchao Wang
2025-09-04T00:23:40Z

Introduce ksw_watch_show() and ksw_watch_fire() for runtime debugging of
kstackwatch's watch mechanism:

- ksw_watch_show(): prints the currently armed watch address and length
- ksw_watch_fire(): forcibly triggers the watch by writing to the watched
address

These functions help validate the dynamic watch behavior and facilitate
testing without requiring real events.

Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
---
mm/kstackwatch/kstackwatch.h | 2 ++
mm/kstackwatch/watch.c | 17 ++++++++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/mm/kstackwatch/kstackwatch.h b/mm/kstackwatch/kstackwatch.h
index bc8664af4fa6..d1bb5ae75aae 100644
--- a/mm/kstackwatch/kstackwatch.h
+++ b/mm/kstackwatch/kstackwatch.h
@@ -47,5 +47,7 @@ int ksw_watch_init(struct ksw_config *config);
void ksw_watch_exit(void);
int ksw_watch_on(u64 watch_addr, u64 watch_len);
void ksw_watch_off(void);
+void ksw_watch_show(void);
+void ksw_watch_fire(void);

#endif /* _KSTACKWATCH_H */
diff --git a/mm/kstackwatch/watch.c b/mm/kstackwatch/watch.c
index c563f8d17829..8f3f6cb9f17a 100644
--- a/mm/kstackwatch/watch.c
+++ b/mm/kstackwatch/watch.c
@@ -116,7 +116,6 @@ int ksw_watch_on(u64 watch_addr, u64 watch_len)
ksw_watch_on_local_cpu(&watch_info);
} else {
call_single_data_t *csd = &per_cpu(watch_csd, cpu);
-
smp_call_function_single_async(cpu, csd);
}
}
@@ -158,3 +157,19 @@ void ksw_watch_exit(void)

pr_info("KSW: watch exited\n");
}
+
+/* self debug function */
+void ksw_watch_show(void)
+{
+ pr_info("KSW: watch target bp_addr: 0x%llx len:%llu\n",
+ watch_info.addr, watch_info.len);
+}
+
+/* self debug function */
+void ksw_watch_fire(void)
+{
+ char *ptr = (char *)watch_info.addr;
+
+ pr_warn("KSW: watch triggered immediately\n");
+ *ptr = 0x42; // This should trigger immediately
+}
--
2.43.0