From patchwork Fri Jun 19 14:29:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 191220 Delivered-To: patch@linaro.org Received: by 2002:a92:cf06:0:0:0:0:0 with SMTP id c6csp622741ilo; Fri, 19 Jun 2020 08:19:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtsuhTGFTZCvBNZYy4U5yWDVOyYL2rMmE5o+3w5hnQah0ZUQ+/J3M4cGV6/Gzrx//AcIbI X-Received: by 2002:a05:6402:7cb:: with SMTP id u11mr3669263edy.316.1592579952370; Fri, 19 Jun 2020 08:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592579952; cv=none; d=google.com; s=arc-20160816; b=oJONWqPYNQF8kFQf6ssxG9oDbcmT4agcG83yyCHlxBIOQRIwnmOGUaJXmm1e7nS+Zn uycnDdEv0N5TZPsbHMlpENsORtzC1D5mYKKQ3Buua8japejgccBUze7NMbJCh+Pa2soV N/+g1p8fafUSJbfgo1kgt45Rs2R1+mGZGXBv9/dOWmunhowvkJy3m6TQG5vMrL50pT2U HrUTkgClqfcB7eq6bh64uR89DFwwNZP23fwxy6emMDRgWByCvY6sFN6tUtFWbeb+rct4 cqUUWHG07vnsjWYVFkB4Gblcbvzq03O1PRJLmS9x5Qyk/oAB/NqzfZ8YYdnvWDmLrZ6f hneg== 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=rVRmH/zWKz64TwJzru3BgzolD6vxqVZ1vgm+Iho8vWmigJYpGL8z3FBCJ+7vCnpYNi BR1mp0eUA0tC9Qg/wO7BBxMy/AaBeaOsQRY9jr0Jo+gzMOr3TlIeXO+4SQyy+YFpUfAT ueR2vyxrPaJh8aWw5dsf7hyWpADsykQLNpOQGwN6mrzY6Fjnypv/VrOBsUybbmP/K2TP OVY1za0809Ijfj14JzpzNfZXhvMLzzQ+grRRIQlYhZjNyMmqfB+n6u8i7RFeFcqC8kGq 3WbRYx2JQyALuDpvlCKf1Q0iUZ3tb1O77Hn8uMw3WWkc+lzrdxYV6nHwgX9ut0VAGzmn Y8bw== 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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 s16si3991966ejx.298.2020.06.19.08.19.12; Fri, 19 Jun 2020 08:19:12 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392513AbgFSPRi (ORCPT + 15 others); Fri, 19 Jun 2020 11:17:38 -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 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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(-) -- 2.25.1 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(); }