Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4001650ybz; Mon, 4 May 2020 13:50:28 -0700 (PDT) X-Google-Smtp-Source: APiQypL3pBiR1R2CQQWcLJcd3CoEWIFqDfrBVczYscUpefn+vfpRntlGPsYU20IaRs0qkUP3ae6L X-Received: by 2002:a17:906:130d:: with SMTP id w13mr16375004ejb.253.1588625428263; Mon, 04 May 2020 13:50:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588625428; cv=none; d=google.com; s=arc-20160816; b=zTJdUHn6+b2AmfJHkpMQi3P90Nt0MAH2chRgxTbNbDGcjbJP0pcD3uwdUG1XX9H1vz dWoMQX/ak1223O4nHYSaRE7Vwx/H2gDWOvsFodoMrWXT14vlT1A0S/RGH918fr28rU0X hss9TT9BBLZqyH+Ln4UnYj0jFgRE1cRZCbyLVfFygyGAMKj7do3sluxC6MxnY+HNTUme wuUKA8dAv8C/DZtEAqEjP5eSRJD1WxgtbMqRebzVOrnVmBZzxGLMTT4TxiSO27L3exiX gThYlcFpclKoh5h7Qcvfl2JiZY4pzAcoDso+12494F/FZCy1xc9KDcbIAGrXAgF7dtmN wiuA== 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:dkim-signature; bh=q4sov0ChNy4hrwZcHSP8BPY1Z4jhUiC/e3n8rJIvq6U=; b=Mvr19V6rfYzyaLVICzZ738Tohq90i6hji7n4SCXRN7RepXA/GU2sX5wSfRvdZY5sft QrpgIUI1PTA1MrKSNxbheB5TuxVvh2V8qUrKtTuoFoB7MVvSRiz2wFX6ifvcBTKOwg3w ZY7fJxLwES2s56FGSkDWbEpQCTfAcXsKnxJnHf/hKAMEXbe8dDm8LfGQ8ogujuOC+fRP oSRrMCD4bEEGF+TaL35uECh3/yf67SeiMbiIA6ImMJvNFvGDk97DWOOLCVQGSSvGJRFS cSkO+UQFQJ+PyHcGyh1tJ0l2g4NMHTWtckUUChqDqG39heQnETNIVJU32mhsOAqtdjNT 06sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xWVk+Kqa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x5si58437eds.496.2020.05.04.13.50.04; Mon, 04 May 2020 13:50:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xWVk+Kqa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727804AbgEDUsJ (ORCPT + 99 others); Mon, 4 May 2020 16:48:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:52716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726433AbgEDUsJ (ORCPT ); Mon, 4 May 2020 16:48:09 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B7E01206A4; Mon, 4 May 2020 20:48:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588625289; bh=uhstx6i6VStcX5tnxEtH4iTtQS0OGgGawfl0YTLt7FM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=xWVk+KqavPLzos8trQkkwJKJqC1RRw0zo6X3ZZmPzXdB1Z3iDAZMvN0af3UToUUiF FeBKcul0IpAF/yLlCvP3KXWqB79UXjuFKubP6LkstHKFXB/97OeV862n3tG8I19fFc 4KFxgu7ymxHTr0OJVpfzNHafDm1zUTDqmKi4dFCo= Date: Mon, 4 May 2020 21:48:04 +0100 From: Will Deacon To: Daniel Thompson Cc: Catalin Marinas , Douglas Anderson , Jason Wessel , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, patches@linaro.org Subject: Re: [PATCH v2] arm64: cacheflush: Fix KGDB trap detection Message-ID: <20200504204803.GA5657@willie-the-truck> References: <20200504170518.2959478-1-daniel.thompson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200504170518.2959478-1-daniel.thompson@linaro.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 04, 2020 at 06:05:18PM +0100, Daniel Thompson wrote: > flush_icache_range() contains a bodge to avoid issuing IPIs when the kgdb > trap handler is running because issuing IPIs is unsafe (and not needed) > in this execution context. However the current test, based on > kgdb_connected is flawed: it both over-matches and under-matches. > > The over match occurs because kgdb_connected is set when gdb attaches > to the stub and remains set during normal running. This is relatively > harmelss because in almost all cases irq_disabled() will be false. > > The under match is more serious. When kdb is used instead of kgdb to access > the debugger then kgdb_connected is not set in all the places that the > debug core updates sw breakpoints (and hence flushes the icache). This > can lead to deadlock. > > Fix by replacing the ad-hoc check with the proper kgdb macro. This also > allows us to drop the #ifdef wrapper. > > Fixes: 3b8c9f1cdfc5 ("arm64: IPI each CPU after invalidating the I-cache for kernel mappings") > Signed-off-by: Daniel Thompson > Reviewed-by: Douglas Anderson > --- > > Notes: > v2: Improve the commit message based based on feedback from Doug > Anderson > > arch/arm64/include/asm/cacheflush.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/include/asm/cacheflush.h b/arch/arm64/include/asm/cacheflush.h > index e6cca3d4acf7..ce50c1f1f1ea 100644 > --- a/arch/arm64/include/asm/cacheflush.h > +++ b/arch/arm64/include/asm/cacheflush.h > @@ -79,7 +79,7 @@ static inline void flush_icache_range(unsigned long start, unsigned long end) > * IPI all online CPUs so that they undergo a context synchronization > * event and are forced to refetch the new instructions. > */ > -#ifdef CONFIG_KGDB > + > /* > * KGDB performs cache maintenance with interrupts disabled, so we > * will deadlock trying to IPI the secondary CPUs. In theory, we can > @@ -89,9 +89,9 @@ static inline void flush_icache_range(unsigned long start, unsigned long end) > * the patching operation, so we don't need extra IPIs here anyway. > * In which case, add a KGDB-specific bodge and return early. > */ > - if (kgdb_connected && irqs_disabled()) > + if (in_dbg_master()) Does this imply that irqs are disabled? Will