Skip to contentSkip to conversation

perf tests vmlinux-kallsyms: ignore hidden symbols

PATCH Applied Michael Petlan 3 participants 4 messages Sep 22, 2021 – Sep 29, 2021 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf tests vmlinux-kallsyms: ignore hidden symbols

Certain kernel symbols are purposely hidden from kallsyms. The function is_ignored_symbol() from scripts/kallsyms.c decides if a symbol should be hidden or not.

The perf test "vmlinux symtab matches kallsyms" fails in case perf finds some of the hidden symbols in its machine image and can't match them to kallsyms.

Let's add a filter to check if a symbol not found isn't one of these before failing the test.

The function is_ignored_symbol() has been copied from scripts/kallsyms.c and needs to be updated along with the original.

---
 tools/perf/tests/vmlinux-kallsyms.c | 102 ++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
tools/perf/tests/vmlinux-kallsyms.c +102 -0
index 193b7c91b4e2..4f884aabc7f4 100644
@@ -3,6 +3,7 @@
 #include <linux/rbtree.h>
 #include <inttypes.h>
 #include <string.h>
+#include <ctype.h>
 #include <stdlib.h>
 #include "dso.h"
 #include "map.h"
@@ -14,6 +15,102 @@
 
 #define UM(x) kallsyms_map->unmap_ip(kallsyms_map, (x))
 
+static bool is_ignored_symbol(const char *name, char type)
+{
+	/* Symbol names that exactly match to the following are ignored.*/
+	static const char * const ignored_symbols[] = {
+		/*
+		 * Symbols which vary between passes. Passes 1 and 2 must have
+		 * identical symbol lists. The kallsyms_* symbols below are
+		 * only added after pass 1, they would be included in pass 2
+		 * when --all-symbols is specified so exclude them to get a
+		 * stable symbol list.
+		 */
+		"kallsyms_addresses",
+		"kallsyms_offsets",
+		"kallsyms_relative_base",
+		"kallsyms_num_syms",
+		"kallsyms_names",
+		"kallsyms_markers",
+		"kallsyms_token_table",
+		"kallsyms_token_index",
+		/* Exclude linker generated symbols which vary between passes */
+		"_SDA_BASE_",		/* ppc */
+		"_SDA2_BASE_",		/* ppc */
+		NULL
+	};
+
+	/* Symbol names that begin with the following are ignored.*/
+	static const char * const ignored_prefixes[] = {
+		"$",			/* local symbols for ARM, MIPS, etc. */
+		".LASANPC",		/* s390 kasan local symbols */
+		"__crc_",		/* modversions */
+		"__efistub_",		/* arm64 EFI stub namespace */
+		"__kvm_nvhe_",		/* arm64 non-VHE KVM namespace */
+		"__AArch64ADRPThunk_",	/* arm64 lld */
+		"__ARMV5PILongThunk_",	/* arm lld */
+		"__ARMV7PILongThunk_",
+		"__ThumbV7PILongThunk_",
+		"__LA25Thunk_",		/* mips lld */
+		"__microLA25Thunk_",
+		NULL
+	};
+
+	/* Symbol names that end with the following are ignored.*/
+	static const char * const ignored_suffixes[] = {
+		"_from_arm",		/* arm */
+		"_from_thumb",		/* arm */
+		"_veneer",		/* arm */
+		NULL
+	};
+
+	/* Symbol names that contain the following are ignored.*/
+	static const char * const ignored_matches[] = {
+		".long_branch.",	/* ppc stub */
+		".plt_branch.",		/* ppc stub */
+		NULL
+	};
+
+	const char * const *p;
+
+	for (p = ignored_symbols; *p; p++)
+		if (!strcmp(name, *p))
+			return true;
+
+	for (p = ignored_prefixes; *p; p++)
+		if (!strncmp(name, *p, strlen(*p)))
+			return true;
+
+	for (p = ignored_suffixes; *p; p++) {
+		int l = strlen(name) - strlen(*p);
+
+		if (l >= 0 && !strcmp(name + l, *p))
+			return true;
+	}
+
+	for (p = ignored_matches; *p; p++) {
+		if (strstr(name, *p))
+			return true;
+	}
+
+	if (type == 'U' || type == 'u')
+		return true;
+	/* exclude debugging symbols */
+	if (type == 'N' || type == 'n')
+		return true;
+
+	if (toupper(type) == 'A') {
+		/* Keep these useful absolute symbols */
+		if (strcmp(name, "__kernel_syscall_via_break") &&
+		    strcmp(name, "__kernel_syscall_via_epc") &&
+		    strcmp(name, "__kernel_sigtramp") &&
+		    strcmp(name, "__gp"))
+			return true;
+	}
+
+	return false;
+}
+
 int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest __maybe_unused)
 {
 	int err = -1;
@@ -169,6 +266,11 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 			 * such as __indirect_thunk_end.
 			 */
 			continue;
+		} else if (is_ignored_symbol(sym->name, sym->type)) {
+			/*
+			 * Ignore hidden symbols, see scripts/kallsyms.c for the details
+			 */
+			continue;
 		} else {
 			pr_debug("ERR : %#" PRIx64 ": %s not on kallsyms\n",
 				 mem_start, sym->name);
Signature · 1 line
2.18.4
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Michael Petlan

Certain kernel symbols are purposely hidden from kallsyms. The function is_ignored_symbol() from scripts/kallsyms.c decides if a symbol should be hidden or not.

The perf test "vmlinux symtab matches kallsyms" fails in case perf finds some of the hidden symbols in its machine image and can't match them to kallsyms.

Quoted 7 lines

Let's add a filter to check if a symbol not found isn't one of these before failing the test.

The function is_ignored_symbol() has been copied from scripts/kallsyms.c and needs to be updated along with the original.

It is a shame this can't be a library to ensure the function is kept in sync.

Quoted 32 lines
---
 tools/perf/tests/vmlinux-kallsyms.c | 102 ++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
tools/perf/tests/vmlinux-kallsyms.c +13 -0
index 193b7c91b4e2..4f884aabc7f4 100644
@@ -3,6 +3,7 @@
 #include <linux/rbtree.h>
 #include <inttypes.h>
 #include <string.h>
+#include <ctype.h>
 #include <stdlib.h>
 #include "dso.h"
 #include "map.h"
@@ -14,6 +15,102 @@
 
 #define UM(x) kallsyms_map->unmap_ip(kallsyms_map, (x))
 
+static bool is_ignored_symbol(const char *name, char type)
+{
+       /* Symbol names that exactly match to the following are ignored.*/
+       static const char * const ignored_symbols[] = {
+               /*
+                * Symbols which vary between passes. Passes 1 and 2 must have
+                * identical symbol lists. The kallsyms_* symbols below are
+                * only added after pass 1, they would be included in pass 2
+                * when --all-symbols is specified so exclude them to get a
+                * stable symbol list.
+                */
+               "kallsyms_addresses",

tools/perf/tests/vmlinux-kallsyms.c line 39

Quoted 10 lines
tools/perf/tests/vmlinux-kallsyms.c +10 -0
+               "kallsyms_offsets",
+               "kallsyms_relative_base",
+               "kallsyms_num_syms",
+               "kallsyms_names",
+               "kallsyms_markers",
+               "kallsyms_token_table",
+               "kallsyms_token_index",
+               /* Exclude linker generated symbols which vary between passes */
+               "_SDA_BASE_",           /* ppc */
+               "_SDA2_BASE_",          /* ppc */

Do values like this belong behind an architecture #ifdef? I know that's not currently the case in scripts/kallsyms.c.

Quoted 92 lines
tools/perf/tests/vmlinux-kallsyms.c +79 -1
+               NULL
+       };
+
+       /* Symbol names that begin with the following are ignored.*/
+       static const char * const ignored_prefixes[] = {
+               "$",                    /* local symbols for ARM, MIPS, etc. */
+               ".LASANPC",             /* s390 kasan local symbols */
+               "__crc_",               /* modversions */
+               "__efistub_",           /* arm64 EFI stub namespace */
+               "__kvm_nvhe_",          /* arm64 non-VHE KVM namespace */
+               "__AArch64ADRPThunk_",  /* arm64 lld */
+               "__ARMV5PILongThunk_",  /* arm lld */
+               "__ARMV7PILongThunk_",
+               "__ThumbV7PILongThunk_",
+               "__LA25Thunk_",         /* mips lld */
+               "__microLA25Thunk_",
+               NULL
+       };
+
+       /* Symbol names that end with the following are ignored.*/
+       static const char * const ignored_suffixes[] = {
+               "_from_arm",            /* arm */
+               "_from_thumb",          /* arm */
+               "_veneer",              /* arm */
+               NULL
+       };
+
+       /* Symbol names that contain the following are ignored.*/
+       static const char * const ignored_matches[] = {
+               ".long_branch.",        /* ppc stub */
+               ".plt_branch.",         /* ppc stub */
+               NULL
+       };
+
+       const char * const *p;
+
+       for (p = ignored_symbols; *p; p++)
+               if (!strcmp(name, *p))
+                       return true;
+
+       for (p = ignored_prefixes; *p; p++)
+               if (!strncmp(name, *p, strlen(*p)))
+                       return true;
+
+       for (p = ignored_suffixes; *p; p++) {
+               int l = strlen(name) - strlen(*p);
+
+               if (l >= 0 && !strcmp(name + l, *p))
+                       return true;
+       }
+
+       for (p = ignored_matches; *p; p++) {
+               if (strstr(name, *p))
+                       return true;
+       }
+
+       if (type == 'U' || type == 'u')
+               return true;
+       /* exclude debugging symbols */
+       if (type == 'N' || type == 'n')
+               return true;
+
+       if (toupper(type) == 'A') {
+               /* Keep these useful absolute symbols */
+               if (strcmp(name, "__kernel_syscall_via_break") &&
+                   strcmp(name, "__kernel_syscall_via_epc") &&
+                   strcmp(name, "__kernel_sigtramp") &&
+                   strcmp(name, "__gp"))
+                       return true;
+       }
+
+       return false;
+}
+
 int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest __maybe_unused)
 {
        int err = -1;
@@ -169,6 +266,11 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
                         * such as __indirect_thunk_end.
                         */
                        continue;
+               } else if (is_ignored_symbol(sym->name, sym->type)) {
+                       /*
+                        * Ignore hidden symbols, see scripts/kallsyms.c for the details
+                        */
+                       continue;
                } else {
                        pr_debug("ERR : %#" PRIx64 ": %s not on kallsyms\n",
                                 mem_start, sym->name);
--

2.18.4

maintainer Applied
#2 lore raw

Em Wed, Sep 22, 2021 at 09:36:11AM -0700, Ian Rogers escreveu:

Quoted 13 lines · Michael Petlan
Quoted 12 lines

Certain kernel symbols are purposely hidden from kallsyms. The function is_ignored_symbol() from scripts/kallsyms.c decides if a symbol should be hidden or not.

The perf test "vmlinux symtab matches kallsyms" fails in case perf finds some of the hidden symbols in its machine image and can't match them to kallsyms.

Let's add a filter to check if a symbol not found isn't one of these before failing the test.

Quoted 8 lines
Quoted 4 lines

The function is_ignored_symbol() has been copied from scripts/kallsyms.c and needs to be updated along with the original.

It is a shame this can't be a library to ensure the function is kept in sync.

Thanks, applied.

- Arnaldo

#3 lore raw
In reply to Ian Rogers

Em Wed, Sep 22, 2021 at 09:36:11AM -0700, Ian Rogers escreveu:

Quoted 13 lines · Michael Petlan
Quoted 12 lines

Certain kernel symbols are purposely hidden from kallsyms. The function is_ignored_symbol() from scripts/kallsyms.c decides if a symbol should be hidden or not.

The perf test "vmlinux symtab matches kallsyms" fails in case perf finds some of the hidden symbols in its machine image and can't match them to kallsyms.

Let's add a filter to check if a symbol not found isn't one of these before failing the test.

Quoted 8 lines
Quoted 4 lines

The function is_ignored_symbol() has been copied from scripts/kallsyms.c and needs to be updated along with the original.

It is a shame this can't be a library to ensure the function is kept in sync.

We can adapt :-)

⬢[acme@toolbox perf]$ sed -n -e '/static bool is_ignored_symbol.*/,/^}.*/ p' scripts/kallsyms.c > original ⬢[acme@toolbox perf]$ sed -n -e '/static bool is_ignored_symbol.*/,/^}.*/ p' tools/perf/tests/vmlinux-kallsyms.c > copy ⬢[acme@toolbox perf]$ diff -u original copy
⬢[acme@toolbox perf]$

⬢[acme@toolbox perf]$ sed -n -e '/static bool is_ignored_symbol.*/,/^}.*/ p' scripts/kallsyms.c static bool is_ignored_symbol(const char *name, char type)

{
	/* Symbol names that exactly match to the following are ignored.*/
	static const char * const ignored_symbols[] = {
		/*
		 * Symbols which vary between passes. Passes 1 and 2 must have
		 * identical symbol lists. The kallsyms_* symbols below are
		 * only added after pass 1, they would be included in pass 2
		 * when --all-symbols is specified so exclude them to get a
		 * stable symbol list.
		 */
		"kallsyms_addresses",
		"kallsyms_offsets",
		"kallsyms_relative_base",
		"kallsyms_num_syms",
		"kallsyms_names",
		"kallsyms_markers",
		"kallsyms_token_table",
		"kallsyms_token_index",
		/* Exclude linker generated symbols which vary between passes */
		"_SDA_BASE_",		/* ppc */
		"_SDA2_BASE_",		/* ppc */
		NULL
	};

	/* Symbol names that begin with the following are ignored.*/
	static const char * const ignored_prefixes[] = {
		"$",			/* local symbols for ARM, MIPS, etc. */
		".LASANPC",		/* s390 kasan local symbols */
		"__crc_",		/* modversions */
		"__efistub_",		/* arm64 EFI stub namespace */
		"__kvm_nvhe_",		/* arm64 non-VHE KVM namespace */
		"__AArch64ADRPThunk_",	/* arm64 lld */
		"__ARMV5PILongThunk_",	/* arm lld */
		"__ARMV7PILongThunk_",
		"__ThumbV7PILongThunk_",
		"__LA25Thunk_",		/* mips lld */
		"__microLA25Thunk_",
		NULL
	};

	/* Symbol names that end with the following are ignored.*/
	static const char * const ignored_suffixes[] = {
		"_from_arm",		/* arm */
		"_from_thumb",		/* arm */
		"_veneer",		/* arm */
		NULL
	};

	/* Symbol names that contain the following are ignored.*/
	static const char * const ignored_matches[] = {
		".long_branch.",	/* ppc stub */
		".plt_branch.",		/* ppc stub */
		NULL
	};

	const char * const *p;

	for (p = ignored_symbols; *p; p++)
		if (!strcmp(name, *p))
			return true;

	for (p = ignored_prefixes; *p; p++)
		if (!strncmp(name, *p, strlen(*p)))
			return true;

	for (p = ignored_suffixes; *p; p++) {
		int l = strlen(name) - strlen(*p);

		if (l >= 0 && !strcmp(name + l, *p))
			return true;
	}

	for (p = ignored_matches; *p; p++) {
		if (strstr(name, *p))
			return true;
	}

	if (type == 'U' || type == 'u')
		return true;
	/* exclude debugging symbols */
	if (type == 'N' || type == 'n')
		return true;

	if (toupper(type) == 'A') {
		/* Keep these useful absolute symbols */
		if (strcmp(name, "__kernel_syscall_via_break") &&
		    strcmp(name, "__kernel_syscall_via_epc") &&
		    strcmp(name, "__kernel_sigtramp") &&
		    strcmp(name, "__gp"))
			return true;
	}

	return false;
}

⬢[acme@toolbox perf]$

This should be added to tools/perf/check-headers.sh as a new function_check() function that receives three parameters:

function_check scripts/kallsyms.c tools/perf/tests/vmlinux-kallsyms.c is_ignored_symbol

The regexps can also be tightened up a bit.

Michael, can you cook up a patch for this?

Thanks,

- Arnaldo