Re: [PATCH 5/8] ring-buffer: Add ring_buffer_meta data
Hi Steven, kernel test robot noticed the following build errors: [auto build test ERROR on next-20240305] [cannot apply to tip/x86/core akpm-mm/mm-everything linus/master v6.8-rc7 v6.8-rc6 v6.8-rc5 v6.8-rc7] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Steven-Rostedt/ring-buffer-Allow-mapped-field-to-be-set-without-mapping/20240306-100047 base: next-20240305 patch link:https://lore.kernel.org/r/20240306020006.100449500%40goodmis.org patch subject: [PATCH 5/8] ring-buffer: Add ring_buffer_meta data config: s390-defconfig (https://download.01.org/0day-ci/archive/20240308/202403081843.qykjkyk4-...@intel.com/config) compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 503c55e17037436dcd45ac69dea8967e67e3f5e8) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240308/202403081843.qykjkyk4-...@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202403081843.qykjkyk4-...@intel.com/ All errors (new ones prefixed by >>): In file included from kernel/trace/ring_buffer.c:8: In file included from include/linux/trace_events.h:6: In file included from include/linux/ring_buffer.h:5: In file included from include/linux/mm.h:2208: include/linux/vmstat.h:508:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion] 508 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS + |~ ^ 509 |item]; | include/linux/vmstat.h:515:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion] 515 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS + |~ ^ 516 |NR_VM_NUMA_EVENT_ITEMS + |~~ include/linux/vmstat.h:522:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion] 522 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_" | ~~~ ^ ~~~ include/linux/vmstat.h:527:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion] 527 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS + |~ ^ 528 |NR_VM_NUMA_EVENT_ITEMS + |~~ include/linux/vmstat.h:536:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion] 536 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS + |~ ^ 537 |NR_VM_NUMA_EVENT_ITEMS + |~~ In file included from kernel/trace/ring_buffer.c:8: In file included from include/linux/trace_events.h:10: In file included from include/linux/perf_event.h:62: In file included from include/linux/security.h:35: include/linux/bpf.h:736:48: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_arg_type') [-Wenum-enum-conversion] 736 | ARG_PTR_TO_MAP_VALUE_OR_NULL= PTR_MAYBE_NULL | ARG_PTR_TO_MAP_VALUE, | ~~ ^ include/linux/bpf.h:737:43: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_arg_type') [-Wenum-enum-conversion] 737 | ARG_PTR_TO_MEM_OR_NULL = PTR_MAYBE_NULL | ARG_PTR_TO_MEM, | ~~ ^ ~~ include/linux/bpf.h:738:43: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_arg_type') [-Wenum-enum-conversion] 738 | ARG_PTR_TO_CTX_OR_NULL = PTR_MAYBE_NULL | ARG_PTR_TO_CTX, | ~~ ^ ~~ include/linux/bpf.h:739:45: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_arg_type') [-Wenum-enum-conv
Re: [PATCH 5/8] ring-buffer: Add ring_buffer_meta data
Hi Steven, kernel test robot noticed the following build warnings: [auto build test WARNING on next-20240305] [cannot apply to tip/x86/core akpm-mm/mm-everything linus/master v6.8-rc7 v6.8-rc6 v6.8-rc5 v6.8-rc7] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Steven-Rostedt/ring-buffer-Allow-mapped-field-to-be-set-without-mapping/20240306-100047 base: next-20240305 patch link:https://lore.kernel.org/r/20240306020006.100449500%40goodmis.org patch subject: [PATCH 5/8] ring-buffer: Add ring_buffer_meta data config: sh-defconfig (https://download.01.org/0day-ci/archive/20240308/202403081831.ewsqpo2a-...@intel.com/config) compiler: sh4-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240308/202403081831.ewsqpo2a-...@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202403081831.ewsqpo2a-...@intel.com/ All warnings (new ones prefixed by >>): kernel/trace/ring_buffer.c: In function 'rb_set_commit_to_write': >> kernel/trace/ring_buffer.c:3224:45: warning: assignment to 'long unsigned >> int' from 'struct buffer_data_page *' makes integer from pointer without a >> cast [-Wint-conversion] 3224 | meta->commit_buffer = cpu_buffer->commit_page->page; | ^ vim +3224 kernel/trace/ring_buffer.c 3192 3193 static __always_inline void 3194 rb_set_commit_to_write(struct ring_buffer_per_cpu *cpu_buffer) 3195 { 3196 unsigned long max_count; 3197 3198 /* 3199 * We only race with interrupts and NMIs on this CPU. 3200 * If we own the commit event, then we can commit 3201 * all others that interrupted us, since the interruptions 3202 * are in stack format (they finish before they come 3203 * back to us). This allows us to do a simple loop to 3204 * assign the commit to the tail. 3205 */ 3206 again: 3207 max_count = cpu_buffer->nr_pages * 100; 3208 3209 while (cpu_buffer->commit_page != READ_ONCE(cpu_buffer->tail_page)) { 3210 if (RB_WARN_ON(cpu_buffer, !(--max_count))) 3211 return; 3212 if (RB_WARN_ON(cpu_buffer, 3213 rb_is_reader_page(cpu_buffer->tail_page))) 3214 return; 3215 /* 3216 * No need for a memory barrier here, as the update 3217 * of the tail_page did it for this page. 3218 */ 3219 local_set(_buffer->commit_page->page->commit, 3220rb_page_write(cpu_buffer->commit_page)); 3221 rb_inc_page(_buffer->commit_page); 3222 if (cpu_buffer->ring_meta) { 3223 struct ring_buffer_meta *meta = cpu_buffer->ring_meta; > 3224 meta->commit_buffer = > cpu_buffer->commit_page->page; 3225 } 3226 /* add barrier to keep gcc from optimizing too much */ 3227 barrier(); 3228 } 3229 while (rb_commit_index(cpu_buffer) != 3230 rb_page_write(cpu_buffer->commit_page)) { 3231 3232 /* Make sure the readers see the content of what is committed. */ 3233 smp_wmb(); 3234 local_set(_buffer->commit_page->page->commit, 3235rb_page_write(cpu_buffer->commit_page)); 3236 RB_WARN_ON(cpu_buffer, 3237 local_read(_buffer->commit_page->page->commit) & 3238 ~RB_WRITE_MASK); 3239 barrier(); 3240 } 3241 3242 /* again, keep gcc from optimizing */ 3243 barrier(); 3244 3245 /* 3246 * If an interrupt came in just after the first while loop 3247 * and pushed the tail page forward, we will be left with 3248 * a dangling commit that will never go forward. 3249 */ 3250 if (unlikely(cpu_buffer->commit_page != READ_ONCE(cpu_buffer->tail_page))) 3251 goto again; 3252 } 3253 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
[PATCH 5/8] ring-buffer: Add ring_buffer_meta data
From: "Steven Rostedt (Google)" Populate the ring_buffer_meta array. It holds the pointer to the head_buffer (next to read), the commit_buffer (next to write) the size of the sub-buffers, number of sub-buffers and an array that keeps track of the order of the sub-buffers. This information will be stored in the persistent memory to help on reboot to reconstruct the ring buffer. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ring_buffer.c | 207 - 1 file changed, 182 insertions(+), 25 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 367597dc766b..5a90ada49366 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -42,6 +42,11 @@ static void update_pages_handler(struct work_struct *work); struct ring_buffer_meta { + unsigned long head_buffer; + unsigned long commit_buffer; + __u32 subbuf_size; + __u32 nr_subbufs; + int buffers[]; }; /* @@ -497,6 +502,7 @@ struct ring_buffer_per_cpu { struct mutexmapping_lock; unsigned long *subbuf_ids;/* ID to subbuf addr */ struct trace_buffer_meta*meta_page; + struct ring_buffer_meta *ring_meta; /* ring buffer pages to update, > 0 to add, < 0 to remove */ longnr_pages_to_update; @@ -1206,6 +1212,11 @@ static void rb_head_page_activate(struct ring_buffer_per_cpu *cpu_buffer) * Set the previous list pointer to have the HEAD flag. */ rb_set_list_to_head(head->list.prev); + + if (cpu_buffer->ring_meta) { + struct ring_buffer_meta *meta = cpu_buffer->ring_meta; + meta->head_buffer = (unsigned long)head->page; + } } static void rb_list_head_clear(struct list_head *list) @@ -1453,50 +1464,124 @@ rb_range_align_subbuf(unsigned long addr, int subbuf_size, int nr_subbufs) } /* - * Return a specific sub-buffer for a given @cpu defined by @idx. + * Return the ring_buffer_meta for a given @cpu. */ -static void *rb_range_buffer(struct trace_buffer *buffer, int cpu, int nr_pages, int idx) +static void *rb_range_meta(struct trace_buffer *buffer, int nr_pages, int cpu) { - unsigned long ptr; int subbuf_size = buffer->subbuf_size + BUF_PAGE_HDR_SIZE; + unsigned long ptr = buffer->range_addr_start; + struct ring_buffer_meta *meta; int nr_subbufs; - /* Include the reader page */ - nr_subbufs = nr_pages + 1; + if (!ptr) + return NULL; + + /* When nr_pages passed in is zero, the first meta has already been initialized */ + if (!nr_pages) { + meta = (struct ring_buffer_meta *)ptr; + nr_subbufs = meta->nr_subbufs; + } else { + meta = NULL; + /* Include the reader page */ + nr_subbufs = nr_pages + 1; + } /* * The first chunk may not be subbuffer aligned, where as * the rest of the chunks are. */ - ptr = buffer->range_addr_start; - ptr = rb_range_align_subbuf(ptr, subbuf_size, nr_subbufs); if (cpu) { - unsigned long p; - - ptr += subbuf_size * nr_subbufs; - - /* Save the beginning of this CPU chunk */ - p = ptr; - ptr = rb_range_align_subbuf(ptr, subbuf_size, nr_subbufs); + ptr += subbuf_size * nr_subbufs; if (cpu > 1) { unsigned long size; + unsigned long p; + /* Save the beginning of this CPU chunk */ + p = ptr; + ptr = rb_range_align_subbuf(ptr, subbuf_size, nr_subbufs); ptr += subbuf_size * nr_subbufs; /* Now all chunks after this are the same size */ size = ptr - p; ptr += size * (cpu - 2); - - ptr = rb_range_align_subbuf(ptr, subbuf_size, nr_subbufs); } } - if (ptr + subbuf_size * nr_subbufs > buffer->range_addr_end) + return (void *)ptr; +} + +static void *rb_subbufs_from_meta(struct ring_buffer_meta *meta) +{ + int subbuf_size = meta->subbuf_size; + unsigned long ptr; + + ptr = (unsigned long)meta; + ptr = rb_range_align_subbuf(ptr, subbuf_size, meta->nr_subbufs); + + return (void *)ptr; +} + +/* + * Return a specific sub-buffer for a given @cpu defined by @idx. + */ +static void *rb_range_buffer(struct ring_buffer_per_cpu *cpu_buffer, int idx) +{ + struct ring_buffer_meta *meta; + unsigned long ptr; + int subbuf_size; + + meta = rb_range_meta(cpu_buffer->buffer, 0, cpu_buffer->cpu); + if (!meta) + return NULL; + + if (WARN_ON_ONCE(idx