提交 6584140b 编写于 作者: N Namhyung Kim 提交者: Arnaldo Carvalho de Melo

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: NNamhyung 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.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 9903c64f
...@@ -133,7 +133,7 @@ void thread__put(struct thread *thread) ...@@ -133,7 +133,7 @@ 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)) if (list_empty(&thread->namespaces_list))
return NULL; return NULL;
...@@ -141,10 +141,21 @@ struct namespaces *thread__namespaces(const struct thread *thread) ...@@ -141,10 +141,21 @@ struct namespaces *thread__namespaces(const struct thread *thread)
return list_first_entry(&thread->namespaces_list, struct namespaces, list); 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, static int __thread__set_namespaces(struct thread *thread, u64 timestamp,
struct namespaces_event *event) struct namespaces_event *event)
{ {
struct namespaces *new, *curr = thread__namespaces(thread); struct namespaces *new, *curr = __thread__namespaces(thread);
new = namespaces__new(event); new = namespaces__new(event);
if (!new) if (!new)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册