Skip to content

Commit ab8ad27

Browse files
Daniel Thompsonwilldeacon
authored andcommitted
arm64: cacheflush: Fix KGDB trap detection
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: 3b8c9f1 ("arm64: IPI each CPU after invalidating the I-cache for kernel mappings") Signed-off-by: Daniel Thompson <[email protected]> Reviewed-by: Douglas Anderson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent da7bad9 commit ab8ad27

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

arch/arm64/include/asm/cacheflush.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static inline void flush_icache_range(unsigned long start, unsigned long end)
7979
* IPI all online CPUs so that they undergo a context synchronization
8080
* event and are forced to refetch the new instructions.
8181
*/
82-
#ifdef CONFIG_KGDB
82+
8383
/*
8484
* KGDB performs cache maintenance with interrupts disabled, so we
8585
* 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)
8989
* the patching operation, so we don't need extra IPIs here anyway.
9090
* In which case, add a KGDB-specific bodge and return early.
9191
*/
92-
if (kgdb_connected && irqs_disabled())
92+
if (in_dbg_master())
9393
return;
94-
#endif
94+
9595
kick_all_cpus_sync();
9696
}
9797

0 commit comments

Comments
 (0)