From nobody Mon Apr 13 12:01:51 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BC4AC25B08 for ; Thu, 18 Aug 2022 01:58:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239688AbiHRB6l (ORCPT ); Wed, 17 Aug 2022 21:58:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234661AbiHRB6h (ORCPT ); Wed, 17 Aug 2022 21:58:37 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F157441D01 for ; Wed, 17 Aug 2022 18:58:34 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4M7SgJ1bcPzGpXS; Thu, 18 Aug 2022 09:57:00 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 18 Aug 2022 09:58:33 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 18 Aug 2022 09:58:33 +0800 From: Chen Zhongjin To: CC: , , , , , , , , , Subject: [PATCH] x86/unwind/orc: unwind ftrace trampolines with correct orc Date: Thu, 18 Aug 2022 09:55:25 +0800 Message-ID: <20220818015525.222053-1-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When meeting ftrace trampolines in orc unwinding, unwinder uses address of ftrace_{regs_}call address to find the orc, which gets next frame at sp+176. If there is an irq hitting at sub $0xa8,%rsp, the next frame should be sp+8 instead of 176. It makes unwinder skip correct frame and throw warnings such as "wrong direction" or "can't access registers", etc, depending on the content of the wrong frame address. By adding the base address ftrace_{regs_}caller with the offset *ip - ops->trampoline*, we can get the correct address to find orc. Also change "caller" to "tramp_addr" to make variable name conform to its content. Fixes: 6be7fa3c74d1 ("ftrace, orc, x86: Handle ftrace dynamically allocated= trampolines") Cc: Signed-off-by: Chen Zhongjin --- arch/x86/kernel/unwind_orc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c index 38185aedf7d1..a938c5d0ed6f 100644 --- a/arch/x86/kernel/unwind_orc.c +++ b/arch/x86/kernel/unwind_orc.c @@ -93,22 +93,25 @@ static struct orc_entry *orc_find(unsigned long ip); static struct orc_entry *orc_ftrace_find(unsigned long ip) { struct ftrace_ops *ops; - unsigned long caller; + unsigned long tramp_addr, offset; =20 ops =3D ftrace_ops_trampoline(ip); if (!ops) return NULL; =20 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) - caller =3D (unsigned long)ftrace_regs_call; + tramp_addr =3D (unsigned long)ftrace_regs_caller; else - caller =3D (unsigned long)ftrace_call; + tramp_addr =3D (unsigned long)ftrace_caller; + + offset =3D ip - ops->trampoline; + tramp_addr +=3D offset; =20 /* Prevent unlikely recursion */ - if (ip =3D=3D caller) + if (ip =3D=3D tramp_addr) return NULL; =20 - return orc_find(caller); + return orc_find(tramp_addr); } #else static struct orc_entry *orc_ftrace_find(unsigned long ip) --=20 2.17.1