]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ftrace: Have init/main.c call ftrace directly to free init memory
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Mon, 3 Apr 2017 16:57:35 +0000 (12:57 -0400)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Mon, 3 Apr 2017 18:04:00 +0000 (14:04 -0400)
Relying on free_reserved_area() to call ftrace to free init memory proved to
not be sufficient. The issue is that on x86, when debug_pagealloc is
enabled, the init memory is not freed, but simply set as not present. Since
ftrace was uninformed of this, starting function tracing still tries to
update pages that are not present according to the page tables, causing
ftrace to bug, as well as killing the kernel itself.

Instead of relying on free_reserved_area(), have init/main.c call ftrace
directly just before it frees the init memory. Then it needs to use
__init_begin and __init_end to know where the init memory location is.
Looking at all archs (and testing what I can), it appears that this should
work for each of them.

Reported-by: kernel test robot <xiaolong.ye@intel.com>
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
include/linux/ftrace.h
init/main.c
kernel/trace/ftrace.c
mm/page_alloc.c

index 0276a2c487e6276ab085a8de7276982d4a549e29..ef7123219f14ace625b13631220bea78be6ad567 100644 (file)
@@ -147,9 +147,9 @@ struct ftrace_ops_hash {
        struct mutex                    regex_lock;
 };
 
-void ftrace_free_mem(void *start, void *end);
+void ftrace_free_init_mem(void);
 #else
-static inline void ftrace_free_mem(void *start, void *end) { }
+static inline void ftrace_free_init_mem(void) { }
 #endif
 
 /*
@@ -266,7 +266,7 @@ static inline int ftrace_nr_registered_ops(void)
 }
 static inline void clear_ftrace_function(void) { }
 static inline void ftrace_kill(void) { }
-static inline void ftrace_free_mem(void *start, void *end) { }
+static inline void ftrace_free_init_mem(void) { }
 #endif /* CONFIG_FUNCTION_TRACER */
 
 #ifdef CONFIG_STACK_TRACER
index c0137b916aa12ba9fa3e027da4d613bc182e81d2..0e8849f74561b8454bb64ad4bce6ad900e57e8de 100644 (file)
@@ -962,6 +962,7 @@ static int __ref kernel_init(void *unused)
        kernel_init_freeable();
        /* need to finish all async __init code before freeing the memory */
        async_synchronize_full();
+       ftrace_free_init_mem();
        free_initmem();
        mark_readonly();
        system_state = SYSTEM_RUNNING;
index aff7a2c0838775e4411cd6b472ff24fdbb9343e8..8efd9fe7aec0fd093350acb2421c7f0a36a488bb 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <trace/events/sched.h>
 
+#include <asm/sections.h>
 #include <asm/setup.h>
 
 #include "trace_output.h"
@@ -5279,10 +5280,10 @@ void ftrace_module_init(struct module *mod)
 }
 #endif /* CONFIG_MODULES */
 
-void ftrace_free_mem(void *start_ptr, void *end_ptr)
+void __init ftrace_free_init_mem(void)
 {
-       unsigned long start = (unsigned long)start_ptr;
-       unsigned long end = (unsigned long)end_ptr;
+       unsigned long start = (unsigned long)(&__init_begin);
+       unsigned long end = (unsigned long)(&__init_end);
        struct ftrace_page **last_pg = &ftrace_pages_start;
        struct ftrace_page *pg;
        struct dyn_ftrace *rec;
index eee82bfb7cd8e4c456298810e22520b3bfc5c2d5..178bf9c2a2cbdd9084258c15d8af8159268ad70e 100644 (file)
@@ -6606,9 +6606,6 @@ unsigned long free_reserved_area(void *start, void *end, int poison, char *s)
        void *pos;
        unsigned long pages = 0;
 
-       /* This may be .init text, inform ftrace to remove it */
-       ftrace_free_mem(start, end);
-
        start = (void *)PAGE_ALIGN((unsigned long)start);
        end = (void *)((unsigned long)end & PAGE_MASK);
        for (pos = start; pos < end; pos += PAGE_SIZE, pages++) {