From nobody Sat Sep 26 12:26:49 2026 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 239A347F2CC for ; Tue, 1 Sep 2026 13:46:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788270379; cv=none; b=F153E/VqrXehqfI4wRmw0RQe+xoivv7ImMo826YLKGjUa7HBfbn9JYRQfhibKj0IarXLPBH8vyXNOgVYw4KbiEK1a7MTNyB+2zbEr2zGNVVspMxO9w8KWeJEQT+xKa0wSPRd7RV0VgAQvoeZbZf1t18u98+OT1R8ggBFzbYd7zc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788270379; c=relaxed/simple; bh=vTuXdHjoahpfvREK3vR0JpIpWmDjOwvXZYApg71J5w0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pY1X7Cadj67wDplQtBYe+3YN7O12V43JkEsRBXc7LpJXnRwf4GIB5oYF3h2DA8e4eSlTa+oI8ww1lnyAnd3SqvawtMPtB+ogHbixw8rXBsfyYZ4lnoY+nw3T5An13GFJF+HxpHUW3+Yho4AfC5rFVZZQoHwfFqMyDoh349bV0AA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mQubPDbH; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mQubPDbH" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-852c481415fso6067852b3a.3 for ; Tue, 01 Sep 2026 06:46:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788270377; x=1788875177; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VVcj/Jgo+entMeAtqsoiHxTBvbTk7zVsLySF0C5WcdM=; b=mQubPDbHp2C4r0ur3ETgpaE3iTvn5Q2owz3zGfUibQrN99R2igaGfQpmfnNHcvH+85 p7pX6URJbq3XijPUATSZbnvL+CovUQTu+uWYBjffuvp8Q7FrvBbGaAyMUZaSDnOgmE8V e3rUlOJWBM2MBI9Vdime67UDhyTC4qKa1FZWzZ+SuE7ifAQjw9mRBN6L1ilTBZKbCfqD o2O576aQxFOFlnqFEuc+Rpwv1HlI02BmGB8v16OGfUKRiyQvH7zV+qaPn4Mkb1NqdbyI BLxuGX+W0pUnp692Md5Eya6mZocWdrO1FHUpyxRXERf7ow4lVFX8Db+bYP6da3ODzBT+ UOBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788270377; x=1788875177; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=VVcj/Jgo+entMeAtqsoiHxTBvbTk7zVsLySF0C5WcdM=; b=Kd9VvwKv+1BHr+yMNekSR+uk8VG9xpMAfwpDhtPDiQ3A+ZYSNEsAXn1/mzxRcIIik3 9kZeSEhhgjNCyIshQ1xntDdAniqlmc4FRBJtfGyMhgW4/JIPmi6KfgLqA1zAzVC4u25Y vMRwC3tyaGv1Z78q/fNpXbKs3oK24ScZB+wE38ze84UXBmK5cUP1vDk+cQ1A8UjxYYud nBDrMHezZUp5mILXb2kHLnS+C3XPyzU1yr54DwvgpBOW9IVRK+m2p4orHK++wNNxdLWf N94j7G4yKh1XJfaWl90swuGsXOZxq5C6R30ruMeKsqQbiGRo4XkFw0ZhjyLP9I1/xlG5 LOIQ== X-Forwarded-Encrypted: i=1; AHgh+RqZsSTBzGHCQF/k61l7jhkNFIPmgYZIWlm+wJQcN2OP3dvf2o3M+hIiHPEzXmkV0D+6k/ANS77y6WZqX7M=@vger.kernel.org X-Gm-Message-State: AFuF++mKVBVCEJsIgAYPQk5q8zsbw7r+zr4Ntq9AGC+zrn3BHhWV5xyE CtoU4Ewvvf6+CzVOL2J7SdDrypoTH+pd8oyfeoth9iF0Wb6jbESInIuc X-Gm-Gg: AR+sD13FdFAtqj5n4qhpAnV0SaGOqb8wyi516T2J4m7TbQ/T7ZibvZJXrTQnon2jTRB 2dz3PLr+yUCvRKd57poFmKLiKp5V6omykn0sVOovp/S58jiApTAHjfj3bLSZd1Fc83ynirHrxBJ 0JIpxRvqvZvQwYtjQKdH64gHKqslv/pVzfpjfVjwvCa0kYBdo20NbYO1/62TZ7Z14TSiiQQaet8 C7dZdj7eGR/jnTIzGpyr0W32Pp58YjqUudy4jK7vz+EY16MbNPMBW0pUwVSpH8vVeignspLeP83 D1fSJXweY21CsWMWhFms4vSbTAlDsdeFNZJ8+8JHgkWH0+m2wW1qcSlOI+hDBErSwPrRIdJJuT1 8weWtrp4mizzM64hK5FLhqVl9+qbp6RFJmkER/2RCbdYN9Pf01TkJmQOamH+X30dtFXlIOQBAMt gvX/oY2xUBx5kTbGHxjy8B/DQVfMSFCThaAdoINu1y8MPkNEs89gTzryhZbIg+Xcwd9i71XKpsJ Jua X-Received: by 2002:a05:6a00:a221:b0:857:7337:5db9 with SMTP id d2e1a72fcca58-85773375f9cmr32559402b3a.23.1788270377256; Tue, 01 Sep 2026 06:46:17 -0700 (PDT) Received: from pengdl-pc.mioffice.cn ([43.224.245.249]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-85be8f52cb4sm1132502b3a.39.2026.09.01.06.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2026 06:46:16 -0700 (PDT) From: Donglin Peng To: rostedt@goodmis.org Cc: mhiramat@kernel.org, dolinux.peng@gmai.com, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, pengdonglin , Xiaoqin Zhang Subject: [PATCH v5 1/3] ftrace: Build trace_btf.c when CONFIG_DEBUG_INFO_BTF is enabled Date: Tue, 1 Sep 2026 21:46:02 +0800 Message-Id: <20260901134604.4052265-2-dolinux.peng@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260901134604.4052265-1-dolinux.peng@gmail.com> References: <20260901134604.4052265-1-dolinux.peng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: pengdonglin The trace_btf.c file provides BTF helper functions used by the ftrace subsystem. Make the compilation of trace_btf.c solely depend on CONFIG_DEBUG_INFO_BTF, allowing features like funcgraph-retval to also utilize these helpers. Additionally, the redundant dependency on CONFIG_PROBE_EVENTS_BTF_ARGS is removed, as CONFIG_DEBUG_INFO_BTF already depends on CONFIG_BPF_SYSCALL. Cc: Steven Rostedt (Google) Cc: Masami Hiramatsu Cc: Xiaoqin Zhang Signed-off-by: pengdonglin Acked-by: Masami Hiramatsu (Google) --- kernel/trace/Kconfig | 2 +- kernel/trace/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index 0ab5916575a9..d8faeb659cfc 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -770,7 +770,7 @@ config FPROBE_EVENTS config PROBE_EVENTS_BTF_ARGS depends on HAVE_FUNCTION_ARG_ACCESS_API depends on FPROBE_EVENTS || KPROBE_EVENTS - depends on DEBUG_INFO_BTF && BPF_SYSCALL + depends on DEBUG_INFO_BTF bool "Support BTF function arguments for probe events" default y help diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile index f934ff586bd4..28b08f31e7e5 100644 --- a/kernel/trace/Makefile +++ b/kernel/trace/Makefile @@ -119,7 +119,7 @@ obj-$(CONFIG_KGDB_KDB) +=3D trace_kdb.o endif obj-$(CONFIG_DYNAMIC_EVENTS) +=3D trace_dynevent.o obj-$(CONFIG_PROBE_EVENTS) +=3D trace_probe.o -obj-$(CONFIG_PROBE_EVENTS_BTF_ARGS) +=3D trace_btf.o +obj-$(CONFIG_DEBUG_INFO_BTF) +=3D trace_btf.o obj-$(CONFIG_UPROBE_EVENTS) +=3D trace_uprobe.o obj-$(CONFIG_BOOTTIME_TRACING) +=3D trace_boot.o obj-$(CONFIG_FTRACE_RECORD_RECURSION) +=3D trace_recursion_record.o --=20 2.34.1 From nobody Sat Sep 26 12:26:49 2026 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E11147F765 for ; Tue, 1 Sep 2026 13:46:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788270382; cv=none; b=J5tUrE9zo4BfoTmRQi19tCHxC75IgOC2yEWTmbqvG5uZf4ZXXEE5Sn43LuvKVm7efBa4znv7P0RVERaq9PgE19FTgqPOItorgdaPFo8NMaxei6bAqzM4IIBjlfBjiFO9WVgafCpqozjOSSWUXkoYJQ5Uf6duEPUXXf9CXJeCong= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788270382; c=relaxed/simple; bh=DbOu4itQQUQot2uL+glfUJyFG3dv01u2DN/NL0enzog=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R/Ds95hpvnQ8J71Oigauelmxb65wheYDJimxwKPT/4zcuW3P4JdXzDRNPxHSt4XPVHjIn/urC5tEhkAtRmAwYFt2O/sVC8RJeuOWpXnGLywqQgzELur0p4SxMM6xhymqGDcRChlUr2hHalVapVVGHLQ76Yl4Xp55srLEeK3xfx4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Qc9ywNg+; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Qc9ywNg+" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-84f3ab8750cso3721929b3a.0 for ; Tue, 01 Sep 2026 06:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788270380; x=1788875180; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BmXxudQOrIc1hrZ9sSNT8017ofPSKdmo87vA8sHUzVM=; b=Qc9ywNg+nwE9nejo2iQpSMmwhtlAkBZWGinsBKQKQiCqzYXnS0K0ijCmwWSiCkx82I KUwv4EAWNJ/i4GuQrqh+BbSITuHvzKAWxYcA6t/txl+fGhpXcRk06xlWDmjY0F50NggO nJ4DZG6/nlleUFRaJJhEdMrocr3TS+J+1ud7MZQOqoJaV7+mbO5hiN9vAOq6nwcjAYfA yZaObpQBsM81IfWowBWndyotqSs68ruwkxWJpsum0UM4Y7LU4CZUG+atO8TSWv9K+Z8S R7owp+ptkhL9+NdCOlTSZL4zg0YWDOdtvpOLqqz0wUJUFdJUGdrS195I/cM3ZxmpcjGB 9clA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788270380; x=1788875180; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=BmXxudQOrIc1hrZ9sSNT8017ofPSKdmo87vA8sHUzVM=; b=LiyLDd8i/vvXd5HCcLlRrMvoFh96j9zeh7pns0X7FWrUFkD8oFEigNQxYM3g5vFdYu Z4ODvqaCTsX3mx6Mtt2YdBvdJHsJYAWeJTtC4hDWAXERtjoajl7vqDUpkYjXwICw9iYL wsU50oAdAxzfAgNPVwmI9Q3xoBqspAeHQhR2GfRK7jlNbzi/4NP6qL0X3/NPO4L+W1nq GZ1upZDR32UAx2Bz1FW0CeKFGDn5FMQ3DMqtTMRHTg9NTo/n787wKHItAyYGxOb0xnpA y0EnixAJ/e/o2qOFTwj25IUAXlKB1ptpnPmcibxax/8WeD3jwAnWLJ7a1kpFJ2gCqa0q no1g== X-Forwarded-Encrypted: i=1; AHgh+RpBmvZWtGW469LG3ggnozUL1opMQ2BZ6BkN55vrvq0HYRxaMhCsxYma/nKXJt02o67qmA2gxAiuGo7V4qw=@vger.kernel.org X-Gm-Message-State: AFuF++muAKuMLrEegeF8e15bMi03DOaGAac/XD5WQwp/kj57sxg5a41A 90gotTgd4v7OTY+1MFbdVZO+Hj+YQTw1PtAJIBd2rOdJwZMPPEX8CcYqx3nNMnUnCI1Tuw== X-Gm-Gg: AR+sD13w1xqdx4GWK1w9ppgelsspg1Jbcp+LDEbd92HtubbxU9vcTXV3GVV5J5RTePG sQKLh7KZHq7aT1MLUDhunx/6AguJm4FY4sCuVGEfJGm7BfArts03AJszz/G9iND8hQWazD3uD73 HxeIvGpclFOpQjOz0AY3a/K8XGMEM3ShKeUvqJ319RBs4L4b7H5uJ1bKF3SajtwIroaIB8FhIxl JsOJQ8NJrLbeQE1/2S7KYiW/Wb67U+BlonsLKlcUnEptZqsBhAXuL5i6zQlV8QMlHzUOZ+0iNRW fAAW3eYO0n1ZHkKBeKmHmfl9wOfyaidxS4awbBr895Yq6G09XMtDIqVut9qwXZnvwZuDPKE7Eqk YT9nrHHJRSwr4gF9/4/0vn2MyTOATZr3rY90KEP5pScH+EYLZ0Ki526HeIssSZSd0f4TbsuzFf6 DUEE/Ycfnb8rI6PxFYB4aVQMUaRtp9oY0+FSJ38LgwZIQAMeQMXXDCJ3sav+zUfN50X/YhqhkL5 jju X-Received: by 2002:a05:6a00:a01:b0:845:ce5f:c926 with SMTP id d2e1a72fcca58-85b59593e6dmr11671845b3a.1.1788270379544; Tue, 01 Sep 2026 06:46:19 -0700 (PDT) Received: from pengdl-pc.mioffice.cn ([43.224.245.249]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-85be8f52cb4sm1132502b3a.39.2026.09.01.06.46.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2026 06:46:19 -0700 (PDT) From: Donglin Peng To: rostedt@goodmis.org Cc: mhiramat@kernel.org, dolinux.peng@gmai.com, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, pengdonglin , Xiaoqin Zhang Subject: [PATCH v5 2/3] fgraph: Enhance funcgraph-retval with BTF-based type-aware output Date: Tue, 1 Sep 2026 21:46:03 +0800 Message-Id: <20260901134604.4052265-3-dolinux.peng@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260901134604.4052265-1-dolinux.peng@gmail.com> References: <20260901134604.4052265-1-dolinux.peng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: pengdonglin The current funcgraph-retval implementation suffers from two accuracy issues: 1. Void-returning functions still print a return value, creating misleading noise in the trace output. 2. For functions returning narrower types (e.g., char, short), the displayed value can be incorrect because high bits of the register may contain undefined data. This patch addresses both problems by leveraging BTF to obtain the exact return type of each traced kernel function. The key changes are: 1. Void function filtering: Functions with void return type no longer display any return value in the trace output, eliminating unnecessary clutter. 2. Type-aware value formatting: The return value is now properly truncated to match the actual width of the return type before being displayed. Additionally, the value is formatted according to its type for better human readability. Here is an output comparison: Before: # perf ftrace -G vfs_read --graph-opts retval ... 1) | touch_atime() { 1) | atime_needs_update() { 1) 0.069 us | make_vfsuid(); /* ret=3D0x0 */ 1) 0.067 us | make_vfsgid(); /* ret=3D0x0 */ 1) | current_time() { 1) 0.197 us | ktime_get_coarse_real_ts64_mg(); /* ret=3D0x187= f886aec3ed6f5 */ 1) 0.352 us | } /* current_time ret=3D0x69380753 */ 1) 0.792 us | } /* atime_needs_update ret=3D0x0 */ 1) 0.937 us | } /* touch_atime ret=3D0x0 */ After: # perf ftrace -G vfs_read --graph-opts retval ... 2) | touch_atime() { 2) | atime_needs_update() { 2) 0.070 us | make_vfsuid(); /* ret=3D0x0 */ 2) 0.070 us | make_vfsgid(); /* ret=3D0x0 */ 2) | current_time() { 2) 0.162 us | ktime_get_coarse_real_ts64_mg(); 2) 0.312 us | } /* current_time ret=3D0x69380649(trunc) */ 2) 0.753 us | } /* atime_needs_update ret=3Dfalse */ 2) 0.899 us | } /* touch_atime */ Cc: Steven Rostedt (Google) Cc: Masami Hiramatsu Cc: Xiaoqin Zhang Signed-off-by: pengdonglin --- kernel/trace/trace_btf.c | 68 ++++++++++++++++++++++++++++ kernel/trace/trace_btf.h | 16 +++++++ kernel/trace/trace_functions_graph.c | 50 ++++++++++++++------ 3 files changed, 121 insertions(+), 13 deletions(-) diff --git a/kernel/trace/trace_btf.c b/kernel/trace/trace_btf.c index 00172f301f25..38825f566235 100644 --- a/kernel/trace/trace_btf.c +++ b/kernel/trace/trace_btf.c @@ -2,6 +2,7 @@ #include #include #include +#include =20 #include "trace_btf.h" =20 @@ -120,3 +121,70 @@ const struct btf_member *btf_find_struct_member(struct= btf *btf, return member; } =20 +#ifdef CONFIG_DEBUG_INFO_BTF +void btf_trim_retval(unsigned long func, unsigned long *retval, bool *prin= t_retval, + int *fmt) +{ + const struct btf_type *t; + char name[KSYM_NAME_LEN]; + struct btf *btf; + u32 v, msb; + int kind; + + if (lookup_symbol_name(func, name)) + return; + + t =3D btf_find_func_proto(name, &btf); + if (IS_ERR_OR_NULL(t)) + return; + + t =3D btf_type_skip_modifiers(btf, t->type, NULL); + kind =3D t ? BTF_INFO_KIND(t->info) : BTF_KIND_UNKN; + switch (kind) { + case BTF_KIND_UNKN: + *print_retval =3D false; + break; + case BTF_KIND_STRUCT: + case BTF_KIND_UNION: + case BTF_KIND_ENUM: + case BTF_KIND_ENUM64: + if (kind =3D=3D BTF_KIND_STRUCT || kind =3D=3D BTF_KIND_UNION) + *fmt =3D RETVAL_FMT_HEX; + else + *fmt =3D RETVAL_FMT_DEC; + + if (t->size > sizeof(unsigned long)) { + *fmt |=3D RETVAL_FMT_TRUNC; + } else { + msb =3D BITS_PER_BYTE * t->size - 1; + *retval &=3D GENMASK(msb, 0); + } + break; + case BTF_KIND_INT: + v =3D *(u32 *)(t + 1); + if (BTF_INT_ENCODING(v) =3D=3D BTF_INT_BOOL) { + *fmt =3D RETVAL_FMT_BOOL; + msb =3D 0; + } else { + if (BTF_INT_ENCODING(v) =3D=3D BTF_INT_SIGNED) + *fmt =3D RETVAL_FMT_DEC; + else + *fmt =3D RETVAL_FMT_HEX; + + if (t->size > sizeof(unsigned long)) { + *fmt |=3D RETVAL_FMT_TRUNC; + msb =3D BITS_PER_LONG - 1; + } else { + msb =3D BTF_INT_BITS(v) - 1; + } + } + *retval &=3D GENMASK(msb, 0); + break; + default: + *fmt =3D RETVAL_FMT_HEX; + break; + } + + btf_put(btf); +} +#endif diff --git a/kernel/trace/trace_btf.h b/kernel/trace/trace_btf.h index 4bc44bc261e6..3675d99c22eb 100644 --- a/kernel/trace/trace_btf.h +++ b/kernel/trace/trace_btf.h @@ -1,6 +1,13 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include =20 +enum { + RETVAL_FMT_HEX =3D BIT(0), + RETVAL_FMT_DEC =3D BIT(1), + RETVAL_FMT_BOOL =3D BIT(2), + RETVAL_FMT_TRUNC =3D BIT(3), +}; + const struct btf_type *btf_find_func_proto(const char *func_name, struct btf **btf_p); const struct btf_param *btf_get_func_param(const struct btf_type *func_pro= to, @@ -9,3 +16,12 @@ const struct btf_member *btf_find_struct_member(struct bt= f *btf, const struct btf_type *type, const char *member_name, u32 *anon_offset); +#ifdef CONFIG_DEBUG_INFO_BTF +void btf_trim_retval(unsigned long func, unsigned long *retval, bool *prin= t_retval, + int *fmt); +#else +static inline void btf_trim_retval(unsigned long func, unsigned long *retv= al, + bool *print_retval, int *fmt) +{ +} +#endif diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_func= tions_graph.c index ff7cb1a76b95..89a64982df2c 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c @@ -15,6 +15,7 @@ =20 #include "trace.h" #include "trace_output.h" +#include "trace_btf.h" =20 /* When set, irq functions might be ignored */ static int ftrace_graph_skip_irqs; @@ -877,7 +878,7 @@ static void print_graph_retval(struct trace_seq *s, str= uct ftrace_graph_ent_entr unsigned long retval =3D 0; bool print_retaddr =3D false; bool print_retval =3D false; - bool hex_format =3D !!(opt_flags & TRACE_GRAPH_PRINT_RETVAL_HEX); + int retval_fmt =3D 0; =20 #ifdef CONFIG_FUNCTION_GRAPH_RETVAL retval =3D graph_ret->retval; @@ -888,17 +889,35 @@ static void print_graph_retval(struct trace_seq *s, s= truct ftrace_graph_ent_entr print_retaddr =3D !!(opt_flags & TRACE_GRAPH_PRINT_RETADDR); #endif =20 - if (print_retval && retval && !hex_format) { - /* Check if the return value matches the negative format */ - if (IS_ENABLED(CONFIG_64BIT) && (retval & BIT(31)) && - (((u64)retval) >> 32) =3D=3D 0) { - err_code =3D sign_extend64(retval, 31); - } else { - err_code =3D retval; + if (print_retval) { + int fmt =3D RETVAL_FMT_HEX; + + btf_trim_retval((unsigned long)func, &retval, &print_retval, &fmt); + if (print_retval) { + if (opt_flags & TRACE_GRAPH_PRINT_RETVAL_HEX) + retval_fmt =3D RETVAL_FMT_HEX; + + if (retval && retval_fmt !=3D RETVAL_FMT_HEX) { + /* Check if the return value matches the negative format */ + if (IS_ENABLED(CONFIG_64BIT) && (retval & BIT(31)) && + (((u64)retval) >> 32) =3D=3D 0) { + err_code =3D sign_extend64(retval, 31); + } else { + err_code =3D retval; + } + + if (!IS_ERR_VALUE(err_code)) + err_code =3D 0; + } + + if (retval_fmt =3D=3D RETVAL_FMT_HEX) { + retval_fmt |=3D (fmt & RETVAL_FMT_TRUNC); + } else { + if (err_code && fmt & RETVAL_FMT_HEX) + fmt =3D (fmt & ~RETVAL_FMT_HEX) | RETVAL_FMT_DEC; + retval_fmt =3D fmt; + } } - - if (!IS_ERR_VALUE(err_code)) - err_code =3D 0; } =20 if (entry) { @@ -925,10 +944,15 @@ static void print_graph_retval(struct trace_seq *s, s= truct ftrace_graph_ent_entr trace_flags, false); =20 if (print_retval) { - if (hex_format || (err_code =3D=3D 0)) + if (retval_fmt & RETVAL_FMT_HEX) trace_seq_printf(s, " ret=3D0x%lx", retval); + else if (retval_fmt & RETVAL_FMT_BOOL) + trace_seq_printf(s, " ret=3D%s", retval ? "true" : "false"); else - trace_seq_printf(s, " ret=3D%ld", err_code); + trace_seq_printf(s, " ret=3D%ld", err_code ?: retval); + + if (retval_fmt & RETVAL_FMT_TRUNC) + trace_seq_printf(s, "(trunc)"); } =20 if (!entry || print_retval || print_retaddr) --=20 2.34.1 From nobody Sat Sep 26 12:26:49 2026 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B986947F779 for ; Tue, 1 Sep 2026 13:46:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788270384; cv=none; b=CcPtlL5EcQ0Z3jZnJ7IbLgdxMYQWNqfFbZ4pCKmVzs8jdmbeBWbfUlf9YbxjtzyEa/BcQYg8fk5dWdFwIr+A0CpAwTaCP79RMBXqGzaLwIHP0qkIsSPUAVv4jx1/4iO+eFLxN2CVONmPKd3IrQ5VRxK+yn0+i6ANHBvv34yVwLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788270384; c=relaxed/simple; bh=Dr1eFYf0KAOq3d4noAOFx4h+3dYSj5kdLG8+hPm06U4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qLQohgThTZFx3STB3KYUl2sAlC+IaetyEzBlMxpD02u4j50R9S2XeaWK+2Y3c2v326vrcBF5eJaR50T6/SWpRS/3MtQKX19mrnZTwuP37KBzvcyCFJlX9DHSfFvfE7WLqFKIgkaNkofmnlMdqxpS0iuSG+0TKQ/vj8y2uE+9QyA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=rNP3qjVj; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rNP3qjVj" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-ca766c1c9ccso3323947a12.0 for ; Tue, 01 Sep 2026 06:46:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788270382; x=1788875182; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FDTK3zfJKeOHQ/kUEowX8lWsllkazH/BKZLeMUQjwCQ=; b=rNP3qjVjLYOmqhDyaNIy/7xn/adqumZXSEO+ADZBeYMudNITt6O03VwC3/tBMzbbf0 p5LZk7C4FT4ldgFToRNVJ4MN+oHtUROn8sFeiUJwtX4lhkyGFb4c73jdnzP4oowMN2aO v451jIGSaUmC/vm970rx5SiXO7LicpyPKaE0xOCFZ5ei46prjq9anxt9ehBKPv539/kD iqADRlPMF8OE8gYLRzN4ROuDgrBO4iBR0h0ESgHQzytJwitUl1vKSTKvMHDkdLIN0D50 kR0bDLKJsxlhieIgJBB99Fnp9S/+pdgSvcc/AsyXcl1CIWwvLs3fbwVn6FnEVJ1rnPd7 0I3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788270382; x=1788875182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=FDTK3zfJKeOHQ/kUEowX8lWsllkazH/BKZLeMUQjwCQ=; b=pp+SfbLePnJ6REo7whkaZK13r8yv7qrRAU8rZeHxLebU//WYbYZqDh2SWoFq4WoQSd 1Rdvedkr2IsPoQ3LkaS2LtfMv7LZ7xgOK/KcHYKILzs46UjSjh5A3WC6tI41LH5c52sm K669AEPxToMZLaCpO7QNZ2kgI4flMMgi5cWSlcr728k2mg8O928+jSS6u8pmRNNEy1lG MkiYsFOkqPx4pouKIpNGYzdrNnqvc39gKM8bWFNosVhbfPnCkngKGY9u8BBBV1+MRB8k W4R3X3wwqHQetado0/4/uiRyvpeO9h+EwqW6F6nad9Upkgv6HK8RFfUnGeBnlBCee/Xy MWMg== X-Forwarded-Encrypted: i=1; AHgh+RpgrqZCyBSS2SWZN/JxaMQZJvBPgfjDQboAcKHa3/Ly/7anE+QbsDOkusSOvDc+q4oXLlH5MDeBVVMMn50=@vger.kernel.org X-Gm-Message-State: AFuF++nYeToFU9p+JsE994Pz+Ux8snqU91gTmKlLER++9JR0ZrJ4Urf6 DTxuVwnuCdUFdsXOvXLWhtKmn1+KrMylPdGfi7QCuPomGfftxJZb4N0G X-Gm-Gg: AR+sD115Bkly26NHHXINIl2qR2IDIV1tfWcTZ9tJdKhsYf3tiNFBwAyksRec+f61nUk MsLotngngoZF+ViwLiYP5nD4NBvK4+gDuhYXVVlqt6++QFATnBYsXU1zGQGFPvBd96jHQuOyVZx j43anmLIggWHHPQXFkItovqOc6Clp4yP0J+HPGkrTz1DyL3rnP0aues6f5J+rtCEM3re0Gk9+Lx otZTUdQ90kZbwwsgkbnV2KekHpj93T9ehsnMVw1XyMd3AM1c23aNZfVygqD7Uwx6I0rjs3eOMBh BCe+H7zle1TDWwwz9wfNipzi3sarM8qsEzYObrc4EX1V3M7CJL7hYY33Q6pIbwrHQYxNzh+2IX4 2lwyiEH3XFZ7EyL2koiKUn9BMZ8U8UxY52SZ+JzQAR3vDyYJClaxfRGCoIz8s+ybNHc6LBRxc2b wSLr6y1mtWnGSBuglbMtWMzqLYzHGSAhHwGs4y6W+oo2uED35MdyuAH70ykM4V/wQ9cGf6Mdg2h 8IkltF4S+N4sOc= X-Received: by 2002:a05:6a00:8015:b0:842:2419:6c0b with SMTP id d2e1a72fcca58-8562b499a0dmr53844448b3a.10.1788270381890; Tue, 01 Sep 2026 06:46:21 -0700 (PDT) Received: from pengdl-pc.mioffice.cn ([43.224.245.249]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-85be8f52cb4sm1132502b3a.39.2026.09.01.06.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2026 06:46:21 -0700 (PDT) From: Donglin Peng To: rostedt@goodmis.org Cc: mhiramat@kernel.org, dolinux.peng@gmai.com, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, pengdonglin , Xiaoqin Zhang Subject: [PATCH v5 3/3] tracing: Update funcgraph-retval documentation Date: Tue, 1 Sep 2026 21:46:04 +0800 Message-Id: <20260901134604.4052265-4-dolinux.peng@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260901134604.4052265-1-dolinux.peng@gmail.com> References: <20260901134604.4052265-1-dolinux.peng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: pengdonglin The existing documentation for funcgraph-retval is outdated and partially incorrect, as it describes limitations that have now been resolved. Recent changes (e.g., using BTF to obtain function return types) have addressed key issues: 1. Return values are now printed only for non-void functions. 2. Values are trimmed to the correct width of the return type, avoiding garbage data from high bits. Cc: Steven Rostedt (Google) Cc: Masami Hiramatsu Cc: Xiaoqin Zhang Signed-off-by: pengdonglin --- Documentation/trace/ftrace.rst | 88 +++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/Documentation/trace/ftrace.rst b/Documentation/trace/ftrace.rst index 7261f25f8b4b..696bfbede590 100644 --- a/Documentation/trace/ftrace.rst +++ b/Documentation/trace/ftrace.rst @@ -1483,6 +1483,10 @@ Options for function_graph tracer: printed in hexadecimal format. By default, this option is off. =20 + funcgraph-retaddr + When set, the return address will always be printed. + By default, this option is off. + sleep-time When running function graph tracer, to include the time a task schedules out in its function. @@ -2829,7 +2833,7 @@ It is default disabled. 0) 2.861 us | } /* putname() */ =20 The return value of each traced function can be displayed after -an equal sign "=3D". When encountering system call failures, it +an equal sign "ret=3D". When encountering system call failures, it can be very helpful to quickly locate the function that first returns an error code. =20 @@ -2839,16 +2843,16 @@ returns an error code. Example with funcgraph-retval:: =20 1) | cgroup_migrate() { - 1) 0.651 us | cgroup_migrate_add_task(); /* =3D 0xffff93fcfd= 346c00 */ + 1) 0.651 us | cgroup_migrate_add_task(); /* ret=3D0xffff93fc= fd346c00 */ 1) | cgroup_migrate_execute() { 1) | cpu_cgroup_can_attach() { 1) | cgroup_taskset_first() { - 1) 0.732 us | cgroup_taskset_next(); /* =3D 0xffff93fc= 8fb20000 */ - 1) 1.232 us | } /* cgroup_taskset_first =3D 0xffff93fc8f= b20000 */ - 1) 0.380 us | sched_rt_can_attach(); /* =3D 0x0 */ - 1) 2.335 us | } /* cpu_cgroup_can_attach =3D -22 */ - 1) 4.369 us | } /* cgroup_migrate_execute =3D -22 */ - 1) 7.143 us | } /* cgroup_migrate =3D -22 */ + 1) 0.732 us | cgroup_taskset_next(); /* ret=3D0xffff93= fc8fb20000 */ + 1) 1.232 us | } /* cgroup_taskset_first ret=3D0xffff93fc= 8fb20000 */ + 1) 0.380 us | sched_rt_can_attach(); /* ret=3D0x0 */ + 1) 2.335 us | } /* cpu_cgroup_can_attach ret=3D-22 */ + 1) 4.369 us | } /* cgroup_migrate_execute ret=3D-22 */ + 1) 7.143 us | } /* cgroup_migrate ret=3D-22 */ =20 The above example shows that the function cpu_cgroup_can_attach returned the error code -22 firstly, then we can read the code @@ -2865,37 +2869,41 @@ printed in hexadecimal format. Example with funcgraph-retval-hex:: =20 1) | cgroup_migrate() { - 1) 0.651 us | cgroup_migrate_add_task(); /* =3D 0xffff93fc= fd346c00 */ + 1) 0.651 us | cgroup_migrate_add_task(); /* ret=3D0xffff93= fcfd346c00 */ 1) | cgroup_migrate_execute() { 1) | cpu_cgroup_can_attach() { 1) | cgroup_taskset_first() { - 1) 0.732 us | cgroup_taskset_next(); /* =3D 0xffff93= fc8fb20000 */ - 1) 1.232 us | } /* cgroup_taskset_first =3D 0xffff93fc= 8fb20000 */ - 1) 0.380 us | sched_rt_can_attach(); /* =3D 0x0 */ - 1) 2.335 us | } /* cpu_cgroup_can_attach =3D 0xffffffea = */ - 1) 4.369 us | } /* cgroup_migrate_execute =3D 0xffffffea */ - 1) 7.143 us | } /* cgroup_migrate =3D 0xffffffea */ - -At present, there are some limitations when using the funcgraph-retval -option, and these limitations will be eliminated in the future: - -- Even if the function return type is void, a return value will still - be printed, and you can just ignore it. - -- Even if return values are stored in multiple registers, only the - value contained in the first register will be recorded and printed. - To illustrate, in the x86 architecture, eax and edx are used to store - a 64-bit return value, with the lower 32 bits saved in eax and the - upper 32 bits saved in edx. However, only the value stored in eax - will be recorded and printed. - -- In certain procedure call standards, such as arm64's AAPCS64, when a - type is smaller than a GPR, it is the responsibility of the consumer - to perform the narrowing, and the upper bits may contain UNKNOWN values. - Therefore, it is advisable to check the code for such cases. For instanc= e, - when using a u8 in a 64-bit GPR, bits [63:8] may contain arbitrary value= s, - especially when larger types are truncated, whether explicitly or implic= itly. - Here are some specific cases to illustrate this point: + 1) 0.732 us | cgroup_taskset_next(); /* ret=3D0xffff= 93fc8fb20000 */ + 1) 1.232 us | } /* cgroup_taskset_first ret=3D0xffff93= fc8fb20000 */ + 1) 0.380 us | sched_rt_can_attach(); /* ret=3D0x0 */ + 1) 2.335 us | } /* cpu_cgroup_can_attach ret=3D0xffffffe= a */ + 1) 4.369 us | } /* cgroup_migrate_execute ret=3D0xffffffea= */ + 1) 7.143 us | } /* cgroup_migrate ret=3D0xffffffea */ + +Note that there are some limitations when using the funcgraph-retval +option: + +- If CONFIG_DEBUG_INFO_BTF is disabled (n), a return value is printed even= for + functions with a void return type. When CONFIG_DEBUG_INFO_BTF is enabled= (y), + the return value is printed only for non-void functions. + +- If a return value occupies multiple registers, only the value in the fir= st + register is recorded and printed. For example, on the x86 architecture, a + 64-bit return value is stored across eax (lower 32 bits) and edx (upper = 32 bits), + but only the contents of eax are captured. If CONFIG_DEBUG_INFO_BTF is e= nabled, + the suffix "(trunc)" is appended to the printed value to indicate that t= he + output may be truncated because high-order register contents are omitted. + +- Under certain procedure-call standards (e.g., arm64's AAPCS64), when the= return + type is smaller than a general-purpose register (GPR), the caller is res= ponsible + for narrowing the value; the upper bits of the register may contain unde= fined data. + For instance, when a u8 is returned in 64-bit GPR, bits [63:8] can hold = arbitrary + values, especially when larger types are truncated (explicitly or implic= itly). It + is therefore advisable to inspect the code in such cases. If CONFIG_DEBU= G_INFO_BTF + is enabled (y), the return value is automatically trimmed to the width o= f the return + type. + + The following examples illustrate the behavior: =20 **Case One**: =20 @@ -2914,7 +2922,9 @@ option, and these limitations will be eliminated in t= he future: RET =20 If you pass 0x123456789abcdef to this function and want to narrow it, - it may be recorded as 0x123456789abcdef instead of 0xef. + it may be recorded as 0x123456789abcdef instead of 0xef. When + CONFIG_DEBUG_INFO_BTF is enabled, the value will be correctly truncated + to 0xef based on the size constraints of the u8 type. =20 **Case Two**: =20 @@ -2939,7 +2949,9 @@ option, and these limitations will be eliminated in t= he future: RET =20 When passing 0x2_0000_0000 to it, the return value may be recorded as - 0x2_0000_0000 instead of 0. + 0x2_0000_0000 instead of 0. When CONFIG_DEBUG_INFO_BTF is enabled, the + value will be correctly truncated to 0 based on the size constraints of + the int type. =20 You can put some comments on specific functions by using trace_printk() For example, if you want to put a comment inside --=20 2.34.1