From nobody Sun May 24 18:42:29 2026 Received: from va-1-112.ptr.blmpb.com (va-1-112.ptr.blmpb.com [209.127.230.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1343E37C916 for ; Fri, 22 May 2026 08:26:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779438406; cv=none; b=r7htUdkOksIo46h/GfXamXTsXe/3mLGrK2UbeLMzt3qm+2KnO5ojD8nsi/c1fZStO2mREkw7mt28ueQSSTIC5REF8xNt0/CJ0V9/VV6U9ckd4TV4pw1QFOd7Fqr7sXqz6t76w+g6XpSyKT9ViniGOrpb4w4OUrDq2etCrtJk2dY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779438406; c=relaxed/simple; bh=fYeg5MTOYEEP3bfwW7O2z9k0LRolcbIkNFMsYotBOHg=; h=Cc:From:References:To:Mime-Version:In-Reply-To:Content-Type: Subject:Date:Message-Id; b=RA2N+xwYUbOxwcpJrbyjOw15O/ZbSnCcPfdS+ff4733Rm8lpoRuzhtccL9uqVMJzNOArXaJb7YgTWA+4XxGvMY5opp048YG78+3TvCSn2HlOVt+Ap8woEC4H0ft0LZYvCGJD1psPmVDZuo8rKDvT6bq9/HAiGWqKr/1gK3OPLgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=g/BTKqT4; arc=none smtp.client-ip=209.127.230.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="g/BTKqT4" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1779438394; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=/QeToWwHjCm4j+wwEu3mC7hfaKb7rk0SUmjPJl/Utu8=; b=g/BTKqT4ElC9dKoqrI0sTF5WRea68BQkg4QjNaMxyY8RkOoykEVNMgmOo/me4nGLbyC+n5 OkHPzExzvkwwVyqU+9SJAwN2SzFhyT4yKvaOzPQMIgXNSYZikQL4v7qChpFQVfQ+v/c8dW z+yXoaP++AklSvnYaElX2cGEG3s8HE8bCBrawKYZsgaD5n/4kJnxrEv96ZjwW+rYA+1QPG FNkrmqlSJcrefrRpKvmPIxeDMFc7V3s+0a/JwEQ3aKMy4tRgLCt130uPt9AtOrkjCdYWNl U/RJRlw0IDu3SlSUGHSkCHuUWiYakegexi533fLnhfMmmLTdX07oBBwnhJDwfA== X-Mailer: git-send-email 2.20.1 Cc: "Mark Rutland" , "Alexander Shishkin" , "Jiri Olsa" , "Ian Rogers" , "Adrian Hunter" , "James Clark" , , , "Rui Qi" From: "Rui Qi" X-Original-From: Rui Qi References: <20260507071103.2772577-1-qirui.001@bytedance.com> <20260522082604.89447-1-qirui.001@bytedance.com> Content-Transfer-Encoding: quoted-printable To: "Peter Zijlstra" , "Ingo Molnar" , "Arnaldo Carvalho de Melo" , "Namhyung Kim" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Lms-Return-Path: In-Reply-To: <20260522082604.89447-1-qirui.001@bytedance.com> Subject: [PATCH v4 1/2] perf: Extract is_ignored_kernel_symbol() for kernel mapping symbol filtering Date: Fri, 22 May 2026 16:26:03 +0800 Message-Id: <20260522082604.89447-2-qirui.001@bytedance.com> Content-Type: text/plain; charset="utf-8" Mapping symbol filtering is scattered across multiple files with inconsistent checks. The kernel's own is_mapping_symbol() covers x86 local symbols ('.L*' and 'L0*') on top of the '$' prefix used by ARM/AArch64/RISC-V, but the perf tool only checks '$'. Extract is_ignored_kernel_symbol() into symbol.h matching the kernel definition, and convert the kallsyms and ksymbol event paths to use it. Add ksymbol event name validation and early mapping symbol filtering before any state mutation. Signed-off-by: Rui Qi --- tools/perf/util/machine.c | 18 +++++++++++++++++- tools/perf/util/symbol.c | 4 ++-- tools/perf/util/symbol.h | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index e76f8c86e62a..07e4ad56d757 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "callchain.h" #include "debug.h" #include "dso.h" @@ -729,9 +730,15 @@ static int machine__process_ksymbol_register(struct ma= chine *machine, { struct symbol *sym; struct dso *dso =3D NULL; - struct map *map =3D maps__find(machine__kernel_maps(machine), event->ksym= bol.addr); + struct map *map; int err =3D 0; =20 + /* Ignore mapping symbols in ksymbol events - check early before any stat= e mutation */ + if (is_ignored_kernel_symbol(event->ksymbol.name)) + return 0; + + map =3D maps__find(machine__kernel_maps(machine), event->ksymbol.addr); + if (!map) { dso =3D dso__new(event->ksymbol.name); =20 @@ -790,6 +797,10 @@ static int machine__process_ksymbol_unregister(struct = machine *machine, struct symbol *sym; struct map *map; =20 + /* Ignore mapping symbols in ksymbol events */ + if (is_ignored_kernel_symbol(event->ksymbol.name)) + return 0; + map =3D maps__find(machine__kernel_maps(machine), event->ksymbol.addr); if (!map) return 0; @@ -814,6 +825,11 @@ int machine__process_ksymbol(struct machine *machine _= _maybe_unused, if (dump_trace) perf_event__fprintf_ksymbol(event, stdout); =20 + if (event->header.size < offsetof(struct perf_record_ksymbol, name) + 2 || + !memchr(event->ksymbol.name, '\0', + event->header.size - offsetof(struct perf_record_ksymbol, name))) + return -EINVAL; + /* no need to process non-JIT BPF as it cannot get samples */ if (event->ksymbol.len =3D=3D 0) return 0; diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index fcaeeddbbb6b..714b6e6048fa 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -770,8 +770,8 @@ static int map__process_kallsym_symbol(void *arg, const= char *name, if (!symbol_type__filter(type)) return 0; =20 - /* Ignore local symbols for ARM modules */ - if (name[0] =3D=3D '$') + /* Ignore mapping symbols in kallsyms */ + if (is_ignored_kernel_symbol(name)) return 0; =20 /* diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index bd6eb90c8668..95592779eb77 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -28,6 +28,21 @@ struct maps; struct option; struct build_id; =20 +/* + * Ignore kernel mapping symbols, matching kernel is_mapping_symbol() logi= c. + * This checks for '$' prefix (used by ARM, AArch64, RISC-V) and + * x86 local symbol prefixes (.L* and L0*). + * Only use this for kernel symbols (kallsyms, ksymbol events, kernel ELF = DSOs). + */ +static inline bool is_ignored_kernel_symbol(const char *str) +{ + if (str[0] =3D=3D '.' && str[1] =3D=3D 'L') + return true; + if (str[0] =3D=3D 'L' && str[1] =3D=3D '0') + return true; + return str[0] =3D=3D '$'; +} + /* * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; * for newer versions we can use mmap to reduce memory usage: --=20 2.20.1 From nobody Sun May 24 18:42:29 2026 Received: from va-1-114.ptr.blmpb.com (va-1-114.ptr.blmpb.com [209.127.230.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE17A3A6B9F for ; Fri, 22 May 2026 08:26:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.114 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779438419; cv=none; b=NbcRwsS66uQeq72hEn1l57V0D/wfwVcJAN6puckvIfXVK6bIyVRiNJVeVku4QkwHZ7NBt+cvVVj1Z5jgHjspIMFiH/0vAoPIDelhMSHzWaUOSuAeJVO/HM6UA4yTtDhqgiy1pvix8zZivU8hFUMiQVNxYKIAHjvB+gKjJk6oCRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779438419; c=relaxed/simple; bh=V5zoyHXxdIR+FWIdUoJu2SfIXA209Z5txBT1C4guMWw=; h=Cc:Date:References:From:Subject:Mime-Version:In-Reply-To:To: Message-Id:Content-Type; b=BK2gDyUmgeOlnG9LdWkIJaBiejY1ye7s2zhAUWdWpKpj5sewDfQg97EYwhD7QbKHFFFWRmG0Pap+nAUWOISGHRecjWG6CK2BLVsssEoJJQeBiKBCK/pItl46B5UmgJ4SveyvQ74H+JldzggUCATkF17BLZoIsOfRS5jFW19vd1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=g/3Jjgu2; arc=none smtp.client-ip=209.127.230.114 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="g/3Jjgu2" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1779438406; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=5Iu5XnqSFHndFk0JX8U3Pr0e2xZYS221KCy9dvuonq8=; b=g/3Jjgu2CTjOEl/1sUCu9AO9W4XL1n5FKoWle2qxa0WTjXIR+75elX5wPFvX36znxMGM60 syk5I4TZkQI8nSi6QbRzCM63UeCVSP82nojdfFta1uXLKdgJ7Xm+WL90TZxUf4Kw8mlz/p OwxRqNOuEze7cXhpo+t2TMfE9JWs1sruQk3N4MTHFe++98SCNbJz4O7+VAtNsT3wlxdFne ZYf1U6O8GdTqFvg/kc8DjuSLI87nLobUF8crpxfww8zyWTIcDihfJOVBNf0D8FQCVocXsH NIqDqXJKuzU5cH4T8fuz36mLohDGaSmutaxLouWLouXrU+bihBu+IoibysySWg== Cc: "Mark Rutland" , "Alexander Shishkin" , "Jiri Olsa" , "Ian Rogers" , "Adrian Hunter" , "James Clark" , , , "Rui Qi" Date: Fri, 22 May 2026 16:26:04 +0800 X-Original-From: Rui Qi References: <20260507071103.2772577-1-qirui.001@bytedance.com> <20260522082604.89447-1-qirui.001@bytedance.com> From: "Rui Qi" Content-Transfer-Encoding: quoted-printable X-Lms-Return-Path: Subject: [PATCH v4 2/2] perf: Apply is_ignored_kernel_symbol() filter in ELF loading path for kernel DSOs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 In-Reply-To: <20260522082604.89447-1-qirui.001@bytedance.com> X-Mailer: git-send-email 2.20.1 To: "Peter Zijlstra" , "Ingo Molnar" , "Arnaldo Carvalho de Melo" , "Namhyung Kim" Message-Id: <20260522082604.89447-3-qirui.001@bytedance.com> Content-Type: text/plain; charset="utf-8" dso__load_sym_internal() had no filtering for .L* and L0* mapping symbols while the kallsyms path already filters them via is_ignored_kernel_symbol(). Add the same check gated by dso__kernel() so that kernel ELF objects (vmlinux, .ko) have mapping symbols filtered across all architectures, but userspace ELF objects are unaffected -- '$' is a valid prefix in languages like Java and Scala. The existing ARM/AArch64 and RISC-V architecture-specific mapping symbol checks are preserved; the new is_ignored_kernel_symbol() check adds x86 local symbol (.L*, L0*) filtering and provides unified cross-architecture coverage for kernel DSOs. Signed-off-by: Rui Qi --- tools/perf/util/symbol-elf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 7afa8a117139..77e6dcba8fda 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1592,9 +1592,11 @@ dso__load_sym_internal(struct dso *dso, struct map *= map, struct symsrc *syms_ss, if (!is_label && !elf_sym__filter(&sym)) continue; =20 - /* Reject ARM ELF "mapping symbols": these aren't unique and + /* + * Reject ARM ELF "mapping symbols": these aren't unique and * don't identify functions, so will confuse the profile - * output: */ + * output: + */ if (ehdr.e_machine =3D=3D EM_ARM || ehdr.e_machine =3D=3D EM_AARCH64) { if (elf_name[0] =3D=3D '$' && strchr("adtx", elf_name[1]) && (elf_name[2] =3D=3D '\0' || elf_name[2] =3D=3D '.')) @@ -1607,6 +1609,10 @@ dso__load_sym_internal(struct dso *dso, struct map *= map, struct symsrc *syms_ss, continue; } =20 + /* Reject kernel mapping symbols for kernel DSOs only */ + if (dso__kernel(dso) && is_ignored_kernel_symbol(elf_name)) + continue; + if (runtime_ss->opdsec && sym.st_shndx =3D=3D runtime_ss->opdidx) { u32 offset =3D sym.st_value - syms_ss->opdshdr.sh_addr; u64 *opd =3D opddata->d_buf + offset; --=20 2.20.1