From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.86 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796535109; b=pLa5Jl7U769bRpNk9RLqlDERfBM2iKdZf1Ik0WxWsRdjaDyZwN5qmEgqkXlrVSuqEXh9 A3eEyESf1Kgyw1TuSnG26mMNLx1Vtqu4FZHhW00myCrWnwXhDUHe+5sZ0I+g4ePM9ByRY iuysBAa7bckpgMSokDi3LhRkppcr5Ptud3XB8K4l2UmjEWXTYeGdOb8s+v5yhn7WY/B/A kOYcPg7ZhO15xyg9mzKfB454MzGZgyJjDZhJ8ncroYCh1gzbsJnN8LtRuGLdwb+VjR9q8 BIJ0N4NCgPxYJkqsGOhUFHLrB4KpdMPrDXOEmHT/fWYfyjVK5NX0ug27Nm7VxayZ6jg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796535109; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=wB3sqcFsQ26xgSz6JmnV9FS0QxEeW0iNk/PIzRmAuyM=; b=zZqoP0KhKpYcV8ZcnVGnYCBDPQNNPEBnPq7ZJ+mUR+FYpxnBdbljoy4BJ9xUa2IDTnys pmTMh9qiktk4B+bMa7YmjvJEQ+t67CUcKAwu6p6QV1VDCSevSQVoamYu+JFLPg13CUvCU dVOce5GDcB0O+5rejPXeijAkUAbIUxvlLSfnI2Sbtl7gIipakumMndz7Y6RBoi0qhMD7V TiAig8pPXkHzEMEbQc2ULn63yXMwFbD05s9mrVkxzxi7TweZkKi3/TTyZYCgU3588GtGw 0gRbwC52JNMa/u3PD2xGqDGB8VVtCsTpalhfAkp5wAGR/ogwA3Y5Vz13COAGve7liLQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=vqGJPBHQ; arc=none smtp.remote-ip=91.218.175.86 Received: from mta0.migadu.com (out-86.mta0.migadu.com [91.218.175.86]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1A92606A32F for ; Sun, 6 Dec 2026 05:31:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C1A92606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=vqGJPBHQ X-Envelope-To: stable@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=KAc3C0j7JdTH7DqF3wkSvgl2lwyJmY02vAG/zr3fV2Y=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796535106; v=1; x=1797139906; b=vqGJPBHQiwgqNwb7yTprY/ZjX805WUa1fqu44Xza8ObFGCG0h6IFikozMLj2c3uJYdrvqpOL +qqa/xPsHBJs2aIVxCy2FmmdxOXnauuTMFqi3AkJ3P3KVnRb4zQl4ySby246umzQ0gGlrJQSzCz AwQZKa+k7v1M3pyt9QOKLObg= X-Envelope-To: stable@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 3a7baa14cb44dc3a; Sun, 06 Dec 2026 05:31:46 +0000 X-Mizu-Trace-ID: 3a7baa14cb44dc3a X-Migadu-Flow: FLOW_OUT From: Tao Cui To: chenhuacai@kernel.org Cc: rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com, kernel@xen0n.name, hejinyang@loongson.cn, zhangqing@loongson.cn, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, loongarch@lists.linux.dev, stable@vger.kernel.org, cui.tao@linux.dev, Tao Cui Subject: [PATCH] LoongArch: ftrace: Fix return address offset in graph tracing Date: Sun, 6 Dec 2026 13:31:33 +0800 Message-ID: <20261206053133.302153-1-cui.tao@linux.dev> X-Mailer: git-send-email 2.53.0 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Tao Cui 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 --- arch/loongarch/kernel/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/loongarch/kernel/ftrace.c b/arch/loongarch/kernel/ftrace.c index 8c3ec1bc7aad..acdd5f1f8426 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--; if (is_ra_save_ins(insn)) - *ra_off = -((1 << 12) - insn->reg2i12_format.immediate); + *ra_off = insn->reg2i12_format.immediate; } while (!is_stack_alloc_ins(insn) && limit); -- 2.43.0