Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp555593lqh; Tue, 7 May 2024 07:21:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU1Q8P36mQZfiDhiXy+x+Ca8zoX0djvihFjeisZlp9oV3WpbdDZPMDB6eHygi4REl4Bc9epHqKYY8gfW/VJdAOzv9xEVOFzNGwA50WfyA== X-Google-Smtp-Source: AGHT+IEUMSqSxXvcFmy6VbzneP8hJGEY556HIhtdyCE9bZup35QmwRPGrUj1UEgQ5hVeQOdXStU0 X-Received: by 2002:a05:6830:3a0a:b0:6ef:a082:5a50 with SMTP id di10-20020a0568303a0a00b006efa0825a50mr13840007otb.28.1715091704184; Tue, 07 May 2024 07:21:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715091704; cv=pass; d=google.com; s=arc-20160816; b=nrsZYWqwaig71Q4XGNq9zOT/Ptsh9lduUlnwl4nictDreZMiTEXuc9SPRzwP/ZwcrP tNXTQ4QLZN+EgNl80LKc8691ruGwSUppyXbyiWQk5qNd3QGf2Yhj2sPzh8nf6JaN23WH IeLaoN7oFJeUZ/AWIqSm3A7NaVSZb/qLTBX7Bb27cQd45TcrWyFXK8fX9U4134XDMAlr JYIBJ0E1wYGx7FibPsjk2CkOvAegJoc05cFbTOohd6o9hRcI9hs1Qm359uuaAWcIBaRV HkJ89SPPixmUlPtJLnzG7Es/iLALGTJ6bbKH97lFGQaonrlVdEcDBYgWRnSDZdwtHLkV NP/w== 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=T5vS/7yfeerxCIxSDwfs5gyjwim2N79bwkVGoFtvk/1Z2VYKSgL6HPpwOXEnXv0p+3 95veaVZn1G001+vz8M0vy0u4XKJ0j4Y1SKW8u1n+S9Vvx3s3j9SULtnJGesAHPjs9nhj H+WBWZVJnEAB1tQGq4TprOezLIdgz3ZuW8eocyrD+5fIfCddW3YIaiTKjYU3rLOF9fIz oW97tIisqGGC+y41nmCR7fxcE3D9m6lpAP5pEdjYdYGIg7j/o5+To6pVA6ClD3rk/CXs yp8oJZjMbv3s//lRP2k4RhrMaTgUryJAqRezwNjOF5rPNFD2xNYPN+os8Ia+86YbBvII rvjQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XjFEu0Qt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171554-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171554-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 c6-20020a05620a268600b0078e5f1704desi12336141qkp.224.2024.05.07.07.21.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:21:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171554-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=XjFEu0Qt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171554-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171554-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 8F1A91C23740 for ; Tue, 7 May 2024 14:21:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00A4B16F90B; Tue, 7 May 2024 14:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XjFEu0Qt" 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 02E8616C85E; Tue, 7 May 2024 14:14:57 +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=1715091298; cv=none; b=k7J5zYZb3H3kCYgM6u3GoT4JEPCuvhiwivnGgM/VZThcG7gme0WAHtA6W1EJFVtr9u4AqsYr5WxUIiqDtkeQI8KPRabBxzi1Z8/gNaV5s8G8f3KnUhPZmISdIAgprwor8IN24Y/nnX5fuMBV5RQ0d3++Fx5KRubSVShFeQlJeTM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715091298; c=relaxed/simple; bh=8t7YVZmoVUR7dCk/2nFP4SmQbrkuMwJVZH30PnGw0sc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=IVfYHo80ZcGupl2VkE49FXtH/0oncD60uPpfcoRPjelxYGKP9GkTk/61nsxD55hKqO8tUcAl6S8aMWUy4k9piwFtmuU5VeTnHUZnQ+CFEsYUxLC78QrbnjmZl8jtmUr+dktwBr3WvzB3chHuDx6snNHetmsrnVQ/61JgOqMToHA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XjFEu0Qt; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C4B8C2BBFC; Tue, 7 May 2024 14:14:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715091297; bh=8t7YVZmoVUR7dCk/2nFP4SmQbrkuMwJVZH30PnGw0sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XjFEu0Qt8KozkfMbdpyY24z0pgfPzRHkynLWueA0ZvU40GAXYhvN0uh74Y/LUu2H8 By9QD+OLgNEzA34eHLyf+no1f3w895moJCxSY5CV0yWZ1pvty+881Xn0sgXy/iPyBy FxYe9Wq45CQa0nnaDOsBkqPBS1/upRXv+Y49K6PaEvjDmZT16oWNTyHIZRzebxyhOv ke5OUyGJfjNgNZV4nMw+Slo/DhEYfOT3TjRrFuXqXBpu24K22Q4IdIYXShCl4aJtoF klW06GSHlb1aX1RnoZGor+nqLF5bZ6/tG9PkROL+1PoquElZQX66ePu/olgcH0yI36 LS7HvA4w8Ig7Q== 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 v10 35/36] Documentation: probes: Update fprobe on function-graph tracer Date: Tue, 7 May 2024 23:14:51 +0900 Message-Id: <171509129107.162236.1791729856199912729.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <171509088006.162236.7227326999861366050.stgit@devnote2> References: <171509088006.162236.7227326999861366050.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