From patchwork Sun Sep 24 13:35: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: 144077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668219vqu; Sun, 24 Sep 2023 06:37:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpyqVUpNOQpLQ6keoQ87IppIM273q27Nh0G2jf+a8OnqsLK/5UJ0zZqkts3kaDXHw4CkAm X-Received: by 2002:a05:6808:14c7:b0:3a7:4e0c:faa2 with SMTP id f7-20020a05680814c700b003a74e0cfaa2mr5408695oiw.27.1695562645632; Sun, 24 Sep 2023 06:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562645; cv=none; d=google.com; s=arc-20160816; b=KdmM4e4daHDo+XjKuMR682mgwNdGyBYEXRvBdYCnxgmxFqpVCpi0B6/rBgJC2z8MUy tGS+nv7k4iYtDp7jpio2q4mkpTFVI+OBInRAMg76GJNC0PhYuITokSUByOVU9XJdB0HS tAwYrYGfTWBmhzYfMaA//w6kwZdGMZmljvr7dLG3QMm0X1iT4jIn2TXIf6dNyY1JmuQX FYfe72a1jbKzPV4Hxx+j9Mn4ZUjvRrMueKLk5IBAK2WPEbtumrgyp2PylOzZdHP7k+5T uA2BxF8Qxu9Gsuw5i+z/kYVoo5ej1e4TCKRn5TK6Wh8KlGZORfhhHohFC/49cagOnavV LEmA== 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=nx4/xRf8O07J/m0o1KCUS43kr0+rGIsEw2cAKhWVGno=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=dzKturTQK8+5mEkG2Gsyygpqpkmnetf6PsfG/NMAYlD+QfsITZ5zbgSlWome8UsAt8 //kekNuWTijaKaEa/TFhAF0abc2qZ5EpMUmsv4syKAVkXCXJTBIeKSrBgtoP1MOL9zNw TckRpexH2RyjpNMZenN5VlUr8A0vAYheQyyfnSsNG1dpUqmIe245yYChYb0XoQvwrvCh iY0E+X7Pd5tTnUS53w61Ta8ATqzZYYWAM+8YMNlfwo3Kk/+3asFQtcq39oiK7thLtrtc A99hNvb1ruidmVu4BW5/A/PdWo6rAsWQZWMsytPpEWVnzqOcjgi6igEglLVblCeEu6X/ M4SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oqIRRymL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id l3-20020a63ea43000000b00573fbbb7803si7575735pgk.613.2023.09.24.06.37.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:37:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oqIRRymL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 54139830D345; Sun, 24 Sep 2023 06:37:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230486AbjIXNhX (ORCPT + 30 others); Sun, 24 Sep 2023 09:37:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231211AbjIXNhJ (ORCPT ); Sun, 24 Sep 2023 09:37:09 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B533E40 for ; Sun, 24 Sep 2023 06:36:06 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1710AC433C8; Sun, 24 Sep 2023 13:36:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562565; bh=LhYnyuDASlXkoXmwCgKG/bRCaq518SQW1Kv1bqMglGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oqIRRymLElY+P25kTdNjEVyJB1A9ldCYTxgORJ2fY34/Up+1xmNu/blxLvgvO5d9v YiLVnE8f+DqJ9TRtFd+qISOHrQMIzP3no7VHIYYfltA8O88TF9oWSzN1loDL1H8+Av y2pog5Q99aZxCYiO+eGs+EcZEK5QCFRKxQ1H0BoMXnKzdM7ZmuvT++GsX3E5aZ6zkP RcNxCFEkV5UQYuJsW4OtyYkLV7KQiGlqwJLrJvlkTB1UERoEbXgseOI6XFhvKBFitR O+Q57mxrGf5S2tiOPkc0LYv4MVrdrsoBejfM774lHvH+n9ZtLBCoy5+6jnf/Ar9sx+ WlJQquCgwUxMg== 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 01/12] riscv: ftrace: Fix to pass correct ftrace_regs to ftrace_func_t functions Date: Sun, 24 Sep 2023 22:35:59 +0900 Message-Id: <169556255915.146934.16583650430641758878.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 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 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 (howler.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:37:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926297083225504 X-GMAIL-MSGID: 1777926297083225504 From: Masami Hiramatsu (Google) Since ftrace_func_t requires to pass 'struct ftrace_regs *' as the 4th argument even if FTRACE_OPS_FL_SAVE_REGS is not set, ftrace_caller must pass 'struct ftrace_regs *', which is a partial pt_regs, on the stack to the ftrace_func_t functions, so that the ftrace_func_t functions can access some partial registers. Fix to allocate 'struct ftrace_regs' (which has the same size of 'struct pt_regs') on the stack and save partial (argument) registers on it instead of reduced size custom data structure. Fixes: afc76b8b8011 ("riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT") Signed-off-by: Masami Hiramatsu (Google) --- arch/riscv/kernel/mcount-dyn.S | 65 +++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S index 669b8697aa38..84963680eff4 100644 --- a/arch/riscv/kernel/mcount-dyn.S +++ b/arch/riscv/kernel/mcount-dyn.S @@ -14,46 +14,37 @@ .text #define FENTRY_RA_OFFSET 8 -#define ABI_SIZE_ON_STACK 80 -#define ABI_A0 0 -#define ABI_A1 8 -#define ABI_A2 16 -#define ABI_A3 24 -#define ABI_A4 32 -#define ABI_A5 40 -#define ABI_A6 48 -#define ABI_A7 56 -#define ABI_T0 64 -#define ABI_RA 72 .macro SAVE_ABI - addi sp, sp, -ABI_SIZE_ON_STACK - - REG_S a0, ABI_A0(sp) - REG_S a1, ABI_A1(sp) - REG_S a2, ABI_A2(sp) - REG_S a3, ABI_A3(sp) - REG_S a4, ABI_A4(sp) - REG_S a5, ABI_A5(sp) - REG_S a6, ABI_A6(sp) - REG_S a7, ABI_A7(sp) - REG_S t0, ABI_T0(sp) - REG_S ra, ABI_RA(sp) + addi sp, sp, -PT_SIZE_ON_STACK + + /* Save t0 as epc for ftrace_regs_get_instruction_pointer() */ + REG_S t0, PT_EPC(sp) + REG_S a0, PT_A0(sp) + REG_S a1, PT_A1(sp) + REG_S a2, PT_A2(sp) + REG_S a3, PT_A3(sp) + REG_S a4, PT_A4(sp) + REG_S a5, PT_A5(sp) + REG_S a6, PT_A6(sp) + REG_S a7, PT_A7(sp) + REG_S t0, PT_T0(sp) + REG_S ra, PT_RA(sp) .endm .macro RESTORE_ABI - REG_L a0, ABI_A0(sp) - REG_L a1, ABI_A1(sp) - REG_L a2, ABI_A2(sp) - REG_L a3, ABI_A3(sp) - REG_L a4, ABI_A4(sp) - REG_L a5, ABI_A5(sp) - REG_L a6, ABI_A6(sp) - REG_L a7, ABI_A7(sp) - REG_L t0, ABI_T0(sp) - REG_L ra, ABI_RA(sp) - - addi sp, sp, ABI_SIZE_ON_STACK + REG_L a0, PT_A0(sp) + REG_L a1, PT_A1(sp) + REG_L a2, PT_A2(sp) + REG_L a3, PT_A3(sp) + REG_L a4, PT_A4(sp) + REG_L a5, PT_A5(sp) + REG_L a6, PT_A6(sp) + REG_L a7, PT_A7(sp) + REG_L t0, PT_T0(sp) + REG_L ra, PT_RA(sp) + + addi sp, sp, PT_SIZE_ON_STACK .endm #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS @@ -96,8 +87,8 @@ ftrace_call: call ftrace_stub #ifdef CONFIG_FUNCTION_GRAPH_TRACER - addi a0, sp, ABI_RA - REG_L a1, ABI_T0(sp) + addi a0, sp, PT_RA + REG_L a1, PT_T0(sp) addi a1, a1, -FENTRY_RA_OFFSET #ifdef HAVE_FUNCTION_GRAPH_FP_TEST mv a2, s0 From patchwork Sun Sep 24 13:36:11 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: 144078 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668238vqu; Sun, 24 Sep 2023 06:37:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwbmSQ+O/fHU4OBo1DoISkZhrkLyOm4qz4wGjS8va332ToXiufFGqM+yoZj6DAxJO1QXf1 X-Received: by 2002:a05:6358:912:b0:143:8ea6:483 with SMTP id r18-20020a056358091200b001438ea60483mr4825588rwi.0.1695562650348; Sun, 24 Sep 2023 06:37:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562650; cv=none; d=google.com; s=arc-20160816; b=EZaPCyjC78pOxCREVODb/z4Sa8Lqo7UryOmH3b7/G3GFzo5Dy4WcGpa8qWhZvWwobK +25jy1k84hyrx49jS7cv1crl28K+HXVSdEnXXWyetCd78iPVWz/+5fEWqBhWooqih59Z 5Bx5EEqf8Yqv+CjkHrEYqCJQWDobGW64ZZ+yr16RzcMkgGbON8gha1tq0XByZRBYstxC PPqIlJnn5YaD5GPVrHEfxFOIH4EaICVkyvgEyvvOeN+up/mzY4M2FwKmz8/XrJpQqu7V 0jZEaoc649pO4V/Scv21f022NQL6aoKBNBf/QssYb7tpZDTDziWHZ+BGEeXAlehKeLgT vacQ== 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=wokmZOHmg7bNlKeqKWMyYA8YtfNcuv7/ZzTJJcuKqeE=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=Tu4EMGuwXt3Zj8RBH9hryXQpmFuOtNOHEthCzwaxEadiN8f1oA4sDzenpuEdkR0ezd cVuGhm3Hr6yIWuIKncyzVph9HB54YIHLk50Wdw3dzpWeQ5EWD2tAkTUccUGm0eRkVOts BgpCbpLWPu0e4zvlhvrBIr5Va8CYiwpswZr6MP+9W7a203lP/fz6VUQWRqAxcdbBMJNt ZovYu0xoXo2Lm8zvKhJXVH+fxGiT4nVmhfy5PLs7cgi9wsvre4lNlqd9KeUaofC42kVa kKjFBzHwTct+OVmgFPktl4wlpiNx1brCjg3Ptjc/lN9lUFxD3YIuX2RhKQJb3hzFQErF tA5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LmvhuVJM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id bk13-20020a056a02028d00b00582f2161cb4si290289pgb.300.2023.09.24.06.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:37:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LmvhuVJM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 4DDB9807C74C; Sun, 24 Sep 2023 06:37:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230387AbjIXNh0 (ORCPT + 30 others); Sun, 24 Sep 2023 09:37:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231213AbjIXNhK (ORCPT ); Sun, 24 Sep 2023 09:37:10 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A42FCC2 for ; Sun, 24 Sep 2023 06:36:18 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48650C433C8; Sun, 24 Sep 2023 13:36:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562578; bh=+UQOaXyf7wYEVeoHCkzfXpWdvixzMC9xY2Nvd7e4ziM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LmvhuVJMBb4WW8ut2rEFn6UqOgvJDGGewzA/jDlUL48jPr1c/bNobdkx2NKnlo7Jh lB9eKDPuxclzehBqTqfcTwjLmnEf9wRDc2SmVrkIecey2MC6t/4LCd1sjEkTRPeNBX bwHYgiQagiGiYzkqeV1iTB8DaunYCY6ephxg16OGbHls7bo9Ng0r5CcWbHScWgp0eW h/0EMkw1VNjh7Gsh4nlyJglbvbbtB0QKLVHb/B5iX9tGvJ+nnEodkvqM6AKs1B3S0y 0/FECAJYwyA9GXlPDxNsMBaHSxvg0rhn12xppztVkaGfeU70D8ksb+2iRyocUnNab6 VbbnhtgTPd/Eg== 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 02/12] Documentation: probes: Add a new ret_ip callback parameter Date: Sun, 24 Sep 2023 22:36:11 +0900 Message-Id: <169556257133.146934.13560704846459957726.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:37:28 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926301708284511 X-GMAIL-MSGID: 1777926301708284511 From: Masami Hiramatsu (Google) Add a new ret_ip callback parameter description. Fixes: cb16330d1274 ("fprobe: Pass return address to the handlers") Signed-off-by: Masami Hiramatsu (Google) Acked-by: Florent Revest --- Changes in v4: - Update ret_ip description (Thanks Florent!) --- Documentation/trace/fprobe.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/trace/fprobe.rst b/Documentation/trace/fprobe.rst index 7a895514b537..196f52386aaa 100644 --- a/Documentation/trace/fprobe.rst +++ b/Documentation/trace/fprobe.rst @@ -91,9 +91,9 @@ The prototype of the entry/exit callback function are as follows: .. code-block:: c - int entry_callback(struct fprobe *fp, unsigned long entry_ip, struct pt_regs *regs, void *entry_data); + int entry_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, struct pt_regs *regs, void *entry_data); + void exit_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs, 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. @@ -108,6 +108,10 @@ If the entry callback function returns !0, the corresponding exit callback will Note that this may not be the actual entry address of the function but the address where the ftrace is instrumented. +@ret_ip + 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 From patchwork Sun Sep 24 13:36:23 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: 144079 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668253vqu; Sun, 24 Sep 2023 06:37:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9rFd56RGQEyzMRxyoS0KlAtA5sIRPHSHGB6t6hPpZUW+MFGe7aRDIZO1Ic+bS+wrqEXou X-Received: by 2002:a05:6808:9b9:b0:3ae:2877:9b31 with SMTP id e25-20020a05680809b900b003ae28779b31mr4991736oig.20.1695562654276; Sun, 24 Sep 2023 06:37:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562654; cv=none; d=google.com; s=arc-20160816; b=EsorDt85umLS4xA0JPmoQosIDVk8lUXUSMOJW06bjxA5PWOQ+BkV3ktnQ5MWjSMu0m QQx/sZ9qKAXd4GXvrj6g9Qzyq4oL/iJFU4oKSpLwVrs1kNHDJUOPoSBqmWiJJuBQEOeI cddEiBJCvkPBSCAEToj6gtu/3JbsaIFDl30BonWh9hQNdAVCmWct6y1Z4BPY0sJCtmWN ZsRg8repoqqv+JLMqYeqZApL1M6I8uKzimVx390MwZwHvJDmUDoK8A7LBGRzZBSY4YCk 90RgSTXdKgIqDbHICjJCMC4JA4ZTBsvG4ZKz9syCRdSXzQs1eAdgxi1heuMAnR1PqhtV z3iQ== 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=HtbfxOhGJhjYYagVG0ZjVCVuf30yNuhxYj0zBuoD7ew=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=cKE7lUI1zTM7dj+tQT+p421KPX803Blgz6vr/n3C46L+u4KrcTGcbl0D46GLm1BoxM iIRcSAICOZI41l6p/0H7EUoqmvC37/+xBBtBV0XEVLHruPR/nc4ElfqsbEDjRo/lY8vm T3WcAPT8/mswXTH2v6JoqhMbDUpnZQOa6aFF8eZNW1L01aNRA2g9cRtUxGNpUEPMtXTB JfAgnZwJ5hDGzpjszeKHoMpa+2g2kJy1M5Rk/m64BCRVaWv8cyGVlWw81s4sGlcIIRi5 ire1xTcRlnrhsZ1vzzl5xBXDDDqkTADx0oFF51u3/c0AvyQp/gVL8TiWV+cr4+KtCK50 qrPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hjlxvWFQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id x4-20020a63db44000000b005775c7e503csi5761655pgi.116.2023.09.24.06.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:37:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hjlxvWFQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 47B52830D36C; Sun, 24 Sep 2023 06:37:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230492AbjIXNh3 (ORCPT + 30 others); Sun, 24 Sep 2023 09:37:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbjIXNhL (ORCPT ); Sun, 24 Sep 2023 09:37:11 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4637E44 for ; Sun, 24 Sep 2023 06:36:30 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 720EFC433C9; Sun, 24 Sep 2023 13:36:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562590; bh=tVeWRc6NY/P1SVA880iIBWSSfIP1iQe2tBoTWU/xgMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hjlxvWFQgaGpBMlqFwlnIZ9VGGXN02c/MIxxrj0jkjoXq5Dkp5EVjKLTiQCIZ+qQi t69ATsL1NxjpLZ/BSsGg23XpeCctFsJn6LLHvDohosO1KgMJ6u+R2PRBbG7L+Zaxgx y6+QFBBfA0LjX6LTPp5lOsuNH8U89yONdRb5wIrRKo7ESmLsGg742zPxiF2hCsAyA1 jYMJ6u5zAyz3Zsp/OsY2JWun3v1LFrGm7TIkVPFmKVtxfg03TrJKX5ursI4EgZ+w4w J6bWYTBctWkELztWXwOD2byUYJswu6XGjzXsV8QRIL2Wu6TuAKKbm8K53sFgeXY1Rn +euG0vig0MbyQ== 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 03/12] tracing: Add a comment about the requirements of the ftrace_regs Date: Sun, 24 Sep 2023 22:36:23 +0900 Message-Id: <169556258347.146934.12248055282843332442.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 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 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 (howler.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:37:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926305719238766 X-GMAIL-MSGID: 1777926305719238766 From: Masami Hiramatsu (Google) Add a comment about the requirements of the ftrace_regs if it is implemented on the arch-dependent code with CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS. Signed-off-by: Masami Hiramatsu (Google) --- include/linux/ftrace.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index e8921871ef9a..5da70f238645 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -118,6 +118,14 @@ extern int ftrace_enabled; #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS +/* + * The ftrace_regs will be just a wrapper of the pt_regs if + * CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS is not set. If it is set on an + * architecture, it has to define the ftrace_regs data structure. + * The ftrace_regs is expected to save the registers for the function + * arguments, the registers for stack dump (e.g. stack pointer and the + * frame pointer) and the instruction pointer for reference. + */ struct ftrace_regs { struct pt_regs regs; }; From patchwork Sun Sep 24 13:36:36 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: 144083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668569vqu; Sun, 24 Sep 2023 06:38:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhLnoL6OVul4UXmosK+uB4t8lX42MQJlbRO/Gx+4yPOFIY+kBUZflWktXoEx5PprYc+4/I X-Received: by 2002:a17:90b:128a:b0:274:8249:a85f with SMTP id fw10-20020a17090b128a00b002748249a85fmr2739666pjb.21.1695562700252; Sun, 24 Sep 2023 06:38:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562700; cv=none; d=google.com; s=arc-20160816; b=n/yWhFCwEHBEoCfd8YgeKANNublzpqKSeUr73S+EQWphGphBToyk74aezghCjdgtbW INFcv6AhxfWFY06H66w+brB1QPRapgHYceP6vdL+a+6OjjSmsFhlzwAbSV96W5V1blXs NsRAeGiQxGFUGmIqzaqAT+YueRcfXTaQrn72XgzzOwxQBkHiN1bqLUgrafYo05+B9YoO Mz8McqFwcg1hX6zG0pZfmtmHmoMDCT+FwTBt4POV893SeC3yu2gutmqOx2+GVyVdG5Hr bUhBES24bZtlve5KTG9k8VKe/aeqS4zhjYW9LJRHOFHmwW3VPDLsJlTuhZkL6M2KqL88 CX5w== 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=u4DuEIxAxVsOtj6AVaWmqvj6TTHj/UTcVwJtUW/QzAA=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=suJc0/zE/aTT8vheC7EtwiVdJ+/oh3G8ceAaJbrtLTk82TaoREeqwpV4zC/CX/w4Sg R7PaXpNTqPs4/6DLMPQeGiimd34UtrU1lXBKZ1FZJuXF9S2idOOg2MKQ168/Z19yaX2N hAD1dH5NzTbAa1vTZ8Y6EAFWsi2ObUUBOeLCH6L8gLdJhs8HBSju+xtEZ+A53fOYlJE/ G6rwA6X/RYlzGjEHPw4u+4TXJH9qoagFFhYkX8XcCB9vm23zhNHgFOaVjR10g6BnUGAn QJfHK9b/bClEbgO/HuJUbKXVow7MpZyMfi4+vjsj0mRazcKYaWTLfqBUZoCGTUFvSpGX 06lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=us+FCS94; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id c8-20020a17090ad90800b0027749a98349si1231891pjv.4.2023.09.24.06.38.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:38:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=us+FCS94; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 164C3807FD5D; Sun, 24 Sep 2023 06:38:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230334AbjIXNhm (ORCPT + 30 others); Sun, 24 Sep 2023 09:37:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231250AbjIXNhV (ORCPT ); Sun, 24 Sep 2023 09:37:21 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BDF01F3A for ; Sun, 24 Sep 2023 06:36:43 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B826CC433C9; Sun, 24 Sep 2023 13:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562602; bh=NDtbtS1XdwGmnj+/dKk4f5xEF7uHU3gFzH2zR7S98C0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=us+FCS94DuPWfSBumyQflpoUc47AIea40ziGxK4E5nmvTG9V5xx15+nWZCkP1vNnm hOIZR4LM6AKXVShhIoVoSzyGlfH/RSpm/aJBsHpuPrb7K+LrC9sHUvgWozLWhNZ21+ qG+fWpX5/wrgMLHsQ73qffbjfBahY9t3Cp373Ypxlxk+F2E9LpOz7azoqJSOY421zN xyg6hVSemumvLcUYzb5hohhh0rp1g+B9BO33lOKQiTNankN2tf3c62WAXg52A0cR0Y owm54DkSy/a6F4jR0CRa7rtowHbMXj2Idpg6gc/0YokvjA6I55tYLYBwqwSFf224gT 5hlkjYsKN9CUw== 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 04/12] fprobe: Use ftrace_regs in fprobe entry handler Date: Sun, 24 Sep 2023 22:36:36 +0900 Message-Id: <169556259571.146934.4558592076420704031.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:38:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926353786120756 X-GMAIL-MSGID: 1777926353786120756 From: Masami Hiramatsu (Google) This allows fprobes to be available with CONFIG_DYNAMIC_FTRACE_WITH_ARGS instead of CONFIG_DYNAMIC_FTRACE_WITH_REGS, then we can enable fprobe on arm64. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Florent Revest --- Changes in v3: - Use FTRACE_OPS_FL_SAVE_ARGS instead of FTRACE_OPS_FL_SAVE_REGS. Changes in v4: - Keep CONFIG_FPROBE check for multi-kprobe because this depends on FPROBE API. Changes in v5: - Just fix the typo in title. --- include/linux/fprobe.h | 2 +- kernel/trace/Kconfig | 3 ++- kernel/trace/bpf_trace.c | 10 +++++++--- kernel/trace/fprobe.c | 4 ++-- kernel/trace/trace_fprobe.c | 6 +++++- lib/test_fprobe.c | 4 ++-- samples/fprobe/fprobe_example.c | 2 +- 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/linux/fprobe.h b/include/linux/fprobe.h index 3e03758151f4..36c0595f7b93 100644 --- a/include/linux/fprobe.h +++ b/include/linux/fprobe.h @@ -35,7 +35,7 @@ struct fprobe { int nr_maxactive; int (*entry_handler)(struct fprobe *fp, unsigned long entry_ip, - unsigned long ret_ip, struct pt_regs *regs, + unsigned long ret_ip, struct ftrace_regs *regs, void *entry_data); void (*exit_handler)(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs, diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index 61c541c36596..976fd594b446 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -287,7 +287,7 @@ config DYNAMIC_FTRACE_WITH_ARGS config FPROBE bool "Kernel Function Probe (fprobe)" depends on FUNCTION_TRACER - depends on DYNAMIC_FTRACE_WITH_REGS + depends on DYNAMIC_FTRACE_WITH_REGS || DYNAMIC_FTRACE_WITH_ARGS depends on HAVE_RETHOOK select RETHOOK default n @@ -672,6 +672,7 @@ config FPROBE_EVENTS select TRACING select PROBE_EVENTS select DYNAMIC_EVENTS + depends on DYNAMIC_FTRACE_WITH_REGS default y help This allows user to add tracing events on the function entry and diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index a7264b2c17ad..efb3c265cad8 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2501,7 +2501,7 @@ static int __init bpf_event_init(void) fs_initcall(bpf_event_init); #endif /* CONFIG_MODULES */ -#ifdef CONFIG_FPROBE +#if defined(CONFIG_FPROBE) && defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS) struct bpf_kprobe_multi_link { struct bpf_link link; struct fprobe fp; @@ -2729,10 +2729,14 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link, static int kprobe_multi_link_handler(struct fprobe *fp, unsigned long fentry_ip, - unsigned long ret_ip, struct pt_regs *regs, + unsigned long ret_ip, struct ftrace_regs *fregs, void *data) { struct bpf_kprobe_multi_link *link; + struct pt_regs *regs = ftrace_get_regs(fregs); + + if (!regs) + return 0; link = container_of(fp, struct bpf_kprobe_multi_link, fp); kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs); @@ -2988,7 +2992,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr kvfree(cookies); return err; } -#else /* !CONFIG_FPROBE */ +#else /* !CONFIG_FPROBE || !CONFIG_DYNAMIC_FTRACE_WITH_REGS */ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) { return -EOPNOTSUPP; diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c index 3b21f4063258..07deb52df44a 100644 --- a/kernel/trace/fprobe.c +++ b/kernel/trace/fprobe.c @@ -46,7 +46,7 @@ static inline void __fprobe_handler(unsigned long ip, unsigned long parent_ip, } if (fp->entry_handler) - ret = fp->entry_handler(fp, ip, parent_ip, ftrace_get_regs(fregs), entry_data); + ret = fp->entry_handler(fp, ip, parent_ip, fregs, entry_data); /* If entry_handler returns !0, nmissed is not counted. */ if (rh) { @@ -182,7 +182,7 @@ static void fprobe_init(struct fprobe *fp) fp->ops.func = fprobe_kprobe_handler; else fp->ops.func = fprobe_handler; - fp->ops.flags |= FTRACE_OPS_FL_SAVE_REGS; + fp->ops.flags |= FTRACE_OPS_FL_SAVE_ARGS; } static int fprobe_init_rethook(struct fprobe *fp, int num) diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c index 8bfe23af9c73..71bf38d698f1 100644 --- a/kernel/trace/trace_fprobe.c +++ b/kernel/trace/trace_fprobe.c @@ -320,12 +320,16 @@ NOKPROBE_SYMBOL(fexit_perf_func); #endif /* CONFIG_PERF_EVENTS */ static int fentry_dispatcher(struct fprobe *fp, unsigned long entry_ip, - unsigned long ret_ip, struct pt_regs *regs, + unsigned long ret_ip, struct ftrace_regs *fregs, void *entry_data) { struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp); + struct pt_regs *regs = ftrace_get_regs(fregs); int ret = 0; + if (!regs) + return 0; + if (trace_probe_test_flag(&tf->tp, TP_FLAG_TRACE)) fentry_trace_func(tf, entry_ip, regs); #ifdef CONFIG_PERF_EVENTS diff --git a/lib/test_fprobe.c b/lib/test_fprobe.c index 24de0e5ff859..ff607babba18 100644 --- a/lib/test_fprobe.c +++ b/lib/test_fprobe.c @@ -40,7 +40,7 @@ static noinline u32 fprobe_selftest_nest_target(u32 value, u32 (*nest)(u32)) static notrace int fp_entry_handler(struct fprobe *fp, unsigned long ip, unsigned long ret_ip, - struct pt_regs *regs, void *data) + struct ftrace_regs *fregs, void *data) { KUNIT_EXPECT_FALSE(current_test, preemptible()); /* This can be called on the fprobe_selftest_target and the fprobe_selftest_target2 */ @@ -81,7 +81,7 @@ static notrace void fp_exit_handler(struct fprobe *fp, unsigned long ip, static notrace int nest_entry_handler(struct fprobe *fp, unsigned long ip, unsigned long ret_ip, - struct pt_regs *regs, void *data) + struct ftrace_regs *fregs, void *data) { KUNIT_EXPECT_FALSE(current_test, preemptible()); return 0; diff --git a/samples/fprobe/fprobe_example.c b/samples/fprobe/fprobe_example.c index 64e715e7ed11..1545a1aac616 100644 --- a/samples/fprobe/fprobe_example.c +++ b/samples/fprobe/fprobe_example.c @@ -50,7 +50,7 @@ static void show_backtrace(void) static int sample_entry_handler(struct fprobe *fp, unsigned long ip, unsigned long ret_ip, - struct pt_regs *regs, void *data) + struct ftrace_regs *fregs, void *data) { if (use_trace) /* From patchwork Sun Sep 24 13:36:48 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: 144080 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668431vqu; Sun, 24 Sep 2023 06:38:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdnKrMNFs+0CugxT0V5/+riQmSD68zoqezaNKeNhdmSqFGVPDNdi3MTlHROcNM+SlfNwX5 X-Received: by 2002:a05:6a00:e88:b0:68a:48e7:9deb with SMTP id bo8-20020a056a000e8800b0068a48e79debmr10272528pfb.2.1695562680072; Sun, 24 Sep 2023 06:38:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562680; cv=none; d=google.com; s=arc-20160816; b=Q3R5X/DdPSeeEz9wdNyH4mLIWh/juCJo/O2VbDZHnJLPtiZQFmfUtt0rhW/66C53oI cYmJDWPA1A5uc5yWRPNyVbhLpoqbE1hCtuRPnLmjosXm6QMNlyMzQ7/qQT3dTLJ3ee91 1fgWOmvLF4FiPMe8+snBuBcM6ghiX8ySolnkgGNRo00WKATPR6Vzyh9DM6mf8RcbLt0I umZvf57kwYTe/k9vMYVEcpdSpaKYvY/PwZB1RgS7ODclxITv8trwtgM/O6MYRWaGAwQ9 B9awLsUsQwfVkJjCfRxcFLXAPjQGrvjdZZUMy/jYsAnRYMM9qEK4jUKuZmKwytJHMdse 1IOA== 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=jhYorJE2G0psM9CoW8dsq2y1A4ADt9ByWQJxukzZmKo=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=AyjNggJtarO85Z8oSE9lNyb42sWaey7KpIguHKAV+CCD9UhPmgiixjQJtPHsv+Mhr3 oZF3RyPK/z2mcPhncNzDwHqgxWhWPx+mpDAyBACojBIXW8RV3coydG9rOY+jWdcitv3X gQW372pgtdC6RegC5L/fTo7ZTh5g5LfR8w1MsBiGVF2/pIc3R957HYkFmvLWRFHOCwh2 l6dNkLV8Qm+uyLTM4HzffXGCwIQQxWJV9FhXFznL3Q7AyNsqyyKV6LRXN3kQF8ocDC// nj/9mGJZ5LLSiZm3fcObIXRCLxMMw1xgGh3emMFLHd1jzRahG+b401LHKvRSqflJ1dUC 6CoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AQRxpZ9U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id f20-20020a637554000000b00565dd3fbfdfsi7637587pgn.214.2023.09.24.06.37.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:38:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AQRxpZ9U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 6252F8313006; Sun, 24 Sep 2023 06:37:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231237AbjIXNh5 (ORCPT + 30 others); Sun, 24 Sep 2023 09:37:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231235AbjIXNhk (ORCPT ); Sun, 24 Sep 2023 09:37:40 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 486171717 for ; Sun, 24 Sep 2023 06:36:55 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27DC8C433C7; Sun, 24 Sep 2023 13:36:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562614; bh=jmHWZoJzNc7w2WNK0aSXMKcROawBX8r9FSb7vj/g9k4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AQRxpZ9URRHAkZC5HdJ8I8W4mys6wynoEVlftisU26BNvb9oiXK0Ro0PXYd9qLB2l UL3C0Oy+xI57Izrd/yxuWzsvG4CXpOxOGRD78wJxDt02xtJijhUFSWR7QcUorUwFdx O5hf0wkh9BjAh382ei6TnpnBPotUpzDvkt+JUKJwJnCdDi+nKlNZVymAvIk54keZYY BW4+MqOrdmXmTAfaZXd8nd359ake5zpaQynZsXrSQENdGQz9VryIndwLRoYQVqp8+n R/DUZZZ+mgL/oGSxsVqdK92HPyXr6YtPOR6dFKfl+Ty7MWFdnNNnzqBRbH37eg1mOI eDmk2HLeM2faQ== 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 05/12] tracing: Expose ftrace_regs regardless of CONFIG_FUNCTION_TRACER Date: Sun, 24 Sep 2023 22:36:48 +0900 Message-Id: <169556260811.146934.12334081780807613682.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 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 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 (howler.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:37:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926332738843383 X-GMAIL-MSGID: 1777926332738843383 From: Masami Hiramatsu (Google) In order to be able to use ftrace_regs even from features unrelated to function tracer (e.g. kretprobe), expose ftrace_regs structures and APIs even if the CONFIG_FUNCTION_TRACER=n. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Florent Revest --- Changes in v3: - arch/s390/include/asm/ftrace.h: hide ftrace_regs parts if CONFIG_FUNCTION_TRACER=n to avoid conflict. - Fixed typo. - Define accessor macros only if HAVE_REGS_AND_STACK_ACCESS_API=y --- arch/s390/include/asm/ftrace.h | 4 +++ include/linux/ftrace.h | 51 +++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/arch/s390/include/asm/ftrace.h b/arch/s390/include/asm/ftrace.h index 5a82b08f03cd..6de3bf4d0092 100644 --- a/arch/s390/include/asm/ftrace.h +++ b/arch/s390/include/asm/ftrace.h @@ -41,6 +41,8 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr) return addr; } +#ifdef CONFIG_FUNCTION_TRACER + struct ftrace_regs { struct pt_regs regs; }; @@ -97,6 +99,8 @@ ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs, #define ftrace_regs_query_register_offset(name) \ regs_query_register_offset(name) +#endif /* CONFIG_FUNCTION_TRACER */ + #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS /* * When an ftrace registered caller is tracing a function that is diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 5da70f238645..15f4865a4083 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -112,11 +112,11 @@ static inline int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *val } #endif -#ifdef CONFIG_FUNCTION_TRACER - -extern int ftrace_enabled; - -#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS +/* + * If the architecture doesn't support FTRACE_WITH_ARGS or disables function + * tracer, define the default(pt_regs compatible) ftrace_regs. + */ +#if !defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS) || !defined(CONFIG_FUNCTION_TRACER) /* * The ftrace_regs will be just a wrapper of the pt_regs if @@ -131,13 +131,33 @@ struct ftrace_regs { }; #define arch_ftrace_get_regs(fregs) (&(fregs)->regs) +#ifdef CONFIG_HAVE_REGS_AND_STACK_ACCESS_API + /* * ftrace_regs_set_instruction_pointer() is to be defined by the architecture * if to allow setting of the instruction pointer from the ftrace_regs when * HAVE_DYNAMIC_FTRACE_WITH_ARGS is set and it supports live kernel patching. */ #define ftrace_regs_set_instruction_pointer(fregs, ip) do { } while (0) -#endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */ + +#define ftrace_regs_get_instruction_pointer(fregs) \ + instruction_pointer(ftrace_get_regs(fregs)) +#define ftrace_regs_get_argument(fregs, n) \ + regs_get_kernel_argument(ftrace_get_regs(fregs), n) +#define ftrace_regs_get_stack_pointer(fregs) \ + kernel_stack_pointer(ftrace_get_regs(fregs)) +#define ftrace_regs_return_value(fregs) \ + regs_return_value(ftrace_get_regs(fregs)) +#define ftrace_regs_set_return_value(fregs, ret) \ + regs_set_return_value(ftrace_get_regs(fregs), ret) +#define ftrace_override_function_with_return(fregs) \ + override_function_with_return(ftrace_get_regs(fregs)) +#define ftrace_regs_query_register_offset(name) \ + regs_query_register_offset(name) + +#endif /* CONFIG_HAVE_REGS_AND_STACK_ACCESS_API */ + +#endif /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS || !CONFIG_FUNCTION_TRACER */ static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs) { @@ -159,22 +179,9 @@ static __always_inline bool ftrace_regs_has_args(struct ftrace_regs *fregs) return ftrace_get_regs(fregs) != NULL; } -#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS -#define ftrace_regs_get_instruction_pointer(fregs) \ - instruction_pointer(ftrace_get_regs(fregs)) -#define ftrace_regs_get_argument(fregs, n) \ - regs_get_kernel_argument(ftrace_get_regs(fregs), n) -#define ftrace_regs_get_stack_pointer(fregs) \ - kernel_stack_pointer(ftrace_get_regs(fregs)) -#define ftrace_regs_return_value(fregs) \ - regs_return_value(ftrace_get_regs(fregs)) -#define ftrace_regs_set_return_value(fregs, ret) \ - regs_set_return_value(ftrace_get_regs(fregs), ret) -#define ftrace_override_function_with_return(fregs) \ - override_function_with_return(ftrace_get_regs(fregs)) -#define ftrace_regs_query_register_offset(name) \ - regs_query_register_offset(name) -#endif +#ifdef CONFIG_FUNCTION_TRACER + +extern int ftrace_enabled; typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *op, struct ftrace_regs *fregs); From patchwork Sun Sep 24 13:37:00 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: 144081 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668460vqu; Sun, 24 Sep 2023 06:38:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEd2CXBAOS6fIJeKpDVGpefwAbpEDaxcqMWOhZNPRSssonvHRr6wMKayNBGXO9r1IV/AGsR X-Received: by 2002:a05:6808:d4a:b0:3a4:35bb:edae with SMTP id w10-20020a0568080d4a00b003a435bbedaemr6564006oik.29.1695562683527; Sun, 24 Sep 2023 06:38:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562683; cv=none; d=google.com; s=arc-20160816; b=MJB98DDeiHN0lg3UIDvMEMEN2UNeBVe4b4BMr4EnzTi1TZnENWTDrUbUBuyxxVV96D E/p8wKTiJIKQKSNZRXLxSA/4Fca15cTrzkue1AXxSW4TWVP9+czk0d2upgNbH8FuhR2h s82915frcmEV0P1CgYKIVQBj5xZfrXfTE0UrKU3R0k/mB884UK764I5Z0Z63qMZk0/50 Gfdw2yLur8czM53O5GF2Zbj00xcdwPoNOtqMnGfNXPu/BJ55jSTI+wzDpmg2SlsvWPQy Gak+gflLAV5UpM6jOq8hNbX/6Lu9J9QhDJojfP+IWnf7tdUs2llFBvn9rvV48u103RqU mCRA== 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=yjcCAchi+EaNG7AMtXkw/ZJOnIki7sDcLbCYvTXgo0s=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=HP4agUBKKE1yHr/wiFGJ2W4nwJrKDh+FEs9pLme364c9zdXz4RGHyEpgRJcTWrtiBB C6Nuh8g6ltrMLe0lwdKZozVXxmhxghQ3PR9bUriM4wtgfBNW1/UDdWu51OMjYvMEUGIp dQqRyrI5fYknrPxHgoMeAC7GpICb+YPOt7ghHbsRYrU5v98vXsowphIsSFEY74Q1FhDL v9X/jFwQ6WRhz9C/myN5Hy1klmqXuREKu1n+NCP0ySv2t1cjYAb9gwivx+BCEYqEW5md sEnIQA+cQu1W1+FjGvSnLYX6GUmNGu3k7C3dWTIkdxiSYdDKVuKM53oc4bWdgO0QAmMP g1Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UOSw5wFF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t64-20020a628143000000b0069023e4bcb4si7349837pfd.114.2023.09.24.06.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:38:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UOSw5wFF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 6D69A802DD02; Sun, 24 Sep 2023 06:38:02 -0700 (PDT) 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 S230239AbjIXNiD (ORCPT + 30 others); Sun, 24 Sep 2023 09:38:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbjIXNhu (ORCPT ); Sun, 24 Sep 2023 09:37:50 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EDB9CE9 for ; Sun, 24 Sep 2023 06:37:07 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56F92C433C8; Sun, 24 Sep 2023 13:37:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562627; bh=F+SQMPQuFwuNvF2/gAvfM3FFfKmhMFYc8ubpZC9kP40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UOSw5wFF1cOxb0v3+RYbN3I6PSGUuE2ntY/dy6Iwkp0YZhWizfjusW6NbHsvgCQ/b tfvjknFeR5VfLV7gE0TfgTBj9E0rVhj2D6YY7xO9JiZSyWbpECwSuWNsVELn0CdIQl 8slXKQhlZnNIX7c63f1ZZ0mM9nMAtck4WiBFv/kl2cRHcDkEClM1BCGkvStq481CZJ 17bWdAyMdmZtl4UERvk5l+aHYStgYS8i2GLsuGgzGoIfPJCS6uvmrmoZXhTk/nsrIK lRv2ESr1lLGq2m3v6dUpjWrPn9T0ICaLilPwUb5vwlPUUxIZUFdzeAhOYZL4PmiUJw sXYzDLUl/ThTA== 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 06/12] fprobe: rethook: Use ftrace_regs in fprobe exit handler and rethook Date: Sun, 24 Sep 2023 22:37:00 +0900 Message-Id: <169556262030.146934.16624533747935252102.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 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 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, 24 Sep 2023 06:38:02 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926336608233246 X-GMAIL-MSGID: 1777926336608233246 From: Masami Hiramatsu (Google) Change the fprobe exit handler and rethook to use ftrace_regs structure instead of pt_regs. This also introduce HAVE_PT_REGS_TO_FTRACE_REGS_CAST which means the ftrace_regs's memory layout is equal to the pt_regs so that those are able to cast. Only if it is enabled, kretprobe will use rethook since kretprobe requires pt_regs for backward compatibility. This means the archs which currently implement rethook for kretprobes needs to set that flag and it must ensure struct ftrace_regs is same as pt_regs. If not, it must be either disabling kretprobe or implementing kretprobe trampoline separately from rethook trampoline. Signed-off-by: Masami Hiramatsu (Google) Signed-off-by: Sven Schnelle Acked-by: Florent Revest --- Changes in v3: - Config rename to HAVE_PT_REGS_TO_FTRACE_REGS_CAST - Use ftrace_regs_* APIs instead of ftrace_get_regs(). Changes in v4: - Add static_assert() to ensure at least the size of pt_regs and ftrace_regs are same if HAVE_PT_REGS_TO_FTRACE_REGS_CAST=y. Changes in v5: - Add s390 rethook update by Sven Schnelle. - Add loongarch rethook update. - Add riscv rethook update (with saving regs.s0 in ftrace) --- arch/Kconfig | 1 + arch/loongarch/Kconfig | 1 + arch/loongarch/kernel/rethook.c | 10 +++++----- arch/loongarch/kernel/rethook.h | 4 ++-- arch/riscv/kernel/mcount-dyn.S | 2 ++ arch/riscv/kernel/probes/rethook.c | 12 ++++++------ arch/riscv/kernel/probes/rethook.h | 6 ++++-- arch/s390/Kconfig | 1 + arch/s390/kernel/rethook.c | 10 ++++++---- arch/s390/kernel/rethook.h | 2 +- arch/x86/Kconfig | 1 + arch/x86/kernel/rethook.c | 13 +++++++------ include/linux/fprobe.h | 2 +- include/linux/ftrace.h | 6 ++++++ include/linux/rethook.h | 11 ++++++----- kernel/kprobes.c | 10 ++++++++-- kernel/trace/Kconfig | 7 +++++++ kernel/trace/bpf_trace.c | 6 +++++- kernel/trace/fprobe.c | 6 +++--- kernel/trace/rethook.c | 16 ++++++++-------- kernel/trace/trace_fprobe.c | 6 +++++- lib/test_fprobe.c | 6 +++--- samples/fprobe/fprobe_example.c | 2 +- 23 files changed, 90 insertions(+), 51 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 12d51495caec..300d76c2ad77 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -191,6 +191,7 @@ config KRETPROBE_ON_RETHOOK def_bool y depends on HAVE_RETHOOK depends on KRETPROBES + depends on HAVE_PT_REGS_TO_FTRACE_REGS_CAST || !HAVE_DYNAMIC_FTRACE_WITH_ARGS select RETHOOK config USER_RETURN_NOTIFIER diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index e14396a2ddcb..258e9bee1503 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -108,6 +108,7 @@ config LOONGARCH select HAVE_DMA_CONTIGUOUS select HAVE_DYNAMIC_FTRACE select HAVE_DYNAMIC_FTRACE_WITH_ARGS + select HAVE_PT_REGS_TO_FTRACE_REGS_CAST select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS select HAVE_DYNAMIC_FTRACE_WITH_REGS select HAVE_EBPF_JIT diff --git a/arch/loongarch/kernel/rethook.c b/arch/loongarch/kernel/rethook.c index db1c5f5024fd..d718327d1e88 100644 --- a/arch/loongarch/kernel/rethook.c +++ b/arch/loongarch/kernel/rethook.c @@ -8,19 +8,19 @@ #include "rethook.h" /* This is called from arch_rethook_trampoline() */ -unsigned long __used arch_rethook_trampoline_callback(struct pt_regs *regs) +unsigned long __used arch_rethook_trampoline_callback(struct ftrace_regs *fregs) { - return rethook_trampoline_handler(regs, 0); + return rethook_trampoline_handler(fregs, 0); } NOKPROBE_SYMBOL(arch_rethook_trampoline_callback); -void arch_rethook_prepare(struct rethook_node *rhn, struct pt_regs *regs, bool mcount) +void arch_rethook_prepare(struct rethook_node *rhn, struct ftrace_regs *fregs, bool mcount) { rhn->frame = 0; - rhn->ret_addr = regs->regs[1]; + rhn->ret_addr = fregs->regs.regs[1]; /* replace return addr with trampoline */ - regs->regs[1] = (unsigned long)arch_rethook_trampoline; + fregs->regs.regs[1] = (unsigned long)arch_rethook_trampoline; } NOKPROBE_SYMBOL(arch_rethook_prepare); diff --git a/arch/loongarch/kernel/rethook.h b/arch/loongarch/kernel/rethook.h index 3f1c1edf0d0b..0643a8d6a8dd 100644 --- a/arch/loongarch/kernel/rethook.h +++ b/arch/loongarch/kernel/rethook.h @@ -2,7 +2,7 @@ #ifndef __LOONGARCH_RETHOOK_H #define __LOONGARCH_RETHOOK_H -unsigned long arch_rethook_trampoline_callback(struct pt_regs *regs); -void arch_rethook_prepare(struct rethook_node *rhn, struct pt_regs *regs, bool mcount); +unsigned long arch_rethook_trampoline_callback(struct ftrace_regs *fregs); +void arch_rethook_prepare(struct rethook_node *rhn, struct ftrace_regs *fregs, bool mcount); #endif diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S index 84963680eff4..184f76394ab8 100644 --- a/arch/riscv/kernel/mcount-dyn.S +++ b/arch/riscv/kernel/mcount-dyn.S @@ -20,6 +20,8 @@ /* Save t0 as epc for ftrace_regs_get_instruction_pointer() */ REG_S t0, PT_EPC(sp) + /* Save s0 for reading frame pointer (read only) */ + REG_S s0, PT_S0(sp) REG_S a0, PT_A0(sp) REG_S a1, PT_A1(sp) REG_S a2, PT_A2(sp) diff --git a/arch/riscv/kernel/probes/rethook.c b/arch/riscv/kernel/probes/rethook.c index 5c27c1f50989..052fa1a363e6 100644 --- a/arch/riscv/kernel/probes/rethook.c +++ b/arch/riscv/kernel/probes/rethook.c @@ -8,20 +8,20 @@ #include "rethook.h" /* This is called from arch_rethook_trampoline() */ -unsigned long __used arch_rethook_trampoline_callback(struct pt_regs *regs) +unsigned long __used arch_rethook_trampoline_callback(struct ftrace_regs *fregs) { - return rethook_trampoline_handler(regs, regs->s0); + return rethook_trampoline_handler(fregs, fregs->regs.s0); } NOKPROBE_SYMBOL(arch_rethook_trampoline_callback); -void arch_rethook_prepare(struct rethook_node *rhn, struct pt_regs *regs, bool mcount) +void arch_rethook_prepare(struct rethook_node *rhn, struct ftrace_regs *fregs, bool mcount) { - rhn->ret_addr = regs->ra; - rhn->frame = regs->s0; + rhn->ret_addr = fregs->regs.ra; + rhn->frame = fregs->regs.s0; /* replace return addr with trampoline */ - regs->ra = (unsigned long)arch_rethook_trampoline; + fregs->regs.ra = (unsigned long)arch_rethook_trampoline; } NOKPROBE_SYMBOL(arch_rethook_prepare); diff --git a/arch/riscv/kernel/probes/rethook.h b/arch/riscv/kernel/probes/rethook.h index 4758f7e3ce88..f4ce353d2008 100644 --- a/arch/riscv/kernel/probes/rethook.h +++ b/arch/riscv/kernel/probes/rethook.h @@ -2,7 +2,9 @@ #ifndef __RISCV_RETHOOK_H #define __RISCV_RETHOOK_H -unsigned long arch_rethook_trampoline_callback(struct pt_regs *regs); -void arch_rethook_prepare(struct rethook_node *rhn, struct pt_regs *regs, bool mcount); +#include + +unsigned long arch_rethook_trampoline_callback(struct ftrace_regs *fregs); +void arch_rethook_prepare(struct rethook_node *rhn, struct ftrace_regs *fregs, bool mcount); #endif diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index ae29e4392664..5aedb4320e7c 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -167,6 +167,7 @@ config S390 select HAVE_DMA_CONTIGUOUS select HAVE_DYNAMIC_FTRACE select HAVE_DYNAMIC_FTRACE_WITH_ARGS + select HAVE_PT_REGS_TO_FTRACE_REGS_CAST select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS select HAVE_DYNAMIC_FTRACE_WITH_REGS select HAVE_EBPF_JIT if HAVE_MARCH_Z196_FEATURES diff --git a/arch/s390/kernel/rethook.c b/arch/s390/kernel/rethook.c index af10e6bdd34e..4e86c0a1a064 100644 --- a/arch/s390/kernel/rethook.c +++ b/arch/s390/kernel/rethook.c @@ -3,8 +3,9 @@ #include #include "rethook.h" -void arch_rethook_prepare(struct rethook_node *rh, struct pt_regs *regs, bool mcount) +void arch_rethook_prepare(struct rethook_node *rh, struct ftrace_regs *fregs, bool mcount) { + struct pt_regs *regs = (struct pt_regs *)fregs; rh->ret_addr = regs->gprs[14]; rh->frame = regs->gprs[15]; @@ -13,10 +14,11 @@ void arch_rethook_prepare(struct rethook_node *rh, struct pt_regs *regs, bool mc } NOKPROBE_SYMBOL(arch_rethook_prepare); -void arch_rethook_fixup_return(struct pt_regs *regs, +void arch_rethook_fixup_return(struct ftrace_regs *fregs, unsigned long correct_ret_addr) { /* Replace fake return address with real one. */ + struct pt_regs *regs = (struct pt_regs *)fregs; regs->gprs[14] = correct_ret_addr; } NOKPROBE_SYMBOL(arch_rethook_fixup_return); @@ -24,9 +26,9 @@ NOKPROBE_SYMBOL(arch_rethook_fixup_return); /* * Called from arch_rethook_trampoline */ -unsigned long arch_rethook_trampoline_callback(struct pt_regs *regs) +unsigned long arch_rethook_trampoline_callback(struct ftrace_regs *fregs) { - return rethook_trampoline_handler(regs, regs->gprs[15]); + return rethook_trampoline_handler(fregs, fregs->regs.gprs[15]); } NOKPROBE_SYMBOL(arch_rethook_trampoline_callback); diff --git a/arch/s390/kernel/rethook.h b/arch/s390/kernel/rethook.h index 32f069eed3f3..0fe62424fc78 100644 --- a/arch/s390/kernel/rethook.h +++ b/arch/s390/kernel/rethook.h @@ -2,6 +2,6 @@ #ifndef __S390_RETHOOK_H #define __S390_RETHOOK_H -unsigned long arch_rethook_trampoline_callback(struct pt_regs *regs); +unsigned long arch_rethook_trampoline_callback(struct ftrace_regs *fregs); #endif diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 66bfabae8814..daca05e10956 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -209,6 +209,7 @@ config X86 select HAVE_DYNAMIC_FTRACE select HAVE_DYNAMIC_FTRACE_WITH_REGS select HAVE_DYNAMIC_FTRACE_WITH_ARGS if X86_64 + select HAVE_PT_REGS_TO_FTRACE_REGS_CAST if X86_64 select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS select HAVE_SAMPLE_FTRACE_DIRECT if X86_64 select HAVE_SAMPLE_FTRACE_DIRECT_MULTI if X86_64 diff --git a/arch/x86/kernel/rethook.c b/arch/x86/kernel/rethook.c index 8a1c0111ae79..d714d0276c93 100644 --- a/arch/x86/kernel/rethook.c +++ b/arch/x86/kernel/rethook.c @@ -83,7 +83,8 @@ __used __visible void arch_rethook_trampoline_callback(struct pt_regs *regs) * arch_rethook_fixup_return() which called from this * rethook_trampoline_handler(). */ - rethook_trampoline_handler(regs, (unsigned long)frame_pointer); + rethook_trampoline_handler((struct ftrace_regs *)regs, + (unsigned long)frame_pointer); /* * Copy FLAGS to 'pt_regs::ss' so that arch_rethook_trapmoline() @@ -104,22 +105,22 @@ NOKPROBE_SYMBOL(arch_rethook_trampoline_callback); STACK_FRAME_NON_STANDARD_FP(arch_rethook_trampoline); /* This is called from rethook_trampoline_handler(). */ -void arch_rethook_fixup_return(struct pt_regs *regs, +void arch_rethook_fixup_return(struct ftrace_regs *fregs, unsigned long correct_ret_addr) { - unsigned long *frame_pointer = (void *)(regs + 1); + unsigned long *frame_pointer = (void *)(fregs + 1); /* Replace fake return address with real one. */ *frame_pointer = correct_ret_addr; } NOKPROBE_SYMBOL(arch_rethook_fixup_return); -void arch_rethook_prepare(struct rethook_node *rh, struct pt_regs *regs, bool mcount) +void arch_rethook_prepare(struct rethook_node *rh, struct ftrace_regs *fregs, bool mcount) { - unsigned long *stack = (unsigned long *)regs->sp; + unsigned long *stack = (unsigned long *)ftrace_regs_get_stack_pointer(fregs); rh->ret_addr = stack[0]; - rh->frame = regs->sp; + rh->frame = (unsigned long)stack; /* Replace the return addr with trampoline addr */ stack[0] = (unsigned long) arch_rethook_trampoline; diff --git a/include/linux/fprobe.h b/include/linux/fprobe.h index 36c0595f7b93..b9c0c216dedb 100644 --- a/include/linux/fprobe.h +++ b/include/linux/fprobe.h @@ -38,7 +38,7 @@ struct fprobe { unsigned long ret_ip, struct ftrace_regs *regs, void *entry_data); void (*exit_handler)(struct fprobe *fp, unsigned long entry_ip, - unsigned long ret_ip, struct pt_regs *regs, + unsigned long ret_ip, struct ftrace_regs *regs, void *entry_data); }; diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 15f4865a4083..39a765c71f7e 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -159,6 +159,12 @@ struct ftrace_regs { #endif /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS || !CONFIG_FUNCTION_TRACER */ +#ifdef CONFIG_HAVE_PT_REGS_TO_FTRACE_REGS_CAST + +static_assert(sizeof(struct pt_regs) == sizeof(struct ftrace_regs)); + +#endif /* CONFIG_HAVE_PT_REGS_TO_FTRACE_REGS_CAST */ + static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs) { if (!fregs) diff --git a/include/linux/rethook.h b/include/linux/rethook.h index 26b6f3c81a76..138d64c8b67b 100644 --- a/include/linux/rethook.h +++ b/include/linux/rethook.h @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -14,7 +15,7 @@ struct rethook_node; -typedef void (*rethook_handler_t) (struct rethook_node *, void *, unsigned long, struct pt_regs *); +typedef void (*rethook_handler_t) (struct rethook_node *, void *, unsigned long, struct ftrace_regs *); /** * struct rethook - The rethook management data structure. @@ -64,12 +65,12 @@ void rethook_free(struct rethook *rh); void rethook_add_node(struct rethook *rh, struct rethook_node *node); struct rethook_node *rethook_try_get(struct rethook *rh); void rethook_recycle(struct rethook_node *node); -void rethook_hook(struct rethook_node *node, struct pt_regs *regs, bool mcount); +void rethook_hook(struct rethook_node *node, struct ftrace_regs *regs, bool mcount); unsigned long rethook_find_ret_addr(struct task_struct *tsk, unsigned long frame, struct llist_node **cur); /* Arch dependent code must implement arch_* and trampoline code */ -void arch_rethook_prepare(struct rethook_node *node, struct pt_regs *regs, bool mcount); +void arch_rethook_prepare(struct rethook_node *node, struct ftrace_regs *regs, bool mcount); void arch_rethook_trampoline(void); /** @@ -84,11 +85,11 @@ static inline bool is_rethook_trampoline(unsigned long addr) } /* If the architecture needs to fixup the return address, implement it. */ -void arch_rethook_fixup_return(struct pt_regs *regs, +void arch_rethook_fixup_return(struct ftrace_regs *regs, unsigned long correct_ret_addr); /* Generic trampoline handler, arch code must prepare asm stub */ -unsigned long rethook_trampoline_handler(struct pt_regs *regs, +unsigned long rethook_trampoline_handler(struct ftrace_regs *regs, unsigned long frame); #ifdef CONFIG_RETHOOK diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 0c6185aefaef..821dff656149 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2132,7 +2132,11 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs) if (rp->entry_handler && rp->entry_handler(ri, regs)) rethook_recycle(rhn); else - rethook_hook(rhn, regs, kprobe_ftrace(p)); + /* + * We can cast pt_regs to ftrace_regs because this depends on + * HAVE_PT_REGS_TO_FTRACE_REGS_CAST. + */ + rethook_hook(rhn, (struct ftrace_regs *)regs, kprobe_ftrace(p)); return 0; } @@ -2140,9 +2144,11 @@ NOKPROBE_SYMBOL(pre_handler_kretprobe); static void kretprobe_rethook_handler(struct rethook_node *rh, void *data, unsigned long ret_addr, - struct pt_regs *regs) + struct ftrace_regs *fregs) { struct kretprobe *rp = (struct kretprobe *)data; + /* Ditto, this depends on HAVE_PT_REGS_TO_FTRACE_REGS_CAST. */ + struct pt_regs *regs = (struct pt_regs *)fregs; struct kretprobe_instance *ri; struct kprobe_ctlblk *kcb; diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index 976fd594b446..d56304276318 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -57,6 +57,13 @@ config HAVE_DYNAMIC_FTRACE_WITH_ARGS This allows for use of ftrace_regs_get_argument() and ftrace_regs_get_stack_pointer(). +config HAVE_PT_REGS_TO_FTRACE_REGS_CAST + bool + help + If this is set, the memory layout of the ftrace_regs data structure + is the same as the pt_regs. So the pt_regs is possible to be casted + to ftrace_regs. + config HAVE_DYNAMIC_FTRACE_NO_PATCHABLE bool help diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index efb3c265cad8..8bb003ce7bb2 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2745,10 +2745,14 @@ kprobe_multi_link_handler(struct fprobe *fp, unsigned long fentry_ip, static void kprobe_multi_link_exit_handler(struct fprobe *fp, unsigned long fentry_ip, - unsigned long ret_ip, struct pt_regs *regs, + unsigned long ret_ip, struct ftrace_regs *fregs, void *data) { struct bpf_kprobe_multi_link *link; + struct pt_regs *regs = ftrace_get_regs(fregs); + + if (!regs) + return; link = container_of(fp, struct bpf_kprobe_multi_link, fp); kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs); diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c index 07deb52df44a..dfddc7e8424e 100644 --- a/kernel/trace/fprobe.c +++ b/kernel/trace/fprobe.c @@ -53,7 +53,7 @@ static inline void __fprobe_handler(unsigned long ip, unsigned long parent_ip, if (ret) rethook_recycle(rh); else - rethook_hook(rh, ftrace_get_regs(fregs), true); + rethook_hook(rh, fregs, true); } } @@ -120,7 +120,7 @@ static void fprobe_kprobe_handler(unsigned long ip, unsigned long parent_ip, } static void fprobe_exit_handler(struct rethook_node *rh, void *data, - unsigned long ret_ip, struct pt_regs *regs) + unsigned long ret_ip, struct ftrace_regs *fregs) { struct fprobe *fp = (struct fprobe *)data; struct fprobe_rethook_node *fpr; @@ -141,7 +141,7 @@ static void fprobe_exit_handler(struct rethook_node *rh, void *data, return; } - fp->exit_handler(fp, fpr->entry_ip, ret_ip, regs, + fp->exit_handler(fp, fpr->entry_ip, ret_ip, fregs, fp->entry_data_size ? (void *)fpr->data : NULL); ftrace_test_recursion_unlock(bit); } diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c index 5eb9b598f4e9..7c5cf9d5910c 100644 --- a/kernel/trace/rethook.c +++ b/kernel/trace/rethook.c @@ -189,7 +189,7 @@ NOKPROBE_SYMBOL(rethook_try_get); /** * rethook_hook() - Hook the current function return. * @node: The struct rethook node to hook the function return. - * @regs: The struct pt_regs for the function entry. + * @fregs: The struct ftrace_regs for the function entry. * @mcount: True if this is called from mcount(ftrace) context. * * Hook the current running function return. This must be called when the @@ -199,9 +199,9 @@ NOKPROBE_SYMBOL(rethook_try_get); * from the real function entry (e.g. kprobes) @mcount must be set false. * This is because the way to hook the function return depends on the context. */ -void rethook_hook(struct rethook_node *node, struct pt_regs *regs, bool mcount) +void rethook_hook(struct rethook_node *node, struct ftrace_regs *fregs, bool mcount) { - arch_rethook_prepare(node, regs, mcount); + arch_rethook_prepare(node, fregs, mcount); __llist_add(&node->llist, ¤t->rethooks); } NOKPROBE_SYMBOL(rethook_hook); @@ -269,7 +269,7 @@ unsigned long rethook_find_ret_addr(struct task_struct *tsk, unsigned long frame } NOKPROBE_SYMBOL(rethook_find_ret_addr); -void __weak arch_rethook_fixup_return(struct pt_regs *regs, +void __weak arch_rethook_fixup_return(struct ftrace_regs *fregs, unsigned long correct_ret_addr) { /* @@ -281,7 +281,7 @@ void __weak arch_rethook_fixup_return(struct pt_regs *regs, } /* This function will be called from each arch-defined trampoline. */ -unsigned long rethook_trampoline_handler(struct pt_regs *regs, +unsigned long rethook_trampoline_handler(struct ftrace_regs *fregs, unsigned long frame) { struct llist_node *first, *node = NULL; @@ -295,7 +295,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, BUG_ON(1); } - instruction_pointer_set(regs, correct_ret_addr); + ftrace_regs_set_instruction_pointer(fregs, correct_ret_addr); /* * These loops must be protected from rethook_free_rcu() because those @@ -315,7 +315,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, handler = READ_ONCE(rhn->rethook->handler); if (handler) handler(rhn, rhn->rethook->data, - correct_ret_addr, regs); + correct_ret_addr, fregs); if (first == node) break; @@ -323,7 +323,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, } /* Fixup registers for returning to correct address. */ - arch_rethook_fixup_return(regs, correct_ret_addr); + arch_rethook_fixup_return(fregs, correct_ret_addr); /* Unlink used shadow stack */ first = current->rethooks.first; diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c index 71bf38d698f1..c60d0d9f1a95 100644 --- a/kernel/trace/trace_fprobe.c +++ b/kernel/trace/trace_fprobe.c @@ -341,10 +341,14 @@ static int fentry_dispatcher(struct fprobe *fp, unsigned long entry_ip, NOKPROBE_SYMBOL(fentry_dispatcher); static void fexit_dispatcher(struct fprobe *fp, unsigned long entry_ip, - unsigned long ret_ip, struct pt_regs *regs, + unsigned long ret_ip, struct ftrace_regs *fregs, void *entry_data) { struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp); + struct pt_regs *regs = ftrace_get_regs(fregs); + + if (!regs) + return; if (trace_probe_test_flag(&tf->tp, TP_FLAG_TRACE)) fexit_trace_func(tf, entry_ip, ret_ip, regs); diff --git a/lib/test_fprobe.c b/lib/test_fprobe.c index ff607babba18..d1e80653bf0c 100644 --- a/lib/test_fprobe.c +++ b/lib/test_fprobe.c @@ -59,9 +59,9 @@ static notrace int fp_entry_handler(struct fprobe *fp, unsigned long ip, static notrace void fp_exit_handler(struct fprobe *fp, unsigned long ip, unsigned long ret_ip, - struct pt_regs *regs, void *data) + struct ftrace_regs *fregs, void *data) { - unsigned long ret = regs_return_value(regs); + unsigned long ret = ftrace_regs_return_value(fregs); KUNIT_EXPECT_FALSE(current_test, preemptible()); if (ip != target_ip) { @@ -89,7 +89,7 @@ static notrace int nest_entry_handler(struct fprobe *fp, unsigned long ip, static notrace void nest_exit_handler(struct fprobe *fp, unsigned long ip, unsigned long ret_ip, - struct pt_regs *regs, void *data) + struct ftrace_regs *fregs, void *data) { KUNIT_EXPECT_FALSE(current_test, preemptible()); KUNIT_EXPECT_EQ(current_test, ip, target_nest_ip); diff --git a/samples/fprobe/fprobe_example.c b/samples/fprobe/fprobe_example.c index 1545a1aac616..d476d1f07538 100644 --- a/samples/fprobe/fprobe_example.c +++ b/samples/fprobe/fprobe_example.c @@ -67,7 +67,7 @@ static int sample_entry_handler(struct fprobe *fp, unsigned long ip, } static void sample_exit_handler(struct fprobe *fp, unsigned long ip, - unsigned long ret_ip, struct pt_regs *regs, + unsigned long ret_ip, struct ftrace_regs *regs, void *data) { unsigned long rip = ret_ip; From patchwork Sun Sep 24 13:37:12 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: 144082 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668500vqu; Sun, 24 Sep 2023 06:38:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHf/yXghBBSU6iBF/U5ZTc8UgmilTRjlGf4y9RQPBcjvRPOIvxe6n7Xcc+xr1uEzqbZQGY7 X-Received: by 2002:a17:90a:53a5:b0:268:ef84:b0cd with SMTP id y34-20020a17090a53a500b00268ef84b0cdmr3652334pjh.18.1695562687506; Sun, 24 Sep 2023 06:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562687; cv=none; d=google.com; s=arc-20160816; b=l2GcFK/9ThXeC0l5dJfnfAUmnjkJoP/DMMRCepu0jBWr5y/1tOTLBcI9RFmRC0pTFG TDFS5isZMxBT6611vogjcL7II6nDHAyotr74SNNxXSWMHEMT5vdGpqCITc7IQc6dSikY iKOJkemDbdqZGSu7Qz/vqU9jBn9RaUWSWNX7dype3D9H/HPyzXH44Sf2ejnij9S0cTqC +3SSFNmC8Q90zY3UqLQIa2pAb5ph+oWJfINswW+CYY3vTlluBz8ujVMShAQ8DW698ZRT C6l+gApi4nMZ0leTFZalzZt5AOBg9aUgP+Jlj9kSc7f1a9nBhBVEZjCIIF9mgwctrYUf SNGw== 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=ncge2Zm0yn9fPwwh80aPqSVlA9HyWb2Nt1pMIwQ9oyg=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=W58T6WIyU7oaqrJ/hyjDU6XeFP6xcJP/yoMpVEZdzR0oGHzuIqOzVNhuGU4NMNS5zR vTbcFHdkuxWDS6WREWVZSaIJgEP4O6WicEPqwP+6p1om4gpbIUUrxHi+Q8GMdE9FSIH4 ufRZ4u38otlgNV/gLmPCbC1j1Ed/MVzcSw7fJi4+v3SliXz5N6rhBmSThlqxr0ps1I6k uT05zxJ1ICyzL41QACmDe4J3mr3zbQ75qp55qbVeKt28qdH7tz1szHrMq8ueYKSqzru6 bG6SCnrtyVeW7bcYOjabYrx3TVlLbT7Gm89PIWyesNSWf7bZ0gpl8YPZ6G56Kv/REJYh 2CrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HE5ucNqg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t2-20020a17090aba8200b00276bdabe471si1119538pjr.163.2023.09.24.06.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:38:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HE5ucNqg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 2A88B8029AF1; Sun, 24 Sep 2023 06:38:06 -0700 (PDT) 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 S230168AbjIXNiI (ORCPT + 30 others); Sun, 24 Sep 2023 09:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbjIXNhv (ORCPT ); Sun, 24 Sep 2023 09:37:51 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B75361AB for ; Sun, 24 Sep 2023 06:37:19 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 869FAC433C7; Sun, 24 Sep 2023 13:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562639; bh=z3ZqUJHGicIifDXnSOHi+t2Ua5M0QIoavgEAxehdPoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HE5ucNqgLQ6mEyv5bXIhJHQFfj8vqMflwi8sAXOd+r/H9A2fcYyvgNzrF5aLrM0rq Gnn88OCM45M4cgm1ZQ7zAPV25NOTja+1iT+JWKYWyKkcUojtYaudI5f3L6clmtSE2g 5/0HrCCah3Igi9JDGgSKUvLSXSBoBDnMLVT1OrHDPHU87Lfq5uptwOeto28FJB537Z zxt6cdDCq3A2bd1RT0qIBVQvH7qatk/eQ1LYEgUFEnlTL41DhpWvKisjmh3BwP8B8S 1XV7tvJl15gzEi6hOEyKgFti4ZpfKx5bkECyuOBmtplpl3StNTBjyVOOUNk94eizZY GcddpbvM7kI9w== 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 07/12] tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Sun, 24 Sep 2023 22:37:12 +0900 Message-Id: <169556263259.146934.4055143510535198098.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 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 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, 24 Sep 2023 06:38:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926340112918865 X-GMAIL-MSGID: 1777926340112918865 From: Masami Hiramatsu (Google) Add ftrace_partial_regs() which converts the ftrace_regs to pt_regs. If the architecture defines its own ftrace_regs, this copies partial registers to pt_regs and returns it. If not, ftrace_regs is the same as pt_regs and ftrace_partial_regs() will return ftrace_regs::regs. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Florent Revest --- Changes in v3: - Fix to use pt_regs::regs instead of x. - Return ftrace_regs::regs forcibly if HAVE_PT_REGS_COMPAT_FTRACE_REGS=y. - Fix typo. - Fix to copy correct registers to the pt_regs on arm64. Changes in v4: - Change the patch order in the series so that fprobe event can use this. Changes in v5: - Fix tag in the title (ftrace: -> tracing:) --- arch/arm64/include/asm/ftrace.h | 11 +++++++++++ include/linux/ftrace.h | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index ab158196480c..5ad24f315d52 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -137,6 +137,17 @@ ftrace_override_function_with_return(struct ftrace_regs *fregs) fregs->pc = fregs->lr; } +static __always_inline struct pt_regs * +ftrace_partial_regs(const struct ftrace_regs *fregs, struct pt_regs *regs) +{ + memcpy(regs->regs, fregs->regs, sizeof(u64) * 9); + regs->sp = fregs->sp; + regs->pc = fregs->pc; + regs->regs[29] = fregs->fp; + regs->regs[30] = fregs->lr; + return regs; +} + int ftrace_regs_query_register_offset(const char *name); int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 39a765c71f7e..819511ab75b7 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -173,6 +173,23 @@ static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs return arch_ftrace_get_regs(fregs); } +#if !defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS) || \ + defined(CONFIG_HAVE_PT_REGS_TO_FTRACE_REGS_CAST) + +static __always_inline struct pt_regs * +ftrace_partial_regs(struct ftrace_regs *fregs, struct pt_regs *regs) +{ + /* + * If CONFIG_HAVE_PT_REGS_TO_FTRACE_REGS_CAST=y, ftrace_regs memory + * layout is the same as pt_regs. So always returns that address. + * Since arch_ftrace_get_regs() will check some members and may return + * NULL, we can not use it. + */ + return &fregs->regs; +} + +#endif /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS || CONFIG_HAVE_PT_REGS_TO_FTRACE_REGS_CAST */ + /* * When true, the ftrace_regs_{get,set}_*() functions may be used on fregs. * Note: this can be true even when ftrace_get_regs() cannot provide a pt_regs. From patchwork Sun Sep 24 13:37:25 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: 144085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668754vqu; Sun, 24 Sep 2023 06:38:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEtm24OoF8Ti2bsNGjwEW4VuxkMvMnqNxzBBE8oLWx9mNKkhYt6KaRDKtuGWv9O0KxIKCZb X-Received: by 2002:a9d:664d:0:b0:6bc:c542:6f75 with SMTP id q13-20020a9d664d000000b006bcc5426f75mr5206961otm.0.1695562730671; Sun, 24 Sep 2023 06:38:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562730; cv=none; d=google.com; s=arc-20160816; b=m49G6FoJMr7FHK5ZRtYZIXKajbl2svvB5PXuF1OXBnmgqwZHzOqnWYqYFWz+PhBwFY WGzDSQLA9i0P2eZpv2ueoxbcEVbt/1YDIHtHidjknPcFvDkgh/ytHw42HVcpwByPiITR rbc27Ckp966K1EZiKNz12/Ty1b2KZ/36k0693D7nX2O2vo8i3snaPODAF1PKIbzGQ3Tt M2uZWUgfTJUKqhWz0OVHuniXN2D9LAp++O9k9C+vDNi8UJfEEAvRHDGICwzz7476mfik mQI2KutLtzuE4ohT2Utghggkm+jb0jRb1VrkKmYGv/WNUn2vGWwrUBEohz8lrYFcJNAg MRFg== 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=VhM95YRe6GMPdBwvDMBZxRf2nIhl0BnLG4V9YRCq3o4=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=ndhvZAc5FZP00uZ2wtSgjuFZe/LRD01FAAHi/PLGJsfQmm6nSL0OzdnMxY81AHMx1/ L/hyUC8U6jausiXzVrNlEEIOSpVcrq/woNn0Riz4cxm+4E4tmVY45HWocto6R6HF6+lZ tws+BcF+FbHEfOmhMRzzEB4UCFbQoYadVdmv0bVsrLdS+CKMmb0sSkW7QxZP3C4kNuK0 5Y5S9CABQfNY1N9Pnn0l5WZcagfK260F8+ptgy6k14qd+q80p7LKmPjRLOTkGDJpsxGN GdtRO3MG9OJmd1RTQsH/H3nrGaUwV0CFI6N53ERreoWxHZFZm5dqj7BXkVZsodoiWotB kF6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZqPcYsbq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id u77-20020a627950000000b0069018a768d7si7857305pfc.385.2023.09.24.06.38.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:38:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZqPcYsbq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 5793780298B4; Sun, 24 Sep 2023 06:38:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231241AbjIXNiX (ORCPT + 30 others); Sun, 24 Sep 2023 09:38:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230306AbjIXNh6 (ORCPT ); Sun, 24 Sep 2023 09:37:58 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87466171B for ; Sun, 24 Sep 2023 06:37:32 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB2F9C433B9; Sun, 24 Sep 2023 13:37:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562651; bh=zU6UylpWMhPcntmE4WUBkG80m4hiVOExDKzxHQrqwhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZqPcYsbqMLiLbpcfHCwh07roWj6RSCGhOTxB51sOEG8nlGLfdVQXdMrr6blomR6QZ SuCGpfrfjSRb+y93ncmw10Oz978PpXIvEtJlrWM6pRoWORsgv2wLCjRYHvAU0p31C6 GVhnp3XTxLRED9uh32ukhfRHXrh4+k1+gnP5HOoYfFFJyAZu4otNhFToVm9y2HieYl iAmTpbX+fG+UeQWRUj9ZVp7rbVHma8Hssi8Qcp7BXSfVxuf9mEtpw//tNLW1U6Dcem 9hRCT9cfL3R9u0K359sTpg1ZGlQVnHNpIi3m5CSX5z35uqzD5UNbUiim43xlAU4PGF 1eLs7YeqE8Hxg== 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 08/12] tracing: Add ftrace_fill_perf_regs() for perf event Date: Sun, 24 Sep 2023 22:37:25 +0900 Message-Id: <169556264478.146934.11293821252078942426.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:38:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926385834379095 X-GMAIL-MSGID: 1777926385834379095 From: Masami Hiramatsu (Google) Add ftrace_fill_perf_regs() which should be compatible with the perf_fetch_caller_regs(). In other words, the pt_regs returned from the ftrace_fill_perf_regs() must satisfy 'user_mode(regs) == false' and can be used for stack tracing. Signed-off-by: Masami Hiramatsu (Google) --- arch/arm64/include/asm/ftrace.h | 7 +++++++ arch/powerpc/include/asm/ftrace.h | 7 +++++++ arch/s390/include/asm/ftrace.h | 5 +++++ arch/x86/include/asm/ftrace.h | 7 +++++++ include/linux/ftrace.h | 31 +++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+) diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index 5ad24f315d52..5fbe8fe3e8a5 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -148,6 +148,13 @@ ftrace_partial_regs(const struct ftrace_regs *fregs, struct pt_regs *regs) return regs; } +#define arch_ftrace_fill_perf_regs(fregs, _regs) do { \ + (_regs)->pc = (fregs)->pc; \ + (_regs)->regs[29] = (fregs)->fp; \ + (_regs)->sp = (fregs)->sp; \ + (_regs)->pstate = PSR_MODE_EL1h; \ + } while (0) + int ftrace_regs_query_register_offset(const char *name); int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); diff --git a/arch/powerpc/include/asm/ftrace.h b/arch/powerpc/include/asm/ftrace.h index 9e5a39b6a311..53fa39ef476b 100644 --- a/arch/powerpc/include/asm/ftrace.h +++ b/arch/powerpc/include/asm/ftrace.h @@ -52,6 +52,13 @@ static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs * return fregs->regs.msr ? &fregs->regs : NULL; } +#define arch_ftrace_fill_perf_regs(fregs, _regs) do { \ + (_regs)->result = 0; \ + (_regs)->nip = (fregs)->regs.nip; \ + (_regs)->gpr[1] = (fregs)->regs.gpr[1]; \ + asm volatile("mfmsr %0" : "=r" ((_regs)->msr)); \ + } while (0) + static __always_inline void ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs, unsigned long ip) diff --git a/arch/s390/include/asm/ftrace.h b/arch/s390/include/asm/ftrace.h index 6de3bf4d0092..94ceb9564d44 100644 --- a/arch/s390/include/asm/ftrace.h +++ b/arch/s390/include/asm/ftrace.h @@ -99,6 +99,11 @@ ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs, #define ftrace_regs_query_register_offset(name) \ regs_query_register_offset(name) +#define arch_ftrace_fill_perf_regs(fregs, _regs) do { \ + (_regs)->psw.addr = (fregs)->regs.psw.addr; \ + (_regs)->gprs[15] = (fregs)->regs.gprs[15]; \ + } while (0) + #endif /* CONFIG_FUNCTION_TRACER */ #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS diff --git a/arch/x86/include/asm/ftrace.h b/arch/x86/include/asm/ftrace.h index 897cf02c20b1..800c2af8af01 100644 --- a/arch/x86/include/asm/ftrace.h +++ b/arch/x86/include/asm/ftrace.h @@ -48,6 +48,13 @@ arch_ftrace_get_regs(struct ftrace_regs *fregs) return &fregs->regs; } +#define arch_ftrace_fill_perf_regs(fregs, _regs) do { \ + (_regs)->ip = (fregs)->regs.ip; \ + (_regs)->sp = (fregs)->regs.sp; \ + (_regs)->cs = __KERNEL_CS; \ + (_regs)->flags = 0; \ + } while (0) + #define ftrace_regs_set_instruction_pointer(fregs, _ip) \ do { (fregs)->regs.ip = (_ip); } while (0) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 819511ab75b7..962c3e6c5e3b 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -190,6 +190,37 @@ ftrace_partial_regs(struct ftrace_regs *fregs, struct pt_regs *regs) #endif /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS || CONFIG_HAVE_PT_REGS_TO_FTRACE_REGS_CAST */ +#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS + +/* + * Please define arch dependent pt_regs which compatible to the + * perf_arch_fetch_caller_regs() but based on ftrace_regs. + * This requires + * - user_mode(_regs) returns false (always kernel mode). + * - able to use the _regs for stack trace. + */ +#ifndef arch_ftrace_fill_perf_regs +/* As same as perf_arch_fetch_caller_regs(), do nothing by default */ +#define arch_ftrace_fill_perf_regs(fregs, _regs) do {} while (0) +#endif + +static __always_inline struct pt_regs * +ftrace_fill_perf_regs(struct ftrace_regs *fregs, struct pt_regs *regs) +{ + arch_ftrace_fill_perf_regs(fregs, regs); + return regs; +} + +#else /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */ + +static __always_inline struct pt_regs * +ftrace_fill_perf_regs(struct ftrace_regs *fregs, struct pt_regs *regs) +{ + return &fregs->regs; +} + +#endif + /* * When true, the ftrace_regs_{get,set}_*() functions may be used on fregs. * Note: this can be true even when ftrace_get_regs() cannot provide a pt_regs. From patchwork Sun Sep 24 13:37:37 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: 144084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668648vqu; Sun, 24 Sep 2023 06:38:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErMHH6jViSVFfzp0iLJwjm8nftjgj1pokMBiDNyUhiQ7Xb3iwjhFOCnNKD1H+C9wiffemi X-Received: by 2002:a05:6870:f71d:b0:1c8:c27f:7db7 with SMTP id ej29-20020a056870f71d00b001c8c27f7db7mr4035199oab.40.1695562712964; Sun, 24 Sep 2023 06:38:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562712; cv=none; d=google.com; s=arc-20160816; b=k+sposQVZyica//aeaGF1I9kpR59Ne5G2w9qGpIU55Y2wW9RTYRcqh86e0ucqIAzlE Zhet3GRDrSGonCRUQVe7UZMODZsQ4qOt5HyFL0blbJ1kRtASIEMYb9ACa3kPe1ecWqzL +u+tHYM7SL4b5FKErevWkBKNiTeNQ5XmxKBnmSW5cDjCLLN/lUPi22uHm+kOhlkXBvZN LRZGwQ9bt7ZX3W3SFIXgbeI4SKnRRqraYOgR+1EnMF6y2u+otUYg2mkgBNJUTM5M1dEJ BUxOoj6glzis+qPgb5YZdBPEMRE+hF/lkmmqg62j2yELBV1/1CJgxMLmEs0ewD7jz+5h ocZQ== 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=YoyO9AAvn7S8vlOcrYPTQF8pKT5KTXebZDTNiOB3DmI=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=v6ycpY05k/jalUQbDD255xnO8hPVNG32MH2gmnuTmRX8QbuxhA3Lx8QD9GXHdDFUKS yr7QI5XJsEiHD6/pno9IfdXYufD0Er3yD9XhZpbJY5gwLeYBmLPimCqAZrYioflZJ1/o lFYjvUFnTTd+v5wetP890VWnm+NIRvPSSNUzEAm0x9yMNj8tKXcD+CYYk7xMw/2g2Nlf ppuNF9Zs3UYKtEFE6VbrjflzxNPfOUrqXJtTCNuH591NPt8X5IqHbSAwQRBLZAt05z47 FaIgxFxxXlnnYps/baDp30QhrEaijqXvW54I5tj1tpezqZarPuAWZT9XjhLe/e/ZydGe xNig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u9qqRKmN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id e4-20020a635444000000b005774a3b3efdsi7824215pgm.301.2023.09.24.06.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:38:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u9qqRKmN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 21D788051BAB; Sun, 24 Sep 2023 06:38:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231173AbjIXNic (ORCPT + 30 others); Sun, 24 Sep 2023 09:38:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbjIXNiM (ORCPT ); Sun, 24 Sep 2023 09:38:12 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 606831BC7 for ; Sun, 24 Sep 2023 06:37:44 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 053E5C433C7; Sun, 24 Sep 2023 13:37:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562664; bh=o6W3Qq5RhVZ0SuyRUhPk+n1TEye2b+9YcatTCtUd+IE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u9qqRKmNlNkqrouEsh1ocPk0NicfkGh62kAgsy+mtih9E1MzdbehuGZolMFwcuJjS CfiZ151TcUVYnFH7dsSFXU7wdzQguWvbA5l8Nbrkv646kf8G8EyNk43J7+J9+F6p0k HC8FwQVtaWn+2mlZkE5xwVEbxnJu0jzWXcRYNk7wdVg9U/rPZPGxBbnIo239mwNq+Q Y7kAkYYNb6VKDY5wRO40erURZSzZeGF0GMFUiQ49TsjtV0sL/AxzdlMxmewOCZtmmY RcaT2tP0ox1RFjFDBv7X/HIkPNxhdK/BugvoRcaSsf20dfv7ema73z8PYCViZmKXT8 ClbBtYg6fqtNg== 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 09/12] tracing/fprobe: Enable fprobe events with CONFIG_DYNAMIC_FTRACE_WITH_ARGS Date: Sun, 24 Sep 2023 22:37:37 +0900 Message-Id: <169556265707.146934.9759320469271410104.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 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 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 (howler.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:38:32 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926367386100835 X-GMAIL-MSGID: 1777926367386100835 From: Masami Hiramatsu (Google) Allow fprobe events to be enabled with CONFIG_DYNAMIC_FTRACE_WITH_ARGS. With this change, fprobe events mostly use ftrace_regs instead of pt_regs. Note that if the arch doesn't enable HAVE_PT_REGS_COMPAT_FTRACE_REGS, fprobe events will not be able to be used from perf. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - introduce ftrace_regs_get_kernel_stack_nth(). - fix typo. Changes in v4: - Use per-cpu pt_regs stack and ftrace_partial_regs() for perf event. Changes in v5: - Use perf's per-cpu pt_regs. - Use new ftrace_fill_perf_regs() to fill perf required regs. --- include/linux/ftrace.h | 15 ++++++++ kernel/trace/Kconfig | 1 - kernel/trace/trace_fprobe.c | 74 ++++++++++++++++++++------------------- kernel/trace/trace_probe_tmpl.h | 2 + 4 files changed, 53 insertions(+), 39 deletions(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 962c3e6c5e3b..3748c8100924 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -233,6 +233,21 @@ static __always_inline bool ftrace_regs_has_args(struct ftrace_regs *fregs) return ftrace_get_regs(fregs) != NULL; } +#ifdef CONFIG_HAVE_REGS_AND_STACK_ACCESS_API +static __always_inline unsigned long +ftrace_regs_get_kernel_stack_nth(struct ftrace_regs *fregs, unsigned int nth) +{ + unsigned long *stackp; + + stackp = (unsigned long *)ftrace_regs_get_stack_pointer(fregs); + if (((unsigned long)(stackp + nth) & ~(THREAD_SIZE - 1)) == + ((unsigned long)stackp & ~(THREAD_SIZE - 1))) + return *(stackp + nth); + + return 0; +} +#endif /* CONFIG_HAVE_REGS_AND_STACK_ACCESS_API */ + #ifdef CONFIG_FUNCTION_TRACER extern int ftrace_enabled; diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index d56304276318..6fb4ecf8767d 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -679,7 +679,6 @@ config FPROBE_EVENTS select TRACING select PROBE_EVENTS select DYNAMIC_EVENTS - depends on DYNAMIC_FTRACE_WITH_REGS default y help This allows user to add tracing events on the function entry and diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c index c60d0d9f1a95..882c220333cc 100644 --- a/kernel/trace/trace_fprobe.c +++ b/kernel/trace/trace_fprobe.c @@ -132,7 +132,7 @@ static int process_fetch_insn(struct fetch_insn *code, void *rec, void *dest, void *base) { - struct pt_regs *regs = rec; + struct ftrace_regs *fregs = rec; unsigned long val; int ret; @@ -140,17 +140,17 @@ process_fetch_insn(struct fetch_insn *code, void *rec, void *dest, /* 1st stage: get value from context */ switch (code->op) { case FETCH_OP_STACK: - val = regs_get_kernel_stack_nth(regs, code->param); + val = ftrace_regs_get_kernel_stack_nth(fregs, code->param); break; case FETCH_OP_STACKP: - val = kernel_stack_pointer(regs); + val = ftrace_regs_get_stack_pointer(fregs); break; case FETCH_OP_RETVAL: - val = regs_return_value(regs); + val = ftrace_regs_return_value(fregs); break; #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API case FETCH_OP_ARG: - val = regs_get_kernel_argument(regs, code->param); + val = ftrace_regs_get_argument(fregs, code->param); break; #endif case FETCH_NOP_SYMBOL: /* Ignore a place holder */ @@ -170,7 +170,7 @@ NOKPROBE_SYMBOL(process_fetch_insn) /* function entry handler */ static nokprobe_inline void __fentry_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, - struct pt_regs *regs, + struct ftrace_regs *fregs, struct trace_event_file *trace_file) { struct fentry_trace_entry_head *entry; @@ -184,36 +184,36 @@ __fentry_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, if (trace_trigger_soft_disabled(trace_file)) return; - dsize = __get_data_size(&tf->tp, regs); + dsize = __get_data_size(&tf->tp, fregs); entry = trace_event_buffer_reserve(&fbuffer, trace_file, sizeof(*entry) + tf->tp.size + dsize); if (!entry) return; - fbuffer.regs = regs; + fbuffer.regs = ftrace_get_regs(fregs); entry = fbuffer.entry = ring_buffer_event_data(fbuffer.event); entry->ip = entry_ip; - store_trace_args(&entry[1], &tf->tp, regs, sizeof(*entry), dsize); + store_trace_args(&entry[1], &tf->tp, fregs, sizeof(*entry), dsize); trace_event_buffer_commit(&fbuffer); } static void fentry_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, - struct pt_regs *regs) + struct ftrace_regs *fregs) { struct event_file_link *link; trace_probe_for_each_link_rcu(link, &tf->tp) - __fentry_trace_func(tf, entry_ip, regs, link->file); + __fentry_trace_func(tf, entry_ip, fregs, link->file); } NOKPROBE_SYMBOL(fentry_trace_func); /* Kretprobe handler */ static nokprobe_inline void __fexit_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, - unsigned long ret_ip, struct pt_regs *regs, + unsigned long ret_ip, struct ftrace_regs *fregs, struct trace_event_file *trace_file) { struct fexit_trace_entry_head *entry; @@ -227,60 +227,63 @@ __fexit_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, if (trace_trigger_soft_disabled(trace_file)) return; - dsize = __get_data_size(&tf->tp, regs); + dsize = __get_data_size(&tf->tp, fregs); entry = trace_event_buffer_reserve(&fbuffer, trace_file, sizeof(*entry) + tf->tp.size + dsize); if (!entry) return; - fbuffer.regs = regs; + fbuffer.regs = ftrace_get_regs(fregs); entry = fbuffer.entry = ring_buffer_event_data(fbuffer.event); entry->func = entry_ip; entry->ret_ip = ret_ip; - store_trace_args(&entry[1], &tf->tp, regs, sizeof(*entry), dsize); + store_trace_args(&entry[1], &tf->tp, fregs, sizeof(*entry), dsize); trace_event_buffer_commit(&fbuffer); } static void fexit_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, - unsigned long ret_ip, struct pt_regs *regs) + unsigned long ret_ip, struct ftrace_regs *fregs) { struct event_file_link *link; trace_probe_for_each_link_rcu(link, &tf->tp) - __fexit_trace_func(tf, entry_ip, ret_ip, regs, link->file); + __fexit_trace_func(tf, entry_ip, ret_ip, fregs, link->file); } NOKPROBE_SYMBOL(fexit_trace_func); #ifdef CONFIG_PERF_EVENTS static int fentry_perf_func(struct trace_fprobe *tf, unsigned long entry_ip, - struct pt_regs *regs) + struct ftrace_regs *fregs) { struct trace_event_call *call = trace_probe_event_call(&tf->tp); struct fentry_trace_entry_head *entry; struct hlist_head *head; int size, __size, dsize; + struct pt_regs *regs; int rctx; head = this_cpu_ptr(call->perf_events); if (hlist_empty(head)) return 0; - dsize = __get_data_size(&tf->tp, regs); + dsize = __get_data_size(&tf->tp, fregs); __size = sizeof(*entry) + tf->tp.size + dsize; size = ALIGN(__size + sizeof(u32), sizeof(u64)); size -= sizeof(u32); - entry = perf_trace_buf_alloc(size, NULL, &rctx); + entry = perf_trace_buf_alloc(size, ®s, &rctx); if (!entry) return 0; + regs = ftrace_fill_perf_regs(fregs, regs); + entry->ip = entry_ip; memset(&entry[1], 0, dsize); - store_trace_args(&entry[1], &tf->tp, regs, sizeof(*entry), dsize); + store_trace_args(&entry[1], &tf->tp, fregs, sizeof(*entry), dsize); perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, head, NULL); return 0; @@ -289,30 +292,33 @@ NOKPROBE_SYMBOL(fentry_perf_func); static void fexit_perf_func(struct trace_fprobe *tf, unsigned long entry_ip, - unsigned long ret_ip, struct pt_regs *regs) + unsigned long ret_ip, struct ftrace_regs *fregs) { struct trace_event_call *call = trace_probe_event_call(&tf->tp); struct fexit_trace_entry_head *entry; struct hlist_head *head; int size, __size, dsize; + struct pt_regs *regs; int rctx; head = this_cpu_ptr(call->perf_events); if (hlist_empty(head)) return; - dsize = __get_data_size(&tf->tp, regs); + dsize = __get_data_size(&tf->tp, fregs); __size = sizeof(*entry) + tf->tp.size + dsize; size = ALIGN(__size + sizeof(u32), sizeof(u64)); size -= sizeof(u32); - entry = perf_trace_buf_alloc(size, NULL, &rctx); + entry = perf_trace_buf_alloc(size, ®s, &rctx); if (!entry) return; + regs = ftrace_fill_perf_regs(fregs, regs); + entry->func = entry_ip; entry->ret_ip = ret_ip; - store_trace_args(&entry[1], &tf->tp, regs, sizeof(*entry), dsize); + store_trace_args(&entry[1], &tf->tp, fregs, sizeof(*entry), dsize); perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, head, NULL); } @@ -324,17 +330,14 @@ static int fentry_dispatcher(struct fprobe *fp, unsigned long entry_ip, void *entry_data) { struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp); - struct pt_regs *regs = ftrace_get_regs(fregs); int ret = 0; - if (!regs) - return 0; - if (trace_probe_test_flag(&tf->tp, TP_FLAG_TRACE)) - fentry_trace_func(tf, entry_ip, regs); + fentry_trace_func(tf, entry_ip, fregs); + #ifdef CONFIG_PERF_EVENTS if (trace_probe_test_flag(&tf->tp, TP_FLAG_PROFILE)) - ret = fentry_perf_func(tf, entry_ip, regs); + ret = fentry_perf_func(tf, entry_ip, fregs); #endif return ret; } @@ -345,16 +348,13 @@ static void fexit_dispatcher(struct fprobe *fp, unsigned long entry_ip, void *entry_data) { struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp); - struct pt_regs *regs = ftrace_get_regs(fregs); - - if (!regs) - return; if (trace_probe_test_flag(&tf->tp, TP_FLAG_TRACE)) - fexit_trace_func(tf, entry_ip, ret_ip, regs); + fexit_trace_func(tf, entry_ip, ret_ip, fregs); + #ifdef CONFIG_PERF_EVENTS if (trace_probe_test_flag(&tf->tp, TP_FLAG_PROFILE)) - fexit_perf_func(tf, entry_ip, ret_ip, regs); + fexit_perf_func(tf, entry_ip, ret_ip, fregs); #endif } NOKPROBE_SYMBOL(fexit_dispatcher); diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index 3935b347f874..05445a745a07 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -232,7 +232,7 @@ process_fetch_insn_bottom(struct fetch_insn *code, unsigned long val, /* Sum up total data length for dynamic arrays (strings) */ static nokprobe_inline int -__get_data_size(struct trace_probe *tp, struct pt_regs *regs) +__get_data_size(struct trace_probe *tp, void *regs) { struct probe_arg *arg; int i, len, ret = 0; From patchwork Sun Sep 24 13:37:49 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: 144088 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp670167vqu; Sun, 24 Sep 2023 06:42:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGAu10HZs/qLNuSFbeGft5TyPa3g9hFPBQUz88aKm6qI4e1FiO97vTmMu4JEfLwzJ3yrvG X-Received: by 2002:a17:902:bc47:b0:1c0:afda:540b with SMTP id t7-20020a170902bc4700b001c0afda540bmr2772022plz.8.1695562957006; Sun, 24 Sep 2023 06:42:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562956; cv=none; d=google.com; s=arc-20160816; b=uwMxlSm7FXCkVK4KdD8G5lC5Jj4RE+N3tYTUYv4CwijIRJEJCyEhZQabb9SM+9BRSy HfOS/+vi4ZqEMhcBjZ3Ig6oa5dby89l6VQhRIYhJYG2fZtd3ST1w42Hb33Kd9F920B4Y Y8bXGuyvYAsapNtSgjIFTkJ4Qf0/TROYaAI0omtyoHZKenXkSuUVihBHe1qBRR/aERLF +YYpKMFubtcBE9UOCQ7BBpBtu7gZD1uPhshuiCYzOUKoZDJahLzqcVm5c0XNPbxfp1XZ r5NJY5EVKRnY6hqjuBpFSRFj6g5G5nZ5yXSwVKxGbx8ZTncT3LYUkbNRjhRJm10AL8lm td7g== 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=RAic9iBGIlLTJhUTGHS5T8tVayLVfzas3EBPxmsTXu8=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=Yrb/O642mlUq7ss3frq5bzqQf7Nv196PbSpQe0limcHaGNSpr4sTp5hvfRnl8Kfa45 ZxktpNvDdERcSwDOFncAfEIotQFESX1WT9czuPHdW/UmPj97SUah1Hn6q5BFR/MuOfU+ 33bNm2GNX51faZCRQLbSzvhJH03bGj1Jq/5YAky1ckZWqZOLJT50H+PEEYKuVpi6B/hh i4SMt7hIsYwKzPdEe8VRH1lP2Wdlv9tbkmoJWQMFKaUbL5WuXA5KTqp5B9imxMdT813I gRh3XCp04qSy9PcYh77Cky6d7mLmL/xrT86xk45o4SMUdtA1ep+Ho9SeVbYxkq7+nmOu zANw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NUhxY4N8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id a10-20020a170902ecca00b001bbe13e753esi2231520plh.310.2023.09.24.06.42.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:42:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NUhxY4N8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id BCF14807CED8; Sun, 24 Sep 2023 06:40:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231243AbjIXNih (ORCPT + 30 others); Sun, 24 Sep 2023 09:38:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231218AbjIXNiW (ORCPT ); Sun, 24 Sep 2023 09:38:22 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 736BE126 for ; Sun, 24 Sep 2023 06:37:56 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5909EC433C8; Sun, 24 Sep 2023 13:37:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562676; bh=FEfGDz6clxZ9PLKtBAXOYmli6LSrFixQDspF7u/Z4KA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NUhxY4N8h3ShSDm2qYxveksvNl9zrO2XDzm2UaaVojXVnQrGNh+H6DYGuxn/NNlqj btDQMa8Lp6z5LAEwgsx1ooN6yll4I1549gag/udsMHgDxg8jVgLUELsvsRiwwaD8SZ d39JuIuxXZKH2zhdTwqlI7KRzuTedHAYT/fr9E5NsPCCHlDWTK01If8Dy6tW3UvD9b ecguWWebaF78uUGf3swAMjGj3Tm/7gKa4qZqCs6hPskHFYoJdF1UC/YekLBEUPUpr5 AadOSeUAGI673e+JmebPT3pq1IXStV6K/Jl8n4n38MvkEddiFZQKSX6geivcghXsbJ ntOcH7s15m+Gw== 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 10/12] bpf: Enable kprobe_multi feature if CONFIG_FPROBE is enabled Date: Sun, 24 Sep 2023 22:37:49 +0900 Message-Id: <169556266942.146934.6508273802845934438.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:40:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926623434716011 X-GMAIL-MSGID: 1777926623434716011 From: Masami Hiramatsu (Google) Enable kprobe_multi feature if CONFIG_FPROBE is enabled. The pt_regs is converted from ftrace_regs by ftrace_partial_regs(), thus some registers may always returns 0. But it should be enough for function entry (access arguments) and exit (access return value). Signed-off-by: Masami Hiramatsu (Google) Acked-by: Florent Revest --- kernel/trace/bpf_trace.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 8bb003ce7bb2..808acd56e432 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2501,7 +2501,7 @@ static int __init bpf_event_init(void) fs_initcall(bpf_event_init); #endif /* CONFIG_MODULES */ -#if defined(CONFIG_FPROBE) && defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS) +#ifdef CONFIG_FPROBE struct bpf_kprobe_multi_link { struct bpf_link link; struct fprobe fp; @@ -2524,6 +2524,8 @@ struct user_syms { char *buf; }; +static DEFINE_PER_CPU(struct pt_regs, bpf_kprobe_multi_pt_regs); + static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 cnt) { unsigned long __user usymbol; @@ -2700,13 +2702,14 @@ static u64 bpf_kprobe_multi_entry_ip(struct bpf_run_ctx *ctx) static int kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link, - unsigned long entry_ip, struct pt_regs *regs) + unsigned long entry_ip, struct ftrace_regs *fregs) { struct bpf_kprobe_multi_run_ctx run_ctx = { .link = link, .entry_ip = entry_ip, }; struct bpf_run_ctx *old_run_ctx; + struct pt_regs *regs; int err; if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) { @@ -2716,6 +2719,7 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link, migrate_disable(); rcu_read_lock(); + regs = ftrace_partial_regs(fregs, this_cpu_ptr(&bpf_kprobe_multi_pt_regs)); old_run_ctx = bpf_set_run_ctx(&run_ctx.run_ctx); err = bpf_prog_run(link->link.prog, regs); bpf_reset_run_ctx(old_run_ctx); @@ -2733,13 +2737,9 @@ kprobe_multi_link_handler(struct fprobe *fp, unsigned long fentry_ip, void *data) { struct bpf_kprobe_multi_link *link; - struct pt_regs *regs = ftrace_get_regs(fregs); - - if (!regs) - return 0; link = container_of(fp, struct bpf_kprobe_multi_link, fp); - kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs); + kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), fregs); return 0; } @@ -2749,13 +2749,9 @@ kprobe_multi_link_exit_handler(struct fprobe *fp, unsigned long fentry_ip, void *data) { struct bpf_kprobe_multi_link *link; - struct pt_regs *regs = ftrace_get_regs(fregs); - - if (!regs) - return; link = container_of(fp, struct bpf_kprobe_multi_link, fp); - kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs); + kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), fregs); } static int symbols_cmp_r(const void *a, const void *b, const void *priv) @@ -2996,7 +2992,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr kvfree(cookies); return err; } -#else /* !CONFIG_FPROBE || !CONFIG_DYNAMIC_FTRACE_WITH_REGS */ +#else /* !CONFIG_FPROBE */ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) { return -EOPNOTSUPP; From patchwork Sun Sep 24 13:38:01 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: 144086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668807vqu; Sun, 24 Sep 2023 06:38:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHjV7iUxLLP6omDe88hDOrP/I6sUxJiVUPnVqPI1rUjXI96OD8Af15RdTXr+RVy9/52+QsX X-Received: by 2002:a05:6808:611:b0:3a4:24aa:b556 with SMTP id y17-20020a056808061100b003a424aab556mr4882467oih.13.1695562737416; Sun, 24 Sep 2023 06:38:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562737; cv=none; d=google.com; s=arc-20160816; b=uc7tIqtUsPMzudmylP7UhvL+CjR4ps7XtOmkfWa8EpkmNWUtyYRNtQbE8fEzjor7Ip rZaIGbS7cauQyZ6lGkTRdQ5T8HNQv6JYLlTyy8F01es0x+iwy28TnpZsAPwVfdjoVUod Vg0oTKqekYC+iISZ0Z5eqhJnA1LxpB4J0J/DuhHGm4qnKE+nKX6U4jDpdKnZ09Btph1g lF9CFrWNlPQ4kvP9X/PNRJmfJHMWgXdLAOUN8Q8MoE1VMcNTZfe/i5g/YOTSQ9s6+AG6 pKNaGQr5+Acdu3GO1WKma4W4Bd4nlMALtiZk+opihj36LLt2YuSg66evzBsqPEzwypx6 ZP4Q== 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=FtMigg13SlVXhJwnQHFG7w/Qu8MO8Af/XlF2dg5TXrQ=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=lauX5VzSoMjU5PB1ASu7qIiT+Qdo4POVl9RbTaTlDUaXebPeZ3j9O3KPFSOQMWKojt xhTpLV7I5+morf8xjsbBuUBLXVl8gglRnS1MKfyHndtoAbg2zLfgLU/PDrxIGZ6hZgcP MsAld9C1R1n9pVeJiLgi7bcN7uZZZPKbbEpfEo8Yo0tWZle2pClE1MOmvcMDyChpuKrC TtGBbdmqwCn5sqo08A/Gpk9KoTgzbAJpMZR0RE/LzPjflDDOQJRiW8/YblmfiZ/9nmrr CRXu3u4FdMM4+Cou5NABC0PMgOGnHXrLeVDjM2ry+HB48nHwQR9GWhCU5yDzpnCcp6y3 aPTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pV93df4U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id bk13-20020a056a02028d00b00582f2161cb4si292257pgb.300.2023.09.24.06.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:38:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pV93df4U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 15ACE80298B0; Sun, 24 Sep 2023 06:38:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231283AbjIXNis (ORCPT + 30 others); Sun, 24 Sep 2023 09:38:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229809AbjIXNi3 (ORCPT ); Sun, 24 Sep 2023 09:38:29 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B61ADE4D for ; Sun, 24 Sep 2023 06:38:08 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80C1CC433C9; Sun, 24 Sep 2023 13:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562688; bh=CLUahLECFFMThaMlg6kBR2ihukQ2SmAsdwcA4AdH8rk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pV93df4UU5q1m05W20xMqKCAie39MI7vyF8y2HIqDTWOsxFBvDzv2eP9xz/EzI0oF e0r4Iuz1rqZhPm2sX88w62J6AMOUShFxf9hVU3p8esqhejBVuWBiqvGfDkIsyv8cdz V02/uAiHnmVFhuk0yj086D+g54+ycpHy3bAB3VryqWXWYY/mxSa66sxl400CIEnKNH tHNbC2rokwrO5AowIFkrUaC4WenWq9wlV/3DYfIR5XkbfMCb0g0IcWm9n45dsLd5Mb 4bF04iwvGb3sWZPighPuFFn7s7wBq6B5nrMjhIYKf1I0uJ+RR6vuiW51e7xhy4OvoC ghBfS8cf5aNOA== 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 11/12] Documentation: probes: Update fprobe document to use ftrace_regs Date: Sun, 24 Sep 2023 22:38:01 +0900 Message-Id: <169556268150.146934.2968626447452628416.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:38:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926393107609490 X-GMAIL-MSGID: 1777926393107609490 From: Masami Hiramatsu (Google) Update fprobe document so that the entry/exit handler uses ftrace_regs instead of pt_regs. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Florent Revest --- Documentation/trace/fprobe.rst | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Documentation/trace/fprobe.rst b/Documentation/trace/fprobe.rst index 196f52386aaa..64ef522f7a64 100644 --- a/Documentation/trace/fprobe.rst +++ b/Documentation/trace/fprobe.rst @@ -91,9 +91,9 @@ 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. @@ -112,12 +112,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. From patchwork Sun Sep 24 13:38:14 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: 144087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668901vqu; Sun, 24 Sep 2023 06:39:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIOfH7IHq8GmSEzVgYliJjhpXP84qqCfLZV0JWEtTTLW6DrutGqU/qkYtXXPPH60wCb4Rr X-Received: by 2002:a05:6a21:4982:b0:14c:def0:db07 with SMTP id ax2-20020a056a21498200b0014cdef0db07mr2749886pzc.34.1695562750410; Sun, 24 Sep 2023 06:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562750; cv=none; d=google.com; s=arc-20160816; b=hmx/xBy1+iuVkzU//XTT4Sxq2AowfRRBPcKGNybUA/RFFGYTtYtKglNFq2+lqn+sbu WaE3E9qWKTEwe2vHnJNU2OoN0yACDGf3Tm9rbyiw2OFuxRJBE6cXq37RAYURy2yF8O9w CMsitRTStJ+nDzcbR0qGQPIMuI2Hoyeln/1SnudfvdkKL6woY5Y8QLgqeDvzo8LBJwgq EweEUCuUYIADtAhda8Wj7DuUfuKC02dx7HUn8psT+2yBXiKGtZOAG0lQ5LdxuIGhl1Rm roZiFy20UZMionThiXEpd6Oxl2N/UOf/ihLGIMM0szNsYTLM+u3rFoa7dubBcwCITWut DGdA== 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=vwSY2ST/Vlfp0gGE2bdFHasZePse9yy6k+DQqsdpTGE=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=Ne6OlsDhLvDRPfEzybPoLRaiO6vTTCIXLRqnjn0yVkR+rldj9n46BggmjgiKRE2DBw thqgfE4J+vv6WywuxKJWlVsTRfYtkjNpv4CIpdZzGpNFYnuo0sEF1z1yZEB93C40y/iT K7ZdUJkZPlK/r6QbRXWKD55CQl5npHrNUWhb5T8rntOd9CcsCG57Wd1aNnLl5kPPsfua SM+FwcvwPQCO9s8yJW/jU+fLcxxizeN8XFKl0qQEr6qXA8rZAr/013jxZoG+x8JQoP9q aShlBwanZ8SDg2m1W3nBNCD5pmSaL9Cos1Ou1PBsVXnuavi4F91qh8mpJpflh2yIKbr3 VqsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Noce4mwm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id z1-20020a170903018100b001c611f285aasi1075318plg.541.2023.09.24.06.39.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:39:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Noce4mwm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 72F24830D369; Sun, 24 Sep 2023 06:39:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231329AbjIXNjC (ORCPT + 30 others); Sun, 24 Sep 2023 09:39:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230481AbjIXNif (ORCPT ); Sun, 24 Sep 2023 09:38:35 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2092610E3 for ; Sun, 24 Sep 2023 06:38:21 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE0B3C433C7; Sun, 24 Sep 2023 13:38:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562700; bh=Ylc3TSXa5ifgz7bjH+Ib7u/kImYYyrGh5B2vMyFRLTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Noce4mwmQNAoIZUogYsYCHEBjWbN2VvgLO6lbPFKdhnc1rWxsAAm5qcB/hlWV7MzL 6M8uaClcpljpII0+yuMjMcfoXR2E4R03fEuYY1TBanEt2HyxGqBltgcZGu2xlwMcw1 GT1nBUt9ctylc2zKowKw8YXTloz3jhxqUqutXd+I1UwjeJr3Fz+fgwqCp1jn6obYvX EbnAwCmrhQ7uQFXszvaCznoy6tg4E3WMRuPOSYmv8+iowSy3I/m+5sghxqx/z/F2qm QL6KhyoirapL2JQ/JB64iPfjQKFoZV2VO2aGFRDutjDqBmqcL1+dhLeHtBXi9ik/4B gmhXMtk+X90zQ== 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 12/12] Documentation: tracing: Add a note about argument and retval access Date: Sun, 24 Sep 2023 22:38:14 +0900 Message-Id: <169556269377.146934.14829235476649685954.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 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 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 (howler.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:39:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926406279788233 X-GMAIL-MSGID: 1777926406279788233 From: Masami Hiramatsu (Google) Add a note about the argument and return value accecss will be best effort. Depending on the type, it will be passed via stack or a pair of the registers, but $argN and $retval only support the single register access. Suggested-by: Alexei Starovoitov Signed-off-by: Masami Hiramatsu (Google) --- Documentation/trace/fprobetrace.rst | 8 ++++++-- Documentation/trace/kprobetrace.rst | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Documentation/trace/fprobetrace.rst b/Documentation/trace/fprobetrace.rst index 8e9bebcf0a2e..e35e6b18df40 100644 --- a/Documentation/trace/fprobetrace.rst +++ b/Documentation/trace/fprobetrace.rst @@ -59,8 +59,12 @@ Synopsis of fprobe-events and bitfield are supported. (\*1) This is available only when BTF is enabled. - (\*2) only for the probe on function entry (offs == 0). - (\*3) only for return probe. + (\*2) only for the probe on function entry (offs == 0). Note, this argument access + is best effort, because depending on the argument type, it may be passed on + the stack. But this only support the arguments via registers. + (\*3) only for return probe. Note that this is also best effort. Depending on the + return value type, it might be passed via a pair of registers. But this only + accesses one register. (\*4) this is useful for fetching a field of data structures. (\*5) "u" means user-space dereference. diff --git a/Documentation/trace/kprobetrace.rst b/Documentation/trace/kprobetrace.rst index 8a2dfee38145..bf9cecb69fc9 100644 --- a/Documentation/trace/kprobetrace.rst +++ b/Documentation/trace/kprobetrace.rst @@ -61,8 +61,12 @@ Synopsis of kprobe_events (x8/x16/x32/x64), "char", "string", "ustring", "symbol", "symstr" and bitfield are supported. - (\*1) only for the probe on function entry (offs == 0). - (\*2) only for return probe. + (\*1) only for the probe on function entry (offs == 0). Note, this argument access + is best effort, because depending on the argument type, it may be passed on + the stack. But this only support the arguments via registers. + (\*2) only for return probe. Note that this is also best effort. Depending on the + return value type, it might be passed via a pair of registers. But this only + accesses one register. (\*3) this is useful for fetching a field of data structures. (\*4) "u" means user-space dereference. See :ref:`user_mem_access`.