tracing: Ignore mmiotrace from kernel commandline
Subsystems (2)
PATCH v2 1/1 tracing: Ignore mmiotrace from kernel commandline
From: "Ziqian SUN (Zamir)" <[email protected]>
The mmiotrace tracer cannot be enabled with ftrace=mmiotrace in kernel commandline. With this patch, a trace_noboot_tracer_list is implemented and will be checked during system boot. If the tracer declares itself as not for boot up, system will print out a message and continue booting.
--- kernel/trace/trace.c | 34 +++++++++++++++++++++++++++++++++- kernel/trace/trace.h | 11 +++++++++++ kernel/trace/trace_mmiotrace.c | 4 ++++ 3 files changed, 48 insertions(+), 1 deletion(-)
kernel/trace/trace.c +33 -1
@@ -319,6 +319,33 @@ void trace_free_pid_list(struct trace_pid_list *pid_list)kfree (pid_list); } +struct mutex trace_noboot_tracer_lock; + +DEFINE_MUTEX (trace_noboot_tracer_lock); +LIST_HEAD (trace_noboot_tracer_list); + +void trace_noboot_tracer_put (struct tracer_noboot *noboot_tracer) +{ +mutex_lock (&trace_noboot_tracer_lock); +list_add (&noboot_tracer->list, &trace_noboot_tracer_list); +mutex_unlock (&trace_noboot_tracer_lock); +} + +bool trace_noboot_tracer_find (const char *str) +{ +mutex_lock (&trace_noboot_tracer_lock); +struct tracer_noboot *ptr =NULL ; + +list_for_each_entry (ptr, &trace_noboot_tracer_list, list) { +if (strcmp (ptr->name, str) ==0 ) { +mutex_unlock (&trace_noboot_tracer_lock); +return true; + } + } +mutex_unlock (&trace_noboot_tracer_lock); +return false; +} +/** * trace_find_filtered_pid - check if a pid exists in a filtered_pid list * @filtered_pids: The list of pids to check
@@ -1641,8 +1668,13 @@ int __init register_tracer(struct tracer *type)if (strncmp (default_bootup_tracer, type->name,MAX_TRACER_SIZE )) goto out_unlock; +/* If the tracer should not be enabled by kernel parameter */ +if (trace_noboot_tracer_find (type->name)) { +pr_warn ("Tracer '%s' cannot be enabled during boot\n" , type->name); + goto out_unlock; + } +printk (KERN_INFO "Starting tracer '%s'\n" , type->name); -/* Do we want this tracer to start on bootup? */ tracing_set_tracer (&global_trace, type->name); default_bootup_tracer =NULL ;
kernel/trace/trace.h +11 -0
@@ -502,6 +502,17 @@ enum { TRACE_IRQ_BIT, }; +/* +* For tracer that cannot be enabled during boot time. +*/ + +struct tracer_noboot { +const char *name; +struct list_head list; +}; + +void trace_noboot_tracer_put (struct tracer_noboot *noboot_tracer); +#define trace_recursion_set (bit) do { (current)->trace_recursion |= (1<<(bit)); } while (0)#define trace_recursion_clear (bit) do { (current)->trace_recursion &= ~(1<<(bit)); } while (0)#define trace_recursion_test (bit) ((current)->trace_recursion & (1<<(bit)))
kernel/trace/trace_mmiotrace.c +4 -0
@@ -286,6 +286,10 @@ static enum print_line_t mmio_print_line(struct trace_iterator *iter)__init static int init_mmio_trace (void ) { +struct tracer_noboot mmio_notrace; + + mmio_notrace.name ="mmiotrace" ; +trace_noboot_tracer_put (&mmio_notrace);return register_tracer (&mmio_tracer); }device_initcall (init_mmio_trace);
Signature · 1 line
1.8.3.1
Hi Steve,
Is this solution acceptable? Any suggestions?
Thanks.
----- Original Message -----
Quoted 114 lines
From: "Ziqian SUN (Zamir)" <[email protected]>
The mmiotrace tracer cannot be enabled with ftrace=mmiotrace in kernel commandline. With this patch, a
trace_noboot_tracer_listis implemented and will be checked during system boot. If the tracer declares itself as not for boot up, system will print out a message and continue booting.Signed-off-by Ziqian SUN (Zamir) <[email protected]>--- kernel/trace/trace.c | 34 +++++++++++++++++++++++++++++++++- kernel/trace/trace.h | 11 +++++++++++ kernel/trace/trace_mmiotrace.c | 4 ++++ 3 files changed, 48 insertions(+), 1 deletion(-)kernel/trace/trace.c +27
-0@@ -319,6 +319,33 @@ void trace_free_pid_list(struct trace_pid_list *pid_list)kfree (pid_list); } +struct mutex trace_noboot_tracer_lock; + +DEFINE_MUTEX (trace_noboot_tracer_lock); +LIST_HEAD (trace_noboot_tracer_list); + +void trace_noboot_tracer_put (struct tracer_noboot *noboot_tracer) +{ +mutex_lock (&trace_noboot_tracer_lock); +list_add (&noboot_tracer->list, &trace_noboot_tracer_list); +mutex_unlock (&trace_noboot_tracer_lock); +} + +bool trace_noboot_tracer_find (const char *str) +{ +mutex_lock (&trace_noboot_tracer_lock); +struct tracer_noboot *ptr =NULL ; + +list_for_each_entry (ptr, &trace_noboot_tracer_list, list) { +if (strcmp (ptr->name, str) ==0 ) { +mutex_unlock (&trace_noboot_tracer_lock); +return true; + } + } +mutex_unlock (&trace_noboot_tracer_lock); +return false; +} +/** * trace_find_filtered_pid - check if a pid exists in a filtered_pid list * @filtered_pids: The list of pids to check
kernel/trace/trace.c +6
-1@@ -1641,8 +1668,13 @@ int __init register_tracer(struct tracer *type)if (strncmp (default_bootup_tracer, type->name,MAX_TRACER_SIZE )) goto out_unlock; +/* If the tracer should not be enabled by kernel parameter */ +if (trace_noboot_tracer_find (type->name)) { +pr_warn ("Tracer '%s' cannot be enabled during boot\n" , type->name); + goto out_unlock; + } +printk (KERN_INFO "Starting tracer '%s'\n" , type->name); -/* Do we want this tracer to start on bootup? */ tracing_set_tracer (&global_trace, type->name); default_bootup_tracer =NULL ;kernel/trace/trace.h +11
-0@@ -502,6 +502,17 @@ enum { TRACE_IRQ_BIT, }; +/* +* For tracer that cannot be enabled during boot time. +*/ + +struct tracer_noboot { +const char *name; +struct list_head list; +}; + +void trace_noboot_tracer_put (struct tracer_noboot *noboot_tracer); +#define trace_recursion_set (bit) do { (current)->trace_recursion |= (1<<(bit)); } while (0)#define trace_recursion_clear (bit) do { (current)->trace_recursion &=~(1<<(bit)); } while (0)
#definetrace_recursion_test(bit)((current)->trace_recursion & (1<<(bit)))kernel/trace/trace_mmiotrace.c +4
-0@@ -286,6 +286,10 @@ static enum print_line_t mmio_print_line(struct trace_iterator *iter)__init static int init_mmio_trace (void ) { +struct tracer_noboot mmio_notrace; + + mmio_notrace.name ="mmiotrace" ; +trace_noboot_tracer_put (&mmio_notrace);return register_tracer (&mmio_tracer); }
device_initcall(init_mmio_trace);
--
1.8.3.1
Signature · 3 lines
Ziqian SUN (Zamir) Red Hat Red Hat Software (Beijing) Co.,Ltd 1D86 6D4A 49CE 4BBD 72CF FCF5 D856 6E11 F2A0 525E
Steven Rostedt
maintainerQuoted 4 lines · On Fri, 8 Sep 2017 10:02:04 -0400 (EDT) "Ziqian SUN (Zamir)" <[email protected]>…
Hi Steve,
Is this solution acceptable? Any suggestions?
Sorry this patch got buried in other email. I'll take a look at it now.
-- Steve
Steven Rostedt
maintainerQuoted 96 lines · On Wed, 30 Aug 2017 12:19:30 +0800 "Ziqian SUN (Zamir)" <[email protected]> wrote:
From: "Ziqian SUN (Zamir)" <[email protected]>
The mmiotrace tracer cannot be enabled with ftrace=mmiotrace in kernel commandline. With this patch, a
trace_noboot_tracer_listis implemented and will be checked during system boot. If the tracer declares itself as not for boot up, system will print out a message and continue booting.Signed-off-by Ziqian SUN (Zamir) <[email protected]>--- kernel/trace/trace.c | 34 +++++++++++++++++++++++++++++++++- kernel/trace/trace.h | 11 +++++++++++ kernel/trace/trace_mmiotrace.c | 4 ++++ 3 files changed, 48 insertions(+), 1 deletion(-)kernel/trace/trace.c +33
-1@@ -319,6 +319,33 @@ void trace_free_pid_list(struct trace_pid_list *pid_list)kfree (pid_list); } +struct mutex trace_noboot_tracer_lock; + +DEFINE_MUTEX (trace_noboot_tracer_lock); +LIST_HEAD (trace_noboot_tracer_list); + +void trace_noboot_tracer_put (struct tracer_noboot *noboot_tracer) +{ +mutex_lock (&trace_noboot_tracer_lock); +list_add (&noboot_tracer->list, &trace_noboot_tracer_list); +mutex_unlock (&trace_noboot_tracer_lock); +} + +bool trace_noboot_tracer_find (const char *str) +{ +mutex_lock (&trace_noboot_tracer_lock); +struct tracer_noboot *ptr =NULL ; + +list_for_each_entry (ptr, &trace_noboot_tracer_list, list) { +if (strcmp (ptr->name, str) ==0 ) { +mutex_unlock (&trace_noboot_tracer_lock); +return true; + } + } +mutex_unlock (&trace_noboot_tracer_lock); +return false; +} +/** * trace_find_filtered_pid - check if a pid exists in a filtered_pid list * @filtered_pids: The list of pids to check @@ -1641,8 +1668,13 @@ int __init register_tracer(struct tracer *type)if (strncmp (default_bootup_tracer, type->name,MAX_TRACER_SIZE )) goto out_unlock; +/* If the tracer should not be enabled by kernel parameter */ +if (trace_noboot_tracer_find (type->name)) { +pr_warn ("Tracer '%s' cannot be enabled during boot\n" , type->name); + goto out_unlock; + } +printk (KERN_INFO "Starting tracer '%s'\n" , type->name); -/* Do we want this tracer to start on bootup? */ tracing_set_tracer (&global_trace, type->name); default_bootup_tracer =NULL ;kernel/trace/trace.h +11
-0@@ -502,6 +502,17 @@ enum { TRACE_IRQ_BIT, }; +/* +* For tracer that cannot be enabled during boot time. +*/ + +struct tracer_noboot { +const char *name; +struct list_head list; +}; + +void trace_noboot_tracer_put (struct tracer_noboot *noboot_tracer); +#define trace_recursion_set (bit) do { (current)->trace_recursion |= (1<<(bit)); } while (0)#define trace_recursion_clear (bit) do { (current)->trace_recursion &= ~(1<<(bit)); } while (0)#define trace_recursion_test (bit) ((current)->trace_recursion & (1<<(bit)))kernel/trace/trace_mmiotrace.c +0
-0
kernel/trace/trace_mmiotrace.c static enum print_line_t mmio_print_line(struct trace_iterator *iter) · line 295
Quoted 10 lines
kernel/trace/trace_mmiotrace.c +4
-0@@ -286,6 +286,10 @@ static enum print_line_t mmio_print_line(struct trace_iterator *iter)__init static int init_mmio_trace (void ) { +struct tracer_noboot mmio_notrace; + + mmio_notrace.name ="mmiotrace" ; +trace_noboot_tracer_put (&mmio_notrace);return register_tracer (&mmio_tracer); }device_initcall (init_mmio_trace);
This is way overkill. Just add
bool noboot;
to struct tracer in trace.h and then to the mmiotracer:
struct tracer mmio_tracer = {
[..]
.noboot = true,
};And then in tracing_set_tracer() add after:
if (t == tr->current_trace) goto out;
this:
if (system_state < SYSTEM_RUNNING && t->noboot) {
WARN(1, "Tracer %s not allowed on command line",
t->name);
goto out;
}That's it. No need for locking or anything else.
-- Steve
Quoted 135 lines
Quoted 111 lines · On Wed, 30 Aug 2017 12:19:30 +0800 "Ziqian SUN (Zamir)" <[email protected]> wrote:
From: "Ziqian SUN (Zamir)" <[email protected]>
The mmiotrace tracer cannot be enabled with ftrace=mmiotrace in kernel commandline. With this patch, a
trace_noboot_tracer_listis implemented and will be checked during system boot. If the tracer declares itself as not for boot up, system will print out a message and continue booting.Signed-off-by Ziqian SUN (Zamir) <[email protected]>--- kernel/trace/trace.c | 34 +++++++++++++++++++++++++++++++++- kernel/trace/trace.h | 11 +++++++++++ kernel/trace/trace_mmiotrace.c | 4 ++++ 3 files changed, 48 insertions(+), 1 deletion(-)kernel/trace/trace.c +27
-0@@ -319,6 +319,33 @@ void trace_free_pid_list(struct trace_pid_list *pid_list)kfree (pid_list); } +struct mutex trace_noboot_tracer_lock; + +DEFINE_MUTEX (trace_noboot_tracer_lock); +LIST_HEAD (trace_noboot_tracer_list); + +void trace_noboot_tracer_put (struct tracer_noboot *noboot_tracer) +{ +mutex_lock (&trace_noboot_tracer_lock); +list_add (&noboot_tracer->list, &trace_noboot_tracer_list); +mutex_unlock (&trace_noboot_tracer_lock); +} + +bool trace_noboot_tracer_find (const char *str) +{ +mutex_lock (&trace_noboot_tracer_lock); +struct tracer_noboot *ptr =NULL ; + +list_for_each_entry (ptr, &trace_noboot_tracer_list, list) { +if (strcmp (ptr->name, str) ==0 ) { +mutex_unlock (&trace_noboot_tracer_lock); +return true; + } + } +mutex_unlock (&trace_noboot_tracer_lock); +return false; +} +/** * trace_find_filtered_pid - check if a pid exists in a filtered_pid list * @filtered_pids: The list of pids to check
kernel/trace/trace.c +6
-1@@ -1641,8 +1668,13 @@ int __init register_tracer(struct tracer *type)if (strncmp (default_bootup_tracer, type->name,MAX_TRACER_SIZE )) goto out_unlock; +/* If the tracer should not be enabled by kernel parameter */ +if (trace_noboot_tracer_find (type->name)) { +pr_warn ("Tracer '%s' cannot be enabled during boot\n" , type->name); + goto out_unlock; + } +printk (KERN_INFO "Starting tracer '%s'\n" , type->name); -/* Do we want this tracer to start on bootup? */ tracing_set_tracer (&global_trace, type->name); default_bootup_tracer =NULL ;kernel/trace/trace.h +11
-0@@ -502,6 +502,17 @@ enum { TRACE_IRQ_BIT, }; +/* +* For tracer that cannot be enabled during boot time. +*/ + +struct tracer_noboot { +const char *name; +struct list_head list; +}; + +void trace_noboot_tracer_put (struct tracer_noboot *noboot_tracer); +#define trace_recursion_set (bit) do { (current)->trace_recursion |= (1<<(bit)); } while (0)#define trace_recursion_clear (bit) do { (current)->trace_recursion &=~(1<<(bit)); } while (0)
#definetrace_recursion_test(bit)((current)->trace_recursion &
(1<<(bit)))kernel/trace/trace_mmiotrace.c +4
-0@@ -286,6 +286,10 @@ static enum print_line_t mmio_print_line(struct trace_iterator *iter)__init static int init_mmio_trace (void ) { +struct tracer_noboot mmio_notrace; + + mmio_notrace.name ="mmiotrace" ; +trace_noboot_tracer_put (&mmio_notrace);return register_tracer (&mmio_tracer); }Quoted 1 line
device_initcall(init_mmio_trace);This is way overkill. Just add
bool noboot;to struct tracer in
trace.hand then to the mmiotracer:struct tracer mmio_tracer = { [..] .noboot = true, };And then in
tracing_set_tracer()add after:if (t == tr->current_trace) goto out;this:
Quoted 8 lines
if (system_state < SYSTEM_RUNNING && t->noboot) { WARN(1, "Tracer %s not allowed on command line", t->name); goto out; }That's it. No need for locking or anything else.
Thanks for the suggestions. I will send a patch v3 after testing.
Quoted 4 lines
-- Steve
Signature · 1 line
Ziqian SUN