History

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.

Steven Rostedt committed 2 years ago

Commit bca704f1 parent 4c57d0b1 file · +24 −8Browse files

Unified · Split

kernel/trace/ring_buffer.c+24−8
@@ -1817,12 +1817,19 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer) · 1816 unmodified lines
1817/* Used to calculate data delta */1817/* Used to calculate data delta */
1818static char rb_data_ptr[] = "";1818static char rb_data_ptr[] = "";
1819 1819
1820#define THIS_TEXT_PTR ((unsigned long)rb_meta_init_text_addr)
1821#define THIS_DATA_PTR ((unsigned long)rb_data_ptr)
1822
1823static 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
1820static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages)1829static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages)
1821{1830{
1822 struct ring_buffer_meta *meta;1831 struct ring_buffer_meta *meta;
1823 unsigned long delta;1832 unsigned long delta;
1824 unsigned long this_text = (unsigned long)rb_range_meta_init;
1825 unsigned long this_data = (unsigned long)rb_data_ptr;
1826 void *subbuf;1833 void *subbuf;
1827 int cpu;1834 int cpu;
1828 int i;1835 int i;
@@ -1839,10 +1846,8 @@ static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages) · 10 unmodified lines
1839 meta->first_buffer += delta;1846 meta->first_buffer += delta;
1840 meta->head_buffer += delta;1847 meta->head_buffer += delta;
1841 meta->commit_buffer += delta;1848 meta->commit_buffer += delta;
1842 buffer->last_text_delta = this_text - meta->text_addr;1849 buffer->last_text_delta = THIS_TEXT_PTR - meta->text_addr;
1843 buffer->last_data_delta = this_data - meta->data_addr;1850 buffer->last_data_delta = THIS_DATA_PTR - meta->data_addr;
1844 meta->text_addr = this_text;
1845 meta->data_addr = this_data;
1846 continue;1851 continue;
1847 }1852 }
1848 1853
@@ -1859,8 +1864,7 @@ static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages) · 10 unmodified lines
1859 subbuf = rb_subbufs_from_meta(meta);1864 subbuf = rb_subbufs_from_meta(meta);
1860 1865
1861 meta->first_buffer = (unsigned long)subbuf;1866 meta->first_buffer = (unsigned long)subbuf;
1862 meta->text_addr = this_text;1867 rb_meta_init_text_addr(meta);
1863 meta->data_addr = this_data;
1864 1868
1865 /*1869 /*
1866 * The buffers[] array holds the order of the sub-buffers1870 * 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) · 4123 unmodified lines
5990void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu)5994void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu)
5991{5995{
5992 struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];5996 struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
5997 struct ring_buffer_meta *meta;
5993 5998
5994 if (!cpumask_test_cpu(cpu, buffer->cpumask))5999 if (!cpumask_test_cpu(cpu, buffer->cpumask))
5995 return;6000 return;
@@ -6008,6 +6013,11 @@ void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu) · 12 unmodified lines
6008 atomic_dec(&cpu_buffer->record_disabled);6013 atomic_dec(&cpu_buffer->record_disabled);
6009 atomic_dec(&cpu_buffer->resize_disabled);6014 atomic_dec(&cpu_buffer->resize_disabled);
6010 6015
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
6011 mutex_unlock(&buffer->mutex);6021 mutex_unlock(&buffer->mutex);
6012}6022}
6013EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu);6023EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu);
@@ -6022,6 +6032,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu); · 8 unmodified lines
6022void ring_buffer_reset_online_cpus(struct trace_buffer *buffer)6032void ring_buffer_reset_online_cpus(struct trace_buffer *buffer)
6023{6033{
6024 struct ring_buffer_per_cpu *cpu_buffer;6034 struct ring_buffer_per_cpu *cpu_buffer;
6035 struct ring_buffer_meta *meta;
6025 int cpu;6036 int cpu;
6026 6037
6027 /* prevent another thread from changing buffer sizes */6038 /* prevent another thread from changing buffer sizes */
@@ -6049,6 +6060,11 @@ void ring_buffer_reset_online_cpus(struct trace_buffer *buffer) · 21 unmodified lines
6049 6060
6050 reset_disabled_cpu_buffer(cpu_buffer);6061 reset_disabled_cpu_buffer(cpu_buffer);
6051 6062
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
6052 atomic_dec(&cpu_buffer->record_disabled);6068 atomic_dec(&cpu_buffer->record_disabled);
6053 atomic_sub(RESET_BIT, &cpu_buffer->resize_disabled);6069 atomic_sub(RESET_BIT, &cpu_buffer->resize_disabled);
6054 }6070 }

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