Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be0e6266 authored by Namhyung Kim's avatar Namhyung Kim Committed by Greg Kroah-Hartman
Browse files

perf namespace: Protect reading thread's namespace



[ Upstream commit 6584140ba9e6762dd7ec73795243289b914f31f9 ]

It seems that the current code lacks holding the namespace lock in
thread__namespaces().  Otherwise it can see inconsistent results.

Signed-off-by: default avatarNamhyung 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 7d523e33
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -128,7 +128,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))
		return NULL;
@@ -136,10 +136,21 @@ struct namespaces *thread__namespaces(const struct thread *thread)
	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)