Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1347238rwb; Fri, 19 Aug 2022 01:55:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR64LzGKTvG/CAfdsJcyN/ARdWTYn1PeQ/elWR0E1HJavj6lDH9am0epIlWgahyxcMfS/9Pz X-Received: by 2002:a63:2048:0:b0:41c:daad:450d with SMTP id r8-20020a632048000000b0041cdaad450dmr5415014pgm.240.1660899337278; Fri, 19 Aug 2022 01:55:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660899337; cv=none; d=google.com; s=arc-20160816; b=MMrUWmwBplMUiISGq49XyFJqlXew9Yyhikqdk2J82PMbfyXjpT1MiEBza80QXO1Irq jamK9eCPBvQcEBR942E5AqHZcXjjDpOUwt0yp73/uGCo3yB9GjbRWwv+3J8uYE6CcmSu vaFuEmouYwSk2opoPx2wIZLe/9Z0ZRduc5Yu05n18kVwX//rH5VgsE4jeCpdTpGSAfvb 7noIyvFXdr1V6VjeBPRMifkT12PCfPUI+TdwM2QqUUE4V0vBjhiSglFwpWLd41FUeFr1 AGx+7dtap1JvfRINBScUNn+rY7c4Jh5lK0y7oKDSgtzhE4PBLSt6oAZ4uRD8oXL2m3tU kXMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=av08piYyc0/JIBES95Vf3/5PhYltjzFtr1pJVRHJjVU=; b=fAAnrpAh+VdWXXJmfdBpe6yzA7JrluFk/bD+W3AwoAnAoAVBTBa/IrGjV2+6S2oBha WzlM++lniYsQ6FrMQLzXGdZw+Y+CI8Q5JQ9UjXxzADUL6R2PHzZpA7w6kXRwFA+wr9Lx iGkieJf7ALPa2TM2vB0jDwWPEzho2ksKGeri0Vxz8Pg/7RJmZzF+ZWwy1QVhWp0CqTO2 WztfvyqreGgoBJ6wFySkqByQsn27Odk54guaGCX8b7v6wrQ+d3VZCZHYDnMLewWtoDuK JOs8tjUF/36gxCjfqIwXiwYc3Rp28A/FpVTSoNxr3MmYdszveHCAlorHREykFhToo7Iw Aatw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m8-20020a63fd48000000b00420849eff47si3468862pgj.679.2022.08.19.01.55.25; Fri, 19 Aug 2022 01:55:37 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347156AbiHSIqu (ORCPT + 99 others); Fri, 19 Aug 2022 04:46:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347732AbiHSIqr (ORCPT ); Fri, 19 Aug 2022 04:46:47 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 048F4CAC4D for ; Fri, 19 Aug 2022 01:46:46 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4M8Fck1czWzXdgb; Fri, 19 Aug 2022 16:42:30 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 19 Aug 2022 16:46:42 +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; Fri, 19 Aug 2022 16:46:42 +0800 From: Chen Zhongjin To: CC: , , , , , , , , , Subject: [PATCH v2] x86/unwind/orc: unwind ftrace trampolines with correct orc Date: Fri, 19 Aug 2022 16:43:34 +0800 Message-ID: <20220819084334.244016-1-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 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 --- v1 -> v2: Add some comments. --- arch/x86/kernel/unwind_orc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c index 38185aedf7d1..0ea57da92940 100644 --- a/arch/x86/kernel/unwind_orc.c +++ b/arch/x86/kernel/unwind_orc.c @@ -93,22 +93,27 @@ 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; 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) -- 2.17.1