From patchwork Thu Mar 22 03:34:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ji Zhang X-Patchwork-Id: 10300815 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 64F70602B3 for ; Thu, 22 Mar 2018 03:34:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57EA829943 for ; Thu, 22 Mar 2018 03:34:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C1F029970; Thu, 22 Mar 2018 03:34:41 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 C50FE29943 for ; Thu, 22 Mar 2018 03:34:40 +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=3hPEGJ7SYXxOHTaUZJZC3EN9pi0voZyT/RflI+yeSas=; b=RNaPu+2FBRee6E 068KIPfuJRTwl+NuR7U/KgoN6rrVjdERCrPVKS9h1QyMZUElRWj3pwH5LzXGbSCw13xOUz5ep87SS IFi7yr/dWeapxcqdYbSzcxC9sZCS2TCCJhxW3puN2cKhQkItlsvd1ovz5B9QVANWTxRWGzS6ijKeJ BVf6R8uLYSgLNvs7lpffrrWUz/GBgQP8Wz43EVYYp0qUdFXCdxbQ1T3FOw3SwBaiBISgrA9hO6ZS5 7S4HZ95em3wD+EyDrSQG8Cfth08yxLGracGH3RJkppNc5N7pLYnqZxLuMPGcgUuKTWKJ6te408KqT Z16L9KiVvzCJuLSa0Wmg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1eyqzt-0000jm-CO; Thu, 22 Mar 2018 03:34:37 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1eyqzp-0000dB-Uc; Thu, 22 Mar 2018 03:34:35 +0000 X-UUID: 04ac4a54797d4b50a2d6e69912e03563-20180322 Received: from mtkcas09.mediatek.inc [(172.21.101.178)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 51543095; Thu, 22 Mar 2018 11:34:19 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Thu, 22 Mar 2018 11:34:17 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Thu, 22 Mar 2018 11:34:17 +0800 From: Ji Zhang To: Russell King , Matthias Brugger , Mickael GUENE , Andrew Morton , Ji Zhang , Nicolas Pitre , Mark Rutland Subject: [PATCH] arm: avoid race condition issue in dump_backtrace Date: Thu, 22 Mar 2018 11:34:16 +0800 Message-ID: <1521689656-4694-1-git-send-email-ji.zhang@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180321_203434_162855_F08EDF53 X-CRM114-Status: GOOD ( 12.02 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: shadanji@163.com, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, wsd_upstream@mediatek.com Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When we dump the backtrace of some specific task, there is a potential race condition due to the task may be running on other cores if SMP enabled. That is because for current implementation, if the task is not the current task, we will get the registers used for unwind from cpu_context saved in thread_info, which the snapshot before context switch, but if the task is running on other cores, the registers and the content of stack are changed. This may cause that we get the wrong backtrace or incomplete backtrace or even crash the kernel. To avoid this case, do not dump the backtrace of the task which is running on other cores. This patch cannot solve the issue completely but can shrink the window of race condition. Signed-off-by: Ji Zhang --- arch/arm/kernel/traps.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index 5e3633c..faa3d45 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -220,6 +220,10 @@ static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk) fp = frame_pointer(regs); mode = processor_mode(regs); } else if (tsk != current) { + if (tsk->state == TASK_RUNNING) { + pr_notice("Do not dump other running tasks\n"); + return; + } fp = thread_saved_fp(tsk); mode = 0x10; } else {