From patchwork Thu May 18 05:24:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 9502 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp255434vqo; Wed, 17 May 2023 22:33:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6t/iBu5G7aNg1/vO40oiQZPvwHNsSl/jeVrw14oTjHev46WzUdlSffedNqxALj+cn8dCZP X-Received: by 2002:a05:6a00:1a02:b0:64b:e8:24ff with SMTP id g2-20020a056a001a0200b0064b00e824ffmr1465029pfv.17.1684387997976; Wed, 17 May 2023 22:33:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684387997; cv=none; d=google.com; s=arc-20160816; b=Kws6OjRlkBrljqJENdpGMHWA7tZM232ZYeOM4NjyNlxGpIRhJncrO6KD9UTRDvaaMO 0EGWuOVKYjQrO9mIRzMQzr3eRQc/pwf1J2IT2HbqWIjXmigPZW+hewBEDKqJ64KIYwFW +ZgA6acoSSrPYwbeWMqTrqzriYPsx/+hoHS/ZqjTlAB0ioPL7m/RFgvKOv/j2ZNF2C+w FQ0c3E9N9mzKf9hFgP9KLYe5HWEyDbRpxiWldaNLrAVga7B4fT1zNelFZL7MPPzRnRPc cbIxiXaI4zrdG7ZbJMIByNxTdy0V7v4hNCtt3Fb4pcgBXG28b+r3fdPimBZlFk/NQ2Wi Oiqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:subject:cc:to:from:dkim-signature; bh=stuO5j4seaq8CGse6VWb8Yin8aJD1QcJDGnIO6FmT1E=; b=bnSJFm10Vmxo/7QrF09u9tKOjLYPbCoM4isCIgni1gp95MgSnms2h3Z+Kw+GSqo2Pv vPSaERA2BfqovdVvmNqdMyXhoZGzDw+U6nd0yp9ejWszoXHCjTE3MwgcjpxabN4qfEcH UA9pjWGDdnC+pmqwgcPidZ8XvjRwGOc161elhQ/umMub07kczTqgwCOAWFVq0+hxe8AO e4jHH5m8zulqh55DnklcHJ4uQDR53DlgBuLid5/dFaN02E6rd+nCMWue1ATRnfSNEB3o lgfGVBSiAKsLVWcZMf2fs833DE16qNDsSUfh2+oOlfUDB/AYeJ0UmdwChphosyVeLLbX czJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LtTlM9I4; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bs65-20020a632844000000b005139e0d2b5csi572456pgb.487.2023.05.17.22.33.05; Wed, 17 May 2023 22:33:17 -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=LtTlM9I4; 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 S229747AbjERFZB (ORCPT + 99 others); Thu, 18 May 2023 01:25:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229557AbjERFZA (ORCPT ); Thu, 18 May 2023 01:25:00 -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 4D21610FB; Wed, 17 May 2023 22:24:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C2D8564BD0; Thu, 18 May 2023 05:24:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93DF3C433D2; Thu, 18 May 2023 05:24:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684387498; bh=KnUDYWPkRoIVOsC2YPug++2HnnoiLtLdoUJ7TEZLpnM=; h=From:To:Cc:Subject:Date:From; b=LtTlM9I4sO6xJ7oYgkYJXEEYQKLs1KOKNt4KKBBnPeMdzPsRTamb6AJJo0CeZaHA/ hk5bjYm3mstGd6qLmh9kQBwZ3kr78zxkU1LH4g9QQ3264dFolVno9LoNHec6VIHWCu IcOaGfwFIl3l7133r8Gi2tcXBPKQQLzgjnoZ45+5HN3C9kx67JWI8CvbTR9yLrHtoA Pbfyjfm/cvhEvfraEJv8GBeK2h7ZIhJhbuuMC2wajB6jNLMEbmCB7RDo42A8QEHTn6 kuf1OtqaSSMPbmnT9CdaVQm1tMAbcbKkKsDHD9psslTVdHxjudxXKqbir9iac1qto/ N9LRNMo5fEQLg== From: "Masami Hiramatsu (Google)" To: linux-trace-kernel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Steven Rostedt , mhiramat@kernel.org, Florent Revest , Mark Rutland , Will Deacon , Mathieu Desnoyers , Martin KaFai Lau , bpf@vger.kernel.org, Bagas Sanjaya Subject: [PATCH v12 00/11] tracing: Add fprobe/tracepoint events Date: Thu, 18 May 2023 14:24:53 +0900 Message-ID: <168438749373.1517340.14083401972478496211.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog User-Agent: StGit/0.19 MIME-Version: 1.0 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,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766208829485977690?= X-GMAIL-MSGID: =?utf-8?q?1766208829485977690?= Hi, Here is the 12th version of add a basic fprobe event support for ftrace (tracefs) and perf. Here is the previous version. https://lore.kernel.org/all/168432112492.1351929.9265172785506392923.stgit@mhiramat.roam.corp.google.com/ There are minor fixes on the selftest [09/11] and the document [11/11]. (Thanks Bagas!) You can also get this series from: git://git.kernel.org/pub/scm/linux/kernel/git/mhiramat/linux.git topic/fprobe-event-ext With this fprobe events, we can continue to trace function entry/exit even if the CONFIG_KPROBES_ON_FTRACE is not available. Since CONFIG_KPROBES_ON_FTRACE requires the CONFIG_DYNAMIC_FTRACE_WITH_REGS, it is not available if the architecture only supports CONFIG_DYNAMIC_FTRACE_WITH_ARGS (e.g. arm64). And that means kprobe events can not probe function entry/exit effectively on such architecture. But this problem can be solved if the dynamic events supports fprobe events because fprobe events doesn't use kprobe but ftrace via fprobe. FPROBE EVENTS ============= Fprobe events allows user to add new events on the entry and exit of kernel functions (which can be ftraced). Unlike kprobe events, the fprobe events can only probe the function entry and exit, and it can only trace the function args, return value, and stacks. (no registers) For probing function body, users can continue to use the kprobe events. The tracepoint probe events (tprobe events) also allows user to add new events dynamically on the tracepoint. Most of the tracepoint already has trace-events, so this feature is useful if you only want to know a specific parameter, or trace the tracepoints which has no trace-events (e.g. sched_*_tp tracepoints only exposes the tracepoints.) The fprobe events syntax is; f[:[GRP/][EVENT]] FUNCTION [FETCHARGS] f[MAXACTIVE][:[GRP/][EVENT]] FUNCTION%return [FETCHARGS] And tracepoint probe events syntax is; t[:[GRP/][EVENT]] TRACEPOINT [FETCHARGS] This series includes BTF argument support for fprobe/tracepoint events, and kprobe events. This allows us to fetch a specific function parameter by name, and all parameters by '$arg*'. Note that enabling this feature, you need to enable CONFIG_BPF_SYSCALL and confirm that your arch supports CONFIG_HAVE_FUNCTION_ARG_ACCESS_API. E.g. # echo 't kfree ptr' >> dynamic_events # echo 'f kfree object' >> dynamic_events # cat dynamic_events t:tracepoints/kfree kfree ptr=ptr f:fprobes/kfree__entry kfree object=object # echo 1 > events/fprobes/enable # echo 1 > events/tracepoints/enable # echo > trace # head -n 20 trace | tail # TASK-PID CPU# ||||| TIMESTAMP FUNCTION # | | | ||||| | | tail-84 [000] ..... 1324.561958: kfree__entry: (kfree+0x4/0x140) object=0xffff888006383c00 tail-84 [000] ...1. 1324.561961: kfree: (__probestub_kfree+0x4/0x10) ptr=0xffff888006383c00 tail-84 [000] ..... 1324.561988: kfree__entry: (kfree+0x4/0x140) object=0x0 tail-84 [000] ...1. 1324.561988: kfree: (__probestub_kfree+0x4/0x10) ptr=0x0 tail-84 [000] ..... 1324.561989: kfree__entry: (kfree+0x4/0x140) object=0xffff88800671e600 tail-84 [000] ...1. 1324.561989: kfree: (__probestub_kfree+0x4/0x10) ptr=0xffff88800671e600 tail-84 [000] ..... 1324.562368: kfree__entry: (kfree+0x4/0x140) object=0xffff8880065e0580 tail-84 [000] ...1. 1324.562369: kfree: (__probestub_kfree+0x4/0x10) ptr=0xffff8880065e0580 Thank you, --- Masami Hiramatsu (Google) (11): fprobe: Pass return address to the handlers tracing/probes: Add fprobe events for tracing function entry and exit. selftests/ftrace: Add fprobe related testcases tracing/probes: Add tracepoint support on fprobe_events tracing/probes: Move event parameter fetching code to common parser tracing/probes: Support function parameters if BTF is available tracing/probes: Add $arg* meta argument for all function args tracing/probes: Add BTF retval type support selftests/ftrace: Add tracepoint probe test case selftests/ftrace: Add BTF arguments test cases Documentation: tracing/probes: Add fprobe event tracing document Documentation/trace/fprobetrace.rst | 188 +++ Documentation/trace/index.rst | 1 Documentation/trace/kprobetrace.rst | 2 include/linux/fprobe.h | 11 include/linux/rethook.h | 2 include/linux/trace_events.h | 3 include/linux/tracepoint-defs.h | 1 include/linux/tracepoint.h | 5 kernel/kprobes.c | 1 kernel/trace/Kconfig | 26 kernel/trace/Makefile | 1 kernel/trace/bpf_trace.c | 6 kernel/trace/fprobe.c | 17 kernel/trace/rethook.c | 3 kernel/trace/trace.c | 13 kernel/trace/trace.h | 11 kernel/trace/trace_eprobe.c | 44 - kernel/trace/trace_fprobe.c | 1197 ++++++++++++++++++++ kernel/trace/trace_kprobe.c | 33 - kernel/trace/trace_probe.c | 629 +++++++++-- kernel/trace/trace_probe.h | 45 + kernel/trace/trace_uprobe.c | 8 lib/test_fprobe.c | 10 samples/fprobe/fprobe_example.c | 6 .../ftrace/test.d/dynevent/add_remove_btfarg.tc | 54 + .../ftrace/test.d/dynevent/add_remove_fprobe.tc | 26 .../ftrace/test.d/dynevent/add_remove_tprobe.tc | 27 .../ftrace/test.d/dynevent/fprobe_syntax_errors.tc | 102 ++ .../ftrace/test.d/dynevent/tprobe_syntax_errors.tc | 82 + .../ftrace/test.d/kprobe/kprobe_syntax_errors.tc | 16 30 files changed, 2407 insertions(+), 163 deletions(-) create mode 100644 Documentation/trace/fprobetrace.rst create mode 100644 kernel/trace/trace_fprobe.c create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/add_remove_tprobe.tc create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/tprobe_syntax_errors.tc -- Masami Hiramatsu (Google)