Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4408208rwl; Tue, 28 Mar 2023 06:50:01 -0700 (PDT) X-Google-Smtp-Source: AKy350aFO7ZbaJP13KtXdpB5kFRPiDsO4592zzRc4xUQxx/zqacvc3AX/yIZOD2r8XmUnB4pzqvO X-Received: by 2002:a05:6402:150b:b0:501:d18f:af83 with SMTP id f11-20020a056402150b00b00501d18faf83mr15285343edw.8.1680011401182; Tue, 28 Mar 2023 06:50:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680011401; cv=none; d=google.com; s=arc-20160816; b=byS/5vrydSxZg3yFP8cPpoK4HFPyb89zm03AeyCEAUgEJJF1OBiwyshwyoFpzb2yVF /5utlayqPEFAU/lX2Qzf06uYl+Fi307CLZMvnlGeEEE8t9qVBKdP458d3LuH+2PIDhpS LhsycZwR9BRyKw+/DuIU1EetZR6UmhBwuhoQoqMZE8iwPMVURnpglPawRABLZeNlLe78 hgrbCepOCb24ugNZ6eB38mMo3Lz3irFr1OZAwW4yi5m8K0pIUwt/e8TfO3VJJ8gg9lN0 J0UT2/u7jWc+nBbArGjk7tHrQCNfT7Dk1gI7VnAEuhFReQqq49dPrV4Fs1GKHQKfhF3t lRUA== 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 :message-id:date:subject:cc:to:from; bh=td9W9OJt2jlh66QWrShWxUPDcSXfOyY697zVs8ULxwc=; b=1BDMaGl3YY8uM/tpMGxZgN0r6wVw3A9pYCwD7Vmbldcfqs3840RBuhZumgSVR+0PqT wIWD3zy8n2GrSLi8mGsfBhdjVYkC/DzToiVGUSB18VmE6sOc+RJnaAnl54jPh3RLgTcu TGd3SZ1EA2laAf0pxBMQIZrDVj6CmCIbh+KoBG1ULS1oQwecQIXEp5tAv3keIM6sTh17 8O424PYIXSvZutAQmPIXp/7+6NENGFoBg6265FuANLH14hheziNQyKfySEvRJwiwFF8w 4EdKWbccDH6BbxSWntRIXncs768QUuKIO39GflJzkVFgWW2AqMcv4JnTGgWfyzBQNvXz 0khg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sangfor.com.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c13-20020aa7c98d000000b004fd29e75157si32008451edt.343.2023.03.28.06.49.36; Tue, 28 Mar 2023 06:50:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sangfor.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233368AbjC1Noq (ORCPT + 99 others); Tue, 28 Mar 2023 09:44:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233312AbjC1NoR (ORCPT ); Tue, 28 Mar 2023 09:44:17 -0400 Received: from mail-m118111.qiye.163.com (mail-m118111.qiye.163.com [115.236.118.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30ACEC656; Tue, 28 Mar 2023 06:44:01 -0700 (PDT) Received: from ubuntu.localdomain (unknown [117.133.56.22]) by mail-m118111.qiye.163.com (Hmail) with ESMTPA id 96D2158042C; Tue, 28 Mar 2023 21:43:21 +0800 (CST) From: Donglin Peng To: mhiramat@kernel.org, rostedt@goodmis.org, linux@armlinux.org.uk, mark.rutland@arm.com, will@kernel.org, catalin.marinas@arm.com, palmer@dabbelt.com, paul.walmsley@sifive.com, tglx@linutronix.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, chenhuacai@kernel.org, zhangqing@loongson.cn, kernel@xen0n.name, mingo@redhat.com, peterz@infradead.org, xiehuan09@gmail.com, dinghui@sangfor.com.cn, huangcun@sangfor.com.cn, dolinux.peng@gmail.com Cc: linux-trace-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Donglin Peng Subject: [PATCH v8 0/8] function_graph: Support recording and printing the return value of function Date: Tue, 28 Mar 2023 06:43:11 -0700 Message-Id: <20230328134319.2185812-1-pengdonglin@sangfor.com.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkZQkhMVkofTBhKTU4aHk0eGVUTARMWGhIXJBQOD1 lXWRgSC1lBWUpKTFVKSEhVTk1VSUlZV1kWGg8SFR0UWUFZT0tIVUpISkJIT1VKS0tVS1kG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6PzI6Dxw5Iz0cA1Y8EQoXDzEY SRwwCgNVSlVKTUNLS0pKS0tIS0hLVTMWGhIXVQseFRwfFBUcFxIVOwgaFRwdFAlVGBQWVRgVRVlX WRILWUFZSkpMVUpISFVOTVVJSVlXWQgBWUFDQkJMNwY+ X-HM-Tid: 0a87287582a52eb7kusn96d2158042c X-HM-MType: 1 X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When using the function_graph tracer to analyze system call failures, it can be time-consuming to analyze the trace logs and locate the kernel function that first returns an error. This change aims to simplify the process by recording the function return value to the 'retval' member of 'ftrace_graph_ent' and printing it when outputing the trace log. Note that even if a function's return type is void, a return value will still be printed, so it should be ignored. If you care about this, the BTF file can be used to obtain the details of function return type. We can implement a tool to process the trace log and display the return value based on its actual type. Here is an example: ... 1) | cgroup_attach_task() { 1) | cgroup_migrate_add_src() { 1) 1.403 us | cset_cgroup_from_root(); /* = 0xffff93fc86f58010 */ 1) 2.154 us | } /* cgroup_migrate_add_src = 0xffffb286c1297d00 */ 1) ! 386.538 us | cgroup_migrate_prepare_dst(); /* = 0x0 */ 1) | cgroup_migrate() { 1) 0.651 us | cgroup_migrate_add_task(); /* = 0xffff93fcfd346c00 */ 1) | cgroup_migrate_execute() { 1) | cpu_cgroup_can_attach() { 1) | cgroup_taskset_first() { 1) 0.732 us | cgroup_taskset_next(); /* = 0xffff93fc8fb20000 */ 1) 1.232 us | } /* cgroup_taskset_first = 0xffff93fc8fb20000 */ 1) 0.380 us | sched_rt_can_attach(); /* = 0x0 */ 1) 2.335 us | } /* cpu_cgroup_can_attach = -22 */ 1) 4.369 us | } /* cgroup_migrate_execute = -22 */ 1) 7.143 us | } /* cgroup_migrate = -22 */ 1) | cgroup_migrate_finish() { 1) 0.411 us | put_css_set_locked(); /* = 0x8 */ 1) + 62.397 us | put_css_set_locked(); /* = 0x80000001 */ 1) + 64.742 us | } /* cgroup_migrate_finish = 0x80000000 */ 1) ! 465.605 us | } /* cgroup_attach_task = -22 */ ... After processing the above trace logs using BTF information: ... 1) | cgroup_attach_task() { 1) | cgroup_migrate_add_src() { 1) 1.403 us | cset_cgroup_from_root(); /* = 0xffff93fc86f58010 */ 1) 2.154 us | } /* cgroup_migrate_add_src */ 1) ! 386.538 us | cgroup_migrate_prepare_dst(); /* = 0 */ 1) | cgroup_migrate() { 1) 0.651 us | cgroup_migrate_add_task(); 1) | cgroup_migrate_execute() { 1) | cpu_cgroup_can_attach() { 1) | cgroup_taskset_first() { 1) 0.732 us | cgroup_taskset_next(); /* = 0xffff93fc8fb20000 */ 1) 1.232 us | } /* cgroup_taskset_first = 0xffff93fc8fb20000 */ 1) 0.380 us | sched_rt_can_attach(); /* = 0 */ 1) 2.335 us | } /* cpu_cgroup_can_attach = -22 */ 1) 4.369 us | } /* cgroup_migrate_execute = -22 */ 1) 7.143 us | } /* cgroup_migrate = -22 */ 1) | cgroup_migrate_finish() { 1) 0.411 us | put_css_set_locked(); 1) + 62.397 us | put_css_set_locked(); 1) + 64.742 us | } /* cgroup_migrate_finish */ 1) ! 465.605 us | } /* cgroup_attach_task = -22 */ ... --- v8: - Fix issues in ARM64 asm code - Fix issues in selftest - Add some comments on CONFIG_HAVE_FUNCTION_GRAPH_RETVAL - Make CONFIG_FUNCTION_GRAPH_RETVAL switable - Modify the control range of CONFIG_HAVE_FUNCTION_GRAPH_RETVAL v7: - Rename trace option 'graph_retval_hex' to 'funcgraph-retval-hex' - Introduce a new structure fgraph_ret_regs for each architecture to hold return registers - Separate each architecture modification info individual patches - Add a test case for funcgraph-retval - Update documentation description - Support LoongArch v6: - Remove the conversion code for short and char types, because these two types are rarely used to store an error code. - Modify the limitations for funcgraph-retval - Optimize the English expression v5: - Pass both the return values to ftrace_return_to_handler - Modify the parameter sequence of ftrace_return_to_handler to decrease the modification of assembly code, thanks to Russell King - Wrap __ftrace_return_to_handler with ftrace_return_to_handler for compatible - Describe the limitations of funcgraph-retval v4: - Modify commit message - Introduce new option graph_retval_hex to control display format - Introduce macro CONFIG_FUNCTION_GRAPH_RETVAL and CONFIG_HAVE_FUNCTION_GRAPH_RETVAL - Add related arch maintainers to review v3: - Modify the commit message: add trace logs processed with the btf tool v2: - Modify the commit message: use BTF to get the return type of function *** BLURB HERE *** Donglin Peng (8): function_graph: Support recording and printing the return value of function tracing: Add documentation for funcgraph-retval and funcgraph-retval-hex ARM: ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL arm64: ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL riscv: ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL x86/ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL LoongArch: ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL selftests/ftrace: Add funcgraph-retval test case Documentation/trace/ftrace.rst | 74 +++++++++++++++ arch/arm/Kconfig | 1 + arch/arm/include/asm/ftrace.h | 18 ++++ arch/arm/kernel/entry-ftrace.S | 6 +- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/ftrace.h | 20 ++++ arch/arm64/kernel/asm-offsets.c | 12 +++ arch/arm64/kernel/entry-ftrace.S | 27 +++--- arch/loongarch/Kconfig | 1 + arch/loongarch/include/asm/ftrace.h | 18 ++++ arch/loongarch/kernel/mcount.S | 6 +- arch/loongarch/kernel/mcount_dyn.S | 7 +- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/ftrace.h | 19 ++++ arch/riscv/kernel/mcount.S | 7 +- arch/x86/Kconfig | 1 + arch/x86/include/asm/ftrace.h | 18 ++++ arch/x86/kernel/ftrace_32.S | 8 +- arch/x86/kernel/ftrace_64.S | 7 +- include/linux/ftrace.h | 3 + kernel/trace/Kconfig | 15 +++ kernel/trace/fgraph.c | 23 ++++- kernel/trace/trace.h | 2 + kernel/trace/trace_entries.h | 26 ++++++ kernel/trace/trace_functions_graph.c | 93 +++++++++++++++++-- .../ftrace/test.d/ftrace/fgraph-retval.tc | 39 ++++++++ 26 files changed, 411 insertions(+), 42 deletions(-) create mode 100644 tools/testing/selftests/ftrace/test.d/ftrace/fgraph-retval.tc -- 2.25.1