From patchwork Thu Mar 22 03:06:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ji Zhang X-Patchwork-Id: 10300809 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 1F1D260385 for ; Thu, 22 Mar 2018 03:16:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F41BA29902 for ; Thu, 22 Mar 2018 03:16:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAF912990A; Thu, 22 Mar 2018 03:16:49 +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 5EC4D29902 for ; Thu, 22 Mar 2018 03:16: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=AKQCeAb52mv0oSjZrFYdCrG/hd0S5wKBlwxMAMrlikE=; b=kbPVYsH/X0qlEI BMFq3Z6Ry3rZRWyRBn7ig7/A0EBgQwe9hDb8MRB5to5aC4XjS/1WorN29aPin6/K6p66rBj0t0/NZ AREcGyy6sdRBzofw3vPOm0oqKGDwHYs9you+MguXN0SWje7cCtmi89P9lpGiMzaoY6s13EApgpUO+ bAM8q8G9We8CuwcRUFXC91mUkxNntlQoJDESbv91N1y1MA+KMMqi4bmfKljbDwfxKqAHgBAMycTFL hNEe+XtCA14qabRJqdO5Te83g+IGvHKG6nMZ3X+BWshq+a5Lx+AkJVLS5wSAUpJQ8rkFPbMFKd4RR S+6g3UxJe7dQ3Z1kNmDg==; 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 1eyqic-0003MY-SQ; Thu, 22 Mar 2018 03:16:46 +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 1eyqiZ-0003KY-HP; Thu, 22 Mar 2018 03:16:45 +0000 X-UUID: 2787c780c0bc46a39345fba5e43671d7-20180322 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 838413949; Thu, 22 Mar 2018 11:06:04 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Thu, 22 Mar 2018 11:06:02 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Thu, 22 Mar 2018 11:06:02 +0800 From: Ji Zhang To: Catalin Marinas , Will Deacon , Matthias Brugger , Mark Rutland , Ard Biesheuvel , James Morse , Dave Martin , Marc Zyngier , Michael Weiser , Julien Thierry , Xie XiuQi Subject: [PATCH] arm64: avoid race condition issue in dump_backtrace Date: Thu, 22 Mar 2018 11:06:00 +0800 Message-ID: <1521687960-3744-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_201643_721409_86831AE3 X-CRM114-Status: GOOD ( 13.12 ) 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: wsd_upstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Ji Zhang , shadanji@163.com, linux-arm-kernel@lists.infradead.org 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 is 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 tasks which are 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/arm64/kernel/traps.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index eb2d151..95749364 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -113,6 +113,9 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk) if (tsk == current) { frame.fp = (unsigned long)__builtin_frame_address(0); frame.pc = (unsigned long)dump_backtrace; + else if (tsk->state == TASK_RUNNING) { + pr_notice("Do not dump other running tasks\n"); + return; } else { /* * task blocked in __switch_to