Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp567750ybt; Fri, 19 Jun 2020 08:21:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxz9gtJ2wNdeftVboPeBzY4z5/bblMPyi4lJxjccKO1FCimXSx1/EEwPc753IPpahqyVqG6 X-Received: by 2002:a05:6402:3078:: with SMTP id bs24mr3791504edb.284.1592580074157; Fri, 19 Jun 2020 08:21:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592580074; cv=none; d=google.com; s=arc-20160816; b=JQN5tVAAXwWK9tXMq9Lvlzja9RYzqkMRBjs9sbjXIrDLlA0v6qDO1JWhuASkszGuXm RQD+6eCtI+68kBTe+IBxftxnGhueLL0UiXf4dqh8R8/L49Re8GXYKLM4pHE2bb0HiYMf 6VxVrKF8wJ9fc3xiZu+6vf/9CNqe4W3dWn/82twF1a6e5iJily9Aycc149ylkQZ2gq12 5vryDqYPGWkFTpRP8JHXi1aNcJOzujX3ZuzzsZ2soehsB+OZqBoF4x6ezfi7lGDbPcdq N7egVwv8Bi8JQexVh7ucZhyHayXEMRv5OlAxTF+4OL75OIF6+KRyQmX+Yvo6Y+uIpWXs G3YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kmzaqVRCTEKiwN0L6FygVeJ0FiYklNdjW/hzjrpZI74=; b=IhGSzPDTPFmywy2N31mYxzJpMLHbPsgSV3F2yA139VgseoXWFvT01nKvFtDZ8G6YdV fmMNYuHNX+rYX1TxnyW/vzWZAdTSts5hir0ipPMfFXTDtez4MBukmzlYgHUgxQTiZH+s jBiR2HH78iAidtln898bHuE6TCCbVYzHmqgfmpiFQCRFf2FWJWUj3HLeSAyfICbXR8e0 zjDY2+qNpSRwPuX2vsBXs8IfQgvu52lzKRigwCiHz26jRPFQSe8r+vofBNigNyeCsnvQ 9nbUIs9R6s0ce+F0CttiYsQlIraOifr7VFpviiwKm8eZ7D3/rP3dP5kRt1xPAvMkEmCk z2rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AXXYJaFj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x8si3940638ejw.747.2020.06.19.08.20.50; Fri, 19 Jun 2020 08:21:14 -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=AXXYJaFj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390811AbgFSPRr (ORCPT + 99 others); Fri, 19 Jun 2020 11:17:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:48202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389741AbgFSPRg (ORCPT ); Fri, 19 Jun 2020 11:17:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 59B8421919; Fri, 19 Jun 2020 15:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592579855; bh=PG0qiH2KEanMcWHB5FHf6WHtqvnKB05Xm9dmC6kGVQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AXXYJaFjwV5ruqG0DCO55eo9DcwyQlh1jwf32Khaspace2eEVsy1wLaqWCRcXcint OPluPdoE8v1SJgrJBRqCETYPLF/BjM1hoR2YdKfhX2+Jbqvgu8dcpBScoTcdECU+9W qvLRPQ14opHliX+fZboWygDVZNjfluMEHJaCxrmo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Thompson , Douglas Anderson , Will Deacon , Sasha Levin Subject: [PATCH 5.7 030/376] arm64: cacheflush: Fix KGDB trap detection Date: Fri, 19 Jun 2020 16:29:08 +0200 Message-Id: <20200619141711.780398678@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141710.350494719@linuxfoundation.org> References: <20200619141710.350494719@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Thompson [ Upstream commit ab8ad279ceac4fc78ae4dcf1a26326e05695e537 ] 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 Link: https://lore.kernel.org/r/20200504170518.2959478-1-daniel.thompson@linaro.org Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- 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()) return; -#endif + kick_all_cpus_sync(); } -- 2.25.1