Received: by 10.213.65.68 with SMTP id h4csp371719imn; Wed, 21 Mar 2018 21:58:33 -0700 (PDT) X-Google-Smtp-Source: AG47ELvMxQoGkIwSGypppTyCt8ZcJpV33n4G1+2yXtaLXdI2t5vJ7mgaA7EK10AmVtKV+XoN2xSE X-Received: by 10.99.124.14 with SMTP id x14mr16798142pgc.290.1521694713520; Wed, 21 Mar 2018 21:58:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521694713; cv=none; d=google.com; s=arc-20160816; b=ZOdj0z/sEo7bOCLasX26fRLmjMiyR/PZkhVAewJg+3XPZQ1ZKY+SEPIFBEbvKGQ+eH ON4qy5TMHNlyo1ad9QI531phR/Cd/7YpqReSx1K/7ywKXybXsZpkYHFMDnU9WuKtiY4I IGM3Q71ROKgbfbwmoIGGB6DrHjdTv2uywKBFgNak7hcytFSonzMX4rKtDj6EFhfRVpNM 7UEY4QDNabpyEWjxAY8FJv0gPSsCgzQOyc9NdwSEpq9ayaEP0cYmy9nj8NPwLvrr2NPH Kz7OKbppyE0chPiK4eScOYstsyKZN7wQ657ILzlewfd8xeIGSFs1R5h26yMc1+Sd74Em dLUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=z36UE5LB0Scj2SSn9HIZjaV7p2bQHQgPt6Pbh+hlsvY=; b=Dx91uJcnPVwWgZZ7WVVfRNlVUQ6Ijy8PJJR7GBORWEXO9eqYZAMeyDtUBXyic6Etxg Q4ddEQTIxBZYpy3LDQvy1bkrkxFA2EwG/oq6HR++geGxBYGuqTUkBMuaGE+Ie8+cB08H MizxvZ9dEzfFxxmXu+FK4UGS5PnW9akHNWvLofDck91fY0NyUmfeVExwbYZ0n1hLN/W1 CdH9GqGhfPSzMelryxs8W1f4vtDOyWYW/p11H9tsbrQQh4N7yaPkDPQCiiWe0OmkPmY8 Z27Oibdkd22+j9gUjpAgo3MVXBFjxxpxex9b7R2XzKqU3v8Mf1qTGaWegFBWn6rUCrsx wbPQ== 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 o66si2216281pfb.0.2018.03.21.21.58.19; Wed, 21 Mar 2018 21:58:33 -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 S1752159AbeCVE5R (ORCPT + 99 others); Thu, 22 Mar 2018 00:57:17 -0400 Received: from guitar.tcltek.co.il ([192.115.133.116]:57000 "EHLO mx.tkos.co.il" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751945AbeCVE5P (ORCPT ); Thu, 22 Mar 2018 00:57:15 -0400 Received: from sapphire.tkos.co.il (unknown [10.0.4.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx.tkos.co.il (Postfix) with ESMTPS id 458014404B9; Thu, 22 Mar 2018 06:57:12 +0200 (IST) Date: Thu, 22 Mar 2018 06:57:10 +0200 From: Baruch Siach To: Ji Zhang Cc: Catalin Marinas , Will Deacon , Matthias Brugger , Mark Rutland , Ard Biesheuvel , James Morse , Dave Martin , Marc Zyngier , Michael Weiser , Julien Thierry , Xie XiuQi , wsd_upstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, shadanji@163.com, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] arm64: avoid race condition issue in dump_backtrace Message-ID: <20180322045710.vmmjr2wcankea45o@sapphire.tkos.co.il> References: <1521687960-3744-1-git-send-email-ji.zhang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1521687960-3744-1-git-send-email-ji.zhang@mediatek.com> User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ji Zhang, On Thu, Mar 22, 2018 at 11:06:00AM +0800, Ji Zhang wrote: > 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) { Missing closing brace. Does this build? > + pr_notice("Do not dump other running tasks\n"); > + return; > } else { > /* > * task blocked in __switch_to baruch -- http://baruch.siach.name/blog/ ~. .~ Tk Open Systems =}------------------------------------------------ooO--U--Ooo------------{= - baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -