Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1421425lqp; Mon, 15 Apr 2024 06:17:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWgN9rEhJy6XSpWW+SU4X3RE5KsAMRIAbh/wFoJiEvxbo9eo36hqSq/XNVZJBged3/ZrEC+WdSZCEAWZmkay9mRyqLyaxoYUcmESWQvSA== X-Google-Smtp-Source: AGHT+IEAVnJdbwJUT4opgSEdiAotXQ3N+q6tfgPYHN9slQoCyPreuxI4iBHy18VlVPJ5hWFP4kau X-Received: by 2002:a05:6102:160d:b0:47a:2e85:d983 with SMTP id cu13-20020a056102160d00b0047a2e85d983mr9073409vsb.13.1713187044349; Mon, 15 Apr 2024 06:17:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713187044; cv=pass; d=google.com; s=arc-20160816; b=zpt03um8y84lY+bVwfRbVs5970dukexZ/w0Q2foUPYFGAT2lEyDZYRAMP1+xeJQexg WmgqmXCPI4KtIasiBp8y4mlrrGzpiAIiTr2YXWiHCyIIj2Uc56xlZcamaibeaZZlZWRi NZ42TD908jjISBqNe0WEQqGqW1OnPUFja/54mIwUHiF/Xo5V5dhBj4bspNy3xj55ClTR btkrPpQtA26PcFhcvezzfkxLf5EzSjIBbNR6w2HM9JqaprpgHeftcH1XCsQmmgzQM5aU +GsNCxtLOzgThAhDHa/W5N4bYu7Q1VHJjUxAAD0Un26J3WupGNx5UBIz18p+bnLWgkE2 Ce6w== ARC-Message-Signature: i=2; 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=aYx1Ec6bY/VdQ0//74wIAiA4bGWBRds6k/E52q6SAgvI0E8O8gPdaTvXcD+tqiMMki 4v3jLOffUEZDUazKODbV4Y630U6z73I47UyJSO4tmnibCnrehb8OlXk5Zi+DBH6SBKmd AmzebJhxA/au7Vzo5Wab+jB/sLVK0CfLc0iEnNRnywFwUetz7oIJQg2tKbKxttbzkekl eE3ezsRk+KpMlWdxESCk9Ys4jSl8DA2riet7YFkwmInzItc62/Mmxk7ouMUy9o+VQjfY +GY6hCtdTgyUE/f/3M1uN5sv84/zMBQcXWB3p49oHFgIQW8hQ2hg5oXDrHiokOtROpbK uBUA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c3ZG7R8E; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-145206-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145206-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b13-20020a056102232d00b00479e23f8326si1271995vsa.535.2024.04.15.06.17.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 06:17:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145206-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c3ZG7R8E; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-145206-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145206-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C5E271C21433 for ; Mon, 15 Apr 2024 13:17:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94A6384FA9; Mon, 15 Apr 2024 12:55:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="c3ZG7R8E" 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 957D774419; Mon, 15 Apr 2024 12:55:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713185754; cv=none; b=FWGTMlSqQmuisZ5APiMjsvo/nI4yjdXZ4YTLoaKaAmmhSxQG0Uj/dgf1Pa5rniFMFWxLWssFqHvQDQeyr6bu5Nw53SYgrEHHYrAtbqit7QeemEyxJrgUGhRQelD2iA0Knawd4vTbxgwRF2wEUNJL+0PwRtPNNxCHJh52p2zTrLc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713185754; c=relaxed/simple; bh=8t7YVZmoVUR7dCk/2nFP4SmQbrkuMwJVZH30PnGw0sc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=dFCoeTLBo4WQDFaZutCGbxqbDIbxxnNiwh/dZPuDhlv0dMZI5nDq1fmxgWez68wI8lpPCav0RYuIPj2/zHdJF9QVKAziVa29WdtXjlu8LpnC6CRiP+YDj43ch6rqDNOgqyO+D87L9hGPtMRXWvJy2jrVLsISpoaQBXr8Q1ask8w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c3ZG7R8E; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B27CBC113CC; Mon, 15 Apr 2024 12:55:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713185754; bh=8t7YVZmoVUR7dCk/2nFP4SmQbrkuMwJVZH30PnGw0sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c3ZG7R8EhHkf9shSPPvWFON892orCuOKuAUyJtFknyQMIOHUejZi6rwwDlJUH7b6D LbwLkVcStp5TEjEx8yVJm608TrB2eNlZmBoAokRgaQ9+opOxppg5aNZvhFaUWiHLmJ 72EgDM0oq7jL8uE6TMWPQZArnp8QaWH4cSnfYHTDg4aX76MTPeZUuImf7R960/Y4UI Nz0SVoMNSln5uvYCqJPaFsL4DM+p5IEfQYXlgPnVJhAxKAj57iYc1MVIVwxjSX7FUE ru/OKY/4j31cNNaDToCZhP5TddgbGMtbuknsSFdhyKOb4mJxmgzVXnJ7I87uzua8aD NEzKJJ4TGZTFA== 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 v9 35/36] Documentation: probes: Update fprobe on function-graph tracer Date: Mon, 15 Apr 2024 21:55:48 +0900 Message-Id: <171318574857.254850.2343327942717996239.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <171318533841.254850.15841395205784342850.stgit@devnote2> References: <171318533841.254850.15841395205784342850.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