Skip to content

Commit

Permalink
perf namespace: Protect reading thread's namespace
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed May 28, 2019
1 parent 9903c64 commit 6584140
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tools/perf/util/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,29 @@ void thread__put(struct thread *thread)
}
}

struct namespaces *thread__namespaces(const struct thread *thread)
static struct namespaces *__thread__namespaces(const struct thread *thread)
{
if (list_empty(&thread->namespaces_list))
return NULL;

return list_first_entry(&thread->namespaces_list, struct namespaces, list);
}

struct namespaces *thread__namespaces(const struct thread *thread)
{
struct namespaces *ns;

down_read((struct rw_semaphore *)&thread->namespaces_lock);
ns = __thread__namespaces(thread);
up_read((struct rw_semaphore *)&thread->namespaces_lock);

return ns;
}

static int __thread__set_namespaces(struct thread *thread, u64 timestamp,
struct namespaces_event *event)
{
struct namespaces *new, *curr = thread__namespaces(thread);
struct namespaces *new, *curr = __thread__namespaces(thread);

new = namespaces__new(event);
if (!new)
Expand Down

0 comments on commit 6584140

Please sign in to comment.