History

Merge tag 'trace-ringbuffer-v7.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull ring-buffer fixes from Steven Rostedt: - Fix reporting MISSED EVENTS in trace iterator When the "trace" file is read with tracing enabled, if the writer were to pass the iterator reader, it resets, sets a "missed_events" flag and continues. The tracing output checks for missed events and if there are some, it prints out "[LOST EVENTS]" to let the user know events were dropped. But the clearing of the missed_events happened when the tracing system queried the ring buffer iterator about missed events. This was premature as the ring buffer is per CPU, and the tracing code reads all the CPU buffers and checks for missed events when it is read. If the CPU iterator that had missed events isn't printed next, the output for the LOST EVENTS is lost. Clear the missed_events flag when the iterator moves to the next event and not when the missed_events flag is queried. Also clear it on reset. - Flush and stop the persistent ring buffer on panic On panic the persistent ring buffer is used to debug what caused the panic. But on some architectures, it requires flushing the memory from cache, otherwise, the ring buffer persistent memory may not have the last events and this could also cause the ring buffer to be corrupted on the next boot. - Fix nr_subbufs initialization in simple_ring_buffer_init_mm The remote simple ring buffer meta data nr_subbufs is initialized too early and gets cleared later on, making it zero and not reflect the actual number of sub-buffers. - Fix unload_page for simple_ring_buffer init rollback On error, the pages loaded need to be unloaded. To unload a page it is expected that: page = load_page(va); -> unload_page(page). But the code was doing: unload_page(va) and not unload_page(page). - Create output file from cmd_check_undefined The check for undefined symbols checks if the file *.o.checked exists and if so it skips doing the work. But the *.o.checked file never was created making every build do the work even when it was already done previously. * tag 'trace-ringbuffer-v7.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: tracing: Create output file from cmd_check_undefined tracing: Fix unload_page for simple_ring_buffer init rollback tracing: Fix nr_subbufs initialization in simple_ring_buffer_init_mm() ring-buffer: Flush and stop persistent ring buffer on panic ring-buffer: Fix reporting of missed events in iterator

Linus Torvalds committed 5 months ago

Commit 7acfa2c2 parents 758c807 057caac25 files · +72 −8Browse files

Showing the changes to kernel (3 of 25 files). Show all

Unified · Split

3 files
  1. kernel/trace/Makefile +2 −1
  2. kernel/trace/ring_buffer.c +25 −5
  3. kernel/trace/simple_ring_buffer.c +2 −2
kernel/trace/Makefile+2−1
@@ -154,7 +154,8 @@ quiet_cmd_check_undefined = NM $< · 153 unmodified lines
154154 echo "Unexpected symbols in $<:" >&2; \
155155 echo "$$undefsyms" >&2; \
156156 false; \
157− fi
157+ fi; \
158+ touch $@
158159
159160 $(obj)/%.o.checked: $(obj)/%.o $(obj)/undefsyms_base.o FORCE
160161 $(call if_changed,check_undefined)
kernel/trace/ring_buffer.c+25−5
@@ -7,6 +7,7 @@ · 6 unmodified lines
77 #include <linux/ring_buffer_types.h>
88 #include <linux/sched/isolation.h>
99 #include <linux/trace_recursion.h>
10+#include <linux/panic_notifier.h>
1011 #include <linux/trace_events.h>
1112 #include <linux/ring_buffer.h>
1213 #include <linux/trace_clock.h>
@@ -31,6 +32,7 @@ · 18 unmodified lines
3132 #include <linux/oom.h>
3233 #include <linux/mm.h>
3334
35+#include <asm/ring_buffer.h>
3436 #include <asm/local64.h>
3537 #include <asm/local.h>
3638 #include <asm/setup.h>
@@ -559,6 +561,7 @@ struct trace_buffer { · 522 unmodified lines
559561
560562 unsigned long range_addr_start;
561563 unsigned long range_addr_end;
564+ struct notifier_block flush_nb;
562565
563566 struct ring_buffer_meta *meta;
564567
@@ -2521,6 +2524,16 @@ static void rb_free_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer) · 1956 unmodified lines
25212524 kfree(cpu_buffer);
25222525 }
25232526
2527+/* Stop recording on a persistent buffer and flush cache if needed. */
2528+static int rb_flush_buffer_cb(struct notifier_block *nb, unsigned long event, void *data)
2529+{
2530+ struct trace_buffer *buffer = container_of(nb, struct trace_buffer, flush_nb);
2531+
2532+ ring_buffer_record_off(buffer);
2533+ arch_ring_buffer_flush_range(buffer->range_addr_start, buffer->range_addr_end);
2534+ return NOTIFY_DONE;
2535+}
2536+
25242537 static struct trace_buffer *alloc_buffer(unsigned long size, unsigned flags,
25252538 int order, unsigned long start,
25262539 unsigned long end,
@@ -2651,6 +2664,12 @@ static struct trace_buffer *alloc_buffer(unsigned long size, unsigned flags, · 124 unmodified lines
26512664
26522665 mutex_init(&buffer->mutex);
26532666
2667+ /* Persistent ring buffer needs to flush cache before reboot. */
2668+ if (start && end) {
2669+ buffer->flush_nb.notifier_call = rb_flush_buffer_cb;
2670+ atomic_notifier_chain_register(&panic_notifier_list, &buffer->flush_nb);
2671+ }
2672+
26542673 return_ptr(buffer);
26552674
26562675 fail_free_buffers:
@@ -2749,6 +2768,9 @@ ring_buffer_free(struct trace_buffer *buffer) · 92 unmodified lines
27492768 {
27502769 int cpu;
27512770
2771+ if (buffer->range_addr_start && buffer->range_addr_end)
2772+ atomic_notifier_chain_unregister(&panic_notifier_list, &buffer->flush_nb);
2773+
27522774 cpuhp_state_remove_instance(CPUHP_TRACE_RB_PREPARE, &buffer->node);
27532775
27542776 irq_work_sync(&buffer->irq_work.work);
@@ -5407,6 +5429,7 @@ static void rb_iter_reset(struct ring_buffer_iter *iter) · 2652 unmodified lines
54075429 iter->head_page = cpu_buffer->reader_page;
54085430 iter->head = cpu_buffer->reader_page->read;
54095431 iter->next_event = iter->head;
5432+ iter->missed_events = 0;
54105433
54115434 iter->cache_reader_page = iter->head_page;
54125435 iter->cache_read = cpu_buffer->read;
@@ -6086,10 +6109,7 @@ ring_buffer_peek(struct trace_buffer *buffer, int cpu, u64 *ts, · 673 unmodified lines
60866109 */
60876110 bool ring_buffer_iter_dropped(struct ring_buffer_iter *iter)
60886111 {
6089− bool ret = iter->missed_events != 0;
6090−
6091− iter->missed_events = 0;
6092− return ret;
6112+ return iter->missed_events != 0;
60936113 }
60946114 EXPORT_SYMBOL_GPL(ring_buffer_iter_dropped);
60956115
@@ -6251,7 +6271,7 @@ void ring_buffer_iter_advance(struct ring_buffer_iter *iter) · 155 unmodified lines
62516271 unsigned long flags;
62526272
62536273 raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
6254−
6274+ iter->missed_events = 0;
62556275 rb_advance_iter(iter);
62566276
62576277 raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
kernel/trace/simple_ring_buffer.c+2−2
@@ -395,7 +395,6 @@ int simple_ring_buffer_init_mm(struct simple_rb_per_cpu *cpu_buffer, · 394 unmodified lines
395395
396396 memset(cpu_buffer->meta, 0, sizeof(*cpu_buffer->meta));
397397 cpu_buffer->meta->meta_page_size = PAGE_SIZE;
398− cpu_buffer->meta->nr_subbufs = cpu_buffer->nr_pages;
399398
400399 /* The reader page is not part of the ring initially */
401400 page = load_page(desc->page_va[0]);
@@ -431,12 +430,13 @@ int simple_ring_buffer_init_mm(struct simple_rb_per_cpu *cpu_buffer, · 29 unmodified lines
431430
432431 if (ret) {
433432 for (i--; i >= 0; i--)
434− unload_page((void *)desc->page_va[i]);
433+ unload_page(bpages[i].page);
435434 unload_page(cpu_buffer->meta);
436435
437436 return ret;
438437 }
439438
439+ cpu_buffer->meta->nr_subbufs = cpu_buffer->nr_pages;
440440 /* Close the ring */
441441 bpage->link.next = &cpu_buffer->tail_page->link;
442442 cpu_buffer->tail_page->link.prev = &bpage->link;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t