From patchwork Tue Feb 6 15:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 197508 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1614476dyb; Tue, 6 Feb 2024 07:23:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFyZnDKpfD7Kv1Kg/eUoICr0qaYdUHrKO5K95cHX71hG5925YAe/kOHR5nwt6HdoHKSdUIC X-Received: by 2002:a05:6358:719:b0:175:cfa7:953d with SMTP id e25-20020a056358071900b00175cfa7953dmr3727555rwj.2.1707233013748; Tue, 06 Feb 2024 07:23:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707233013; cv=pass; d=google.com; s=arc-20160816; b=RurO7NG8bo+3QUIPzoj9SSWerl/aw4PA4TP1Wfb5nrOOBDCFgvSVypII2K1jE8uR1N 3lDcs4v7Fry2b+5IO5wfMKqdk5eNryGxUmrP9akAR1rmwHrVWUYRvFaUz4XloKO0ycyV +YozMycCfLJ7/lvIQICGiLGZYsTF0UJOwTr/OTnY6RQE0Ps8WFDYPH3BKU93KqO7Sx3G R6mwJbm+750yiIADr9Hp5XoMxlH7YHX8jqCVz22psMnVXdI0r0/s9gUJHjSMAOmrptJm 6nB9XgkUKTHzb0Lgm3ujuAhI8S1AAbAQYxIBNhy5y1HDZRhwaO0mUJGOuB4yYYMiboKW j2HA== 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=CJ0w+OWXIlL10XkSs6TfkAjFNTOpc0739n+NYnym4nM=; b=gHZSRhAUpSAdHVGlOKEbCo9rJkHgZ/Hq36g4KQ9KFkfR/eTWgMvi6NmMOyAmjSqn+V sQQXtGBViqmQ9YWH96Eaj9lDkvm2tkIRdCKEih9LnXIeKdqg1TzWq2a39k2ze18yL9eL gjMsLGZv9vyWojFZW+nt5gR05eCFgTm8EPoSNgjwlUW1loDAnc1/1WTUIS4nzsNjj2Y7 vWmuAScrLWEbGDGqG9ID4I5hKQXfNYoriZHx8XkEr0LltQcAbZD5lCPIeqei6ylC+X9G DfPq0JkLVWFnTsMCMNdPQ704nPmYiVt7VUxlMkCzXJUObXI5HhGtINaD01HoNMzuxaIq I2xQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u4p6i6QU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55222-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55222-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCVaDZzKhsP4aLB/hNsw4V0rJHhkF5TMr6iAnFjfXFIuQOTiNV+Dq+1MeR1np0pWwabjQWUt/M4JOdcTW7OFAAZfCA/3cQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h18-20020a63e152000000b005d68eec351esi1793004pgk.740.2024.02.06.07.23.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 07:23:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55222-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u4p6i6QU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55222-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55222-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7EF292914A3 for ; Tue, 6 Feb 2024 15:23:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9A3B13D517; Tue, 6 Feb 2024 15:14:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="u4p6i6QU" 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 C21B7132C3A; Tue, 6 Feb 2024 15:14:16 +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=1707232456; cv=none; b=rHLCQvhxsdGJSicx9ijvNNi5Ar9ERCrF/GnmaeLI6JmXGraFCpY+Xj5vREhPT7CHHuujP3vjKZXvEStPKh7eo14efuasu+wOPN99oyxaQCcEWhzXyB52Ul+r5ebX4TL0eCz5N89BAguo361m9ShrpZK3miLyXVeqgI6GsA24DT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707232456; c=relaxed/simple; bh=8t7YVZmoVUR7dCk/2nFP4SmQbrkuMwJVZH30PnGw0sc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=RqczFtWVWjYdsgC5HXyEqfuU+GZ+NprY+5a1lgnYmzsjETEAVI13Yb5sFEgFql2wEhMw9AK2k7mzNTh3Fgrp+sryuE6El7ALc/rqWEbD6QQYWWBO9976v2TTYwm8LSx4FgBvG9UwHs46TYx/tXkLHPkZUmzt02ao0LBT3MDSAfc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u4p6i6QU; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 887CEC433C7; Tue, 6 Feb 2024 15:14:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707232456; bh=8t7YVZmoVUR7dCk/2nFP4SmQbrkuMwJVZH30PnGw0sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u4p6i6QUvB1lmToWncDmKrM6GaNvi/jEZ/g+nhNx5D/L2J/hZDX24E165LUBcvK7b SuLgtaQOhtHCEFucuFRU/AcvJX9LnLf8Gmy8CgHXhfwiTyFnUt0TuTVVFSQYS4P4+5 j+tePW7xuLh/z+zRLINZ5ABrYo6cBj3XJAmS8M09yGZ/PZn+AJUg6xbIitupolq5iz RimZa7DqIYXUxaDpdO19uwrpgJ3aJRsTIvQ2ySxZFoNvI9gDhS/KMhWO402qVfPGB/ Gp7rduXQy/5pqORw3eVvt2GswExfdtoOubIk9oD+NwQZzvXfN8uLGUQWqwZs3rB+4p SARF3quPrel1w== 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 v7 36/36] Documentation: probes: Update fprobe on function-graph tracer Date: Wed, 7 Feb 2024 00:14:10 +0900 Message-Id: <170723245029.502590.2313180068078569074.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170723204881.502590.11906735097521170661.stgit@devnote2> References: <170723204881.502590.11906735097521170661.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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790163564210769771 X-GMAIL-MSGID: 1790163564210769771 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