From patchwork Mon May 4 17:05:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 186160 Delivered-To: patches@linaro.org Received: by 2002:a50:3a95:0:0:0:0:0 with SMTP id v21csp2696472ecc; Mon, 4 May 2020 10:05:33 -0700 (PDT) X-Received: by 2002:a5d:694a:: with SMTP id r10mr296602wrw.228.1588611933858; Mon, 04 May 2020 10:05:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588611933; cv=none; d=google.com; s=arc-20160816; b=0A+qVzf9+AzUWTZRgU8wyx00JKCa1MUnJH1f81MjkeMv5wwnSBSfYicPZFS5V3N6um MaH637JNPTT1ErdzgKjYsOIpYXqP7IYFDAllkJ3amw8KQDu92BrHKNn1sLueBEZGvAxw 27Auf5mXiBpdOLnKrPcPclpUX/U4Ofu030RLOiKiicjMcBQ3pq/mO+zMMjPXDuYZDCvT pgX/+Yufmej06qTjJa8UhcZqGmIUYzOCS7zrGSrLZSXi/Oq0iGevjBApqgUtJ1BZpIAV QiVnhcWS//ZK8hMdwcgpz6Neh4ktDviBGzQwwmY575Vy2zmK7AqUdFrwtUcPlTbjPGDR Lb/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=6inNII5kkrOkGxC9SM+OHKVL1fdGg+tB1bP7x4RQ9Z4=; b=v/h3ihtb/IJ8ADsS+mp0UC2DSpINJ2kyaAhIap8tpnbEtlUp4nsAvDgGnrmwIjapiz /Wa1QOJYhBdt+RJCqPDcbiCUykrewZY8sVuxm9V5Fe6vsWePlUGS1tBfrqeYhU/JUaFf v2N8TPSF7qyTtCLIhtsqf1XSl55wOnE0n3EEzc3TmOy+Jh3QeeeZWxPSOOwjau5mArXe EOgZU77mqVCkVM6jGTirTrwfRMnlC8oT6dDMLK4TF4Y/z4v41wowwdiqLmx1Z31VqAny QZzYCkes9BPxtoZfO4D8a/NT9kIPXQloXbUl7eHUles69gx3JkTWhLUMB5qQZC2RNuIV dd1A== 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 daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 18sor74675wmf.14.2020.05.04.10.05.33 for (Google Transport Security); Mon, 04 May 2020 10:05:33 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cijHvyVG; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=je3wjHggXLvZeUPVT5jMkBEaZllGyQnLLJHT1AmqDy4BfsmJdUQKmWD9Y/PSJbH91C 75msSGQyU6eOqEiw7XBltUyMM1h6OWWwv3dNP9pARcuy30/Rsc0xXJn0/m/2In/cNLyx tj3EAzC/vh0h/G1aNuIeGMq1QhGFmPOCOGa1+hH0KrCwadTEIT0TaOYBVvTKtvAdAzrr r4mWT9sxvV3L6CvdDtZj8JrXtWycXDNP3DyLKrrGoic+etwZCh5XX351juQb54twDNfM O4c79uhJEuHxYu6bUq9C6ndyOMoVcjgD1WeBe880bFC0T2xtMxvf3gHRRZ0wQedWV5KL 4ORQ== X-Gm-Message-State: AGi0Pubd4DuF7busPxVA8lvUbVAhOES0tjMEF9luCUU6pmuPKerM5IUS LtT7n4/4lUyiTLnoJ4DH6pJs5kKC X-Google-Smtp-Source: APiQypLEH8rWgUJNRBujiwV8QQWpBqFdu3lEr6ulnlk/jeyXwqeuTWfHXN16q97LrCSCICrrlo4YJw== X-Received: by 2002:a1c:bc09:: with SMTP id m9mr15131404wmf.145.1588611933238; Mon, 04 May 2020 10:05:33 -0700 (PDT) Return-Path: 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 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(-) base-commit: 6a8b55ed4056ea5559ebe4f6a4b247f627870d4c -- 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(); }