Skip to content

Commit bca704f

Browse files
committed
ring-buffer: Don't reset persistent ring-buffer meta saved addresses
The text and data address is saved in the meta data so that it can be used to know the delta of the text and data addresses of the last boot compared to the text and data addresses of the current boot. The delta is used to convert function pointer entries in the ring buffer to something that can be used by kallsyms (note this only works for built-in functions). But the saved addresses get reset on boot up. If the buffer is not used and there's another reboot, then the saved text and data addresses will be of the last boot and not that of the boot that created the content in the ring buffer. To get an idea of the issue: # trace-cmd start -B boot_mapped -p function # reboot # trace-cmd show -B boot_mapped | tail <...>-1 [000] d..1. 461.983243: native_apic_msr_write <-native_kick_ap <...>-1 [000] d..1. 461.983244: __pfx_native_apic_msr_eoi <-native_kick_ap <...>-1 [000] d..1. 461.983244: reserve_irq_vector_locked <-native_kick_ap <...>-1 [000] d..1. 461.983262: branch_emulate_op <-native_kick_ap <...>-1 [000] d..1. 461.983262: __ia32_sys_ia32_pread64 <-native_kick_ap <...>-1 [000] d..1. 461.983263: native_kick_ap <-__smpboot_create_thread <...>-1 [000] d..1. 461.983263: store_cache_disable <-native_kick_ap <...>-1 [000] d..1. 461.983279: acpi_power_off_prepare <-native_kick_ap <...>-1 [000] d..1. 461.983280: __pfx_acpi_ns_delete_node <-acpi_suspend_enter <...>-1 [000] d..1. 461.983280: __pfx_acpi_os_release_lock <-acpi_suspend_enter # reboot # trace-cmd show -B boot_mapped |tail <...>-1 [000] d..1. 461.983243: 0xffffffffa9669220 <-0xffffffffa965f3db <...>-1 [000] d..1. 461.983244: 0xffffffffa96690f0 <-0xffffffffa965f3db <...>-1 [000] d..1. 461.983244: 0xffffffffa9663fa0 <-0xffffffffa965f3db <...>-1 [000] d..1. 461.983262: 0xffffffffa9672e80 <-0xffffffffa965f3e0 <...>-1 [000] d..1. 461.983262: 0xffffffffa962b940 <-0xffffffffa965f3ec <...>-1 [000] d..1. 461.983263: 0xffffffffa965f540 <-0xffffffffa96e1362 <...>-1 [000] d..1. 461.983263: 0xffffffffa963c940 <-0xffffffffa965f55b <...>-1 [000] d..1. 461.983279: 0xffffffffa9ee30c0 <-0xffffffffa965f59b <...>-1 [000] d..1. 461.983280: 0xffffffffa9f16c10 <-0xffffffffa9ee3157 <...>-1 [000] d..1. 461.983280: 0xffffffffa9ee02e0 <-0xffffffffa9ee3157 By not updating the saved text and data addresses in the meta data at every boot up and only updating them when the buffer is reset, it allows multiple boots to see the same data. Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Vincent Donnefort <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 4c57d0b commit bca704f

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

kernel/trace/ring_buffer.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,12 +1817,19 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
18171817
/* Used to calculate data delta */
18181818
static char rb_data_ptr[] = "";
18191819

1820+
#define THIS_TEXT_PTR ((unsigned long)rb_meta_init_text_addr)
1821+
#define THIS_DATA_PTR ((unsigned long)rb_data_ptr)
1822+
1823+
static void rb_meta_init_text_addr(struct ring_buffer_meta *meta)
1824+
{
1825+
meta->text_addr = THIS_TEXT_PTR;
1826+
meta->data_addr = THIS_DATA_PTR;
1827+
}
1828+
18201829
static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages)
18211830
{
18221831
struct ring_buffer_meta *meta;
18231832
unsigned long delta;
1824-
unsigned long this_text = (unsigned long)rb_range_meta_init;
1825-
unsigned long this_data = (unsigned long)rb_data_ptr;
18261833
void *subbuf;
18271834
int cpu;
18281835
int i;
@@ -1839,10 +1846,8 @@ static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages)
18391846
meta->first_buffer += delta;
18401847
meta->head_buffer += delta;
18411848
meta->commit_buffer += delta;
1842-
buffer->last_text_delta = this_text - meta->text_addr;
1843-
buffer->last_data_delta = this_data - meta->data_addr;
1844-
meta->text_addr = this_text;
1845-
meta->data_addr = this_data;
1849+
buffer->last_text_delta = THIS_TEXT_PTR - meta->text_addr;
1850+
buffer->last_data_delta = THIS_DATA_PTR - meta->data_addr;
18461851
continue;
18471852
}
18481853

@@ -1859,8 +1864,7 @@ static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages)
18591864
subbuf = rb_subbufs_from_meta(meta);
18601865

18611866
meta->first_buffer = (unsigned long)subbuf;
1862-
meta->text_addr = this_text;
1863-
meta->data_addr = this_data;
1867+
rb_meta_init_text_addr(meta);
18641868

18651869
/*
18661870
* The buffers[] array holds the order of the sub-buffers
@@ -5990,6 +5994,7 @@ static void reset_disabled_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer)
59905994
void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu)
59915995
{
59925996
struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
5997+
struct ring_buffer_meta *meta;
59935998

59945999
if (!cpumask_test_cpu(cpu, buffer->cpumask))
59956000
return;
@@ -6008,6 +6013,11 @@ void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu)
60086013
atomic_dec(&cpu_buffer->record_disabled);
60096014
atomic_dec(&cpu_buffer->resize_disabled);
60106015

6016+
/* Make sure persistent meta now uses this buffer's addresses */
6017+
meta = rb_range_meta(buffer, 0, cpu_buffer->cpu);
6018+
if (meta)
6019+
rb_meta_init_text_addr(meta);
6020+
60116021
mutex_unlock(&buffer->mutex);
60126022
}
60136023
EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu);
@@ -6022,6 +6032,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu);
60226032
void ring_buffer_reset_online_cpus(struct trace_buffer *buffer)
60236033
{
60246034
struct ring_buffer_per_cpu *cpu_buffer;
6035+
struct ring_buffer_meta *meta;
60256036
int cpu;
60266037

60276038
/* prevent another thread from changing buffer sizes */
@@ -6049,6 +6060,11 @@ void ring_buffer_reset_online_cpus(struct trace_buffer *buffer)
60496060

60506061
reset_disabled_cpu_buffer(cpu_buffer);
60516062

6063+
/* Make sure persistent meta now uses this buffer's addresses */
6064+
meta = rb_range_meta(buffer, 0, cpu_buffer->cpu);
6065+
if (meta)
6066+
rb_meta_init_text_addr(meta);
6067+
60526068
atomic_dec(&cpu_buffer->record_disabled);
60536069
atomic_sub(RESET_BIT, &cpu_buffer->resize_disabled);
60546070
}

0 commit comments

Comments
 (0)