1. 02 Nov, 2023 12 commits
  2. 28 Oct, 2023 1 commit
    • Kees Cook's avatar
      seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_str() · dcc4e572
      Kees Cook authored
      Solve two ergonomic issues with struct seq_buf;
      
      1) Too much boilerplate is required to initialize:
      
      	struct seq_buf s;
      	char buf[32];
      
      	seq_buf_init(s, buf, sizeof(buf));
      
      Instead, we can build this directly on the stack. Provide
      DECLARE_SEQ_BUF() macro to do this:
      
      	DECLARE_SEQ_BUF(s, 32);
      
      2) %NUL termination is fragile and requires 2 steps to get a valid
         C String (and is a layering violation exposing the "internals" of
         seq_buf):
      
      	seq_buf_terminate(s);
      	do_something(s->buffer);
      
      Instead, we can just return s->buffer directly after terminating it in
      the refactored seq_buf_terminate(), now known as seq_buf_str():
      
      	do_something(seq_buf_str(s));
      
      Link: https://lore.kernel.org/linux-trace-kernel/20231027155634.make.260-kees@kernel.org
      Link: https://lore.kernel.org/linux-trace-kernel/20231026194033.it.702-kees@kernel.org/
      
      Cc: Yosry Ahmed <yosryahmed@google.com>
      Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Justin Stitt <justinstitt@google.com>
      Cc: Kent Overstreet <kent.overstreet@linux.dev>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Jonathan Corbet <corbet@lwn.net>
      Cc: Yun Zhou <yun.zhou@windriver.com>
      Cc: Jacob Keller <jacob.e.keller@intel.com>
      Cc: Zhen Lei <thunder.leizhen@huawei.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      dcc4e572
  3. 26 Oct, 2023 3 commits
  4. 23 Oct, 2023 1 commit
  5. 20 Oct, 2023 5 commits
  6. 18 Oct, 2023 1 commit
  7. 05 Oct, 2023 2 commits
  8. 04 Oct, 2023 6 commits
    • Steven Rostedt (Google)'s avatar
      tracing/selftests: Update kprobe args char/string to match new functions · f5d9e8e0
      Steven Rostedt (Google) authored
      The function that the kprobe_args_char and kprobes_arg_string attaches to
      for its test has changed its name once again. Now we need to check for
      eventfs_create_dir(), and if it exists, use that, otherwise check for
      eventfs_add_dir() and if that exists use that, otherwise use the original
      tracefs_create_dir()!
      
      Link: https://lore.kernel.org/linux-trace-kernel/20230914163535.487267410@goodmis.org
      
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Ajay Kaher <akaher@vmware.com>
      Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      f5d9e8e0
    • Steven Rostedt (Google)'s avatar
      eventfs: Remove eventfs_file and just use eventfs_inode · 5790b1fb
      Steven Rostedt (Google) authored
      Instead of having a descriptor for every file represented in the eventfs
      directory, only have the directory itself represented. Change the API to
      send in a list of entries that represent all the files in the directory
      (but not other directories). The entry list contains a name and a callback
      function that will be used to create the files when they are accessed.
      
      struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry *parent,
      						const struct eventfs_entry *entries,
      						int size, void *data);
      
      is used for the top level eventfs directory, and returns an eventfs_inode
      that will be used by:
      
      struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode *parent,
      					 const struct eventfs_entry *entries,
      					 int size, void *data);
      
      where both of the above take an array of struct eventfs_entry entries for
      every file that is in the directory.
      
      The entries are defined by:
      
      typedef int (*eventfs_callback)(const char *name, umode_t *mode, void **data,
      				const struct file_operations **fops);
      
      struct eventfs_entry {
      	const char			*name;
      	eventfs_callback		callback;
      };
      
      Where the name is the name of the file and the callback gets called when
      the file is being created. The callback passes in the name (in case the
      same callback is used for multiple files), a pointer to the mode, data and
      fops. The data will be pointing to the data that was passed in
      eventfs_create_dir() or eventfs_create_events_dir() but may be overridden
      to point to something else, as it will be used to point to the
      inode->i_private that is created. The information passed back from the
      callback is used to create the dentry/inode.
      
      If the callback fills the data and the file should be created, it must
      return a positive number. On zero or negative, the file is ignored.
      
      This logic may also be used as a prototype to convert entire pseudo file
      systems into just-in-time allocation.
      
      The "show_events_dentry" file has been updated to show the directories,
      and any files they have.
      
      With just the eventfs_file allocations:
      
       Before after deltas for meminfo (in kB):
      
         MemFree:		-14360
         MemAvailable:	-14260
         Buffers:		40
         Cached:		24
         Active:		44
         Inactive:		48
         Inactive(anon):	28
         Active(file):	44
         Inactive(file):	20
         Dirty:		-4
         AnonPages:		28
         Mapped:		4
         KReclaimable:	132
         Slab:		1604
         SReclaimable:	132
         SUnreclaim:		1472
         Committed_AS:	12
      
       Before after deltas for slabinfo:
      
         <slab>:		<objects>	[ * <size> = <total>]
      
         ext4_inode_cache	27		[* 1184 = 31968 ]
         extent_status	102		[*   40 = 4080 ]
         tracefs_inode_cache	144		[*  656 = 94464 ]
         buffer_head		39		[*  104 = 4056 ]
         shmem_inode_cache	49		[*  800 = 39200 ]
         filp			-53		[*  256 = -13568 ]
         dentry		251		[*  192 = 48192 ]
         lsm_file_cache	277		[*   32 = 8864 ]
         vm_area_struct	-14		[*  184 = -2576 ]
         trace_event_file	1748		[*   88 = 153824 ]
         kmalloc-1k		35		[* 1024 = 35840 ]
         kmalloc-256		49		[*  256 = 12544 ]
         kmalloc-192		-28		[*  192 = -5376 ]
         kmalloc-128		-30		[*  128 = -3840 ]
         kmalloc-96		10581		[*   96 = 1015776 ]
         kmalloc-64		3056		[*   64 = 195584 ]
         kmalloc-32		1291		[*   32 = 41312 ]
         kmalloc-16		2310		[*   16 = 36960 ]
         kmalloc-8		9216		[*    8 = 73728 ]
      
       Free memory dropped by 14,360 kB
       Available memory dropped by 14,260 kB
       Total slab additions in size: 1,771,032 bytes
      
      With this change:
      
       Before after deltas for meminfo (in kB):
      
         MemFree:		-12084
         MemAvailable:	-11976
         Buffers:		32
         Cached:		32
         Active:		72
         Inactive:		168
         Inactive(anon):	176
         Active(file):	72
         Inactive(file):	-8
         Dirty:		24
         AnonPages:		196
         Mapped:		8
         KReclaimable:	148
         Slab:		836
         SReclaimable:	148
         SUnreclaim:		688
         Committed_AS:	324
      
       Before after deltas for slabinfo:
      
         <slab>:		<objects>	[ * <size> = <total>]
      
         tracefs_inode_cache	144		[* 656 = 94464 ]
         shmem_inode_cache	-23		[* 800 = -18400 ]
         filp			-92		[* 256 = -23552 ]
         dentry		179		[* 192 = 34368 ]
         lsm_file_cache	-3		[* 32 = -96 ]
         vm_area_struct	-13		[* 184 = -2392 ]
         trace_event_file	1748		[* 88 = 153824 ]
         kmalloc-1k		-49		[* 1024 = -50176 ]
         kmalloc-256		-27		[* 256 = -6912 ]
         kmalloc-128		1864		[* 128 = 238592 ]
         kmalloc-64		4685		[* 64 = 299840 ]
         kmalloc-32		-72		[* 32 = -2304 ]
         kmalloc-16		256		[* 16 = 4096 ]
         total = 721352
      
       Free memory dropped by 12,084 kB
       Available memory dropped by 11,976 kB
       Total slab additions in size:  721,352 bytes
      
      That's over 2 MB in savings per instance for free and available memory,
      and over 1 MB in savings per instance of slab memory.
      
      Link: https://lore.kernel.org/linux-trace-kernel/20231003184059.4924468e@gandalf.local.home
      Link: https://lore.kernel.org/linux-trace-kernel/20231004165007.43d79161@gandalf.local.home
      
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Ajay Kaher <akaher@vmware.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      5790b1fb
    • Beau Belgrave's avatar
      tracing/user_events: Document persist event flags · 2c6d0950
      Beau Belgrave authored
      Users need to know how to make events persist now that we allow for
      that. We also now allow the dynamic_events file to create events by
      utilizing the persist flag during event register.
      
      Add back in to documentation how /sys/kernel/tracing/dynamic_events can
      be used to create persistent user_events. Add a section under registering
      for the currently supported flags (USER_EVENT_REG_PERSIST) and the
      required permissions. Add a note under deleting that deleting a
      persistent event also requires sufficient permission.
      
      Link: https://lkml.kernel.org/r/20230912180704.1284-4-beaub@linux.microsoft.comSigned-off-by: default avatarBeau Belgrave <beaub@linux.microsoft.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      2c6d0950
    • Beau Belgrave's avatar
      selftests/user_events: Test persist flag cases · cf74c59c
      Beau Belgrave authored
      Now that we have exposed USER_EVENT_REG_PERSIST events can persist both
      via the ABI and in the /sys/kernel/tracing/dynamic_events file.
      
      Ensure both the ABI and DYN cases work by calling both during the parse
      tests. Add new flags test that ensures only USER_EVENT_REG_PERSIST is
      honored and any other flag is invalid.
      
      Link: https://lkml.kernel.org/r/20230912180704.1284-3-beaub@linux.microsoft.comSigned-off-by: default avatarBeau Belgrave <beaub@linux.microsoft.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      cf74c59c
    • Beau Belgrave's avatar
      tracing/user_events: Allow events to persist for perfmon_capable users · 5dbd04ed
      Beau Belgrave authored
      There are several scenarios that have come up where having a user_event
      persist even if the process that registered it exits. The main one is
      having a daemon create events on bootup that shouldn't get deleted if
      the daemon has to exit or reload. Another is within OpenTelemetry
      exporters, they wish to potentially check if a user_event exists on the
      system to determine if exporting the data out should occur. The
      user_event in this case must exist even in the absence of the owning
      process running (such as the above daemon case).
      
      Expose the previously internal flag USER_EVENT_REG_PERSIST to user
      processes. Upon register or delete of events with this flag, ensure the
      user is perfmon_capable to prevent random user processes with access to
      tracefs from creating events that persist after exit.
      
      Link: https://lkml.kernel.org/r/20230912180704.1284-2-beaub@linux.microsoft.comSigned-off-by: default avatarBeau Belgrave <beaub@linux.microsoft.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      5dbd04ed
    • Uros Bizjak's avatar
      ring_buffer: Use try_cmpxchg instead of cmpxchg in rb_insert_pages · bdf4fb62
      Uros Bizjak authored
      Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in
      rb_insert_pages. x86 CMPXCHG instruction returns success in ZF flag,
      so this change saves a compare after cmpxchg (and related move
      instruction in front of cmpxchg).
      
      No functional change intended.
      
      Link: https://lore.kernel.org/linux-trace-kernel/20230914163420.12923-1-ubizjak@gmail.com
      
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarUros Bizjak <ubizjak@gmail.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      bdf4fb62
  9. 03 Oct, 2023 1 commit
    • Zheng Yejian's avatar
      tracing: Expand all ring buffers individually · a1f157c7
      Zheng Yejian authored
      The ring buffer of global_trace is set to the minimum size in
      order to save memory on boot up and then it will be expand when
      some trace feature enabled.
      
      However currently operations under an instance can also cause
      global_trace ring buffer being expanded, and the expanded memory
      would be wasted if global_trace then not being used.
      
      See following case, we enable 'sched_switch' event in instance 'A', then
      ring buffer of global_trace is unexpectedly expanded to be 1410KB, also
      the '(expanded: 1408)' from 'buffer_size_kb' of instance is confusing.
      
        # cd /sys/kernel/tracing
        # mkdir instances/A
        # cat buffer_size_kb
        7 (expanded: 1408)
        # cat instances/A/buffer_size_kb
        1410 (expanded: 1408)
        # echo sched:sched_switch > instances/A/set_event
        # cat buffer_size_kb
        1410
        # cat instances/A/buffer_size_kb
        1410
      
      To fix it, we can:
        - Make 'ring_buffer_expanded' as a member of 'struct trace_array';
        - Make 'ring_buffer_expanded' of instance is defaultly true,
          global_trace is defaultly false;
        - In order not to expose 'global_trace' outside of file
          'kernel/trace/trace.c', introduce trace_set_ring_buffer_expanded()
          to set 'ring_buffer_expanded' as 'true';
        - Pass the expected trace_array to tracing_update_buffers().
      
      Link: https://lore.kernel.org/linux-trace-kernel/20230906091837.3998020-1-zhengyejian1@huawei.comSigned-off-by: default avatarZheng Yejian <zhengyejian1@huawei.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      a1f157c7
  10. 01 Oct, 2023 8 commits