]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.54/perf-namespace-protect-reading-thread-s-namespace.patch
Linux 4.19.54
[thirdparty/kernel/stable-queue.git] / releases / 4.19.54 / perf-namespace-protect-reading-thread-s-namespace.patch
CommitLineData
a15a8890
SL
1From d3f7cba32820e241abf2f94ada3ce83ad96b04e4 Mon Sep 17 00:00:00 2001
2From: Namhyung Kim <namhyung@kernel.org>
3Date: Wed, 22 May 2019 14:32:48 +0900
4Subject: perf namespace: Protect reading thread's namespace
5
6[ Upstream commit 6584140ba9e6762dd7ec73795243289b914f31f9 ]
7
8It seems that the current code lacks holding the namespace lock in
9thread__namespaces(). Otherwise it can see inconsistent results.
10
11Signed-off-by: Namhyung Kim <namhyung@kernel.org>
12Cc: Hari Bathini <hbathini@linux.vnet.ibm.com>
13Cc: Jiri Olsa <jolsa@redhat.com>
14Cc: Krister Johansen <kjlx@templeofstupid.com>
15Link: http://lkml.kernel.org/r/20190522053250.207156-2-namhyung@kernel.org
16Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
17Signed-off-by: Sasha Levin <sashal@kernel.org>
18---
19 tools/perf/util/thread.c | 15 +++++++++++++--
20 1 file changed, 13 insertions(+), 2 deletions(-)
21
22diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
23index 2048d393ece6..56007a7e0b4d 100644
24--- a/tools/perf/util/thread.c
25+++ b/tools/perf/util/thread.c
26@@ -128,7 +128,7 @@ void thread__put(struct thread *thread)
27 }
28 }
29
30-struct namespaces *thread__namespaces(const struct thread *thread)
31+static struct namespaces *__thread__namespaces(const struct thread *thread)
32 {
33 if (list_empty(&thread->namespaces_list))
34 return NULL;
35@@ -136,10 +136,21 @@ struct namespaces *thread__namespaces(const struct thread *thread)
36 return list_first_entry(&thread->namespaces_list, struct namespaces, list);
37 }
38
39+struct namespaces *thread__namespaces(const struct thread *thread)
40+{
41+ struct namespaces *ns;
42+
43+ down_read((struct rw_semaphore *)&thread->namespaces_lock);
44+ ns = __thread__namespaces(thread);
45+ up_read((struct rw_semaphore *)&thread->namespaces_lock);
46+
47+ return ns;
48+}
49+
50 static int __thread__set_namespaces(struct thread *thread, u64 timestamp,
51 struct namespaces_event *event)
52 {
53- struct namespaces *new, *curr = thread__namespaces(thread);
54+ struct namespaces *new, *curr = __thread__namespaces(thread);
55
56 new = namespaces__new(event);
57 if (!new)
58--
592.20.1
60