linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kdb: Make kdb_printf robust to run in NMI context
@ 2020-05-22 10:02 Sumit Garg
  2020-05-22 10:38 ` Daniel Thompson
  0 siblings, 1 reply; 3+ messages in thread
From: Sumit Garg @ 2020-05-22 10:02 UTC (permalink / raw)
  To: kgdb-bugreport
  Cc: jason.wessel, daniel.thompson, dianders, pmladek,
	sergey.senozhatsky, linux-kernel, 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.

Suggested-by: Petr Mladek <pmladek@suse.com>
Suggested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 kernel/debug/kdb/kdb_io.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
index 924bc92..e32ece6 100644
--- a/kernel/debug/kdb/kdb_io.c
+++ b/kernel/debug/kdb/kdb_io.c
@@ -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();
 		}
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] kdb: Make kdb_printf robust to run in NMI context
  2020-05-22 10:02 [PATCH] kdb: Make kdb_printf robust to run in NMI context Sumit Garg
@ 2020-05-22 10:38 ` Daniel Thompson
  2020-05-22 10:52   ` Sumit Garg
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Thompson @ 2020-05-22 10:38 UTC (permalink / raw)
  To: Sumit Garg
  Cc: kgdb-bugreport, jason.wessel, dianders, pmladek,
	sergey.senozhatsky, linux-kernel

On Fri, May 22, 2020 at 03:32:26PM +0530, Sumit Garg wrote:
> 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.
> 
> Suggested-by: Petr Mladek <pmladek@suse.com>
> Suggested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
> ---
>  kernel/debug/kdb/kdb_io.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
> index 924bc92..e32ece6 100644
> --- a/kernel/debug/kdb/kdb_io.c
> +++ b/kernel/debug/kdb/kdb_io.c
> @@ -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.



>  			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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kdb: Make kdb_printf robust to run in NMI context
  2020-05-22 10:38 ` Daniel Thompson
@ 2020-05-22 10:52   ` Sumit Garg
  0 siblings, 0 replies; 3+ messages in thread
From: Sumit Garg @ 2020-05-22 10:52 UTC (permalink / raw)
  To: Daniel Thompson
  Cc: kgdb-bugreport, Jason Wessel, Douglas Anderson, Petr Mladek,
	Sergey Senozhatsky, Linux Kernel Mailing List

On Fri, 22 May 2020 at 16:08, Daniel Thompson
<daniel.thompson@linaro.org> wrote:
>
> On Fri, May 22, 2020 at 03:32:26PM +0530, Sumit Garg wrote:
> > 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.
> >
> > Suggested-by: Petr Mladek <pmladek@suse.com>
> > Suggested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> > Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
> > ---
> >  kernel/debug/kdb/kdb_io.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
> > index 924bc92..e32ece6 100644
> > --- a/kernel/debug/kdb/kdb_io.c
> > +++ b/kernel/debug/kdb/kdb_io.c
> > @@ -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.

> 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

>
>
> Daniel.
>
>
>
> >                       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
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-22 10:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-22 10:02 [PATCH] kdb: Make kdb_printf robust to run in NMI context Sumit Garg
2020-05-22 10:38 ` Daniel Thompson
2020-05-22 10:52   ` Sumit Garg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).