Skip to contentSkip to conversation

perf tests: Check for ARM [vectors] page

PATCH Superseded Florian Fainelli 3 participants 10 messages Oct 25, 2018 – Oct 31, 2018

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover perf tests: Check for ARM [vectors] page

Hi all,

I just painfully learned that perf would segfault when CONFIG_KUSER_HELPERS is disabled because it unconditionally makes use of it. This patch series adds an ARM test for that by leveraging the existing find_vdso_map() function and making it more generic and capable of location any map within /proc/self/maps.

Florian Fainelli (2):
perf tools: Make find_vdso_map() more modular perf tests: Add a test for the ARM 32-bit [vectors] page

 tools/perf/arch/arm/tests/Build          |  1 +
 tools/perf/arch/arm/tests/arch-tests.c   |  4 +++
 tools/perf/arch/arm/tests/vectors-page.c | 20 +++++++++++++++
 tools/perf/tests/tests.h                 |  5 ++++
 tools/perf/util/find-map.c               | 31 ++++++++++++++++++++++++
 tools/perf/util/find-vdso-map.c          | 30 +++--------------------
 6 files changed, 64 insertions(+), 27 deletions(-)
 create mode 100644 tools/perf/arch/arm/tests/vectors-page.c
 create mode 100644 tools/perf/util/find-map.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 perf tools: Make find_vdso_map() more modular

In preparation for checking that the vectors page on the ARM architecture, refactor the find_vdso_map() function to accept finding an arbitrary string and create a dedicated helper function for that under util/find-map.c and update find_vdso_map() to use it.

---
 tools/perf/util/find-map.c      | 31 +++++++++++++++++++++++++++++++
 tools/perf/util/find-vdso-map.c | 30 +++---------------------------
 2 files changed, 34 insertions(+), 27 deletions(-)
 create mode 100644 tools/perf/util/find-map.c
tools/perf/util/find-map.c new file +31 -0
new file mode 100644
index 000000000000..42533fc21108
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+static int find_map(void **start, void **end, const char *name)
+{
+	FILE *maps;
+	char line[128];
+	int found = 0;
+
+	maps = fopen("/proc/self/maps", "r");
+	if (!maps) {
+		fprintf(stderr, "vdso: cannot open maps\n");
+		return -1;
+	}
+
+	while (!found && fgets(line, sizeof(line), maps)) {
+		int m = -1;
+
+		/* We care only about private r-x mappings. */
+		if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n",
+				start, end, &m))
+			continue;
+		if (m < 0)
+			continue;
+
+		if (!strncmp(&line[m], name, sizeof(name) - 1))
+			found = 1;
+	}
+
+	fclose(maps);
+	return !found;
+}
+
tools/perf/util/find-vdso-map.c +3 -27
index d7823e3508fc..840d7d6e29e2 100644
@@ -1,31 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
+#include "find-map.c"
+
 static int find_vdso_map(void **start, void **end)
 {
-	FILE *maps;
-	char line[128];
-	int found = 0;
-
-	maps = fopen("/proc/self/maps", "r");
-	if (!maps) {
-		fprintf(stderr, "vdso: cannot open maps\n");
-		return -1;
-	}
-
-	while (!found && fgets(line, sizeof(line), maps)) {
-		int m = -1;
-
-		/* We care only about private r-x mappings. */
-		if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n",
-				start, end, &m))
-			continue;
-		if (m < 0)
-			continue;
-
-		if (!strncmp(&line[m], VDSO__MAP_NAME,
-			     sizeof(VDSO__MAP_NAME) - 1))
-			found = 1;
-	}
-
-	fclose(maps);
-	return !found;
+	return find_map(start, end, VDSO__MAP_NAME);
 }
Signature · 1 line
2.17.1
#3 lore raw

PATCH 2/2 perf tests: Add a test for the ARM 32-bit [vectors] page

In reply to Florian Fainelli

perf on ARM requires CONFIG_KUSER_HELPERS to be turned on to allow some independance with respect to the ARM CPU being used. Add a test which tries to locate the [vectors] page, created when CONFIG_KUSER_HELPERS is turned on to help asses the system's health.

---
 tools/perf/arch/arm/tests/Build          |  1 +
 tools/perf/arch/arm/tests/arch-tests.c   |  4 ++++
 tools/perf/arch/arm/tests/vectors-page.c | 20 ++++++++++++++++++++
 tools/perf/tests/tests.h                 |  5 +++++
 4 files changed, 30 insertions(+)
 create mode 100644 tools/perf/arch/arm/tests/vectors-page.c
tools/perf/arch/arm/tests/Build +1 -0
index 883c57ff0c08..d9ae2733f9cc 100644
@@ -1,4 +1,5 @@
 libperf-y += regs_load.o
 libperf-y += dwarf-unwind.o
+libperf-y += vectors-page.o
 
 libperf-y += arch-tests.o
tools/perf/arch/arm/tests/arch-tests.c +4 -0
index 5b1543c98022..6848101a855f 100644
@@ -10,6 +10,10 @@ struct test arch_tests[] = {
 		.func = test__dwarf_unwind,
 	},
 #endif
+	{
+		.desc = "Vectors page",
+		.func = test__vectors_page,
+	},
 	{
 		.func = NULL,
 	},
tools/perf/arch/arm/tests/vectors-page.c new file +20 -0
new file mode 100644
index 000000000000..e44223cbf0df
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <string.h>
+#include <linux/compiler.h>
+
+#include "tests/tests.h"
+#include "util/find-map.c"
+
+#define VECTORS__MAP_NAME "[vectors]"
+
+int test__vectors_page(struct test *test __maybe_unused,
+		       int subtest __maybe_unused)
+{
+	void *start, *end;
+
+	if (find_map(&start, &end, VECTORS__MAP_NAME))
+		return -1;
+
+	return 0;
+}
tools/perf/tests/tests.h +5 -0
index b82f55fcc294..399f18ca71a3 100644
@@ -119,4 +119,9 @@ int test__arch_unwind_sample(struct perf_sample *sample,
 			     struct thread *thread);
 #endif
 #endif
+
+#if defined(__arm__)
+int test__vectors_page(struct test *test, int subtest);
+#endif
+
 #endif /* TESTS_H */
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 1/2] perf tools: Make find_vdso_map() more modular

In reply to Florian Fainelli
Quoted 32 lines · Florian Fainelli

In preparation for checking that the vectors page on the ARM architecture, refactor the find_vdso_map() function to accept finding an arbitrary string and create a dedicated helper function for that under util/find-map.c and update find_vdso_map() to use it.

---
 tools/perf/util/find-map.c      | 31 +++++++++++++++++++++++++++++++
 tools/perf/util/find-vdso-map.c | 30 +++---------------------------
 2 files changed, 34 insertions(+), 27 deletions(-)
 create mode 100644 tools/perf/util/find-map.c
tools/perf/util/find-map.c new file +14 -0
new file mode 100644
index 000000000000..42533fc21108
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+static int find_map(void **start, void **end, const char *name)
+{
+	FILE *maps;
+	char line[128];
+	int found = 0;
+
+	maps = fopen("/proc/self/maps", "r");
+	if (!maps) {
+		fprintf(stderr, "vdso: cannot open maps\n");
+		return -1;
+	}
+
+	while (!found && fgets(line, sizeof(line), maps)) {

tools/perf/util/find-map.c line 24

Quoted 10 lines
tools/perf/util/find-map.c new file +10 -0
+		int m = -1;
+
+		/* We care only about private r-x mappings. */
+		if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n",
+				start, end, &m))
+			continue;
+		if (m < 0)
+			continue;
+
+		if (!strncmp(&line[m], name, sizeof(name) - 1))

Meh, this should be strlen() now, but I would like to hear comments before submitting a v2 of this anyway. Thanks!

Signature · 1 line
Florian
#4 lore raw

Re: [PATCH 2/2] perf tests: Add a test for the ARM 32-bit [vectors] page

In reply to Florian Fainelli
Quoted 4 lines · Florian Fainelli

perf on ARM requires CONFIG_KUSER_HELPERS to be turned on to allow some independance with respect to the ARM CPU being used. Add a test which tries to locate the [vectors] page, created when CONFIG_KUSER_HELPERS is turned on to help asses the system's health.

Hi Florian

I've suffered the pain from missing CONFIG_KUSER_HELPERS. The segfaults give little clue as to what is going wrong,and gdb is not much use either.

What i don't see here is any clue to CONFIG_KUSER_HELPERS. If the test fails, could you print a message suggesting CONFIG_KUSER_HELPERS on ARM?

Andrew

#5 lore raw

Re: [PATCH 2/2] perf tests: Add a test for the ARM 32-bit [vectors] page

Quoted 11 lines · Andrew Lunn
Quoted 4 lines · Florian Fainelli

perf on ARM requires CONFIG_KUSER_HELPERS to be turned on to allow some independance with respect to the ARM CPU being used. Add a test which tries to locate the [vectors] page, created when CONFIG_KUSER_HELPERS is turned on to help asses the system's health.

Hi Florian

I've suffered the pain from missing CONFIG_KUSER_HELPERS. The segfaults give little clue as to what is going wrong,and gdb is not much use either.

If you have a working backtrace, you can typically see the virtual address being in 0xffff_xxxx which gives a bit of a clue, but yes, this is not particularly helpful.

Quoted 4 lines

What i don't see here is any clue to CONFIG_KUSER_HELPERS. If the test fails, could you print a message suggesting CONFIG_KUSER_HELPERS on ARM?

Sure, sounds reasonable, thanks for taking a look.

Signature · 1 line
Florian
#6 lore raw

Re: [PATCH 2/2] perf tests: Add a test for the ARM 32-bit [vectors] page

Quoted 18 lines · Florian Fainelli
Quoted 11 lines · Andrew Lunn
Quoted 4 lines · Florian Fainelli

perf on ARM requires CONFIG_KUSER_HELPERS to be turned on to allow some independance with respect to the ARM CPU being used. Add a test which tries to locate the [vectors] page, created when CONFIG_KUSER_HELPERS is turned on to help asses the system's health.

Hi Florian

I've suffered the pain from missing CONFIG_KUSER_HELPERS. The segfaults give little clue as to what is going wrong,and gdb is not much use either.

If you have a working backtrace, you can typically see the virtual address being in 0xffff_xxxx which gives a bit of a clue, but yes, this is not particularly helpful.

Quoted 1 line
Quoted 5 lines
Quoted 3 lines

What i don't see here is any clue to CONFIG_KUSER_HELPERS. If the test fails, could you print a message suggesting CONFIG_KUSER_HELPERS on ARM?

Sure, sounds reasonable, thanks for taking a look.

An alternative would be rather than adding this to user programs, to have the kernel detect it and print a warning itself.

BTW, I note that the help text for CONFIG_KUSER_HELPERS needs to be updated.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#7 lore raw

Re: [PATCH 2/2] perf tests: Add a test for the ARM 32-bit [vectors] page

Quoted 19 lines · Russell King - ARM Linux
Quoted 18 lines · Florian Fainelli
Quoted 11 lines · Andrew Lunn
Quoted 4 lines · Florian Fainelli

perf on ARM requires CONFIG_KUSER_HELPERS to be turned on to allow some independance with respect to the ARM CPU being used. Add a test which tries to locate the [vectors] page, created when CONFIG_KUSER_HELPERS is turned on to help asses the system's health.

Hi Florian

I've suffered the pain from missing CONFIG_KUSER_HELPERS. The segfaults give little clue as to what is going wrong,and gdb is not much use either.

If you have a working backtrace, you can typically see the virtual address being in 0xffff_xxxx which gives a bit of a clue, but yes, this is not particularly helpful.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

What i don't see here is any clue to CONFIG_KUSER_HELPERS. If the test fails, could you print a message suggesting CONFIG_KUSER_HELPERS on ARM?

Sure, sounds reasonable, thanks for taking a look.

An alternative would be rather than adding this to user programs, to have the kernel detect it and print a warning itself.

Something like this below? It does not have to be an alternative solution, I would find it useful for perf to make sure the vectors page is present in the virtual address space by having an explicit test. perf maintains, what do you think?

arch/arm/mm/fault.c +0 -0
index f4ea4c62c613..b045b48d368d 100644
@@ -173,6 +173,11 @@ __do_user_fault(struct task_struct *tsk, unsigned

long addr,

                show_regs(regs);
        }

#endif
+#ifndef CONFIG_KUSER_HELPERS
+ if (((addr & PAGE_MASK) == 0xffff0000) && (sig == SIGSEGV))
+ printk(KERN_DEBUG "%s: CONFIG_KUSER_HELPERS disabled at
0x%08lx\n",
+ tsk->comm, addr);
+#endif

        tsk->thread.address = addr;
        tsk->thread.error_code = fsr;
Quoted 4 lines

BTW, I note that the help text for CONFIG_KUSER_HELPERS needs to be updated.

Signature · 1 line
Florian
#8 lore raw

Re: [PATCH 2/2] perf tests: Add a test for the ARM 32-bit [vectors] page

Quoted 4 lines · Florian Fainelli

Something like this below? It does not have to be an alternative solution, I would find it useful for perf to make sure the vectors page is present in the virtual address space by having an explicit test. perf maintains, what do you think?

Yep, I'd swap the two tests merely because the check for 'sig' will be slightly cheaper than the mask-and-test of addr, but it probably doesn't make that much difference.

Quoted 29 lines
arch/arm/mm/fault.c +5 -0
index f4ea4c62c613..b045b48d368d 100644
@@ -173,6 +173,11 @@ __do_user_fault(struct task_struct *tsk, unsigned
 long addr,
                show_regs(regs);
        }
 #endif
+#ifndef CONFIG_KUSER_HELPERS
+       if (((addr & PAGE_MASK) == 0xffff0000) && (sig == SIGSEGV))
+               printk(KERN_DEBUG "%s: CONFIG_KUSER_HELPERS disabled at
 0x%08lx\n",
+                      tsk->comm, addr);
+#endif
 
        tsk->thread.address = addr;
        tsk->thread.error_code = fsr;
Quoted 4 lines

BTW, I note that the help text for CONFIG_KUSER_HELPERS needs to be updated.

Signature · 1 line
Florian
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#9 lore raw
In reply to Florian Fainelli
Quoted 7 lines · Florian Fainelli

Hi all,

I just painfully learned that perf would segfault when CONFIG_KUSER_HELPERS is disabled because it unconditionally makes use of it. This patch series adds an ARM test for that by leveraging the existing find_vdso_map() function and making it more generic and capable of location any map within /proc/self/maps.

Any feedback on this?

Quoted 15 lines

Florian Fainelli (2):
perf tools: Make find_vdso_map() more modular perf tests: Add a test for the ARM 32-bit [vectors] page

 tools/perf/arch/arm/tests/Build          |  1 +
 tools/perf/arch/arm/tests/arch-tests.c   |  4 +++
 tools/perf/arch/arm/tests/vectors-page.c | 20 +++++++++++++++
 tools/perf/tests/tests.h                 |  5 ++++
 tools/perf/util/find-map.c               | 31 ++++++++++++++++++++++++
 tools/perf/util/find-vdso-map.c          | 30 +++--------------------
 6 files changed, 64 insertions(+), 27 deletions(-)
 create mode 100644 tools/perf/arch/arm/tests/vectors-page.c
 create mode 100644 tools/perf/util/find-map.c
Signature · 1 line
Florian