Commit c2489bb
tracing: Introduce pipe_cpumask to avoid race on trace_pipes
There is race issue when concurrently splice_read main trace_pipe and
per_cpu trace_pipes which will result in data read out being different
from what actually writen.
As suggested by Steven:
> I believe we should add a ref count to trace_pipe and the per_cpu
> trace_pipes, where if they are opened, nothing else can read it.
>
> Opening trace_pipe locks all per_cpu ref counts, if any of them are
> open, then the trace_pipe open will fail (and releases any ref counts
> it had taken).
>
> Opening a per_cpu trace_pipe will up the ref count for just that
> CPU buffer. This will allow multiple tasks to read different per_cpu
> trace_pipe files, but will prevent the main trace_pipe file from
> being opened.
But because we only need to know whether per_cpu trace_pipe is open or
not, using a cpumask instead of using ref count may be easier.
After this patch, users will find that:
- Main trace_pipe can be opened by only one user, and if it is
opened, all per_cpu trace_pipes cannot be opened;
- Per_cpu trace_pipes can be opened by multiple users, but each per_cpu
trace_pipe can only be opened by one user. And if one of them is
opened, main trace_pipe cannot be opened.
Link: https://lore.kernel.org/linux-trace-kernel/20230818022645.1948314-1-zhengyejian1@huawei.com
Suggested-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Zheng Yejian <zhengyejian1@huawei.com>
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>1 parent eecb91b commit c2489bb
2 files changed
Lines changed: 50 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6718 | 6718 | | |
6719 | 6719 | | |
6720 | 6720 | | |
| 6721 | + | |
| 6722 | + | |
| 6723 | + | |
| 6724 | + | |
| 6725 | + | |
| 6726 | + | |
| 6727 | + | |
| 6728 | + | |
| 6729 | + | |
| 6730 | + | |
| 6731 | + | |
| 6732 | + | |
| 6733 | + | |
| 6734 | + | |
| 6735 | + | |
| 6736 | + | |
| 6737 | + | |
| 6738 | + | |
| 6739 | + | |
| 6740 | + | |
| 6741 | + | |
| 6742 | + | |
| 6743 | + | |
| 6744 | + | |
| 6745 | + | |
6721 | 6746 | | |
6722 | 6747 | | |
6723 | 6748 | | |
6724 | 6749 | | |
| 6750 | + | |
6725 | 6751 | | |
6726 | 6752 | | |
6727 | 6753 | | |
6728 | 6754 | | |
6729 | 6755 | | |
6730 | 6756 | | |
6731 | 6757 | | |
| 6758 | + | |
| 6759 | + | |
| 6760 | + | |
| 6761 | + | |
6732 | 6762 | | |
6733 | 6763 | | |
6734 | 6764 | | |
6735 | 6765 | | |
6736 | 6766 | | |
6737 | | - | |
6738 | | - | |
| 6767 | + | |
6739 | 6768 | | |
6740 | 6769 | | |
6741 | 6770 | | |
| |||
6758 | 6787 | | |
6759 | 6788 | | |
6760 | 6789 | | |
6761 | | - | |
| 6790 | + | |
6762 | 6791 | | |
6763 | 6792 | | |
6764 | 6793 | | |
| |||
6768 | 6797 | | |
6769 | 6798 | | |
6770 | 6799 | | |
6771 | | - | |
| 6800 | + | |
6772 | 6801 | | |
6773 | 6802 | | |
6774 | 6803 | | |
6775 | 6804 | | |
6776 | 6805 | | |
| 6806 | + | |
| 6807 | + | |
| 6808 | + | |
6777 | 6809 | | |
6778 | 6810 | | |
6779 | 6811 | | |
| |||
6790 | 6822 | | |
6791 | 6823 | | |
6792 | 6824 | | |
6793 | | - | |
| 6825 | + | |
6794 | 6826 | | |
6795 | 6827 | | |
6796 | 6828 | | |
| |||
9454 | 9486 | | |
9455 | 9487 | | |
9456 | 9488 | | |
| 9489 | + | |
| 9490 | + | |
| 9491 | + | |
9457 | 9492 | | |
9458 | 9493 | | |
9459 | 9494 | | |
| |||
9495 | 9530 | | |
9496 | 9531 | | |
9497 | 9532 | | |
| 9533 | + | |
9498 | 9534 | | |
9499 | 9535 | | |
9500 | 9536 | | |
| |||
9597 | 9633 | | |
9598 | 9634 | | |
9599 | 9635 | | |
| 9636 | + | |
9600 | 9637 | | |
9601 | 9638 | | |
9602 | 9639 | | |
| |||
10394 | 10431 | | |
10395 | 10432 | | |
10396 | 10433 | | |
| 10434 | + | |
| 10435 | + | |
| 10436 | + | |
10397 | 10437 | | |
10398 | 10438 | | |
10399 | 10439 | | |
10400 | | - | |
| 10440 | + | |
10401 | 10441 | | |
10402 | | - | |
10403 | 10442 | | |
10404 | 10443 | | |
10405 | 10444 | | |
| |||
10452 | 10491 | | |
10453 | 10492 | | |
10454 | 10493 | | |
| 10494 | + | |
| 10495 | + | |
10455 | 10496 | | |
10456 | 10497 | | |
10457 | 10498 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| 380 | + | |
| 381 | + | |
380 | 382 | | |
381 | 383 | | |
382 | 384 | | |
| |||
0 commit comments