From patchwork Sun Nov 5 16:12:59 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: 161688 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2198936vqu; Sun, 5 Nov 2023 08:13:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDH5DHqQjEblztmksyQEVlQr3K84v0n1ZaJL5m1jBZdLFIM9z5c7BqmOi//eWsqmP5OMdX X-Received: by 2002:a17:903:24d:b0:1cc:9781:4782 with SMTP id j13-20020a170903024d00b001cc97814782mr7907204plh.62.1699200807397; Sun, 05 Nov 2023 08:13:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699200807; cv=none; d=google.com; s=arc-20160816; b=pDqFJupWVIeUnwFpPak08Z6OcR9Ea12i0POranTMqpABuqUfjykduV5UIhtW45VNEJ ujs1IPFAH27Hm7hP7AqFrmVtysnFCdam61GUuKDCg/o9RcJH3GFUgZtT58opyo1+lxo5 kI851gOekc90oJZ9/1YaoPNhrb1FoBwCHOnWcGTdEYv8fRZyQUM8RyE8LqlrjktO9ixg 8zE5OGAf0kM4SgaEVgeLWyQ4f6GoSPirAboyvoxoikp8mCih7G+1qV1Af+6I6vgc9NLZ hfi/6mbRr+KIZxzYqgRqUel2PaoVbzJDpmpAlNyvFZl7idBdDPN7LTFkh5+PJ0cvK+oC JmYQ== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Gj2uNnmhVzJHjb7fQ2DkJguySdmSbMjQnu/zyX+fX9w=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=t7PVzTgqmcANLXhM/TFDYVKdL59EVfOOwfmqPV6S/qQMCQ2sc4JJhhG2gYhVU6kk1i Jln5sRxlhbipg73TiAzm/a6JE8NLit3WNcP4GoW8U5SZ4UZB0JkkWr2sMwoNAlf1YlR+ 5xF8vqSzoMkS/l8WnrmDBlksuyyNEaMlv5u+CBrw8ETXRTYgV+7vndrCuNh7zigkNd46 uSlbSqhEdyySydzEeDq0+vNQ3N/SsU85TbdbzQUgUZbPJaCvrHmiABf7Cz95D+4FOVk4 JCEtvDYxLj5NfI9IuWD8wTnSlvTpfkr6kCvD0qv5ulE5NIeMtRn+wW/5eg1civuOeMVG MxDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZTesYE3H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n9-20020a170902d2c900b001c1e4f9c63esi6568205plc.491.2023.11.05.08.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 08:13:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZTesYE3H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7A47780B2312; Sun, 5 Nov 2023 08:13:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229879AbjKEQNT (ORCPT + 34 others); Sun, 5 Nov 2023 11:13:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjKEQNJ (ORCPT ); Sun, 5 Nov 2023 11:13:09 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B31110E2 for ; Sun, 5 Nov 2023 08:13:06 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E42C5C433C7; Sun, 5 Nov 2023 16:13:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699200786; bh=0wwZpMxwKGIQyZo3TSMiWZ/Y22+/QBwUQ7If+R6veeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZTesYE3HpdWVCNJcBHB8i8hTSur4IzVb2plFlfyVN1bO8in5i2u6e4dC5fVOpjRLI EKf3NRwfGo7pIZ6ZdC4Ycn4M1iD9dS2yxq3ocdLZ2qWQbLtIGdUghfJpGhjWYHtmsP aBhOm6RWEyJK6YouZzWAGLRpPwjtjNpyh5IldtDMLtFMCSiWrEXO9D57AQjqBqZ5ib Lg0lU2UFXoDLxwQQkJl0HSupXNV3AjqIPCSu+aPb0c1c64x+QyJsiWXV5ILknpNLHz CGICyD9yZbV0qTU6zotdjN0ZKlajrcGiaFhSxCHsQ2hHokVxRdKMIPhN+7F6GeqEtn gYSUjmbuldTZA== From: "Masami Hiramatsu (Google)" To: Alexei Starovoitov , Steven Rostedt , Florent Revest Cc: linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: [RFC PATCH 32/32] Documentation: probes: Update fprobe on function-graph tracer Date: Mon, 6 Nov 2023 01:12:59 +0900 Message-Id: <169920077887.482486.9572304320229899702.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169920038849.482486.15796387219966662967.stgit@devnote2> References: <169920038849.482486.15796387219966662967.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 05 Nov 2023 08:13:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781741185678207043 X-GMAIL-MSGID: 1781741185678207043 From: Masami Hiramatsu (Google) Update fprobe documentation for the new fprobe on function-graph tracer. This includes some bahvior changes and pt_regs to ftrace_regs interface change. Signed-off-by: Masami Hiramatsu (Google) --- Documentation/trace/fprobe.rst | 42 ++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Documentation/trace/fprobe.rst b/Documentation/trace/fprobe.rst index 196f52386aaa..fb0446f68bcb 100644 --- a/Documentation/trace/fprobe.rst +++ b/Documentation/trace/fprobe.rst @@ -9,9 +9,10 @@ Fprobe - Function entry/exit probe Introduction ============ -Fprobe is a function entry/exit probe mechanism based on ftrace. -Instead of using ftrace full feature, if you only want to attach callbacks -on function entry and exit, similar to the kprobes and kretprobes, you can +Fprobe is a function entry/exit probe mechanism based on the function-graph +tracer. +Instead of tracing all functions, if you want to attach callbacks on specific +function entry and exit, similar to the kprobes and kretprobes, you can use fprobe. Compared with kprobes and kretprobes, fprobe gives faster instrumentation for multiple functions with single handler. This document describes how to use fprobe. @@ -91,12 +92,14 @@ The prototype of the entry/exit callback function are as follows: .. code-block:: c - int entry_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs, void *entry_data); + int entry_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct ftrace_regs *fregs, void *entry_data); - void exit_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs, void *entry_data); + void exit_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct ftrace_regs *fregs, void *entry_data); -Note that the @entry_ip is saved at function entry and passed to exit handler. -If the entry callback function returns !0, the corresponding exit callback will be cancelled. +Note that the @entry_ip is saved at function entry and passed to exit +handler. +If the entry callback function returns !0, the corresponding exit callback +will be cancelled. @fp This is the address of `fprobe` data structure related to this handler. @@ -112,12 +115,10 @@ If the entry callback function returns !0, the corresponding exit callback will This is the return address that the traced function will return to, somewhere in the caller. This can be used at both entry and exit. -@regs - This is the `pt_regs` data structure at the entry and exit. Note that - the instruction pointer of @regs may be different from the @entry_ip - in the entry_handler. If you need traced instruction pointer, you need - to use @entry_ip. On the other hand, in the exit_handler, the instruction - pointer of @regs is set to the current return address. +@fregs + This is the `ftrace_regs` data structure at the entry and exit. Note that + the instruction pointer of @fregs may be incorrect in entry handler and + exit handler, so you have to use @entry_ip and @ret_ip instead. @entry_data This is a local storage to share the data between entry and exit handlers. @@ -125,6 +126,17 @@ If the entry callback function returns !0, the corresponding exit callback will and `entry_data_size` field when registering the fprobe, the storage is allocated and passed to both `entry_handler` and `exit_handler`. +Entry data size and exit handlers on the same function +====================================================== + +Since the entry data is passed via per-task stack and it is has limited size, +the entry data size per probe is limited to `15 * sizeof(long)`. You also need +to take care that the different fprobes are probing on the same function, this +limit becomes smaller. The entry data size is aligned to `sizeof(long)` and +each fprobe which has exit handler uses a `sizeof(long)` space on the stack, +you should keep the number of fprobes on the same function as small as +possible. + Share the callbacks with kprobes ================================ @@ -165,8 +177,8 @@ This counter counts up when; - fprobe fails to take ftrace_recursion lock. This usually means that a function which is traced by other ftrace users is called from the entry_handler. - - fprobe fails to setup the function exit because of the shortage of rethook - (the shadow stack for hooking the function return.) + - fprobe fails to setup the function exit because of failing to allocate the + data buffer from the per-task shadow stack. The `fprobe::nmissed` field counts up in both cases. Therefore, the former skips both of entry and exit callback and the latter skips the exit