From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796170740; b=uEOqiXUsLmneCrbTj3Wknj7d27m7nivDNguySut8wHuAAINaCJYDkrW1qDZRmkj+t4SV 0F0W3jxaYZ6KzGxQJzledTYPMP9JxdMZ8IaFV3ktzk1akg/MJ0RVXBjJuocgh0/Dudn8l LGNKfHri4Ok/AnMI1yJtkBH1j6HciH8z+fTiahYA4QBCK1hPMqvBnh46FXUwXgGTdx6Bu a7gOI9FsbJJwnYzCoI0LUB2HqgxdvfBLbys7WkU/NrwheLgZbxbw6oc2OKDEDE6bEoGP9 MF3A8ldubkl0JYnWZ29r46/EJEKfTr0sE9IMEBShUTUwp7GW6Gagp8NFQUJq3AjgNWA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796170740; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=7bOkrj0Sb2XtjVLjv++X4TYgssspWZuw3ZbOJC8/EXY=; b=iUo9FDOl/alDs7hEt7mEaUg02PcE+BrWgCeoG24BcKpsage5kDKvQDWxcM1ml8trT5AJ o1/wze2orMJU/q4Th3HFh8A+Xa+BbiDK8yvCkmodx064r7BO1IlBYIngJ6Svhbkc1jHvA rbvdqi1BUW0ptnAeV3He2tSYR8mfQEJo7BqslCRnkDuKy/PgbOKaeLd/lZVwIlvjEsIaR nZ/0HByqHi7l6jsWFdIemk2C78kNcGXIVQEGEOXzlIQSS2j1QgqM7fdc9FRgvX2+gWFxx QNBLFQ8fuqaSTGvDpUP/mj2ZpQmgTNrYx/fQGannRhuo+vIkWRNSmOJFRXDVQzhw5mA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=aJ8wXngQ; arc=none smtp.remote-ip=209.85.222.180 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (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 D6BE5606A31A for ; Wed, 2 Dec 2026 00:18:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D6BE5606A31A 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.a=rsa-sha256 header.s=20260707 header.b=aJ8wXngQ Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-9496577d4c4so1397152885a.1 for ; Tue, 01 Dec 2026 16:18:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796170739; x=1796775539; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=7bOkrj0Sb2XtjVLjv++X4TYgssspWZuw3ZbOJC8/EXY=; b=aJ8wXngQzUfsxyGiRYuRnV2RZPEbTQ8Saa1TJGD3NXWtFW5UnTcWTDcL6qfaM+3WCa lHekoT3y/IL9HMUo4+p8PiAR/2FpnzGsDrZocpLuWbhySn9NE/HEj5vr2rmFkCAiO9gx E5v5C2P+WhtAuTEFXT56FUBfiaHu3Ino9wBPklmOWA5Md7BPZyRmfrc8c0QFvEFKML29 KypZeSk4SXZHJPC27n+975NfseWSQ5CdDa40UcFhlkoqBqhoR5NwxZYAJwiCkykWElta hO7fLeW6e0hRq/RQ7xeu0mFqUr/ZOuBp+un15PcFkksxRuQq8ZoLDWU9oKIN85AaR0yH f2HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796170739; x=1796775539; h=content-transfer-encoding:mime-version: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=7bOkrj0Sb2XtjVLjv++X4TYgssspWZuw3ZbOJC8/EXY=; b=pjW3seCecM7C9/hKyMC/u0SMuYfekJ/taB+uMUoQ4FYUu+CfyyjdKQrU9+dVzkWorm lWI677DPEy2F3h28M8FvVYIzgwX+gdHZEUhWINHKyoufUo72fFHCl03uujnc6WDqqy1l BYv6nd6Sh7olDQXdRBQZwHnnVfIucq+SQyEos3g57GcjFK3w4iA6utF6/QuXbcl3omQ5 HtQ7BupiifHNv2PSq9lPyNW9JNqiaChTMTQu27XNtq+2/Hl3izzSblcT/p4mGWzptZXS ASFPBsynhc9a8RqDjWObZzDx4oBj5L5hSEFg374YM88QJA/1JeaVYeAmNaU4VIdsLPQp VYQw== X-Forwarded-Encrypted: i=1; AL+hErFxm16g++UN3/B8Zbk0JMP2/IA4CG+eVs6Lc7AYNBECZnwmEqHcWVxUX3FPGnKstELYRdJZWnOoIdA6Duc=@vger.kernel.org X-Gm-Message-State: APuU4Z9/PlouI073wGeLJyhWk0dwBI22udIuFVnNYXnE1DxhCt3pG6Ej SMXY1KvchzYNx456m9ygLJMKnRh6cYt5/abDboG67aLQfce8dExeJk0k21m15dDy X-Gm-Gg: AZFdTZfw8Rk7qU3EZXQLfVC6EKAtAXZv1FOmMOFSUPS8+kNq+xZCtxGD4A6L00+XuNp 912frqFU3aqqZSYQN1cumuWRPiDueFEbULrXRnfspjKd3DEICiAWm/rqktgMUhsGsawRTTDwlZT lDigK9gs0vazvObt+gF8UI5vRpGv0ESQ3ZGf5s9OIhL1NcJbPrRh2okHcIDV4pX3bFB4AwDPe7S FwyW3w2K2Jg48mb70rIu2YSgEEXHgvhiWmFjSjNqiNNl/1PTRiTuXwZrK4ByF+Tu9TAcbHtYQhI dONSXDwZ6mbJaEFgF/YBwbSs3S3YLzW5V/uO2KmdHochTuTQuTdbIidD6b0PcloKbffCPAGE36e GYkNrRRNNx4tYNpuY+GwuomHD3nLaEP9bjNpWmdtqp152DKLA2Mjp8Gjxe9PnSHBecYQKxlfNgy DWxEb1kQTCHJ1Xtz+tosV6tnuFlDdZ8Sxlw+wqXdUNGsU5o/+GCSYEV3Y0T4c/wJyJEk80RWBmc fW+h3kyeN+Wg4nTOiDYk9fSAgnt2pdpcgZO57XGkh3e9Yq/ZiET7XAEbCaCMO3On61Dp1+Vtj9+ im2OBO/0rOlMU4sYYN54AU4MbleSUEWs99lb73zY2tmrfsqfnaXcRyzMEdHPDwP/tP8FqTUloQj vlF7LNp5xz71TyMwJZVp+tBmpzxpAdKcKrOuq5A== X-Received: by 2002:a05:620a:84c8:b0:949:6c43:5381 with SMTP id af79cd13be357-949ba8193cemr6293541585a.1.1796170738714; Tue, 01 Dec 2026 16:18:58 -0800 (PST) Received: from FKXX2DL94F.bytedance.net ([72.29.204.230]) by smtp.gmail.com with ESMTPSA id af79cd13be357-949ca98d9d6sm2750985885a.18.2026.12.01.16.18.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 01 Dec 2026 16:18:58 -0800 (PST) From: Yifan Feng To: Josh Poimboeuf , Peter Zijlstra Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Steven Rostedt , Masami Hiramatsu , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, Yifan Feng Subject: [PATCH v2] x86/unwind: Recover the fgraph return address behind a rethook Date: Tue, 1 Dec 2026 16:18:52 -0800 Message-Id: <20261202001852.71375-1-evanfengff@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) X-Mailing-List: linux-kernel@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 unwind_recover_ret_addr() asks ftrace_graph_ret_addr() and then unwind_recover_rethook() for the original return address. That works when the function graph tracer hooks the return of a function after a kretprobe did: the stack has return_to_handler(), the shadow stack of fgraph has arch_rethook_trampoline() and the rethook node has the original address. When the kretprobe hooks the return last, the stack has arch_rethook_trampoline() and the rethook node has return_to_handler(). Nothing translates that address, so the stack trace ends there: => rw_verify_area => vfs_read => return_to_handler This happens when the kretprobe is registered before the function_graph tracer or an fprobe exit handler is enabled for the same function. It also happens in the other order when the function is reached by a tail call from a traced function, like ksys_read(): the rethook node then has the return_to_handler() of the caller. Translate the address found in the rethook node with ftrace_graph_ret_addr(), and repeat, at most 10 times, while that gives the rethook trampoline again. Do it in unwind_recover_rethook(), so that the unwinding from pt_regs gets it, too. Fixes: 19138af1bd88 ("x86/unwind: Recover kretprobe trampoline entry") Signed-off-by: Yifan Feng --- v2: the loop stops after 10 rounds, as asked by Steven Rostedt. v1: https://lore.kernel.org/r/20261125210905.33319-1-evanfengff@gmail.com QEMU: function_graph, fprobe exit and kretprobes on vfs_read()/ksys_read() in 6 orders, stacktrace trigger in rw_verify_area(): complete in 0 of 6 before, 6 of 6 after. kprobes kunit and ftrace selftests (kprobe, dynevent, ftrace) give the same results. Found and written with the help of an AI coding assistant. arch/x86/include/asm/unwind.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/unwind.h b/arch/x86/include/asm/unwind.h index 7cede4dc21f0..b12e1556085c 100644 --- a/arch/x86/include/asm/unwind.h +++ b/arch/x86/include/asm/unwind.h @@ -108,9 +108,17 @@ unsigned long unwind_recover_rethook(struct unwind_state *state, unsigned long addr, unsigned long *addr_p) { #ifdef CONFIG_RETHOOK - if (is_rethook_trampoline(addr)) - return rethook_find_ret_addr(state->task, (unsigned long)addr_p, + /* + * The rethook and the hook of ftrace_graph can sit on top of each + * other in any order, and more than once after a tail call. Stop + * after 10 rounds in case a lookup keeps giving the trampoline. + */ + for (int i = 0; i < 10 && is_rethook_trampoline(addr); i++) { + addr = rethook_find_ret_addr(state->task, (unsigned long)addr_p, &state->kr_cur); + addr = ftrace_graph_ret_addr(state->task, &state->graph_idx, + addr, addr_p); + } #endif return addr; } base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f -- 2.39.3 (Apple Git-146)