Skip to content
  1. Mar 16, 2022
    • Beau Belgrave's avatar
      user_events: Add trace event call as root for low permission cases · 089331d4
      Beau Belgrave authored
      
      
      Tracefs by default is locked down heavily. System operators can open up
      some files, such as user_events to a broader set of users. These users
      do not have access within tracefs beyond just the user_event files. Due
      to this restriction the trace_add_event_call/remove calls will silently
      fail since the caller does not have permissions to create directories.
      
      To fix this trace_add_event_call/remove calls will be issued with
      override creds of the global root UID. Creds are reverted immediately
      afterward.
      
      Link: https://lkml.kernel.org/r/20220308222807.2040-1-beaub@linux.microsoft.com
      
      Signed-off-by: default avatarBeau Belgrave <beaub@linux.microsoft.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      089331d4
  2. Mar 12, 2022
    • Steven Rostedt (Google)'s avatar
      tracing/user_events: Use alloc_pages instead of kzalloc() for register pages · bc47ee48
      Steven Rostedt (Google) authored
      
      
      kzalloc virtual addresses do not work with SetPageReserved, use the actual
      page virtual addresses instead via alloc_pages.
      
      The issue is reported when booting with user_events and
      DEBUG_VM_PGFLAGS=y.
      
      Also make the number of events based on the ORDER.
      
      Link: https://lore.kernel.org/all/CADYN=9+xY5Vku3Ws5E9S60SM5dCFfeGeRBkmDFbcxX0ZMoFing@mail.gmail.com/
      Link: https://lore.kernel.org/all/20220311223028.1865-1-beaub@linux.microsoft.com/
      
      Cc: Beau Belgrave <beaub@linux.microsoft.com>
      Reported-by: default avatarAnders Roxell <anders.roxell@linaro.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      bc47ee48
    • Steven Rostedt (Google)'s avatar
      tracing: Add snapshot at end of kernel boot up · 380af29b
      Steven Rostedt (Google) authored
      
      
      Add ftrace_boot_snapshot kernel parameter that will take a snapshot at the
      end of boot up just before switching over to user space (it happens during
      the kernel freeing of init memory).
      
      This is useful when there's interesting data that can be collected from
      kernel start up, but gets overridden by user space start up code. With
      this option, the ring buffer content from the boot up traces gets saved in
      the snapshot at the end of boot up. This trace can be read from:
      
       /sys/kernel/tracing/snapshot
      
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      380af29b
    • Steven Rostedt (Google)'s avatar
      tracing: Have TRACE_DEFINE_ENUM affect trace event types as well · b3bc8547
      Steven Rostedt (Google) authored
      
      
      The macro TRACE_DEFINE_ENUM is used to convert enums in the kernel to
      their actual value when they are exported to user space via the trace
      event format file.
      
      Currently only the enums in the "print fmt" (TP_printk in the TRACE_EVENT
      macro) have the enums converted. But the enums can be used to denote array
      size:
      
              field:unsigned int fc_ineligible_rc[EXT4_FC_REASON_MAX]; offset:12;      size:36;        signed:0;
      
      The EXT4_FC_REASON_MAX has no meaning to userspace but it needs to know
      that information to know how to parse the array.
      
      Have the array indexes also be parsed as well.
      
      Link: https://lore.kernel.org/all/cover.1646922487.git.riteshh@linux.ibm.com/
      
      Reported-by: default avatarRitesh Harjani <riteshh@linux.ibm.com>
      Tested-by: default avatarRitesh Harjani <riteshh@linux.ibm.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      b3bc8547
    • Tom Zanussi's avatar
      tracing: Fix strncpy warning in trace_events_synth.c · 9f438d4d
      Tom Zanussi authored
      0-day reported the strncpy error below:
      
      ../kernel/trace/trace_events_synth.c: In function 'last_cmd_set':
      ../kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length o\
      f the source argument [-Wstringop-truncation]
         65 |         strncpy(last_cmd, str, strlen(str) + 1);
            |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ../kernel/trace/trace_events_synth.c:65:32: note: length computed here
         65 |         strncpy(last_cmd, str, strlen(str) + 1);
            |                                ^~~~~~~~~~~
      
      There's no reason to use strncpy here, in fact there's no reason to do
      anything but a simple kstrdup() (note we don't even need to check for
      failure since last_cmod is expected to be either the last cmd string
      or NULL, and the containing function is a void return).
      
      Link: https://lkml.kernel.org/r/77deca8cbfd226981b3f1eab203967381e9b5bd9.camel@kernel.org
      
      Fixes: 27c888da
      
       ("tracing: Remove size restriction on synthetic event cmd error logging")
      
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Signed-off-by: default avatarTom Zanussi <zanussi@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      9f438d4d
    • Beau Belgrave's avatar
      user_events: Prevent dyn_event delete racing with ioctl add/delete · 7e348b32
      Beau Belgrave authored
      
      
      Find user_events always while under the event_mutex and before leaving
      the lock, add a ref count to the user_event. This ensures that all paths
      under the event_mutex that check the ref counts will be synchronized.
      
      The ioctl add/delete paths are protected by the reg_mutex. However,
      dyn_event is only protected by the event_mutex. The dyn_event delete
      path cannot acquire reg_mutex, since that could cause a deadlock between
      the ioctl delete case acquiring event_mutex after acquiring the reg_mutex.
      
      Link: https://lkml.kernel.org/r/20220310001141.1660-1-beaub@linux.microsoft.com
      
      Signed-off-by: default avatarBeau Belgrave <beaub@linux.microsoft.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      7e348b32
    • Steven Rostedt (Google)'s avatar
      tracing: Add TRACE_CUSTOM_EVENT() macro · 3a73333f
      Steven Rostedt (Google) authored
      
      
      To make it really easy to add custom events from modules, add a
      TRACE_CUSTOM_EVENT() macro that acts just like the TRACE_EVENT() macro,
      but creates a custom event to an already existing tracepoint.
      
      The trace_custom_sched.[ch] has been updated to use this new macro to show
      how simple it is.
      
      Link: https://lkml.kernel.org/r/20220303220625.738622494@goodmis.org
      
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Joel Fernandes <joel@joelfernandes.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Tom Zanussi <zanussi@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      3a73333f
    • Steven Rostedt (Google)'s avatar
      tracing: Move the defines to create TRACE_EVENTS into their own files · af6b9668
      Steven Rostedt (Google) authored
      
      
      In an effort to add custom event macros that can be used to create your
      own custom events based on existing tracepoints, move the defines of the
      special macros used in TRACE_EVENT() into their own files such that they
      can be reused for TRACE_CUSTOM_EVENT().
      
      Link: https://lkml.kernel.org/r/20220303220625.553406495@goodmis.org
      
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Joel Fernandes <joel@joelfernandes.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Tom Zanussi <zanussi@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      af6b9668
    • Steven Rostedt (Google)'s avatar
      tracing: Add sample code for custom trace events · 953c2f05
      Steven Rostedt (Google) authored
      
      
      Add sample code to show how to create custom trace events in the tracefs
      directory that can be enabled and modified like any event in tracefs
      (including triggers, histograms, synthetic events and event probes).
      
      The example is creating a custom sched_switch and a sched_waking to limit
      what is recorded:
      
      If the custom sched switch only records the prev_prio, next_prio and
      next_pid, it can bring the size from 64 bytes per event, down to just 16
      bytes!
      
      If sched_waking only records the prio and pid of the woken event, it will
      bring the size down from 36 bytes to 12 bytes per event.
      
      This will allow for a much smaller footprint into the ring buffer and keep
      more events from dropping.
      
      Link: https://lkml.kernel.org/r/20220303220625.369226746@goodmis.org
      
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Tom Zanussi <zanussi@kernel.org>
      Suggested-by: default avatarJoel Fernandes <joel@joelfernandes.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      953c2f05
  3. Mar 11, 2022
    • Steven Rostedt (Google)'s avatar
      tracing: Allow custom events to be added to the tracefs directory · 8bcd0663
      Steven Rostedt (Google) authored
      
      
      Allow custom events to be added to the events directory in the tracefs
      file system. For example, a module could be installed that attaches to an
      event and wants to be enabled and disabled via the tracefs file system. It
      would use trace_add_event_call() to add the event to the tracefs
      directory, and trace_remove_event_call() to remove it.
      
      Make both those functions EXPORT_SYMBOL_GPL().
      
      Link: https://lkml.kernel.org/r/20220303220625.186988045@goodmis.org
      
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Joel Fernandes <joel@joelfernandes.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Tom Zanussi <zanussi@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      8bcd0663
    • Steven Rostedt (Google)'s avatar
      tracing: Fix last_cmd_set() string management in histogram code · 5677a3d7
      Steven Rostedt (Google) authored
      Using strnlen(dest, str, n) is confusing, as the size of dest must be
      strlen(dest) + n + 1. Even more confusing, using sizeof(string constant)
      gives you strlen(string constant) + 1 and not just strlen().
      
      These two together made using strncat() with a constant string a bit off
      in the calculations as we have:
      
      	len = sizeof(HIST_PREFIX) + strlen(str) + 1;
      	kfree(last_cmd);
      	last_cmd = kzalloc(len, GFP_KERNEL);
      	strcpy(last_cmd, HIST_PREFIX);
      	len -= sizeof(HIST_PREFIX) + 1;
      	strncat(last_cmd, str, len);
      
      The above works if we s/sizeof/strlen/ with HIST_PREFIX (which is defined
      as "hist:", but because sizeof(HIST_PREFIX) is equal to
      strlen(HIST_PREFIX) + 1, we can drop the +1 in the code. But at least
      comment that we are doing so.
      
      Link: https://lore.kernel.org/all/202203082112.Iu7tvFl4-lkp@intel.com/
      
      Fixes: 9f8e5aee
      
       ("tracing: Fix allocation of last_cmd in last_cmd_set()")
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      5677a3d7
    • Beau Belgrave's avatar
      user_events: Fix potential uninitialized pointer while parsing field · 173c2049
      Beau Belgrave authored
      
      
      Ensure name is initialized by default to NULL to prevent possible edge
      cases that could lead to it being left uninitialized. Add an explicit
      check for NULL name to ensure edge boundaries.
      
      Link: https://lore.kernel.org/bpf/20220224105334.GA2248@kili/
      Link: https://lore.kernel.org/linux-trace-devel/20220224181637.2129-1-beaub@linux.microsoft.com
      
      Signed-off-by: default avatarBeau Belgrave <beaub@linux.microsoft.com>
      Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      173c2049
  4. Feb 24, 2022
  5. Feb 11, 2022
  6. Feb 09, 2022
  7. Feb 05, 2022
  8. Jan 28, 2022