kgdb: fix to kill breakpoints on initmem after boot
authorSumit Garg <sumit.garg@linaro.org>
Fri, 26 Feb 2021 01:22:38 +0000 (17:22 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 26 Feb 2021 17:41:05 +0000 (09:41 -0800)
Currently breakpoints in kernel .init.text section are not handled
correctly while allowing to remove them even after corresponding pages
have been freed.

Fix it via killing .init.text section breakpoints just prior to initmem
pages being freed.

Doug: "HW breakpoints aren't handled by this patch but it's probably
not such a big deal".

Link: https://lkml.kernel.org/r/20210224081652.587785-1-sumit.garg@linaro.org
Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
Suggested-by: Doug Anderson <dianders@chromium.org>
Acked-by: Doug Anderson <dianders@chromium.org>
Acked-by: Daniel Thompson <daniel.thompson@linaro.org>
Tested-by: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Jason Wessel <jason.wessel@windriver.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/kgdb.h
init/main.c
kernel/debug/debug_core.c

index 0444b44bd156de8e3d1f400c9d5e40309fcfc3a2..392a3670944c6e2daf68080ef75b1e10a09fafe0 100644 (file)
@@ -359,9 +359,11 @@ extern atomic_t                    kgdb_active;
 extern bool dbg_is_early;
 extern void __init dbg_late_init(void);
 extern void kgdb_panic(const char *msg);
+extern void kgdb_free_init_mem(void);
 #else /* ! CONFIG_KGDB */
 #define in_dbg_master() (0)
 #define dbg_late_init()
 static inline void kgdb_panic(const char *msg) {}
+static inline void kgdb_free_init_mem(void) { }
 #endif /* ! CONFIG_KGDB */
 #endif /* _KGDB_H_ */
index 3648c9f948826a49d91f38586ea5099489fc22dc..53b278845b886e1aacd643f6bd7e8902080f525a 100644 (file)
@@ -1426,6 +1426,7 @@ static int __ref kernel_init(void *unused)
        async_synchronize_full();
        kprobe_free_init_mem();
        ftrace_free_init_mem();
+       kgdb_free_init_mem();
        free_initmem();
        mark_readonly();
 
index b636d517c02c463e946b2a0395ca093bb4798c1c..4708aec492df9e54145bfc4084adeb4b21639f5e 100644 (file)
@@ -455,6 +455,17 @@ setundefined:
        return 0;
 }
 
+void kgdb_free_init_mem(void)
+{
+       int i;
+
+       /* Clear init memory breakpoints. */
+       for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
+               if (init_section_contains((void *)kgdb_break[i].bpt_addr, 0))
+                       kgdb_break[i].state = BP_UNDEFINED;
+       }
+}
+
 #ifdef CONFIG_KGDB_KDB
 void kdb_dump_stack_on_cpu(int cpu)
 {