From patchwork Fri Jun 19 14:31:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 191255 Delivered-To: patch@linaro.org Received: by 2002:a92:cf06:0:0:0:0:0 with SMTP id c6csp679979ilo; Fri, 19 Jun 2020 09:25:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVA8TqTKLDIVnA26ILxY7P1gadEzdtIowM0LcZ+CGCUZJTSLw3zBnufLwuH7TKuq0wxjhC X-Received: by 2002:a05:6402:1153:: with SMTP id g19mr4035915edw.127.1592583942664; Fri, 19 Jun 2020 09:25:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592583942; cv=none; d=google.com; s=arc-20160816; b=usQ0QboslSDOJQY/h719xhl4Ty2NOywtZuWDeNbcARvM6855Yv8C/GpfkIvw+SB0UH 4Tkjbrc22jDvFdyNF6r2vwcK2ct/NOGN0ne6p/ImqF9UXkAcczge9ZFEEKrsD/bFCqE9 CMoByPnzJsfI2nmW92P9Oh7cJ+0npfXOycHlnBFpb+RjG56QDD+vUa30LGsY5swqb0Z6 h2ciZS+z2pQbDApmcGIYCKnh6Jn9UmoDwHYyGsfErbKiVeXVH4j7Q3T1cjjfWRoudBI8 1ggUYj39deMX2l7cTdkQIFSUBLM0bUajFizbctEMQCaageH5m2rKp+ran25msYTbN1lB F9Zg== 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=b226LvTO5piy35POVom6YT2PHmPaT1iouVbWEbtWwyU=; b=pyRldsKdJI7fenO6ZCiFSRI7LtgK59GMCaxQyi0hMgLP53TYBK8R6wnj2XeNb+qpwY /Q/4gEGSEmppoJtObq5zwIPB9AgiucmvGOEQiTUhoQYxyIE3L4C+SARIZwoPQSyuHcXc +zz5QIcrYFVuviWlTJm8H1q1TFir61+OW/QMbVcfMw9zyplcwHuqNedLTON6LbiwO1zX jH+GfRr44uWYb7lemrXmMhW9qxciP2fM+9L+n4LeD73c8OBpmZGtsGQeRUwqgpT3urx/ jwI8Otsie2pFBnN8G398NYMyNV98SuEB+sKE+lGjPVCQWv4MiwRtqcmvcBQk3qJ9U4DX Vn3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZV5Vc2oc; 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 e9si3909148eja.348.2020.06.19.09.25.42; Fri, 19 Jun 2020 09:25:42 -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=ZV5Vc2oc; 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 S2390614AbgFSQZl (ORCPT + 15 others); Fri, 19 Jun 2020 12:25:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:52810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390236AbgFSO5Z (ORCPT ); Fri, 19 Jun 2020 10:57:25 -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 569CA2158C; Fri, 19 Jun 2020 14:57:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578645; bh=CY52Bl6hIbhNX7WaF6Vsas88tR+RJPp+8Q5PkrVQ+eg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZV5Vc2oc3j4dOmwnk/GDoA7pSOT3xTx+XCYZJ5f5//c7f2gwwf/VlDFolU3AueVAw NskjQsuTp0n0YRoP+zc95P2u+0PcEBiSjGEmz5WHQ9c5auupUyaOzIK/Y+sZw8cj/Y 7aJicn9Hx3iyWXt5BQCx9BGUqEUEd+hEtpRXCMyM= 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 4.19 102/267] arm64: cacheflush: Fix KGDB trap detection Date: Fri, 19 Jun 2020 16:31:27 +0200 Message-Id: <20200619141653.757619395@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141648.840376470@linuxfoundation.org> References: <20200619141648.840376470@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 19844211a4e6..a449a1c602d3 100644 --- a/arch/arm64/include/asm/cacheflush.h +++ b/arch/arm64/include/asm/cacheflush.h @@ -90,7 +90,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 @@ -100,9 +100,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(); }