Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp358011rdb; Sat, 2 Sep 2023 12:09:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/9dJ8tUnnpbSq7KuQb7T1aU/cdYHSh51cWP9plsZ6R8qvGvqwQaEgQarhQGAZGT9RVc6x X-Received: by 2002:a17:907:a047:b0:9a5:7926:e391 with SMTP id gz7-20020a170907a04700b009a57926e391mr4373145ejc.10.1693681754767; Sat, 02 Sep 2023 12:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693681754; cv=none; d=google.com; s=arc-20160816; b=HnDOnnfqroYv+RVBYIL0Cp8XZIZt1r7fyfIf/f3A3ZKshz4Jf8Qv/vdDJQIGtHeUY6 rRXMNKwB1hdS+XR+ivoxJYpsoMBcJcsv92ZJfmB5FtLqBHe9OstKMoggaQBucz4gX2zy aYNkraoaiWQI8i+5Yhmr5R+hgYOiHeVYNC/dcAV8aD2tDkM7HY36m8aKWJpp8jn9+Adg XbnmHm0S4fXZdLH3ozQMZhJEPYWSa80JxfFwkyMDyFM9L7c8HE2fvkaqepHKd3OaZV8f ja+cbw5D4GBqr+8DubkX7jn+fk9gWt8/7MtrrP1U1WQSbq4iRWz4TZ1fdLPuWEr7nH1O 8/BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=0y3wc8MwCDagQyl9gysjCb9pNh8K+D6L4sOJfnlGWFo=; fh=Vk0u/MLXZpGXC43wCsLaZ83MfW/8eBpXkvvRh7BNu44=; b=IcSi0CbCYwGiwgtpX+gigl6u32TzZNrEJNvj/C2f3Ip7NXbhT6gzhhWkD+LnKRXsYr wM6w4L5PA1FmcSUn6hUIWzZPh3FROuV2mA/aP7//P/rMOvj1ZnQhw7a4fPL9UECqC3Y3 5y9NtR0jDOOk0aSEe3t6oXyyNi24xgtfQk8/eXiJncfybxwlFjz0AThMyuacdreBjc7H JV10Nww6ORl9ZDsZczmKJ25FwD7Enx/MTv8DAOY47rwc2i4sjkkmUhjq8dKplZX9poR8 6CV8u896hSYhR4Z9t37V6lzeyg7n1ZouY+JAEdOfOYyZpMesRmt5Jl+vaBqSTcu0DhR7 TERw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VkVmY120; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd14-20020a170906ce2e00b009878e79ba85si3877440ejb.302.2023.09.02.12.08.49; Sat, 02 Sep 2023 12:09:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VkVmY120; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351678AbjIBGhA (ORCPT + 99 others); Sat, 2 Sep 2023 02:37:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231330AbjIBGg7 (ORCPT ); Sat, 2 Sep 2023 02:36:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 171EE1706; Fri, 1 Sep 2023 23:36:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8E99C60BEC; Sat, 2 Sep 2023 06:36:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0117C43140; Sat, 2 Sep 2023 06:36:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693636615; bh=9xn+Gqkfmh1YDEaa6/jkJbanYbq4pFQjGneSrL6XxBg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VkVmY120x11OcQUskcr56GodJSMgkiSDj3lAP29AWTUgo6TQOPesdixYvKpv7X38X nDXBvtduGH1VFzdwo5Xy4DwxPHlfubES39IMaJeRak0FREfPh3bM6TSRMc4KlNE2LG AQclB7mBMWbLjipJKZ0/c4v2c0plyjRBaKBZXPg5Y3tMqHJYSsudMO/jYOvtt+u/wM mZ2xJRFMUzx3zBfOo5Yx5hyPAaLzEar71wU0YJqxFoyeu+XPr6q3MolTOcFZSlbfT0 NxrPrmh23yzsfUtJiPGFo3c+riJCZj/8x8/7fmXA5cYRlZ4x3Z5olCsKZhlUnO1y7N u83G9Zx9sr/eg== Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-573ac2fa37aso1675633eaf.3; Fri, 01 Sep 2023 23:36:54 -0700 (PDT) X-Gm-Message-State: AOJu0Yx0b8Sd0gM2YzKM7ndArlZgjne1vSoWh0SpZTVSeE5fkA6doSnb 8PgMqRM3BNP4ekTQLn1DvtKGdEuW2rwAHJIIrII= X-Received: by 2002:a05:6820:81f:b0:571:1a1d:f230 with SMTP id bg31-20020a056820081f00b005711a1df230mr4203830oob.9.1693636614116; Fri, 01 Sep 2023 23:36:54 -0700 (PDT) MIME-Version: 1.0 References: <20230828080423.3539686-1-alessandro.carminati@gmail.com> In-Reply-To: <20230828080423.3539686-1-alessandro.carminati@gmail.com> From: Masahiro Yamada Date: Sat, 2 Sep 2023 15:36:17 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] scripts/link-vmlinux.sh: Add alias to duplicate symbols for kallsyms To: "Alessandro Carminati (Red Hat)" Cc: Masami Hiramatsu , Steven Rostedt , Daniel Bristot de Oliveira , Josh Poimboeuf , Luis Chamberlain , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Alexander Lobakin , Nick Alcock , Kris Van Hees , Eugene Loh , Francis Laniel , Viktor Malik , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, live-patching@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 28, 2023 at 8:45=E2=80=AFPM Alessandro Carminati (Red Hat) wrote: > > From: Alessandro Carminati > > It is not uncommon for drivers or modules related to similar peripherals > to have symbols with the exact same name. > While this is not a problem for the kernel's binary itself, it becomes an > issue when attempting to trace or probe specific functions using > infrastructure like ftrace or kprobe. > > The tracing subsystem relies on the `nm -n vmlinux` output, which provide= s > symbol information from the kernel's ELF binary. However, when multiple > symbols share the same name, the standard nm output does not differentiat= e > between them. This can lead to confusion and difficulty when trying to > probe the intended symbol. > > ~ # cat /proc/kallsyms | grep " name_show" > ffffffff8c4f76d0 t name_show > ffffffff8c9cccb0 t name_show > ffffffff8cb0ac20 t name_show > ffffffff8cc728c0 t name_show > ffffffff8ce0efd0 t name_show > ffffffff8ce126c0 t name_show > ffffffff8ce1dd20 t name_show > ffffffff8ce24e70 t name_show > ffffffff8d1104c0 t name_show > ffffffff8d1fe480 t name_show > > **kas_alias** addresses this challenge by extending the symbol names with > unique suffixes during the kernel build process. > The newly created aliases for these duplicated symbols are unique names > that can be fed to the ftracefs interface. By doing so, it enables > previously unreachable symbols to be probed. > > ~ # cat /proc/kallsyms | grep " name_show" > ffffffff974f76d0 t name_show > ffffffff974f76d0 t name_show__alias__6340 > ffffffff979cccb0 t name_show > ffffffff979cccb0 t name_show__alias__6341 > ffffffff97b0ac20 t name_show > ffffffff97b0ac20 t name_show__alias__6342 > ffffffff97c728c0 t name_show > ffffffff97c728c0 t name_show__alias__6343 > ffffffff97e0efd0 t name_show > ffffffff97e0efd0 t name_show__alias__6344 > ffffffff97e126c0 t name_show > ffffffff97e126c0 t name_show__alias__6345 > ffffffff97e1dd20 t name_show > ffffffff97e1dd20 t name_show__alias__6346 > ffffffff97e24e70 t name_show > ffffffff97e24e70 t name_show__alias__6347 > ffffffff981104c0 t name_show > ffffffff981104c0 t name_show__alias__6348 > ffffffff981fe480 t name_show > ffffffff981fe480 t name_show__alias__6349 > ~ # echo "p:kprobes/evnt1 name_show__alias__6349" \ > > >/sys/kernel/tracing/kprobe_events > ~ # cat /sys/kernel/tracing/kprobe_events > p:kprobes/evnt1 name_show__alias__6349 > > Changes from v1: > - Integrated changes requested by Masami to exclude symbols with prefixes > "_cfi" and "_pfx". > - Introduced a small framework to handle patterns that need to be exclude= d > from the alias production. > - Excluded other symbols using the framework. > - Introduced the ability to discriminate between text and data symbols. > - Added two new config symbols in this version: CONFIG_KALLSYMS_ALIAS_DAT= A, > which allows data for data, and CONFIG_KALLSYMS_ALIAS_DATA_ALL, which > excludes all filters and provides an alias for each duplicated symbol. > > https://lore.kernel.org/all/20230711151925.1092080-1-alessandro.carminati= @gmail.com/ > > Changes from v2: > - Alias tags are created by querying DWARF information from the vmlinux. > - The filename + line number is normalized and appended to the original n= ame. > - The tag begins with '@' to indicate the symbol source. > - Not a change, but worth mentioning, since the alias is added to the exi= sting > list, the old duplicated name is preserved, and the livepatch way of de= aling > with duplicates is maintained. > - Acknowledging the existence of scenarios where inlined functions declar= ed in > header files may result in multiple copies due to compiler behavior, th= ough > it is not actionable as it does not pose an operational issue. > - Highlighting a single exception where the same name refers to different > functions: the case of "compat_binfmt_elf.c," which directly includes > "binfmt_elf.c" producing identical function copies in two separate > modules. > > sample from new v3 > > ~ # cat /proc/kallsyms | grep gic_mask_irq > ffffd0b03c04dae4 t gic_mask_irq > ffffd0b03c04dae4 t gic_mask_irq@_drivers_irqchip_irq-gic_c_167 > ffffd0b03c050960 t gic_mask_irq > ffffd0b03c050960 t gic_mask_irq@_drivers_irqchip_irq-gic-v3_c_404 > ~ # > > https://lore.kernel.org/all/20230714150326.1152359-1-alessandro.carminati= @gmail.com/ > > Signed-off-by: Alessandro Carminati (Red Hat) > --- > init/Kconfig | 36 ++++ > scripts/Makefile | 4 + > scripts/kas_alias/Makefile | 4 + > scripts/kas_alias/a2l.c | 268 ++++++++++++++++++++++++++++ > scripts/kas_alias/a2l.h | 32 ++++ > scripts/kas_alias/duplicates_list.c | 70 ++++++++ > scripts/kas_alias/duplicates_list.h | 15 ++ > scripts/kas_alias/item_list.c | 230 ++++++++++++++++++++++++ > scripts/kas_alias/item_list.h | 26 +++ > scripts/kas_alias/kas_alias.c | 217 ++++++++++++++++++++++ > scripts/link-vmlinux.sh | 11 +- > 11 files changed, 910 insertions(+), 3 deletions(-) I added some review comments in another thread, but one of the biggest concerns might be "910 insertions". What this program does is quite simple, "find duplicated names, and call addr2line". You wrote a lot of code to self-implement these: - sort function - parse PATH env variable to find addr2line - fork addr2line to establish pipe communications Have you considered writing the code in Python (or Perl)? Is it too slow? Most of the functions you implemented are already available in script languages. I am not sure if "@" is a good solution, but the amount of the added code looks too much to me. -- Best Regards Masahiro Yamada