Skip to contentSkip to conversation

kgdb: Fix spurious true from in_dbg_master()

PATCH In review Daniel Thompson 3 participants 4 messages May 6, 2020 – May 7, 2020 KGDB / KDB /debug_core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kgdb: Fix spurious true from in_dbg_master()

Currently there is a small window where a badly timed migration could cause in_dbg_master() to spuriously return true. Specifically if we migrate to a new core after reading the processor id and the previous core takes a breakpoint then we will evaluate true if we read kgdb_active before we get the IPI to bring us to halt.

Fix this by checking irqs_disabled() first. Interrupts are always disabled when we are executing the kgdb trap so this is an acceptable prerequisite. This also allows us to replace raw_smp_processor_id() with smp_processor_id() since the short circuit logic will prevent warnings from PREEMPT_DEBUG.

Fixes dcc7871128e9 ("kgdb: core changes to support kdb")
---
 include/linux/kgdb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/kgdb.h +1 -1
index b072aeb1fd78..4d6fe87fd38f 100644
@@ -323,7 +323,7 @@ extern void gdbstub_exit(int status);
 extern int			kgdb_single_step;
 extern atomic_t			kgdb_active;
 #define in_dbg_master() \
-	(raw_smp_processor_id() == atomic_read(&kgdb_active))
+	(irqs_disabled() && (smp_processor_id() == atomic_read(&kgdb_active)))
 extern bool dbg_is_early;
 extern void __init dbg_late_init(void);
 extern void kgdb_panic(const char *msg);

base-commit: 6a8b55ed4056ea5559ebe4f6a4b247f627870d4c --
2.25.1

reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 25 lines · Daniel Thompson

Currently there is a small window where a badly timed migration could cause in_dbg_master() to spuriously return true. Specifically if we migrate to a new core after reading the processor id and the previous core takes a breakpoint then we will evaluate true if we read kgdb_active before we get the IPI to bring us to halt.

Fix this by checking irqs_disabled() first. Interrupts are always disabled when we are executing the kgdb trap so this is an acceptable prerequisite. This also allows us to replace raw_smp_processor_id() with smp_processor_id() since the short circuit logic will prevent warnings from PREEMPT_DEBUG.

Fixes dcc7871128e9 ("kgdb: core changes to support kdb")
---
 include/linux/kgdb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/kgdb.h +0 -0
index b072aeb1fd78..4d6fe87fd38f 100644

include/linux/kgdb.h extern void gdbstub_exit(int status); · line 329

Quoted 8 lines
include/linux/kgdb.h +1 -1
@@ -323,7 +323,7 @@ extern void gdbstub_exit(int status);
 extern int                     kgdb_single_step;
 extern atomic_t                        kgdb_active;
 #define in_dbg_master() \
-       (raw_smp_processor_id() == atomic_read(&kgdb_active))
+       (irqs_disabled() && (smp_processor_id() == atomic_read(&kgdb_active)))
 extern bool dbg_is_early;
 extern void __init dbg_late_init(void);
 extern void kgdb_panic(const char *msg);
#2 lore raw
In reply to Daniel Thompson
Quoted 24 lines · Daniel Thompson

Currently there is a small window where a badly timed migration could cause in_dbg_master() to spuriously return true. Specifically if we migrate to a new core after reading the processor id and the previous core takes a breakpoint then we will evaluate true if we read kgdb_active before we get the IPI to bring us to halt.

Fix this by checking irqs_disabled() first. Interrupts are always disabled when we are executing the kgdb trap so this is an acceptable prerequisite. This also allows us to replace raw_smp_processor_id() with smp_processor_id() since the short circuit logic will prevent warnings from PREEMPT_DEBUG.

Fixes dcc7871128e9 ("kgdb: core changes to support kdb")
---
 include/linux/kgdb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/kgdb.h +0 -0
index b072aeb1fd78..4d6fe87fd38f 100644

include/linux/kgdb.h extern void gdbstub_exit(int status); · line 329

Quoted 8 lines
include/linux/kgdb.h +1 -1
@@ -323,7 +323,7 @@ extern void gdbstub_exit(int status);
 extern int			kgdb_single_step;
 extern atomic_t			kgdb_active;
 #define in_dbg_master() \
-	(raw_smp_processor_id() == atomic_read(&kgdb_active))
+	(irqs_disabled() && (smp_processor_id() == atomic_read(&kgdb_active)))
 extern bool dbg_is_early;
 extern void __init dbg_late_init(void);
 extern void kgdb_panic(const char *msg);

Cheers, Daniel. I assume you'll route this one via the kgdb tree? I can live with the "small window" in the arm64 for-next/core branch ;)

Will

#3 lore raw
Quoted 20 lines · Will Deacon
Quoted 19 lines · Daniel Thompson

Currently there is a small window where a badly timed migration could cause in_dbg_master() to spuriously return true. Specifically if we migrate to a new core after reading the processor id and the previous core takes a breakpoint then we will evaluate true if we read kgdb_active before we get the IPI to bring us to halt.

Fix this by checking irqs_disabled() first. Interrupts are always disabled when we are executing the kgdb trap so this is an acceptable prerequisite. This also allows us to replace raw_smp_processor_id() with smp_processor_id() since the short circuit logic will prevent warnings from PREEMPT_DEBUG.

Fixes dcc7871128e9 ("kgdb: core changes to support kdb")
---
 include/linux/kgdb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

include/linux/kgdb.h extern void gdbstub_exit(int status); · line 329

Quoted 13 lines
include/linux/kgdb.h +1 -1
index b072aeb1fd78..4d6fe87fd38f 100644
@@ -323,7 +323,7 @@ extern void gdbstub_exit(int status);
 extern int			kgdb_single_step;
 extern atomic_t			kgdb_active;
 #define in_dbg_master() \
-	(raw_smp_processor_id() == atomic_read(&kgdb_active))
+	(irqs_disabled() && (smp_processor_id() == atomic_read(&kgdb_active)))
 extern bool dbg_is_early;
 extern void __init dbg_late_init(void);
 extern void kgdb_panic(const char *msg);

Cheers, Daniel. I assume you'll route this one via the kgdb tree? I can live with the "small window" in the arm64 for-next/core branch ;)

Yes. I'll get this one applied very soon (thanks for Doug for the quick review).

Daniel.