Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3053760rwe; Mon, 29 Aug 2022 05:12:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR7KzxDCT6kG07x/VuHFiAiPrfcBNRBblYfZPACS0AXY/fbEEPoiot2ve83l9dWklGlXw9gy X-Received: by 2002:a17:90a:d484:b0:1fd:7c5b:8fdb with SMTP id s4-20020a17090ad48400b001fd7c5b8fdbmr14100640pju.151.1661775141286; Mon, 29 Aug 2022 05:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661775141; cv=none; d=google.com; s=arc-20160816; b=PD3yYXtAIFOuYqWaeEqtUTqQOXrCgq305pt49b3Dt+P7wXwOgQmjSUSP5LiGj+U1Dy JMu8w/aO8VVu+oohCDqT/IbQkIOgX/6kqlPh7Ydn6tBGWsjEWVOc7hLj7/hN34TU4xml pgnCFzbNKQROlyalb45yU/+FWnDTjX3WWdkiCfiLgyqtVW20kB2nH4DpcPBh1mSvKzZS nGhSlfOV59Nzqn4068XfqzqPz3ZIaHQQ04jpvAKAFTReh7UM/ck8gpbMnLokuMFeGIzy XBlAv0UFkPUX5YROM3JZ2eNZ5anPaRWxEl6yHexzsdCVyoEZFitWhu0jBQfqc5L9+2R2 dm7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1admor3wtQ66liGKPsqBzAze1TbRtQFp0aZxGAXyHv8=; b=ZXnB+ReBqTGj4n8KH9aoRXyeVMzCWzUzxGFMg7UTPiyTFNSWvWrGVucsi2k0j66y7r pGVstD/0e58CcB1jj3H4PtLZTyIyNyJiHL0qkEq/MXkFD7R4fJ/aiPQgefX+Wd3ORJn7 0aArl5tkznigM+6EQl68oIQXK8VfZUbGHwh8Z2BVVK7ybohTsLmBD2ehviJZrnE7FaSt aSccb/RwdljOfEgC3U4g3sWeGwLhgh+zN7dzD6/iusZqzCi/56Rm6B1KvmYkhSXUj9bM A+9+dDxFJ3FIk9Y4jwD/eJaxE7IWTHJdEL0gNr82It/hcV+agDMvN6r5uNbOkScbMHWQ F9qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v8TvZZnl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020a170902f60a00b0016dd4c3c2e2si8884813plg.488.2022.08.29.05.12.03; Mon, 29 Aug 2022 05:12:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v8TvZZnl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231785AbiH2LWC (ORCPT + 99 others); Mon, 29 Aug 2022 07:22:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231556AbiH2LUi (ORCPT ); Mon, 29 Aug 2022 07:20: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 9C2E66A4B6; Mon, 29 Aug 2022 04:13:47 -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 6E97AB80F9C; Mon, 29 Aug 2022 11:10:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2606C433D6; Mon, 29 Aug 2022 11:10:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771456; bh=/YP6VvDcJ9DScd+mjxxX5q2txVxjWzz7n9jvS0JRzxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v8TvZZnlmYPj7vtUJOcipCIL6knEaFCf29Q+9WWxSegJrQcJzeSiSY6UFlA+7/qfo 6w21K+bWoLt02+Jr1n3ZtNW0YSOTxvtATKeZIijNjXqFa4lgyqS5XhnT55SwMKWiU3 +yXmbSyOtgtPHkHEuRJ+kmcFAa4DVBy3KOGFrsz8= 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 5.10 69/86] x86/unwind/orc: Unwind ftrace trampolines with correct ORC entry Date: Mon, 29 Aug 2022 12:59:35 +0200 Message-Id: <20220829105759.370739152@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105756.500128871@linuxfoundation.org> References: <20220829105756.500128871@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 entry. 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 @@ -93,22 +93,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; ops = ftrace_ops_trampoline(ip); if (!ops) return NULL; + /* Set tramp_addr to the start of the code copied by the trampoline */ if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) - caller = (unsigned long)ftrace_regs_call; + tramp_addr = (unsigned long)ftrace_regs_caller; else - caller = (unsigned long)ftrace_call; + tramp_addr = (unsigned long)ftrace_caller; + + /* Now place tramp_addr to the location within the trampoline ip is at */ + offset = ip - ops->trampoline; + tramp_addr += offset; /* Prevent unlikely recursion */ - if (ip == caller) + if (ip == tramp_addr) return NULL; - return orc_find(caller); + return orc_find(tramp_addr); } #else static struct orc_entry *orc_ftrace_find(unsigned long ip)