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: 113074 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp177582qgf; Tue, 19 Sep 2017 18:38:51 -0700 (PDT) X-Google-Smtp-Source: AOwi7QD03jUWRQHCP9oGuANSaDxfPuIxEzLgdoB9X8PZs3Bzx52fvvfPDTVMubZi1xEVjTJ1q/90 X-Received: by 10.98.246.17 with SMTP id x17mr486246pfh.209.1505871530906; Tue, 19 Sep 2017 18:38:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505871530; cv=none; d=google.com; s=arc-20160816; b=0gNuL3owalYWskP1HqlM5A1P/s9ZpO7+lMDiFR1CW+p1Mo8we0QTvPYUy0eGsC83pM L9XEwXnVS6vw7xUT2aorhKKYwX/5hmIvM5WDC2K5eN6qK1/kkUE/s+12jMUwWlo8oU0C bZuhVz9weai+crlHXIlHJEJF0JGJpGxeBr6EeCZgMWF20NqHfAIdlw6xjjz5jpSUJ8lR bM5RPwXuc1watg9d5h++FfTNOahWo8hFHcxI+sDm1VVOfprxIrh7BXMBsuaIjVmNx7oL wxpwEbUyhJkKCMVszJgoESWz8JZ4EljrpSmdp7jhOwpDN5wnk6PcjR8e9tx66XmXPmDJ nA6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=jlkU+Wl59orYQDUJnqMTW+sZDufDnDSWdH4NknM+WGs=; b=IsifWJkmiiaNvsM9Kbc2dDx/LW0mZmvE9C+d6j+cove1CQTW1UlfoaJLAWNPIGpngh /yJ0/oRw5DyV7iQgTBIOwe4PvTwcOzBFuCpcxzmagKTVKMHqFdyS70IM7XTgPEuJ7spH JA4QHu/mDPCwMg2Tb6SwCZA1tBaTYKw8JNBBw58phS7omZ7MyacB1i7e/dJKhcLJvXE6 bwulyHzJe/ag/r5S/Iv3iJ4/x4H5zzWizy9ju62VD34952q+DL1kkGns8ZMSmmN/KnOu l1qia9FU4VtZrmIN3CJJ7M8W65on+tO4HOR9REhjqFzG8frjaFDYDorZRgxx0IiBM/l2 rMNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s24si2364526pgn.339.2017.09.19.18.38.50; Tue, 19 Sep 2017 18:38:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751622AbdITBiq (ORCPT + 26 others); 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 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 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 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 Precedence: bulk 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(-) -- 2.5.0 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);