From patchwork Tue Sep 19 12:57:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 9960585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4930E601E9 for ; Wed, 20 Sep 2017 01:39:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C99E28F63 for ; Wed, 20 Sep 2017 01:39:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F96D28F5F; Wed, 20 Sep 2017 01:39:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=2.0 tests=BAYES_00, DATE_IN_PAST_12_24, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C9AB928F5F for ; Wed, 20 Sep 2017 01:39:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=6NmfTOVn3Mo8EPrlKCn00wBuwP1S2sBo2GzEq1Ap0vQ=; b=slUgYzl1x5S5Zd 4jn3zQQdLXXpiVQ/Nh+12mN5KBsrHdsoDqk0PFD0vCsQP8WZoqn3hCtIcYSw3xkoO+ya5LyIxqN52 3eYFRuZ1gVb8Ai5i3b7AeyrlQds+asMTCGb3xjtoAJgV/Tu7B0W49XAGAWtCmI3JCqFcaqEOffYPW f6H/BJz+YXjLHwcRVNBB8GFF0gpeuIyIdSLMt0Zgo57AZBpHI1/z6gzq4RIlIviGTqNrsnwwI6bD8 h36xPdkePfh5R2TEFgTir5Nck7urgVLa4b/5BeK0DWvsJHpEj3hsV9SfMmpu6hDaqOoO7dTldyDuq l6E/A6tlMHcE+H7x0Huw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1duTzD-0006uT-5P; Wed, 20 Sep 2017 01:39:35 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1duTz8-0006n1-87 for linux-arm-kernel@lists.infradead.org; Wed, 20 Sep 2017 01:39:33 +0000 Received: from 172.30.72.59 (EHLO DGGEMS414-HUB.china.huawei.com) ([172.30.72.59]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DHQ99083; Wed, 20 Sep 2017 09:38:37 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.301.0; Wed, 20 Sep 2017 09:38:30 +0800 From: Zhen Lei To: Russell King , linux-arm-kernel , linux-kernel 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170919_183931_059318_A4A06D4F X-CRM114-Status: GOOD ( 11.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kefeng Wang , Hanjun Guo , Zhen Lei , Libin , Tianhong Ding Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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);