Message ID | 168507466597.913472.10572827237387849017.stgit@mhiramat.roam.corp.google.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp228982vqr; Thu, 25 May 2023 21:52:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5eTzDCWRNzaNEAtyNml4UQIieOMa94dNnq6PHsF1cjBHoJXtzSBw44waxu5K0aQKUiEIO9 X-Received: by 2002:a05:6a20:7d9f:b0:10d:d42:f6bc with SMTP id v31-20020a056a207d9f00b0010d0d42f6bcmr902530pzj.41.1685076759461; Thu, 25 May 2023 21:52:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685076759; cv=none; d=google.com; s=arc-20160816; b=invf5bsaB+sRL8/q/iS/qDrhuxajd/Z7DQ/gGboH8IkyR99cI68dclgkW4vXCiKw6+ KVQcZ7ztUxE3shPoNLy2P/56P3U4vvf8eCzpNt9mJOd6lIuECb0Oe5jWngzAM8wjg4ax mZp3kuVPXcfT80Wg3jqQWMBQM9GQ72plxXHMzTiwmIklBHtK4sZBXqIIbXoJjLAEIMmU RNEuWGhoBw3VN8a+m9l+MHGUKbkkVgNqThDAs9WVPozlEXPeo+2gPpAqLYfJ7X5Hbiif 5rbNzQ6/sO7HfCXExSVAx8AcXfEMVMbGgCgEHcxnqdyxOm48mk/QGDDKNoQmm+yj6HLO 1cUQ== 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=G1ypQ7PhyXY1xncqyV24j5Q1kG2bPK7bP+GhPkHpBQI=; b=B/gUxJLURMZpdR8aVMeG4vIcQ4/9F3doVuS08ShQ8EnljGmE1b8ygZLAbUD88g9zbb bwOwYyjxU1gMgOLwnuOBWF9U+uOss/pEMWyVY7LKYdzTBC1b14PXb+h6uJuR/qEV15GW AF8wjxDAu3sNcqVnhvrNua63SSEkkGtKC6InyLu/YwAd10hqMVZhqOD6f1d/XHy4t8U4 R5/CAso5O8bsrwxe/xVKMSyNheq2bPqO8VqaboN5oL8IfqJkRxjTEZ5i8tgdG/ehz8hg Zb4pLuHcauckw3pEbyzoJeIOfA33ALRYSSRlW9239dHoHczlfCp1SgrxLsH8z0jvfwj4 nZ7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oPN5Pden; 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 u62-20020a638541000000b0053eefa04dc0si2820473pgd.276.2023.05.25.21.52.26; Thu, 25 May 2023 21:52:39 -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=oPN5Pden; 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 S229479AbjEZESB (ORCPT <rfc822;zhanglyra.2023@gmail.com> + 99 others); Fri, 26 May 2023 00:18:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232487AbjEZER6 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 26 May 2023 00:17:58 -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 5E905195; Thu, 25 May 2023 21:17:52 -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 E16D964CA1; Fri, 26 May 2023 04:17:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAAAFC433D2; Fri, 26 May 2023 04:17:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685074671; bh=8JGNVNj1EZHAjY1/R8ICZ76vyLFmaEpzZTmWDtrVlC0=; h=From:To:Cc:Subject:Date:From; b=oPN5PdenUgoVwo6zExqG8iPaAKMZT+MKDH/hXA7xgRWUIR4rZ0iOziM0p9TzbR2Sx E8mWBsliNDtAjxDjstOGjvRAYicdWIUkJ5qjQyh9AArXjO0yO52w7rXHOmeoyI4aat R9vEUMYek12wM/M1cL+WTkmiTebRJRxEu2mbE4R5ve/e3wKRgLe9UjWOWISPFQYymn bO8ZMz56lXZHP4Cs0KqWKxbwBOyCnbSSQczlSa0QBOiCGkgu4C45lJKl3TR0p6l6wO /wzMkH2NiH0O1gZUVqinY+ZgWM6Pi6awBcHCSb4umWshMQZXga5OhvhT+dkDxB0zfD ydotz3qn8AHJQ== From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org> To: linux-trace-kernel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Steven Rostedt <rostedt@goodmis.org>, mhiramat@kernel.org, Florent Revest <revest@chromium.org>, Mark Rutland <mark.rutland@arm.com>, Will Deacon <will@kernel.org>, Mathieu Desnoyers <mathieu.desnoyers@efficios.com>, Martin KaFai Lau <martin.lau@linux.dev>, bpf@vger.kernel.org, Bagas Sanjaya <bagasdotme@gmail.com> Subject: [PATCH v13 00/12] tracing: Add fprobe/tracepoint events Date: Fri, 26 May 2023 12:17:46 +0800 Message-ID: <168507466597.913472.10572827237387849017.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766931047933776479?= X-GMAIL-MSGID: =?utf-8?q?1766931047933776479?= |
Series |
tracing: Add fprobe/tracepoint events
|
|
Message
Masami Hiramatsu (Google)
May 26, 2023, 4:17 a.m. UTC
Hi, Here is the 13th version of add a basic fprobe event support for ftrace (tracefs) and perf. Here is the previous version. https://lore.kernel.org/all/168438749373.1517340.14083401972478496211.stgit@mhiramat.roam.corp.google.com/ This version fixes some minor issues in the previous version. I found that TPARG_FL_FPROBE was not set and TPARG_FL_FENTRY and TPARG_FL_RETURN were not mutually exclusive, so fix it in [2/12] (new patch) and [3/12]. I also fixed the fprobe-event selftest because it didn't found the syntax error that fprobe-event shouldn't access %reg [4/12]. For the BTF var name feature, there is a bug that the BTF var name is used with fetch_type (e.g. varname:u8), it failed to apply the BTF var name as the event argument name. So fixed that in [7/12]. In [8/12], if user specified only '$argN' the kernel crashed, and if BTF is not there, it returned an error. So I fixed both bugs. [8/12] also had another bug that it convert $argN to $argN+1, that is also fixed. 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) (12): fprobe: Pass return address to the handlers tracing/probes: Avoid setting TPARG_FL_FENTRY and TPARG_FL_RETURN 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 | 1199 ++++++++++++++++++++ kernel/trace/trace_kprobe.c | 35 - kernel/trace/trace_probe.c | 652 +++++++++-- kernel/trace/trace_probe.h | 49 + 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 | 58 + .../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 | 111 ++ .../ftrace/test.d/dynevent/tprobe_syntax_errors.tc | 82 + .../ftrace/test.d/kprobe/kprobe_syntax_errors.tc | 16 30 files changed, 2450 insertions(+), 164 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) <mhiramat@kernel.org>