Message ID | 166792255429.919356.14116090269057513181.stgit@devnote3 |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2789858wru; Tue, 8 Nov 2022 07:50:43 -0800 (PST) X-Google-Smtp-Source: AMsMyM6GxygOeACW5NXL3JMWmeheffbtESlROEsS/wkioshDf2IEltC5TbHP1+XLXLwLgj6qh5ti X-Received: by 2002:a05:6402:12d1:b0:463:3f0c:be02 with SMTP id k17-20020a05640212d100b004633f0cbe02mr49652720edx.239.1667922642914; Tue, 08 Nov 2022 07:50:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667922642; cv=none; d=google.com; s=arc-20160816; b=UcaRGoXnFW1Pn4QNvZgfbCxbqHZPAHy887rOMS3LCFTahdKN2F4x8uF/HmoXg273KL 2OMi1LavnmWz2JaGc7vIuOl9S0axUJuAMzyPeRzg8dTVg+MtoQj/9lqHV3HX7k8WqtLr 32qFXgTDNOa3L/LeGig/7o8SEvLYXPYfU3Vy1UrFa7r9DwBlbNGHk5FLdb45KDFhdBy1 ktApW50Jrj9aGUKBpMf3R6mglkk0aELswsnjYiI2jKIogBT6Wz3aWqSz2PDhZsKwUNyM wTeyD8sJ9IFpaEIKoMXEY/P1G0TrO1svCSdbCTKHWl2DoEiou9f1s5JUtfX3XmXm93AG mC8A== 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=gEaAFll9a5l/8H2hLrhu1+EIeJHFIzgkG/hPp8Mtp54=; b=qbX349KpHmwBd3KV5zjRZoqsprORN1j+KrdvpTYaoxbWYyWSUgkw7xpG/GBrzDY71m 5rRI5tQdUaEKh0+7OnVBPzryYKrK43MLfayoFDlQyvGKpC79jG9PPf2aIRk4Rw2hSQTw KMh56IbekmcKNDBcJO+wxfbYEUOl1/pdNAzRKmDRme9Doj6HFqcIOXbfjAI0yze0kmei ufejFb0XgdU95V/7Ghsd7qfl2Awg0r4CzKdx18E8/WzJjkft+dRt55VOyTG92Qd3DPqO w86qDqQfsOxXddoJwQOjMTktjoHbYw/IqeF1nA32qJuNO1Gq7f3ewcxpLN5q9bi9wMza 7JHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qJZttUEs; 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 qq23-20020a17090720d700b0077547abf08fsi10065022ejb.169.2022.11.08.07.50.19; Tue, 08 Nov 2022 07:50:42 -0800 (PST) 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=qJZttUEs; 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 S234466AbiKHPtW (ORCPT <rfc822;tony84727@gmail.com> + 99 others); Tue, 8 Nov 2022 10:49:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233974AbiKHPtT (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 8 Nov 2022 10:49:19 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED0DD1A05C; Tue, 8 Nov 2022 07:49:18 -0800 (PST) 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 900BF61656; Tue, 8 Nov 2022 15:49:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABAC7C433C1; Tue, 8 Nov 2022 15:49:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667922558; bh=OjXhkq0eLX0m3+uGzwgi/GSi4Io4hgZBT5i154Q5krA=; h=From:To:Cc:Subject:Date:From; b=qJZttUEs1+fDdvoazsDFN+Wzhbm262DZyxnsAD/+Rv1WRM15gQh/s+nAug2r8JxIW lz6aXH7JmW5HuAjmVlEE4/dvqgWxRoXDBMh6tOlDg5NkhnLxRmAa4M0do3zqZR4dLK wTY1SBdgLI38pgRjcwObHLY6OOCVX+Lwicg4Afe6/ziVcfrbd3mXdNbkmvoyOGLqww 3JmAf1heSn4JKr1suKvePJDtbRS0Umxl7OuH1yDaMojBn3yw+HBfrumyU61L3ZPre5 kRdUXTmtfpxQlMI60smVg7dY+YU2vlmrJ/s3wDf4++85HW9zBetJzr6ToORw3kxbZw RIp6dhVDODabw== 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> Subject: [RFC PATCH 0/9] tracing: Add fprobe events Date: Wed, 9 Nov 2022 00:49:14 +0900 Message-Id: <166792255429.919356.14116090269057513181.stgit@devnote3> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: <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?1748943652976951448?= X-GMAIL-MSGID: =?utf-8?q?1748943652976951448?= |
Series |
tracing: Add fprobe events
|
|
Message
Masami Hiramatsu (Google)
Nov. 8, 2022, 3:49 p.m. UTC
Hi, Here is a series of patches to improve fprobe and add a basic fprobe event support for ftrace (tracefs) and perf. With this series, user can 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, the IP address will have some offsets from the symbol address. And it can only trace the function args, return value, and stacks. (no registers) The fprobe events syntax is here; f[:[GRP/][EVENT]] FUNCTION [FETCHARGS] f[MAXACTIVE][:[GRP/][EVENT]] FUNCTION%return [FETCHARGS] E.g. # echo 'f vfs_read $arg1' >> dynamic_events # echo 'f vfs_read%return $retval' >> dynamic_events # cat dynamic_events f:fprobes/vfs_read_entry vfs_read arg1=$arg1 f:fprobes/vfs_read_exit vfs_read%return arg1=$retval # echo 1 > events/fprobes/enable # head -n 20 trace | tail # TASK-PID CPU# ||||| TIMESTAMP FUNCTION # | | | ||||| | | sh-142 [005] ...1. 448.386420: vfs_read_entry: (vfs_read+0x4/0x340) arg1=0xffff888007f7c540 sh-142 [005] ..... 448.386436: vfs_read_exit: (ksys_read+0x75/0x100 <- vfs_read) arg1=0x1 sh-142 [005] ...1. 448.386451: vfs_read_entry: (vfs_read+0x4/0x340) arg1=0xffff888007f7c540 sh-142 [005] ..... 448.386458: vfs_read_exit: (ksys_read+0x75/0x100 <- vfs_read) arg1=0x1 sh-142 [005] ...1. 448.386469: vfs_read_entry: (vfs_read+0x4/0x340) arg1=0xffff888007f7c540 sh-142 [005] ..... 448.386476: vfs_read_exit: (ksys_read+0x75/0x100 <- vfs_read) arg1=0x1 sh-142 [005] ...1. 448.602073: vfs_read_entry: (vfs_read+0x4/0x340) arg1=0xffff888007f7c540 sh-142 [005] ..... 448.602089: vfs_read_exit: (ksys_read+0x75/0x100 <- vfs_read) arg1=0x1 Future works: - Trace multiple function entry/exit (wildcard). - Integrate it with the function graph tracer. - Use ftrace_regs instead of pt_regs and remove dependency of CONFIG_DYNAMIC_FTRACE_WITH_REGS. - Support (limited) register access via ftrace_regs. - Support fprobe event by perf probe. - Support entry data accessing from exit event. - Support BTF for trace arguments. This fprobe event may eventually replace the kprobe events for function entry and exit on some archs (e.g. arm64). Here's my current migration (kretprobe to fprobe) idea: Phase 1. introduce fprobe events. (THIS) Phase 2. introduce generic function graph shadow stack Phase 3. Replace the rethook with function shadow stack and use ftrace_regs in fprobe handlers. Phase 4. Extend this fprobe support to other archs. Even if kretprobe event is replaced with fprobe event, tracefs user can transparently use fprobe events for function entry/exit with 'p:...' and 'r:...' syntax (for backward compatibility.) Thank you, --- Masami Hiramatsu (Google) (9): fprobe: Pass entry_data to handlers lib/test_fprobe: Add private entry_data testcases fprobe: Add nr_maxactive to specify rethook_node pool size lib/test_fprobe: Add a test case for nr_maxactive fprobe: Skip exit_handler if entry_handler returns !0 lib/test_fprobe: Add a testcase for skipping exit_handler docs: tracing: Update fprobe documentation fprobe: Pass return address to the handlers tracing/probes: Add fprobe-events Documentation/trace/fprobe.rst | 16 - include/linux/fprobe.h | 17 + include/linux/rethook.h | 2 include/linux/trace_events.h | 3 kernel/kprobes.c | 1 kernel/trace/Kconfig | 14 kernel/trace/Makefile | 1 kernel/trace/bpf_trace.c | 19 + kernel/trace/fprobe.c | 45 +- kernel/trace/rethook.c | 3 kernel/trace/trace.h | 11 kernel/trace/trace_fprobe.c | 1120 +++++++++++++++++++++++++++++++++++++++ kernel/trace/trace_probe.c | 4 kernel/trace/trace_probe.h | 4 lib/test_fprobe.c | 109 ++++ samples/fprobe/fprobe_example.c | 11 16 files changed, 1349 insertions(+), 31 deletions(-) create mode 100644 kernel/trace/trace_fprobe.c -- Masami Hiramatsu (Google) <mhiramat@kernel.org>