perf tests: Check for ARM [vectors] page
Subsystems (3)
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
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
@@ -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
@@ -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
PATCH 2/2 perf tests: Add a test for the ARM 32-bit [vectors] page
In reply to Florian Fainelliperf 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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [PATCH 1/2] perf tools: Make find_vdso_map() more modular
In reply to Florian FainelliQuoted 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 underutil/find-map.cand updatefind_vdso_map()to use it.Signed-off-by Florian Fainelli <[email protected]>--- 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.ctools/perf/util/find-map.c new file +14
-0@@ -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
Re: [PATCH 2/2] perf tests: Add a test for the ARM 32-bit [vectors] page
In reply to Florian FainelliQuoted 4 lines · Florian Fainelli
perf on ARM requires
CONFIG_KUSER_HELPERSto 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 whenCONFIG_KUSER_HELPERSis 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
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_HELPERSto 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 whenCONFIG_KUSER_HELPERSis 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 suggestingCONFIG_KUSER_HELPERSon ARM?
Sure, sounds reasonable, thanks for taking a look.
Signature · 1 line
Florian
Russell King - ARM Linux
maintainerRe: [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_HELPERSto 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 whenCONFIG_KUSER_HELPERSis 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 suggestingCONFIG_KUSER_HELPERSon 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
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_HELPERSto 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 whenCONFIG_KUSER_HELPERSis 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 suggestingCONFIG_KUSER_HELPERSon 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
@@ -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_HELPERSneeds to be updated.
Signature · 1 line
Florian
Russell King - ARM Linux
maintainerRe: [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@@ -173,6 +173,11 @@ __do_user_fault(struct task_struct *tsk, unsignedlong 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_HELPERSneeds 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
Quoted 7 lines · Florian Fainelli
Hi all,
I just painfully learned that perf would segfault when
CONFIG_KUSER_HELPERSis disabled because it unconditionally makes use of it. This patch series adds an ARM test for that by leveraging the existingfind_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: Makefind_vdso_map()more modular perf tests: Add a test for the ARM 32-bit [vectors] pagetools/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