perf tests: Check for ARM [vectors] page
Subsystems (2)
v2 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.
Changes in v2:
- use strlen() instead of sizeof() -1 since we made the page name a parameter
- use TEST_OK/TEST_FAIL in lieu of 0/-1
- added an error message indicating CONFIG_KUSER_HELPERS might be disabled
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 | 24 ++++++++++++++++++ tools/perf/tests/tests.h | 5 ++++ tools/perf/util/find-map.c | 31 ++++++++++++++++++++++++ tools/perf/util/find-vdso-map.c | 30 +++-------------------- 6 files changed, 68 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 v2 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,strlen (name))) + 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
Re: [PATCH v2 1/2] perf tools: Make find_vdso_map() more modular
Quoted 38 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 +20
-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 ;
tools/perf/util/find-map.c line 30
Quoted 10 lines
tools/perf/util/find-map.c new file +10
-0+if (m <0 ) +continue ; + +if (!strncmp (&line[m], name,strlen (name))) + found =1 ; + } + +fclose (maps); +return !found; +}
please keep just one object for both.. looks to me like it coud go to util.c.. or just find-map.c if there's a reason to have this separated
thanks,
jirka
Re: [PATCH v2 1/2] perf tools: Make find_vdso_map() more modular
Quoted 45 lines · Jiri Olsa
Quoted 44 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 +26
-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,strlen (name))) + found =1 ; + }
Quoted 8 lines
tools/perf/util/find-map.c line 30
Quoted 4 lines
tools/perf/util/find-map.c new file +4
-0+ +fclose (maps); +return !found; +}please keep just one object for both.. looks to me like it coud go to
util.c.. or justfind-map.cif there's a reason to have this separated
The reason for keeping both implementations separate is because VDSO__MAP_NAME may not be defined/applicable for all architectures, so instead of having them have to define VDSO__MAP_NAME just to get that file to build, they would only include find-map.c to get access to find_map() and then search for specific tokens.
Would you prefer if find_map() was moved to tools/perf/util/util.c?
Signature · 1 line
Florian
Re: [PATCH v2 1/2] perf tools: Make find_vdso_map() more modular
In reply to Florian FainelliQuoted 54 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 +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,strlen (name))) + found =1 ; + } + +fclose (maps); +return !found; +} +tools/perf/util/find-vdso-map.c +0
-0
tools/perf/util/find-vdso-map.c line 2
Quoted 2 lines
tools/perf/util/find-vdso-map.c +1
-0@@ -1,31 +1,7 @@// SPDX-License-Identifier: GPL-2.0 +#include "find-map.c"
aaah, I was wondering how this could build without 'Build' file record ;-)
jirka
Quoted 35 lines
tools/perf/util/find-vdso-map.c +2
-27+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 v2 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 | 24 ++++++++++++++++++++++++ tools/perf/tests/tests.h | 5 +++++ 4 files changed, 34 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 +24 -0
@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <stdio.h> +#include <string.h> +#include <linux/compiler.h> + +#include "debug.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 )) { +pr_err ("%s not found, is CONFIG_KUSER_HELPERS enabled?\n" , +VECTORS__MAP_NAME ); +return TEST_FAIL ; + } + +return TEST_OK ; +}
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
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.
Did not get much feedback, you are all probably busy attending LPC conferences, but I was wondering if this did make sense or if there is a better approach that should be looked at?
I am starting to see additional tests failing that require some ARM (32-bit) specific changes, and not accumulating too many of these fixes on top of that series would be neat.
Thank you!
Quoted 23 lines
Changes in v2:
- use
strlen()instead ofsizeof()-1 since we made the page name a parameter
- use TEST_OK/TEST_FAIL in lieu of 0/-1
- added an error message indicatingCONFIG_KUSER_HELPERSmight be disabledFlorian 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 | 24 ++++++++++++++++++ tools/perf/tests/tests.h | 5 ++++ tools/perf/util/find-map.c | 31 ++++++++++++++++++++++++ tools/perf/util/find-vdso-map.c | 30 +++-------------------- 6 files changed, 68 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
Quoted 13 lines · Florian Fainelli
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.Did not get much feedback, you are all probably busy attending LPC conferences, but I was wondering if this did make sense or if there is a better approach that should be looked at?
Quoted 5 lines
I am starting to see additional tests failing that require some ARM (32-bit) specific changes, and not accumulating too many of these fixes on top of that series would be neat.
Thank you!
Ping? Would you prefer a resend to avoid any possible conflicts? Thanks
Quoted 26 lines
Quoted 24 lines
Changes in v2:
- use
strlen()instead ofsizeof()-1 since we made the page name a parameter
- use TEST_OK/TEST_FAIL in lieu of 0/-1
- added an error message indicatingCONFIG_KUSER_HELPERSmight be disabledFlorian 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 | 24 ++++++++++++++++++ tools/perf/tests/tests.h | 5 ++++ tools/perf/util/find-map.c | 31 ++++++++++++++++++++++++ tools/perf/util/find-vdso-map.c | 30 +++-------------------- 6 files changed, 68 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
Quoted 8 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.
Quoted 7 lines
Changes in v2:
- use
strlen()instead ofsizeof()-1 since we made the page name a parameter
- use TEST_OK/TEST_FAIL in lieu of 0/-1
- added an error message indicatingCONFIG_KUSER_HELPERSmight be disabled
other than the function placing I mentioned in
my previous email, this seems ok to me
jirka
Quoted 18 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 | 24 ++++++++++++++++++ tools/perf/tests/tests.h | 5 ++++ tools/perf/util/find-map.c | 31 ++++++++++++++++++++++++ tools/perf/util/find-vdso-map.c | 30 +++-------------------- 6 files changed, 68 insertions(+), 27 deletions(-) create mode 100644 tools/perf/arch/arm/tests/vectors-page.c create mode 100644 tools/perf/util/find-map.cSignature · 1 line
2.17.1