Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp98222rdh; Mon, 18 Dec 2023 05:35:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHLk1BW4nc+B0QVvNt1FlZCfBH1rRVn5Mk/zGKfSqq2hrtZwqxUoNi8ha/rZ0TEWzwuAeBB X-Received: by 2002:a05:6a20:7d8e:b0:18f:c81c:4484 with SMTP id v14-20020a056a207d8e00b0018fc81c4484mr20876513pzj.29.1702906529662; Mon, 18 Dec 2023 05:35:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702906529; cv=none; d=google.com; s=arc-20160816; b=Asa4Fos31fxO4g6R6c+bVW4qEHEzASfddPzFCVZpZlOcHcnRDh/DQzYk4TecBBq/1f WSQV6ZsB0absBoI2X022oC5GQqlOKnQ8oMHqpsuBxhEZWwbGQeaEiw+s807rkEWnZ+5b 0mod/I/K8CSHIhl/ZyCleH0Pp+qKzXQZ9gk1MJ/+KITytJ3i1rYxaT/ughY0CQ+SrROH rJPWQJGikzbofiUoMuwcOuAiB4+NwfH52JUGgSz215oj7s7ayb+iMgU35L7wxfEP+XfR LHhH/02iqDvJBNNXHjiRmZbGlWtf740rQjDegojJgGq6vs3jCfJu/5v10X5MW1JWc9yT VZuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=g/RVfnmZcQdfRZB+YRyiXpHH94CCdK1xBgexCLFpl6s=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=Ejsd2keJpW4t17W4ntYa2uLJOPVQWn0NkHe/ozXINeT0I/8cnL2VgYQuMLnUq5nP1D IAsh3ri5qnI2OH3/ZMFocC4f19MxlgD5n1oeDmxGzSDXBVv1exU3Eo+kRlgKqqy/VqxI gaj6lGHhPyyIlzE/dUkJKCU667kfNvzoOQlgl/0CSbfg0w2X862W7QOOg2+TsogUUegY 6iwSL6c3z4NBwjKO25usH5pE2LGC2BaScpSRM4FqVNfMfxk4HoRQUk3SJLtLoEyORppX fd/xnFxyDfBSE5mDsMXq/NUMDNuvflxKhFEjLumldpfWqC6b2djolT4QTImb7U8vSFf/ AS6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gdptaZoH; spf=pass (google.com: domain of linux-kernel+bounces-3742-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3742-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id fa30-20020a056a002d1e00b006cbba705c9esi18183756pfb.207.2023.12.18.05.35.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 05:35:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3742-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gdptaZoH; spf=pass (google.com: domain of linux-kernel+bounces-3742-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3742-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 81EF3B23E44 for ; Mon, 18 Dec 2023 13:27:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C48A7691A; Mon, 18 Dec 2023 13:18:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gdptaZoH" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87C2B1D129; Mon, 18 Dec 2023 13:18:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1BAFC433C7; Mon, 18 Dec 2023 13:18:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702905510; bh=8t7YVZmoVUR7dCk/2nFP4SmQbrkuMwJVZH30PnGw0sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gdptaZoHvqangQBY2bqHwuw2opQxeFkeZFx9In24WN3WXOAIwlqy3DmY0kAtz6FTJ G+q4NbNA93rX+F+0UbpBJJXwEDD3pXoGYWcQ3V+M4q6X4qrYHwSPvXmBTLjHiFnFi7 /q5NeaHXbUuysuw2nR05yhjcKI241e45McSOD6a6YawpVzKv7y9iHFVZW/PGy8xpcy dtma6kDEv1SuXSRh1StcmAhzi4I3x6sFmWIunRS4/U63KEDZ9rlRca+MYH+4HHVFbq doF4JsL472c0c0NZIbvTcPKMxOAx8LWmZH64LU1uGIS21o1A68M8UtCPXmD0iOVlwD btUodJNv1lOhA== 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: [PATCH v5 34/34] Documentation: probes: Update fprobe on function-graph tracer Date: Mon, 18 Dec 2023 22:18:24 +0900 Message-Id: <170290550413.220107.2534299881433621951.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170290509018.220107.1347127510564358608.stgit@devnote2> References: <170290509018.220107.1347127510564358608.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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) --- Changes in v2: - Update @fregs parameter explanation. --- 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..f58bdc64504f 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. This + includes the function parameters, or the return values. So user can + access thos values via appropriate `ftrace_regs_*` APIs. @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