Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp120358ybg; Mon, 8 Jun 2020 18:10:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxThw9phh3kTRPE4KGXTdOgFuLsy9HV54zf5kIjaXF24MspE23/jdvJxLdLyae0EY49X+1s X-Received: by 2002:a50:af25:: with SMTP id g34mr13267334edd.85.1591665043738; Mon, 08 Jun 2020 18:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591665043; cv=none; d=google.com; s=arc-20160816; b=wvJu0RM301cx7mCq9tgX0diwa9ZeBXDrpVt6Kze+bGAns8dUO9qbw11+n0etKPaDQh uf3kEf+vZdh9WHPNSD7mmv8zbfqrSnMEGHiTLPv0tLviSVH3f5yTp/B7z2oYKB92dvXp vN4eFkkMSRxOxs1YP6QlJ/Rl+N1I0V0UIkeA4Ll+DxdOiUBK7uCUCs+O7/lnuh6/J7Uo s7tY2k0kFC3O3YsgRH6ZJrnDjmNXlzByD1rxefMt6SZD677w2xreILABD841P/PDEIpV yXf7+t11RVWmtRMR8wp5e1hl9XJH8ZGW/jFsrV1MvVXcK+HF9mypM5Ii8MpkMO09y93m dhhw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kmzaqVRCTEKiwN0L6FygVeJ0FiYklNdjW/hzjrpZI74=; b=gUdlFjx1A2IjBiQcsXRRE+BPJ4EPBE5LevctbizmyPeQUhrALwPGiOcl8FnbDPWJ8D os6SeWntCnweZ1nxNgO4iV1KA1E7hFQDOKe34C6+lrqNaAhJXuaJoCv1FBrAsUThq2fL qaLZJLAxG+KCwps9dj37fNpZ3xv4Cj2fU+7JARA4X+RVBjm0x/cc8FRGm3ax0cQKGJ2N WqONx3XJhKrrjPtLhMuOtDPi+aT/ad+sSTPLSaHFbczdZcuNKNNIJrmGgXv5PHzy25J7 eCpvN/nnHzfV7JVyT+P7iG8Mxnxai5b88wcRO3pOi6i6IrUxgPLLBKGfRnRdKt6b5rRR Y4dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rmJfWDAQ; 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 h25si9155710ejt.604.2020.06.08.18.10.21; Mon, 08 Jun 2020 18:10:43 -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=rmJfWDAQ; 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 S2388220AbgFIBIX (ORCPT + 99 others); Mon, 8 Jun 2020 21:08:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:50044 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727076AbgFHXGs (ORCPT ); Mon, 8 Jun 2020 19:06:48 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1B8EB20775; Mon, 8 Jun 2020 23:06:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657607; bh=PG0qiH2KEanMcWHB5FHf6WHtqvnKB05Xm9dmC6kGVQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rmJfWDAQ3hLW+8uWpVXf4bpBV29BISzh1lslYqykuhQPSPR1kB3AnR0e19Nhdepal mT07F/I5CIlT40wvpGUUmYvRb+fOidbqg5de6ySkdCyIyxeYIHr/1ixQvFpW1lo3ht 2/y8/4bB0ai8/0RgBriVwBpYNVGirgPaVirJ7+EY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Daniel Thompson , Douglas Anderson , Will Deacon , Sasha Levin , linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.7 032/274] arm64: cacheflush: Fix KGDB trap detection Date: Mon, 8 Jun 2020 19:02:05 -0400 Message-Id: <20200608230607.3361041-32-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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