diff options
author | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2017-08-02 14:20:54 -0400 |
---|---|---|
committer | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2017-08-02 14:23:02 -0400 |
commit | a7e52ad7ed82e21273eccff93d1477a7b313aabb (patch) | |
tree | aa585bef3c5badaf4c9f20b8959ec3dc8a06e04c /kernel/trace/ring_buffer.c | |
parent | 147d88e0b5eb90191bc5c12ca0a3c410b75a13d2 (diff) |
ring-buffer: Have ring_buffer_alloc_read_page() return error on offline CPU
Chunyu Hu reported:
"per_cpu trace directories and files are created for all possible cpus,
but only the cpus which have ever been on-lined have their own per cpu
ring buffer (allocated by cpuhp threads). While trace_buffers_open, the
open handler for trace file 'trace_pipe_raw' is always trying to access
field of ring_buffer_per_cpu, and would panic with the NULL pointer.
Align the behavior of trace_pipe_raw with trace_pipe, that returns -NODEV
when openning it if that cpu does not have trace ring buffer.
Reproduce:
cat /sys/kernel/debug/tracing/per_cpu/cpu31/trace_pipe_raw
(cpu31 is never on-lined, this is a 16 cores x86_64 box)
Tested with:
1) boot with maxcpus=14, read trace_pipe_raw of cpu15.
Got -NODEV.
2) oneline cpu15, read trace_pipe_raw of cpu15.
Get the raw trace data.
Call trace:
[ 5760.950995] RIP: 0010:ring_buffer_alloc_read_page+0x32/0xe0
[ 5760.961678] tracing_buffers_read+0x1f6/0x230
[ 5760.962695] __vfs_read+0x37/0x160
[ 5760.963498] ? __vfs_read+0x5/0x160
[ 5760.964339] ? security_file_permission+0x9d/0xc0
[ 5760.965451] ? __vfs_read+0x5/0x160
[ 5760.966280] vfs_read+0x8c/0x130
[ 5760.967070] SyS_read+0x55/0xc0
[ 5760.967779] do_syscall_64+0x67/0x150
[ 5760.968687] entry_SYSCALL64_slow_path+0x25/0x25"
This was introduced by the addition of the feature to reuse reader pages
instead of re-allocating them. The problem is that the allocation of a
reader page (which is per cpu) does not check if the cpu is online and set
up for the ring buffer.
Link: http://lkml.kernel.org/r/1500880866-1177-1-git-send-email-chuhu@redhat.com
Cc: stable@vger.kernel.org
Fixes: 73a757e63114 ("ring-buffer: Return reader page back into existing ring buffer")
Reported-by: Chunyu Hu <chuhu@redhat.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/ring_buffer.c')
-rw-r--r-- | kernel/trace/ring_buffer.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 529cc50d7243..81279c6602ff 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c | |||
@@ -4386,15 +4386,19 @@ EXPORT_SYMBOL_GPL(ring_buffer_swap_cpu); | |||
4386 | * the page that was allocated, with the read page of the buffer. | 4386 | * the page that was allocated, with the read page of the buffer. |
4387 | * | 4387 | * |
4388 | * Returns: | 4388 | * Returns: |
4389 | * The page allocated, or NULL on error. | 4389 | * The page allocated, or ERR_PTR |
4390 | */ | 4390 | */ |
4391 | void *ring_buffer_alloc_read_page(struct ring_buffer *buffer, int cpu) | 4391 | void *ring_buffer_alloc_read_page(struct ring_buffer *buffer, int cpu) |
4392 | { | 4392 | { |
4393 | struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu]; | 4393 | struct ring_buffer_per_cpu *cpu_buffer; |
4394 | struct buffer_data_page *bpage = NULL; | 4394 | struct buffer_data_page *bpage = NULL; |
4395 | unsigned long flags; | 4395 | unsigned long flags; |
4396 | struct page *page; | 4396 | struct page *page; |
4397 | 4397 | ||
4398 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) | ||
4399 | return ERR_PTR(-ENODEV); | ||
4400 | |||
4401 | cpu_buffer = buffer->buffers[cpu]; | ||
4398 | local_irq_save(flags); | 4402 | local_irq_save(flags); |
4399 | arch_spin_lock(&cpu_buffer->lock); | 4403 | arch_spin_lock(&cpu_buffer->lock); |
4400 | 4404 | ||
@@ -4412,7 +4416,7 @@ void *ring_buffer_alloc_read_page(struct ring_buffer *buffer, int cpu) | |||
4412 | page = alloc_pages_node(cpu_to_node(cpu), | 4416 | page = alloc_pages_node(cpu_to_node(cpu), |
4413 | GFP_KERNEL | __GFP_NORETRY, 0); | 4417 | GFP_KERNEL | __GFP_NORETRY, 0); |
4414 | if (!page) | 4418 | if (!page) |
4415 | return NULL; | 4419 | return ERR_PTR(-ENOMEM); |
4416 | 4420 | ||
4417 | bpage = page_address(page); | 4421 | bpage = page_address(page); |
4418 | 4422 | ||
@@ -4467,8 +4471,8 @@ EXPORT_SYMBOL_GPL(ring_buffer_free_read_page); | |||
4467 | * | 4471 | * |
4468 | * for example: | 4472 | * for example: |
4469 | * rpage = ring_buffer_alloc_read_page(buffer, cpu); | 4473 | * rpage = ring_buffer_alloc_read_page(buffer, cpu); |
4470 | * if (!rpage) | 4474 | * if (IS_ERR(rpage)) |
4471 | * return error; | 4475 | * return PTR_ERR(rpage); |
4472 | * ret = ring_buffer_read_page(buffer, &rpage, len, cpu, 0); | 4476 | * ret = ring_buffer_read_page(buffer, &rpage, len, cpu, 0); |
4473 | * if (ret >= 0) | 4477 | * if (ret >= 0) |
4474 | * process_page(rpage, ret); | 4478 | * process_page(rpage, ret); |