]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
tracing: Only have rmmod clear buffers that its events were active in
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Thu, 31 Aug 2017 21:03:47 +0000 (17:03 -0400)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Thu, 31 Aug 2017 21:47:38 +0000 (17:47 -0400)
Currently, when a module event is enabled, when that module is removed, it
clears all ring buffers. This is to prevent another module from being loaded
and having one of its trace event IDs from reusing a trace event ID of the
removed module. This could cause undesirable effects as the trace event of
the new module would be using its own processing algorithms to process raw
data of another event. To prevent this, when a module is loaded, if any of
its events have been used (signified by the WAS_ENABLED event call flag,
which is never cleared), all ring buffers are cleared, just in case any one
of them contains event data of the removed event.

The problem is, there's no reason to clear all ring buffers if only one (or
less than all of them) uses one of the events. Instead, only clear the ring
buffers that recorded the events of a module that is being removed.

To do this, instead of keeping the WAS_ENABLED flag with the trace event
call, move it to the per instance (per ring buffer) event file descriptor.
The event file descriptor maps each event to a separate ring buffer
instance. Then when the module is removed, only the ring buffers that
activated one of the module's events get cleared. The rest are not touched.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
include/linux/trace_events.h
kernel/trace/trace.c
kernel/trace/trace.h
kernel/trace/trace_events.c

index 536c80ff7ad96680ddcca0a7880cd7df81c57f17..3702b9cb5dc834d0c5bddf291371fd8c098fbe83 100644 (file)
@@ -217,7 +217,6 @@ enum {
        TRACE_EVENT_FL_CAP_ANY_BIT,
        TRACE_EVENT_FL_NO_SET_FILTER_BIT,
        TRACE_EVENT_FL_IGNORE_ENABLE_BIT,
-       TRACE_EVENT_FL_WAS_ENABLED_BIT,
        TRACE_EVENT_FL_TRACEPOINT_BIT,
        TRACE_EVENT_FL_KPROBE_BIT,
        TRACE_EVENT_FL_UPROBE_BIT,
@@ -229,9 +228,6 @@ enum {
  *  CAP_ANY      - Any user can enable for perf
  *  NO_SET_FILTER - Set when filter has error and is to be ignored
  *  IGNORE_ENABLE - For trace internal events, do not enable with debugfs file
- *  WAS_ENABLED   - Set and stays set when an event was ever enabled
- *                    (used for module unloading, if a module event is enabled,
- *                     it is best to clear the buffers that used it).
  *  TRACEPOINT    - Event is a tracepoint
  *  KPROBE        - Event is a kprobe
  *  UPROBE        - Event is a uprobe
@@ -241,7 +237,6 @@ enum {
        TRACE_EVENT_FL_CAP_ANY          = (1 << TRACE_EVENT_FL_CAP_ANY_BIT),
        TRACE_EVENT_FL_NO_SET_FILTER    = (1 << TRACE_EVENT_FL_NO_SET_FILTER_BIT),
        TRACE_EVENT_FL_IGNORE_ENABLE    = (1 << TRACE_EVENT_FL_IGNORE_ENABLE_BIT),
-       TRACE_EVENT_FL_WAS_ENABLED      = (1 << TRACE_EVENT_FL_WAS_ENABLED_BIT),
        TRACE_EVENT_FL_TRACEPOINT       = (1 << TRACE_EVENT_FL_TRACEPOINT_BIT),
        TRACE_EVENT_FL_KPROBE           = (1 << TRACE_EVENT_FL_KPROBE_BIT),
        TRACE_EVENT_FL_UPROBE           = (1 << TRACE_EVENT_FL_UPROBE_BIT),
@@ -306,6 +301,7 @@ enum {
        EVENT_FILE_FL_TRIGGER_MODE_BIT,
        EVENT_FILE_FL_TRIGGER_COND_BIT,
        EVENT_FILE_FL_PID_FILTER_BIT,
+       EVENT_FILE_FL_WAS_ENABLED_BIT,
 };
 
 /*
@@ -321,6 +317,7 @@ enum {
  *  TRIGGER_MODE  - When set, invoke the triggers associated with the event
  *  TRIGGER_COND  - When set, one or more triggers has an associated filter
  *  PID_FILTER    - When set, the event is filtered based on pid
+ *  WAS_ENABLED   - Set when enabled to know to clear trace on module removal
  */
 enum {
        EVENT_FILE_FL_ENABLED           = (1 << EVENT_FILE_FL_ENABLED_BIT),
@@ -333,6 +330,7 @@ enum {
        EVENT_FILE_FL_TRIGGER_MODE      = (1 << EVENT_FILE_FL_TRIGGER_MODE_BIT),
        EVENT_FILE_FL_TRIGGER_COND      = (1 << EVENT_FILE_FL_TRIGGER_COND_BIT),
        EVENT_FILE_FL_PID_FILTER        = (1 << EVENT_FILE_FL_PID_FILTER_BIT),
+       EVENT_FILE_FL_WAS_ENABLED       = (1 << EVENT_FILE_FL_WAS_ENABLED_BIT),
 };
 
 struct trace_event_file {
index 44004d8aa3b33f259ed90dd13ce4c102034da23a..30338a835a514166198691e62d43dd1c1a343780 100644 (file)
@@ -1702,6 +1702,9 @@ void tracing_reset_all_online_cpus(void)
        struct trace_array *tr;
 
        list_for_each_entry(tr, &ftrace_trace_arrays, list) {
+               if (!tr->clear_trace)
+                       continue;
+               tr->clear_trace = false;
                tracing_reset_online_cpus(&tr->trace_buffer);
 #ifdef CONFIG_TRACER_MAX_TRACE
                tracing_reset_online_cpus(&tr->max_buffer);
index 490ba229931d7d00243a1be009dec6ab2b3a5864..fb5d54d0d1b3f297087e96f03a22003fc887d359 100644 (file)
@@ -245,6 +245,7 @@ struct trace_array {
        int                     stop_count;
        int                     clock_id;
        int                     nr_topts;
+       bool                    clear_trace;
        struct tracer           *current_trace;
        unsigned int            trace_flags;
        unsigned char           trace_flags_index[TRACE_FLAGS_MAX_SIZE];
index 36132f9280e627ae91fecc7955148178bb076480..c93540c5df21aa71003819e191283e48d10065d3 100644 (file)
@@ -466,7 +466,7 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
                        set_bit(EVENT_FILE_FL_ENABLED_BIT, &file->flags);
 
                        /* WAS_ENABLED gets set but never cleared. */
-                       call->flags |= TRACE_EVENT_FL_WAS_ENABLED;
+                       set_bit(EVENT_FILE_FL_WAS_ENABLED_BIT, &file->flags);
                }
                break;
        }
@@ -2058,6 +2058,10 @@ static void event_remove(struct trace_event_call *call)
        do_for_each_event_file(tr, file) {
                if (file->event_call != call)
                        continue;
+
+               if (file->flags & EVENT_FILE_FL_WAS_ENABLED)
+                       tr->clear_trace = true;
+
                ftrace_event_enable_disable(file, 0);
                /*
                 * The do_for_each_event_file() is
@@ -2396,15 +2400,11 @@ static void trace_module_add_events(struct module *mod)
 static void trace_module_remove_events(struct module *mod)
 {
        struct trace_event_call *call, *p;
-       bool clear_trace = false;
 
        down_write(&trace_event_sem);
        list_for_each_entry_safe(call, p, &ftrace_events, list) {
-               if (call->mod == mod) {
-                       if (call->flags & TRACE_EVENT_FL_WAS_ENABLED)
-                               clear_trace = true;
+               if (call->mod == mod)
                        __trace_remove_event_call(call);
-               }
        }
        up_write(&trace_event_sem);
 
@@ -2416,8 +2416,7 @@ static void trace_module_remove_events(struct module *mod)
         * over from this module may be passed to the new module events and
         * unexpected results may occur.
         */
-       if (clear_trace)
-               tracing_reset_all_online_cpus();
+       tracing_reset_all_online_cpus();
 }
 
 static int trace_module_notify(struct notifier_block *self,