From nobody Wed Sep 3 01:51:29 2025 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 61EAFECAAD5 for ; Fri, 2 Sep 2022 12:32:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236779AbiIBMcj (ORCPT ); Fri, 2 Sep 2022 08:32:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236666AbiIBMbi (ORCPT ); Fri, 2 Sep 2022 08:31:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDD4EE190E; Fri, 2 Sep 2022 05:26:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B80B9B82ABD; Fri, 2 Sep 2022 12:26:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28271C433B5; Fri, 2 Sep 2022 12:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121592; bh=ygv5b7Fd2GBK1PHrrtgvE32HVeC9KUYkOtlJ+Y/J1Ds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pp9fxtoqede/2v52gayNt+ZHQTHqnTxBEUO0GGFp4k9U4bpDIy3an1DT6rNiPyL77 mSp7y2GfuT/UrwMpbYEBin4MGo03V58+nuqoftmI4hvWcptpXYpYVG2bc6ujIO98r6 3VGo9EA1Bp7iVx/ItSNdBd9h3nPgov0cO5aRyu+Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chen Zhongjin , Ingo Molnar , "Steven Rostedt (Google)" Subject: [PATCH 4.19 30/56] x86/unwind/orc: Unwind ftrace trampolines with correct ORC entry Date: Fri, 2 Sep 2022 14:18:50 +0200 Message-Id: <20220902121401.293170735@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121400.219861128@linuxfoundation.org> References: <20220902121400.219861128@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Chen Zhongjin commit fc2e426b1161761561624ebd43ce8c8d2fa058da upstream. When meeting ftrace trampolines in ORC unwinding, unwinder uses address of ftrace_{regs_}call address to find the ORC entry, 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 incorrect frame address. By adding the base address ftrace_{regs_}caller with the offset *ip - ops->trampoline*, we can get the correct address to find the ORC entr= y. Also change "caller" to "tramp_addr" to make variable name conform to its content. [ mingo: Clarified the changelog a bit. ] Fixes: 6be7fa3c74d1 ("ftrace, orc, x86: Handle ftrace dynamically allocated= trampolines") Signed-off-by: Chen Zhongjin Signed-off-by: Ingo Molnar Reviewed-by: Steven Rostedt (Google) Cc: Link: https://lore.kernel.org/r/20220819084334.244016-1-chenzhongjin@huawei= .com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/unwind_orc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/arch/x86/kernel/unwind_orc.c +++ b/arch/x86/kernel/unwind_orc.c @@ -89,22 +89,27 @@ static struct orc_entry *orc_find(unsign 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 + /* Set tramp_addr to the start of the code copied by the trampoline */ 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; + + /* Now place tramp_addr to the location within the trampoline ip is at */ + 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)