From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751621AbdITBiq (ORCPT ); Tue, 19 Sep 2017 21:38:46 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:6518 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751589AbdITBin (ORCPT ); Tue, 19 Sep 2017 21:38:43 -0400 From: Zhen Lei To: Russell King , linux-arm-kernel , linux-kernel CC: Tianhong Ding , Hanjun Guo , Libin , Kefeng Wang , Zhen Lei Subject: [PATCH 1/1] ARM: add stacktrace support for non current tasks on SMP Date: Tue, 19 Sep 2017 20:57:54 +0800 Message-ID: <1505825874-9528-1-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.59C1C69D.00A7,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 8dee00e24ba5cc211bde1073cbd56686 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 1. An invalid frame.xx can not lead kernel to crash, this should be guaranteed by function unwind_frame itself. Otherwise, walk the stack trace of current is also at risk. 2. There is no way to prevent the walked task becoming rq->curr during walk_stackframe. This means some entries traced maybe inconsistent. But it's better than none. Besides, we can dump it again. Signed-off-by: Zhen Lei --- arch/arm/kernel/stacktrace.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c index 92b7237..80a0e9d 100644 --- a/arch/arm/kernel/stacktrace.c +++ b/arch/arm/kernel/stacktrace.c @@ -120,13 +120,20 @@ static noinline void __save_stack_trace(struct task_struct *tsk, if (tsk != current) { #ifdef CONFIG_SMP /* - * What guarantees do we have here that 'tsk' is not - * running on another CPU? For now, ignore it as we - * can't guarantee we won't explode. + * There is no way to prevent tsk becoming rq->curr during + * walk_stackframe. frame.xx should be sanity checked in + * function unwind_frame. */ - if (trace->nr_entries < trace->max_entries) - trace->entries[trace->nr_entries++] = ULONG_MAX; - return; + if (!task_curr(tsk)) { + frame.fp = thread_saved_fp(tsk); + frame.sp = thread_saved_sp(tsk); + frame.lr = 0; /* recovered from the stack */ + frame.pc = thread_saved_pc(tsk); + } else { + if (trace->nr_entries < trace->max_entries) + trace->entries[trace->nr_entries++] = ULONG_MAX; + return; + } #else frame.fp = thread_saved_fp(tsk); frame.sp = thread_saved_sp(tsk); -- 2.5.0