Skip to contentSkip to conversation

Fix mmap-thread-lookup.c unitialized memory usage

PATCH In review Numfor Mbiziwo-Tiapo 3 participants 5 messages Jul 2, 2019 – Jul 13, 2019 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Fix mmap-thread-lookup.c unitialized memory usage

Running the perf test command after building perf with a memory sanitizer causes a warning that says:
WARNING: MemorySanitizer: use-of-uninitialized-value... in mmap-thread-lookup.c Initializing the go variable to 0 fixes this change.

---
 tools/perf/tests/mmap-thread-lookup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/mmap-thread-lookup.c +1 -1
index 5ede9b561d32..b1abf4752f35 100644
@@ -52,7 +52,7 @@ static void *thread_fn(void *arg)
 {
 	struct thread_data *td = arg;
 	ssize_t ret;
-	int go;
+	int go = 0;
 
 	if (thread_init(td))
 		return NULL;
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#1 lore raw

PATCH 2/2 Fix perf-hooks test

The perf-hooks test fails with Address Sanitizer and Memory Sanitizer builds because it purposefully generates a segfault. Checking if these sanitizers are active when running this test will allow the perf-hooks test to pass.

---
 tools/perf/tests/perf-hooks.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/perf/tests/perf-hooks.c +5 -0
index a693bcf017ea..524ecba63615 100644
@@ -25,7 +25,12 @@ static void the_hook(void *_hook_flags)
 	*hook_flags = 1234;
 
 	/* Generate a segfault, test perf_hooks__recover */
+#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
+defined(THREAD_SANITIZER) || defined(SAFESTACK_SANITIZER)
+	raise(SIGSEGV);
+#else
 	*p = 0;
+#endif
 }
 
 int test__perf_hooks(struct test *test __maybe_unused, int subtest __maybe_unused)
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#2 lore raw

Re: [PATCH 2/2] Fix perf-hooks test

Em Tue, Jul 02, 2019 at 10:37:16AM -0700, Numfor Mbiziwo-Tiapo escreveu:

Quoted 4 lines

The perf-hooks test fails with Address Sanitizer and Memory Sanitizer builds because it purposefully generates a segfault. Checking if these sanitizers are active when running this test will allow the perf-hooks test to pass.

Can you please add to the commit log message, here, the sequence of steps needed to build with these sanitizers, so that one can replicate the steps and reproduce the results?

- Arnaldo

Quoted 24 lines
---
 tools/perf/tests/perf-hooks.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/perf/tests/perf-hooks.c +5 -0
index a693bcf017ea..524ecba63615 100644
@@ -25,7 +25,12 @@ static void the_hook(void *_hook_flags)
 	*hook_flags = 1234;
 
 	/* Generate a segfault, test perf_hooks__recover */
+#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
+defined(THREAD_SANITIZER) || defined(SAFESTACK_SANITIZER)
+	raise(SIGSEGV);
+#else
 	*p = 0;
+#endif
 }
 
 int test__perf_hooks(struct test *test __maybe_unused, int subtest __maybe_unused)
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Signature · 1 line
- Arnaldo
#3 lore raw
In reply to Numfor Mbiziwo-Tiapo

Em Tue, Jul 02, 2019 at 10:37:15AM -0700, Numfor Mbiziwo-Tiapo escreveu:

Quoted 15 lines

Running the perf test command after building perf with a memory sanitizer causes a warning that says:
WARNING: MemorySanitizer: use-of-uninitialized-value... in mmap-thread-lookup.c Initializing the go variable to 0 fixes this change.

---
 tools/perf/tests/mmap-thread-lookup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/mmap-thread-lookup.c +0 -0
index 5ede9b561d32..b1abf4752f35 100644

tools/perf/tests/mmap-thread-lookup.c static void *thread_fn(void *arg) · line 58

Quoted 8 lines
tools/perf/tests/mmap-thread-lookup.c +1 -1
@@ -52,7 +52,7 @@ static void *thread_fn(void *arg)
 {
 	struct thread_data *td = arg;
 	ssize_t ret;
-	int go;
+	int go = 0;
 
 	if (thread_init(td))
 		return NULL;

The test needs to write something to a file, whatever, so this doesn't fix anything, just silences the compiler warning, which is a good thing.

I'll apply and adjust the cset commit log.

Thanks,

- Arnaldo

#4 lore raw

[tip:perf/urgent] perf test mmap-thread-lookup: Initialize variable to suppress memory sanitizer warning

In reply to Numfor Mbiziwo-Tiapo
perf test mmap-thread-lookup: Initialize variable to suppress memory sanitizer warning
Commit-ID:  4e4cf62b37da5ff45c904a3acf242ab29ed5881d
Gitweb:     https://git.kernel.org/tip/4e4cf62b37da5ff45c904a3acf242ab29ed5881d
Author:     Numfor Mbiziwo-Tiapo <[email protected]>
AuthorDate: Tue, 2 Jul 2019 10:37:15 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 9 Jul 2019 09:33:54 -0300

perf test mmap-thread-lookup: Initialize variable to suppress memory sanitizer warning

Running the 'perf test' command after building perf with a memory sanitizer causes a warning that says:

WARNING: MemorySanitizer: use-of-uninitialized-value... in mmap-thread-lookup.c

Initializing the go variable to 0 silences this harmless warning.

Committer warning:

This was harmless, just a simple test writing whatever was at that sizeof(int) memory area just to signal another thread blocked reading that file created with pipe(). Initialize it tho so that we don't get this warning.

---
 tools/perf/tests/mmap-thread-lookup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/mmap-thread-lookup.c +1 -1
index ba87e6e8d18c..0a4301a5155c 100644
@@ -53,7 +53,7 @@ static void *thread_fn(void *arg)
 {
 	struct thread_data *td = arg;
 	ssize_t ret;
-	int go;
+	int go = 0;
 
 	if (thread_init(td))
 		return NULL;