diff options
| author | Namhyung Kim <namhyung@kernel.org> | 2019-05-22 01:32:48 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-05-28 08:52:23 -0400 |
| commit | 6584140ba9e6762dd7ec73795243289b914f31f9 (patch) | |
| tree | 6fe8c8903c16a4a1f296530c7bd7523f824013e4 | |
| parent | 9903c64f0fe7fa4829c948fa0e742f578e084548 (diff) | |
perf namespace: Protect reading thread's namespace
It seems that the current code lacks holding the namespace lock in
thread__namespaces(). Otherwise it can see inconsistent results.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Hari Bathini <hbathini@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Krister Johansen <kjlx@templeofstupid.com>
Link: http://lkml.kernel.org/r/20190522053250.207156-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
| -rw-r--r-- | tools/perf/util/thread.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 403045a2bbea..b413ba5b9835 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c | |||
| @@ -133,7 +133,7 @@ void thread__put(struct thread *thread) | |||
| 133 | } | 133 | } |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | struct namespaces *thread__namespaces(const struct thread *thread) | 136 | static struct namespaces *__thread__namespaces(const struct thread *thread) |
| 137 | { | 137 | { |
| 138 | if (list_empty(&thread->namespaces_list)) | 138 | if (list_empty(&thread->namespaces_list)) |
| 139 | return NULL; | 139 | return NULL; |
| @@ -141,10 +141,21 @@ struct namespaces *thread__namespaces(const struct thread *thread) | |||
| 141 | return list_first_entry(&thread->namespaces_list, struct namespaces, list); | 141 | return list_first_entry(&thread->namespaces_list, struct namespaces, list); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | struct namespaces *thread__namespaces(const struct thread *thread) | ||
| 145 | { | ||
| 146 | struct namespaces *ns; | ||
| 147 | |||
| 148 | down_read((struct rw_semaphore *)&thread->namespaces_lock); | ||
| 149 | ns = __thread__namespaces(thread); | ||
| 150 | up_read((struct rw_semaphore *)&thread->namespaces_lock); | ||
| 151 | |||
| 152 | return ns; | ||
| 153 | } | ||
| 154 | |||
| 144 | static int __thread__set_namespaces(struct thread *thread, u64 timestamp, | 155 | static int __thread__set_namespaces(struct thread *thread, u64 timestamp, |
| 145 | struct namespaces_event *event) | 156 | struct namespaces_event *event) |
| 146 | { | 157 | { |
| 147 | struct namespaces *new, *curr = thread__namespaces(thread); | 158 | struct namespaces *new, *curr = __thread__namespaces(thread); |
| 148 | 159 | ||
| 149 | new = namespaces__new(event); | 160 | new = namespaces__new(event); |
| 150 | if (!new) | 161 | if (!new) |
