From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796536449; b=KBg1ZfnuOhzEvTu15hW5+sFuvAKCHWDKnqk2onspemDuLWblCx8sehdX7UtZ85DEJbnl 7FHh4viOVI+7RqfNZgiMnPHzG9TThffZA2RP5L2hbRAMU/7x6Konv36b1I5vjcoY4qVfd KP7aTM/LcovG1vAbUmatMDy24hWvsGBEnx5+PiRH1L3j+lrmYNaZlFjo/yh/GDWNQO78g B/fmxVDzqQpZYv4aM01Kl0gvAzZmZSYUSOvewAt4EPERk1jOiTzHdEeoPXvEu+wbqV00V v3NKKHFxMQINHTUDfl6kszkSYUc8RiZ9vIyPLMF+RSOAQN2Q37Vzumzvh/e5CbNdgUg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796536449; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=pvpL9Y+UXADkWoA0y6h6KnP0T0lzzLqD7afjfdprCQo=; b=k2c9bmyAQE5ZLLpNGz7VMXNtwn5xKsfIZdo+fWlMG011Q9a3NBwK/v7hVPeFEy22mFlB 8mKopp29H0+3WkYN+a2GFnuu9fgHlCacz2ExXQ+hdVeckZim4mAk1dH0grq0iGWmoEgrr bdcYPHh2sGjca1FhCmlPtU2EZK33bAN/GQvhkVngtxSTF6Sd1+qTsjC1gQbsp7Yjs2ew8 hLcGEn3gHWz5AajlOkp0kBkbWWuy6rT/1s3Ie7JhnM02yRyWtrfvAq/tFohGjhaLSPuv2 Fkwad4XR2jTHbLQF+Exdl6VXfwYt/r7KxCq8YUymxLyIB3J1vzRmegYXy9CGcs8goog== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="eZ6sb/RN"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93F5E606A31F for ; Sun, 6 Dec 2026 05:54:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eZ6sb/RN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 106161F0092B; Sun, 6 Dec 2026 05:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796536449; bh=pvpL9Y+UXADkWoA0y6h6KnP0T0lzzLqD7afjfdprCQo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=eZ6sb/RNASmgoc4nVOW7Ui4STJaMlQ+e9nMvxXEn+OvVwn/CKS3ZaDdDrMhqXVLwA Ix5XGQ051ZLeJfyKbXIYRxN99FoT72ta4B9IqheJP+m8J4WizdSL16Dtw9nXWxELPA M+2Fv/xz4e8lsIDE+fjpJFOP+qkU1v6YYQPWjBQlyMcGObgimjcsWTGKZQLlqeg1q7 8YIE+q590sM01TW7tCJHliCdaCheeArK/8ZESpI3cL1R033l/u/GAupJIJTDh3Z+0a Ke3oNMmCzgviESuLJxw2FT7HtoEdOq0Gxydd6MjKnsIkcw3yk326B8dcgb7cDyHpYn HBkbQ3IGBh6/w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] LoongArch: ftrace: Fix return address offset in graph tracing Reply-To: sashiko-reviews@lists.linux.dev To: "Tao Cui" Cc: linux-trace-kernel@vger.kernel.org In-Reply-To: <20261206053133.302153-1-cui.tao@linux.dev> References: <20261206053133.302153-1-cui.tao@linux.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 05:54:08 +0000 X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] loongarch/ftrace: commit message has impossible reproducer and wrong details - [Low] loongarch/ftrace: patch targets unbuildable dead static ftrace code -- commit 5dd6722f0e3a28bf20fd98220d167b2e44d4295f Author: Tao Cui > LoongArch: ftrace: Fix return address offset in graph tracing > > Enabling the function graph tracer on LoongArch breaks tracing: the > recorded call tree does not match what the traced function actually > calls, and set_graph_function cannot scope the trace to the requested > function. With set_graph_function set to vfs_write, the tracer > records a bogus vfs_write frame whose children are unrelated IRQ > handlers: > > 0) | vfs_write() { > 0) | irq_enter_rcu() { > 0) ! 130.380 us | irqtime_account_irq(); > 0) | handle_cpu_irq() { > 0) | hrtimer_interrupt() { ... > > Worse, for shallow frames the tracer writes 8 bytes below the thread > stack, and LoongArch has no VMAP_STACK, so neighbouring kernel > allocations get corrupted. > > The offset of the saved return address is computed by > ftrace_get_parent_ra_addr(), which scans the function prologue for the > "st.d ra, sp, imm" instruction. is_ra_save_ins() only accepts a > non-negative imm, so the slot is sp + imm, but the offset is evaluated > as -((1 << 12) - imm), i.e. imm - 4096: the tracer reads the parent > address from, and stores its return hook 4096 bytes below, the real > slot. > > Compute the offset directly from the encoded immediate. The graph > tracer then records the scoped subtree: > > 1) | vfs_write() { > 1) | rw_verify_area() { > 1) ! 125.050 us | security_file_permission(); > 1) | } > > This path is reached only through the function graph tracer; plain > function tracing passes the parent address in registers. > > Fixes: dbe3ba3018ec1fc5 ("LoongArch/ftrace: Add basic support") > Cc: stable@vger.kernel.org > Signed-off-by: Tao Cui [Severity: Medium] Can the commit message's reproducer and traces be generated by the modified code? arch/loongarch/kernel/ftrace.c is only built when CONFIG_DYNAMIC_FTRACE is disabled, which the changelog does not mention. In kernel/trace/ftrace.c, set_graph_function is only registered in ftrace_init_dyn_tracefs() under CONFIG_DYNAMIC_FTRACE, so it does not exist when ftrace.c is compiled. Also, prepare_ftrace_return() receives the parent return address in its old parameter and only writes return_hooker to callsite_sp + ra_off, without reading from that slot. Finally, LoongArch uses a 16 KiB (THREAD_SIZE) downward-growing kernel stack, so subtracting up to 4096 bytes stays inside the stack on shallow frames and only underflows below the stack base on deep call stacks. > diff --git a/arch/loongarch/kernel/ftrace.c b/arch/loongarch/kernel/ftrac= e.c > index 8c3ec1bc7aad3..acdd5f1f84263 100644 > --- a/arch/loongarch/kernel/ftrace.c > +++ b/arch/loongarch/kernel/ftrace.c > @@ -36,7 +36,7 @@ static int ftrace_get_parent_ra_addr(unsigned long insn= _addr, int *ra_off) > limit--; > =20 > if (is_ra_save_ins(insn)) > - *ra_off =3D -((1 << 12) - insn->reg2i12_format.immediate); > + *ra_off =3D insn->reg2i12_format.immediate; > =20 > } while (!is_stack_alloc_ins(insn) && limit); [Severity: Low] Can arch/loongarch/kernel/ftrace.c still be built on mainline? arch/loongarch/kernel/Makefile only builds ftrace.o when CONFIG_DYNAMIC_FTRACE is disabled, while arch/loongarch/Kconfig unconditionally selects HAVE_DYNAMIC_FTRACE. Since commit 9b4d5d330fcd ("ftrace: Make DYNAMIC_FTRACE always enabled for architectures that support it"), DYNAMIC_FTRACE is promptless with default y, so this file cannot be compiled or tested on mainline. Even if CONFIG_DYNAMIC_FTRACE were forced off, ftrace_startup_subops() in kernel/trace/ftrace_internal.h returns -EINVAL, preventing register_ftrace_graph() from registering graph_ops. If this fix is only meant for backporting to pre-6.17 stable branches, stating that scope in the commit message would clarify it; otherwise, the dead static ftrace code could be removed. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206053133.3021= 53-1-cui.tao@linux.dev?part=3D1