This patch connects the watch and stack so that all components function
together.

Signed-off-by: Jinchao Wang <wangjinchao...@gmail.com>
---
 mm/kstackwatch/kernel.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/mm/kstackwatch/kernel.c b/mm/kstackwatch/kernel.c
index 95ade95abde1..4c5fbcaddab0 100644
--- a/mm/kstackwatch/kernel.c
+++ b/mm/kstackwatch/kernel.c
@@ -1,10 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <linux/kern_levels.h>
+#include <linux/kernel.h>
 #include <linux/kstrtox.h>
 #include <linux/module.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/string.h>
 #include <linux/uaccess.h>
+#include <linux/utsname.h>
 
 #include "kstackwatch.h"
 
@@ -22,6 +25,29 @@ MODULE_PARM_DESC(panic_on_catch,
 
 static int ksw_start_watching(void)
 {
+       int ret;
+
+       if (strlen(ksw_config->function) == 0) {
+               pr_err("KSW: no target function specified\n");
+               return -EINVAL;
+       }
+
+       /*
+        * Watch init will preallocate the HWBP,
+        * so it must happen before stack init
+        */
+       ret = ksw_watch_init(ksw_config);
+       if (ret) {
+               pr_err("KSW: ksw_watch_init ret: %d\n", ret);
+               return ret;
+       }
+
+       ret = ksw_stack_init(ksw_config);
+       if (ret) {
+               pr_err("KSW: ksw_stack_init_fprobe ret: %d\n", ret);
+               ksw_watch_exit();
+               return ret;
+       }
        watching_active = true;
 
        pr_info("KSW: start watching %s\n", ksw_config->config_str);
@@ -30,6 +56,8 @@ static int ksw_start_watching(void)
 
 static void ksw_stop_watching(void)
 {
+       ksw_stack_exit();
+       ksw_watch_exit();
        watching_active = false;
 
        pr_info("KSW: stop watching %s\n", ksw_config->config_str);
-- 
2.43.0


Reply via email to