Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3899323ybz; Mon, 4 May 2020 11:46:03 -0700 (PDT) X-Google-Smtp-Source: APiQypJ9WLdo72s61ATzQCNXGUkdGj2SeTHMvV8M8gZsOD9QFnchhQa7NVy+gDzPL9c5paiPZAd9 X-Received: by 2002:aa7:c312:: with SMTP id l18mr16502582edq.161.1588617963547; Mon, 04 May 2020 11:46:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588617963; cv=none; d=google.com; s=arc-20160816; b=zeJAtJmeTO3ehw9mvUyXmhaJvAk9bObk7pr7V7SUQqjAaGhPug1sg+vcx0544tctvY M6Vkh4gLeHAbqSqpcH0LR0gzDIYnzAJ/AR9bBkJu123Jih9Q5cWQE7t9/a+1MnTOfLGc fFwezSiZMwt++Ny8cE8LHOneBuOwbm8ekqyzBzU5P7etIOvyTgpu1dJjMWhwxgAaKPeU M83Tf91boIYpByrJdSzpr61qNmbEs+Dz5Ksgxr6fSZVxI+37r6sH3VjS6IB0fLZOJqSC /6Yt0mITdbFSsse3NRkFf+SAkxZdgsISYO9dWM7dwUortB3uYMh33mAkCdQYhbEGujBZ Tzsg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=6inNII5kkrOkGxC9SM+OHKVL1fdGg+tB1bP7x4RQ9Z4=; b=CKdoJzd6lsGidLCVK1hHaShItlbm+02wEUKhhhzRFm9bdsPEHhYNiO5xg5H2uNMXB6 F2Zv5HbRtnc84JiLky00NSjTJrAYtIWOpMemchxJFrH2c048qPu96oL+Nx6BMoF0w5Jc 13w9SQq/snI2bYTHlsXuBMkW936vkqKxym76T3tbqkNFqjxph0i50uIw4sAo8yez+xRL bN4BFzZLcXbHJ5Bp0uB5Wl3cyYpBTXYJxDQhjCKNaasVJ9wLksE29ukUELf79TSyh4L2 TTzvZ3lpa1pDSX0NFUejEccjlX030tUoV+r7PgtkOoqOlH+43yrXQtZoyCLA/ZrLaQ8u qVLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cijHvyVG; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si7535391ejr.224.2020.05.04.11.45.40; Mon, 04 May 2020 11:46:03 -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=@linaro.org header.s=google header.b=cijHvyVG; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729817AbgEDRFf (ORCPT + 99 others); Mon, 4 May 2020 13:05:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729553AbgEDRFe (ORCPT ); Mon, 4 May 2020 13:05:34 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94035C061A0E for ; Mon, 4 May 2020 10:05:34 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id v8so486731wma.0 for ; Mon, 04 May 2020 10:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6inNII5kkrOkGxC9SM+OHKVL1fdGg+tB1bP7x4RQ9Z4=; b=cijHvyVGcv+Hb9axsZx8Iukpxxstp2yEPu+xziQQvcvVnwyZPuSmisGyalVyoLyC3A NG1oq92orVjdooXhp0vRTjTznKlTUbi2XCVMrupD13j2JeFGpQucEO8TwLBivmDepKs3 ob/QKRCyzB26vB1I3HfrnlnA1vEXnhyAsv7jc8RvWFvVfnSVRpQFeXLrdHml8LPRLP66 Dtcr0HjtM6aiKT9YnYEbJjzSyNjveIkTNT/W6rIWa5bx2Jd0GS9Ywdm6C3mVueSg8JEc IhtuoH7UgMky0TuoxzyY8McDmODkJ0MS5CmJcxgaI8Z8AxX15u6TCcMdjaq8JeVLDV8H Q65A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6inNII5kkrOkGxC9SM+OHKVL1fdGg+tB1bP7x4RQ9Z4=; b=hLPAgnauZaFzt57exwqnrQb9wG2pOllTv3n4oScjqib2b/n4cPrvpibFo2JkOA4ftm RUDjw/RYKjsFtaJDK4pjbdcPDeQfUsdPPNT/mw6m6ZCsXCUKj+36MGw6sS98BvO+3qOO 79+XIpR9xn3f9pebw/shns16qW8KBiSmULuepme+m5H3UAELQ6G69bnS+DWR7CHXmLpo gjOaQAy8A31fSEvl1tkwXBB/SVV1PV8An0HTXuVcmPgKgNQK0c93wu7R2gPrLoalLBWG QLc0SB/vkXgOwu2E/OPIsu+eSXiSN3GzPtDm+52HREZVFnV8mlfLiBg5NVfj2KL12Ihe 4Rcw== X-Gm-Message-State: AGi0Pub1VXNxPg4K1l8+6+Gpm2elJzTQh1nXGl6HySzaUVM5YTSzElDm 6deBsKHqykbiEIDV/l7Ze9PIEA== X-Received: by 2002:a1c:bc09:: with SMTP id m9mr15131404wmf.145.1588611933238; Mon, 04 May 2020 10:05:33 -0700 (PDT) Received: from wychelm.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id w9sm3067718wrc.27.2020.05.04.10.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2020 10:05:32 -0700 (PDT) From: Daniel Thompson To: Catalin Marinas , Will Deacon Cc: Daniel Thompson , Douglas Anderson , Jason Wessel , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v2] arm64: cacheflush: Fix KGDB trap detection Date: Mon, 4 May 2020 18:05:18 +0100 Message-Id: <20200504170518.2959478-1-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Notes: v2: Improve the commit message based based on feedback from Doug Anderson 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(); } base-commit: 6a8b55ed4056ea5559ebe4f6a4b247f627870d4c -- 2.25.1