Repository navigation
Commit e2d4dbe
tracing: Introduce trace_create_cpu_file() and tracing_get_cpu()
commit 649e9c7 upstream.
Every "file_operations" used by tracing_init_debugfs_percpu is buggy.
f_op->open/etc does:
1. struct trace_cpu *tc = inode->i_private;
struct trace_array *tr = tc->tr;
2. trace_array_get(tr) or fail;
3. do_something(tc);
But tc (and tr) can be already freed before trace_array_get() is called.
And it doesn't matter whether this file is per-cpu or it was created by
init_tracer_debugfs(), free_percpu() or kfree() are equally bad.
Note that even 1. is not safe, the freed memory can be unmapped. But even
if it was safe trace_array_get() can wrongly succeed if we also race with
the next new_instance_create() which can re-allocate the same tr, or tc
was overwritten and ->tr points to the valid tr. In this case 3. uses the
freed/reused memory.
Add the new trivial helper, trace_create_cpu_file() which simply calls
trace_create_file() and encodes "cpu" in "struct inode". Another helper,
tracing_get_cpu() will be used to read cpu_nr-or-RING_BUFFER_ALL_CPUS.
The patch abuses ->i_cdev to encode the number, it is never used unless
the file is S_ISCHR(). But we could use something else, say, i_bytes or
even ->d_fsdata. In any case this hack is hidden inside these 2 helpers,
it would be trivial to change them if needed.
This patch only changes tracing_init_debugfs_percpu() to use the new
trace_create_cpu_file(), the next patches will change file_operations.
Note: tracing_get_cpu(inode) is always safe but you can't trust the
result unless trace_array_get() was called, without trace_types_lock
which acts as a barrier it can wrongly return RING_BUFFER_ALL_CPUS.
Link: http://lkml.kernel.org/r/20130723152554.GA23710@redhat.com
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent e899e7e commit e2d4dbe
1 file changed
Lines changed: 36 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2834 | 2834 | | |
2835 | 2835 | | |
2836 | 2836 | | |
| 2837 | + | |
| 2838 | + | |
| 2839 | + | |
| 2840 | + | |
| 2841 | + | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
| 2847 | + | |
2837 | 2848 | | |
2838 | 2849 | | |
2839 | 2850 | | |
| |||
5521 | 5532 | | |
5522 | 5533 | | |
5523 | 5534 | | |
| 5535 | + | |
| 5536 | + | |
| 5537 | + | |
| 5538 | + | |
| 5539 | + | |
| 5540 | + | |
| 5541 | + | |
| 5542 | + | |
| 5543 | + | |
| 5544 | + | |
| 5545 | + | |
5524 | 5546 | | |
5525 | 5547 | | |
5526 | 5548 | | |
| |||
5540 | 5562 | | |
5541 | 5563 | | |
5542 | 5564 | | |
5543 | | - | |
5544 | | - | |
| 5565 | + | |
| 5566 | + | |
5545 | 5567 | | |
5546 | 5568 | | |
5547 | | - | |
5548 | | - | |
| 5569 | + | |
| 5570 | + | |
5549 | 5571 | | |
5550 | | - | |
5551 | | - | |
| 5572 | + | |
| 5573 | + | |
5552 | 5574 | | |
5553 | | - | |
5554 | | - | |
| 5575 | + | |
| 5576 | + | |
5555 | 5577 | | |
5556 | | - | |
5557 | | - | |
| 5578 | + | |
| 5579 | + | |
5558 | 5580 | | |
5559 | 5581 | | |
5560 | | - | |
5561 | | - | |
| 5582 | + | |
| 5583 | + | |
5562 | 5584 | | |
5563 | | - | |
5564 | | - | |
| 5585 | + | |
| 5586 | + | |
5565 | 5587 | | |
5566 | 5588 | | |
5567 | 5589 | | |
| |||
0 commit comments