Skip to contentSkip to conversation

kdb: Make kdb_printf robust to run in NMI context

PATCH Superseded Sumit Garg 2 participants 3 messages May 22, 2020 KGDB / KDB /debug_core

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Sumit Garg

author
#0 lore raw

PATCH 1/1 kdb: Make kdb_printf robust to run in NMI context

While rounding up CPUs via NMIs, its possible that a rounded up CPU maybe holding a console port lock leading to kgdb master CPU stuck in a deadlock during invocation of console write operations. So in order to avoid such a deadlock, invoke bust_spinlocks() prior to invocation of console handlers.

Also, add a check for console port to be enabled prior to invocation of corresponding handler.

---
 kernel/debug/kdb/kdb_io.c | 8 ++++++++
 1 file changed, 8 insertions(+)
kernel/debug/kdb/kdb_io.c +8 -0
index 924bc92..e32ece6 100644
@@ -699,7 +699,11 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
 			}
 		}
 		for_each_console(c) {
+			if (!(c->flags & CON_ENABLED))
+				continue;
+			bust_spinlocks(1);
 			c->write(c, cp, retlen - (cp - kdb_buffer));
+			bust_spinlocks(0);
 			touch_nmi_watchdog();
 		}
 	}
@@ -761,7 +765,11 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
 			}
 		}
 		for_each_console(c) {
+			if (!(c->flags & CON_ENABLED))
+				continue;
+			bust_spinlocks(1);
 			c->write(c, moreprompt, strlen(moreprompt));
+			bust_spinlocks(0);
 			touch_nmi_watchdog();
 		}
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 21 lines · Sumit Garg

While rounding up CPUs via NMIs, its possible that a rounded up CPU maybe holding a console port lock leading to kgdb master CPU stuck in a deadlock during invocation of console write operations. So in order to avoid such a deadlock, invoke bust_spinlocks() prior to invocation of console handlers.

Also, add a check for console port to be enabled prior to invocation of corresponding handler.

---
 kernel/debug/kdb/kdb_io.c | 8 ++++++++
 1 file changed, 8 insertions(+)
kernel/debug/kdb/kdb_io.c +0 -0
index 924bc92..e32ece6 100644

kernel/debug/kdb/kdb_io.c int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) · line 706

Quoted 8 lines
kernel/debug/kdb/kdb_io.c +4 -0
@@ -699,7 +699,11 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
 			}
 		}
 		for_each_console(c) {
+			if (!(c->flags & CON_ENABLED))
+				continue;
+			bust_spinlocks(1);
 			c->write(c, cp, retlen - (cp - kdb_buffer));
+			bust_spinlocks(0);

I think it might actually be better to directly manipulate oops_in_progress here.

bust_spinlocks(0) will call unblank_screen() and console_unblank() and I don't think calling these is worth the risk (and whilst kicking klogd is safe I think its also not required).

Daniel.

Quoted 18 lines
kernel/debug/kdb/kdb_io.c +4 -0
 			touch_nmi_watchdog();
 		}
 	}
@@ -761,7 +765,11 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
 			}
 		}
 		for_each_console(c) {
+			if (!(c->flags & CON_ENABLED))
+				continue;
+			bust_spinlocks(1);
 			c->write(c, moreprompt, strlen(moreprompt));
+			bust_spinlocks(0);
 			touch_nmi_watchdog();
 		}
 
Signature · 1 line
2.7.4
author
#2 lore raw
Quoted 18 lines · Daniel Thompson
Quoted 16 lines · Sumit Garg

While rounding up CPUs via NMIs, its possible that a rounded up CPU maybe holding a console port lock leading to kgdb master CPU stuck in a deadlock during invocation of console write operations. So in order to avoid such a deadlock, invoke bust_spinlocks() prior to invocation of console handlers.

Also, add a check for console port to be enabled prior to invocation of corresponding handler.

---
 kernel/debug/kdb/kdb_io.c | 8 ++++++++
 1 file changed, 8 insertions(+)
Quoted 17 lines

kernel/debug/kdb/kdb_io.c int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) · line 706

Quoted 13 lines
kernel/debug/kdb/kdb_io.c +4 -0
index 924bc92..e32ece6 100644
@@ -699,7 +699,11 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
                      }
              }
              for_each_console(c) {
+                     if (!(c->flags & CON_ENABLED))
+                             continue;
+                     bust_spinlocks(1);
                      c->write(c, cp, retlen - (cp - kdb_buffer));
+                     bust_spinlocks(0);

I think it might actually be better to directly manipulate oops_in_progress here.

Okay will directly manipulate oops_in_progress here.

Quoted 3 lines

bust_spinlocks(0) will call unblank_screen() and console_unblank() and I don't think calling these is worth the risk (and whilst kicking klogd is safe I think its also not required).

Makes sense.

-Sumit

Quoted 24 lines

Daniel.

Quoted 18 lines
kernel/debug/kdb/kdb_io.c +4 -1
                      touch_nmi_watchdog();
              }
      }
@@ -761,7 +765,11 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
                      }
              }
              for_each_console(c) {
+                     if (!(c->flags & CON_ENABLED))
+                             continue;
+                     bust_spinlocks(1);
                      c->write(c, moreprompt, strlen(moreprompt));
+                     bust_spinlocks(0);
                      touch_nmi_watchdog();
              }
 
--

2.7.4