Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp624411ybg; Wed, 10 Jun 2020 09:23:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJ52PsDgTsO1SeGttAUhvkFoXAacreGJZWq2ZjzZeUfTNa58hEjhj+/ASO2HvrdQTYiW/J X-Received: by 2002:aa7:c157:: with SMTP id r23mr3212032edp.139.1591806183773; Wed, 10 Jun 2020 09:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591806183; cv=none; d=google.com; s=arc-20160816; b=xVO6USLryjWlX2r76+VuD1ze7X+LOxp+/iazP6RW6dg8BgjBk5qn6CIbxJSLpKK3Ie BAoTGOy6LYph+fDOZ9ICdtk9NYSB/sH/YXVtq6z6B2aIh2WlAAErhSo+DoffGsscTjSp lyI+mwpdxM3ayF8dQ4YpjnUwoItqpLDueIBOAWT9RjkNq3xrLsxQrCSZNYhfbhhQUzNN jBiuXJc+Q9uh1oGnztaxHczgBcd9J+95NnbAQiY2hnzhocG11dkW6FiFKnPHeDtsQNYR 3D9C28qCV6c6eNZXdBQaBm5VjyyV/Ujau61JB/bJCtElMTcwKNdq5TPCli/IDpmL+BcV ON3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=JJhsvFYwW+8tEWWr/oiMmbCKVPyMC4y0gNIMmx5KF+c=; b=JvJf5n77VYe/e8qq5eiUHs3f295FTTw7nPlZeGdK9TYd4QAFjwixr8GDGkZ1Zt2mC7 9UqK76S+hpfPbzuZdZ22Fq3tkXU7jtUaUx8webHFMGLV6dc35g59CxTBdUcX7D1PvtDe NRJzxGqqlBxMznA+Ka64TeD/lrNL0geA0rCX1U+zFlBOq7FxtKO8TgYHR0KY/ak5WGlI LLLnXDF5cK+b6CTkHpwTr8V+bZLoZU/9LxmdhOrqRn/oeopnYw/3PzyUt0uzWNV0bSPj YuEFykGCUD/Qx5cwochvmWRFiBUz5H0c/AYO7TgVQdAAwKZxhH0EdTeTWeh7WxlUP8FZ I2VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=MnUAft4o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si46083edi.172.2020.06.10.09.22.38; Wed, 10 Jun 2020 09:23:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=MnUAft4o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728951AbgFJMN3 (ORCPT + 99 others); Wed, 10 Jun 2020 08:13:29 -0400 Received: from mail-m975.mail.163.com ([123.126.97.5]:53460 "EHLO mail-m975.mail.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728547AbgFJMN2 (ORCPT ); Wed, 10 Jun 2020 08:13:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=JJhsv FYwW+8tEWWr/oiMmbCKVPyMC4y0gNIMmx5KF+c=; b=MnUAft4oj05Sj+PgR67JH pGD5zfdf9iIZRKNMRh683qj4kjFPW5bd6ArAKOtiFbvj9CKn7qcyj9m5K2jowom1 amYuhRMaesbgqE5nsAP4LGH54smYx6Pi/qdxLgV39HPh+zz2GVak8ljXHhSLG/24 HXmJMXQbrUsrgKYraHkADE= Received: from localhost.localdomain (unknown [114.242.249.96]) by smtp5 (Coremail) with SMTP id HdxpCgCX2lxNzuBekc1XBw--.277S4; Wed, 10 Jun 2020 20:13:20 +0800 (CST) From: YuanJunQing To: tsbogend@alpha.franken.de Cc: yszhou4tech@gmail.com, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, liulichao@loongson.cn, YuanJunQing Subject: [PATCH] mips/ftrace: Fix stack backtrace in unwind_stack_by_address() Date: Wed, 10 Jun 2020 20:12:54 +0800 Message-Id: <20200610121254.1780-1-yuanjunqing66@163.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HdxpCgCX2lxNzuBekc1XBw--.277S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxAF4xXrWUuFyktFW5CFWDCFg_yoW5Gw18pr ZIk3ZxtrWkXa12kryfur18Wry5JrykZa42kry7Jry5Z3ZxXF13XryI93WDKr1DJrW0ka4f ury7trsrurZ0vaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UmiiDUUUUU= X-Originating-IP: [114.242.249.96] X-CM-SenderInfo: h1xd0ypxqtx0rjwwqiywtou0bp/xtbBzwA-XFaD7e0wIAAAsp Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Calling the unwind_stack_by_address() function for stack backtrace will fail, when we use "echo function: stacktrace > set_ftrace_filter". The stack backtrace as follows: <...>-3102 [001] ...2 63.557737: => 0 => 0 => 0 => 0 => 0 => 0 => 0 => 0 => -0 [000] .N.2 63.558793: The reason is that when performing stack backtrace, the "ftrace_call" and "ftrace_graph_call" global symbols in ftrace_caller() are treated as functions. If CONFIG_FUNCTION_GRAPH_TRACER is defined, the value in the "ra" register is the address of ftrace_graph_call when the stack backtrace back to ftrace_caller(). ”ftrace_graph_call“ is a global symbol, and the value of "ofs" is set to zero when the kallsyms_lookup_size_offset() is called. Otherwise, the value in the "ra" register is the address of ftrace_call+8. "ftrace_call" is the global symbol, and return one when the get_frame_info() is called. Signed-off-by: YuanJunQing --- arch/mips/kernel/process.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c index b2a797557825..ac4fe79bc5bc 100644 --- a/arch/mips/kernel/process.c +++ b/arch/mips/kernel/process.c @@ -53,6 +53,8 @@ #include #include #include +#include +#include #ifdef CONFIG_HOTPLUG_CPU void arch_cpu_idle_dead(void) @@ -569,6 +571,13 @@ unsigned long notrace unwind_stack_by_address(unsigned long stack_page, * Return ra if an exception occurred at the first instruction */ if (unlikely(ofs == 0)) { +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + extern void ftrace_graph_call(void); + if ((pc == (unsigned long)ftrace_graph_call)) { + pc = ((unsigned long *)(*sp))[PT_R31/sizeof(long)]; + *sp += PT_SIZE; + } else +#endif pc = *ra; *ra = 0; return pc; @@ -583,16 +592,23 @@ unsigned long notrace unwind_stack_by_address(unsigned long stack_page, if (*sp < low || *sp + info.frame_size > high) return 0; - if (leaf) + if (leaf) { /* * For some extreme cases, get_frame_info() can * consider wrongly a nested function as a leaf * one. In that cases avoid to return always the * same value. */ +#ifdef CONFIG_DYNAMIC_FTRACE + if (info.func == (void *)ftrace_call) { + pc = ((unsigned long *)(*sp))[PT_R31/sizeof(long)]; + info.frame_size = PT_SIZE; + } else +#endif pc = pc != *ra ? *ra : 0; - else + } else { pc = ((unsigned long *)(*sp))[info.pc_offset]; + } *sp += info.frame_size; *ra = 0; -- 2.17.1