From patchwork Fri Jun 19 14:30:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 191217 Delivered-To: patch@linaro.org Received: by 2002:a92:cf06:0:0:0:0:0 with SMTP id c6csp610799ilo; Fri, 19 Jun 2020 08:05:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2QeQZyoqfv2d9XcwesGKUJQ/E1cHsqUo3QoO3PURnH8b2cYtcQ7SADujzG5z6d3crsM7C X-Received: by 2002:a17:907:72ca:: with SMTP id du10mr4060484ejc.78.1592579145614; Fri, 19 Jun 2020 08:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592579145; cv=none; d=google.com; s=arc-20160816; b=qgc8/32eo+ufMgUV3CGm5pDHqwYHziibTTMxoA0TwSflS0AN1qNherChzdcdby3XM+ cTIqNlSeMUjOH+sc1VMG/d8FCeWCP1l3f2g8+mMaw0nQq2FGu33NXGunrz0IGq6o3b4Q ZhJ2nSte5lPB3ONQPf90koAwfOr7OUaXr4y146Ssge/KdquQMbqRv5QUagW0zySTfY1l 8/OMjWHnSidztdeeL5HrS5oVXqe6jQWY0ZS1FvBLdG7Ds6U2nJBaI0M8nfg8rGt4Z283 zBhL2izSn2Cd805YF8aotF5JG1/eDyQPSAVn8XLABDDTPKtSMVMbsV0i+paoVxfvex9+ ODyg== 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=vFDwg8JA14sdT/AAq1W995dYJIkPQYKpOsF5457+9y4=; b=FcWiAKnSjMygBAf4ul3915VIMX04FANlLaa/zMFjeTlDg2qN/jzk0djNc+WMOnbkx8 13AO94paZ5yFuvTLdmygxkFeyJ76MP12+CUPDCkV8y9ZzWoB0CM79n+CSHbYmTWMY3hJ sTI6/ovWd93i8+zbPw4yplWAgCv+YeEfjzV5xI/Yj3w00o1FhojPoYwSspj7UfPHeA1o t7tKyui1l4pnZq16nJQxnvZbSg7gucg90WYZVLIwYcgIdABvDJ05hMVv+Upp7RC77tcF rqnovcfyA8CknE4Xtt+Gu794ZkhfhfrSOsa1Na5ImMPVoiHgZ8cuC/z1MtjodXXjg/QF 4beg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nzOiDE92; 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 m3si3786180ejr.329.2020.06.19.08.05.45; Fri, 19 Jun 2020 08:05:45 -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=nzOiDE92; 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 S2391315AbgFSPFl (ORCPT + 15 others); Fri, 19 Jun 2020 11:05:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:34632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391331AbgFSPFk (ORCPT ); Fri, 19 Jun 2020 11:05:40 -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 71E412158C; Fri, 19 Jun 2020 15:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592579140; bh=q2rVo/aR3JTRBRIML0kZmbB8f0+fBsJ6fAx8XSXDfSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nzOiDE924EOoSB++dhIKtoxaTUsFNVvQZBm2KEvni9Rh4nyoGfVBh8YlWfFtKvFaw MfnGptHuzZT5h1QnjI7CDZ+Fr4pZnKHkaJyia2BhfPAUJycxDO+64pgJ63rnCKt0nO 1PLNzt72FNR/5wViCHYJm8EpcFFnjcrmMHbsGgtk= 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.4 022/261] arm64: cacheflush: Fix KGDB trap detection Date: Fri, 19 Jun 2020 16:30:33 +0200 Message-Id: <20200619141650.972111586@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141649.878808811@linuxfoundation.org> References: <20200619141649.878808811@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 665c78e0665a..3e7dda6f1ab1 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(); }