linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] printk: introduce dump_stack_lvl()
@ 2021-05-05  9:22 Alexander Potapenko
  2021-05-05  9:22 ` [PATCH 2/2] kasan: use dump_stack_lvl(KERN_ERR) to print stacks Alexander Potapenko
  2021-05-05 10:37 ` [PATCH 1/2] printk: introduce dump_stack_lvl() Marco Elver
  0 siblings, 2 replies; 4+ messages in thread
From: Alexander Potapenko @ 2021-05-05  9:22 UTC (permalink / raw)
  To: akpm, pmladek, mingo
  Cc: bo.he, yanmin_zhang, psodagud, dvyukov, elver, linux-kernel,
	ryabinin.a.a, Alexander Potapenko, he

dump_stack() is used for many different cases, which may require a log
level consistent with other kernel messages surrounding the dump_stack()
call.
Without that, certain systems that are configured to ignore the default
level messages will miss stack traces in critical error reports.

This patch introduces dump_stack_lvl() that behaves similarly to
dump_stack(), but accepts a custom log level.
The old dump_stack() becomes equal to dump_stack_lvl(KERN_DEFAULT).

A somewhat similar patch has been proposed in 2012:
https://lore.kernel.org/lkml/1332493269.2359.9.camel@hebo/
, but wasn't merged.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: he, bo <bo.he@intel.com>
Cc: Yanmin Zhang <yanmin_zhang@linux.intel.com>
Cc: Prasad Sodagudi <psodagud@quicinc.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Marco Elver <elver@google.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Alexander Potapenko <glider@google.com>
---
 include/linux/printk.h |  1 +
 lib/dump_stack.c       | 19 ++++++++++++-------
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index fe7eb2351610..abe274305d79 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -206,6 +206,7 @@ void __init setup_log_buf(int early);
 __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
 void dump_stack_print_info(const char *log_lvl);
 void show_regs_print_info(const char *log_lvl);
+extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
 extern asmlinkage void dump_stack(void) __cold;
 extern void printk_safe_flush(void);
 extern void printk_safe_flush_on_panic(void);
diff --git a/lib/dump_stack.c b/lib/dump_stack.c
index f5a33b6f773f..3d2c324a4929 100644
--- a/lib/dump_stack.c
+++ b/lib/dump_stack.c
@@ -73,10 +73,10 @@ void show_regs_print_info(const char *log_lvl)
 	dump_stack_print_info(log_lvl);
 }
 
-static void __dump_stack(void)
+static void __dump_stack(const char *log_lvl)
 {
-	dump_stack_print_info(KERN_DEFAULT);
-	show_stack(NULL, NULL, KERN_DEFAULT);
+	dump_stack_print_info(log_lvl);
+	show_stack(NULL, NULL, log_lvl);
 }
 
 /**
@@ -87,7 +87,7 @@ static void __dump_stack(void)
 #ifdef CONFIG_SMP
 static atomic_t dump_lock = ATOMIC_INIT(-1);
 
-asmlinkage __visible void dump_stack(void)
+asmlinkage __visible void dump_stack_lvl(const char *log_lvl)
 {
 	unsigned long flags;
 	int was_locked;
@@ -117,7 +117,7 @@ asmlinkage __visible void dump_stack(void)
 		goto retry;
 	}
 
-	__dump_stack();
+	__dump_stack(log_lvl);
 
 	if (!was_locked)
 		atomic_set(&dump_lock, -1);
@@ -125,9 +125,14 @@ asmlinkage __visible void dump_stack(void)
 	local_irq_restore(flags);
 }
 #else
-asmlinkage __visible void dump_stack(void)
+asmlinkage __visible void dump_stack_lvl(const char *log_lvl)
 {
-	__dump_stack();
+	__dump_stack(log_lvl);
 }
 #endif
+
+asmlinkage __visible void dump_stack(void)
+{
+	dump_stack_lvl(KERN_DEFAULT);
+}
 EXPORT_SYMBOL(dump_stack);
-- 
2.31.1.527.g47e6f16901-goog


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

* [PATCH 2/2] kasan: use dump_stack_lvl(KERN_ERR) to print stacks
  2021-05-05  9:22 [PATCH 1/2] printk: introduce dump_stack_lvl() Alexander Potapenko
@ 2021-05-05  9:22 ` Alexander Potapenko
  2021-05-05 10:37 ` [PATCH 1/2] printk: introduce dump_stack_lvl() Marco Elver
  1 sibling, 0 replies; 4+ messages in thread
From: Alexander Potapenko @ 2021-05-05  9:22 UTC (permalink / raw)
  To: akpm, pmladek, mingo
  Cc: bo.he, yanmin_zhang, psodagud, dvyukov, elver, linux-kernel,
	ryabinin.a.a, Alexander Potapenko

Most of the contents of KASAN reports are printed with pr_err(), so use
a consistent logging level to print the memory access stacks.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Prasad Sodagudi <psodagud@quicinc.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Marco Elver <elver@google.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Alexander Potapenko <glider@google.com>
---
 mm/kasan/report.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index 14bd51ea2348..8fff1825b22c 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -230,7 +230,7 @@ static void print_address_description(void *addr, u8 tag)
 {
 	struct page *page = kasan_addr_to_page(addr);
 
-	dump_stack();
+	dump_stack_lvl(KERN_ERR);
 	pr_err("\n");
 
 	if (page && PageSlab(page)) {
@@ -375,7 +375,7 @@ void kasan_report_async(void)
 	pr_err("BUG: KASAN: invalid-access\n");
 	pr_err("Asynchronous mode enabled: no access details available\n");
 	pr_err("\n");
-	dump_stack();
+	dump_stack_lvl(KERN_ERR);
 	end_report(&flags, 0);
 }
 #endif /* CONFIG_KASAN_HW_TAGS */
@@ -420,7 +420,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write,
 		pr_err("\n");
 		print_memory_metadata(info.first_bad_addr);
 	} else {
-		dump_stack();
+		dump_stack_lvl(KERN_ERR);
 	}
 
 	end_report(&flags, addr);
-- 
2.31.1.527.g47e6f16901-goog


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

* Re: [PATCH 1/2] printk: introduce dump_stack_lvl()
  2021-05-05  9:22 [PATCH 1/2] printk: introduce dump_stack_lvl() Alexander Potapenko
  2021-05-05  9:22 ` [PATCH 2/2] kasan: use dump_stack_lvl(KERN_ERR) to print stacks Alexander Potapenko
@ 2021-05-05 10:37 ` Marco Elver
  2021-05-05 10:58   ` Alexander Potapenko
  1 sibling, 1 reply; 4+ messages in thread
From: Marco Elver @ 2021-05-05 10:37 UTC (permalink / raw)
  To: Alexander Potapenko
  Cc: Andrew Morton, Petr Mladek, Ingo Molnar, bo.he, yanmin_zhang,
	psodagud, Dmitry Vyukov, LKML, Andrey Ryabinin, he

On Wed, 5 May 2021 at 11:22, Alexander Potapenko <glider@google.com> wrote:
> dump_stack() is used for many different cases, which may require a log
> level consistent with other kernel messages surrounding the dump_stack()
> call.
> Without that, certain systems that are configured to ignore the default
> level messages will miss stack traces in critical error reports.
>
> This patch introduces dump_stack_lvl() that behaves similarly to
> dump_stack(), but accepts a custom log level.
> The old dump_stack() becomes equal to dump_stack_lvl(KERN_DEFAULT).
>
> A somewhat similar patch has been proposed in 2012:
> https://lore.kernel.org/lkml/1332493269.2359.9.camel@hebo/
> , but wasn't merged.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Petr Mladek <pmladek@suse.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: he, bo <bo.he@intel.com>
> Cc: Yanmin Zhang <yanmin_zhang@linux.intel.com>
> Cc: Prasad Sodagudi <psodagud@quicinc.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: Marco Elver <elver@google.com>
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Alexander Potapenko <glider@google.com>
> ---
>  include/linux/printk.h |  1 +
>  lib/dump_stack.c       | 19 ++++++++++++-------
>  2 files changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/include/linux/printk.h b/include/linux/printk.h
> index fe7eb2351610..abe274305d79 100644
> --- a/include/linux/printk.h
> +++ b/include/linux/printk.h
> @@ -206,6 +206,7 @@ void __init setup_log_buf(int early);
>  __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
>  void dump_stack_print_info(const char *log_lvl);
>  void show_regs_print_info(const char *log_lvl);
> +extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
>  extern asmlinkage void dump_stack(void) __cold;
>  extern void printk_safe_flush(void);
>  extern void printk_safe_flush_on_panic(void);
> diff --git a/lib/dump_stack.c b/lib/dump_stack.c
> index f5a33b6f773f..3d2c324a4929 100644
> --- a/lib/dump_stack.c
> +++ b/lib/dump_stack.c
> @@ -73,10 +73,10 @@ void show_regs_print_info(const char *log_lvl)
>         dump_stack_print_info(log_lvl);
>  }
>
> -static void __dump_stack(void)
> +static void __dump_stack(const char *log_lvl)
>  {
> -       dump_stack_print_info(KERN_DEFAULT);
> -       show_stack(NULL, NULL, KERN_DEFAULT);
> +       dump_stack_print_info(log_lvl);
> +       show_stack(NULL, NULL, log_lvl);
>  }
>
>  /**
> @@ -87,7 +87,7 @@ static void __dump_stack(void)
>  #ifdef CONFIG_SMP
>  static atomic_t dump_lock = ATOMIC_INIT(-1);
>
> -asmlinkage __visible void dump_stack(void)
> +asmlinkage __visible void dump_stack_lvl(const char *log_lvl)
>  {
>         unsigned long flags;
>         int was_locked;
> @@ -117,7 +117,7 @@ asmlinkage __visible void dump_stack(void)
>                 goto retry;
>         }
>
> -       __dump_stack();
> +       __dump_stack(log_lvl);
>
>         if (!was_locked)
>                 atomic_set(&dump_lock, -1);
> @@ -125,9 +125,14 @@ asmlinkage __visible void dump_stack(void)
>         local_irq_restore(flags);
>  }
>  #else
> -asmlinkage __visible void dump_stack(void)
> +asmlinkage __visible void dump_stack_lvl(const char *log_lvl)
>  {
> -       __dump_stack();
> +       __dump_stack(log_lvl);
>  }
>  #endif

+EXPORT_SYMBOL(dump_stack_lvl);

is missing here?

> +
> +asmlinkage __visible void dump_stack(void)
> +{
> +       dump_stack_lvl(KERN_DEFAULT);
> +}
>  EXPORT_SYMBOL(dump_stack);
> --
> 2.31.1.527.g47e6f16901-goog
>

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

* Re: [PATCH 1/2] printk: introduce dump_stack_lvl()
  2021-05-05 10:37 ` [PATCH 1/2] printk: introduce dump_stack_lvl() Marco Elver
@ 2021-05-05 10:58   ` Alexander Potapenko
  0 siblings, 0 replies; 4+ messages in thread
From: Alexander Potapenko @ 2021-05-05 10:58 UTC (permalink / raw)
  To: Marco Elver
  Cc: Andrew Morton, Petr Mladek, Ingo Molnar, bo.he, yanmin_zhang,
	psodagud, Dmitry Vyukov, LKML, Andrey Ryabinin, he

On Wed, May 5, 2021 at 12:37 PM Marco Elver <elver@google.com> wrote:
>
> On Wed, 5 May 2021 at 11:22, Alexander Potapenko <glider@google.com> wrote:
> > dump_stack() is used for many different cases, which may require a log
> > level consistent with other kernel messages surrounding the dump_stack()
> > call.
> > Without that, certain systems that are configured to ignore the default
> > level messages will miss stack traces in critical error reports.
> >
> > This patch introduces dump_stack_lvl() that behaves similarly to
> > dump_stack(), but accepts a custom log level.
> > The old dump_stack() becomes equal to dump_stack_lvl(KERN_DEFAULT).
> >
> > A somewhat similar patch has been proposed in 2012:
> > https://lore.kernel.org/lkml/1332493269.2359.9.camel@hebo/
> > , but wasn't merged.
> >
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Cc: Petr Mladek <pmladek@suse.com>
> > Cc: Ingo Molnar <mingo@kernel.org>
> > Cc: he, bo <bo.he@intel.com>
> > Cc: Yanmin Zhang <yanmin_zhang@linux.intel.com>
> > Cc: Prasad Sodagudi <psodagud@quicinc.com>
> > Cc: Dmitry Vyukov <dvyukov@google.com>
> > Cc: Marco Elver <elver@google.com>
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Alexander Potapenko <glider@google.com>
> > ---
> >  include/linux/printk.h |  1 +
> >  lib/dump_stack.c       | 19 ++++++++++++-------
> >  2 files changed, 13 insertions(+), 7 deletions(-)
> >
> > diff --git a/include/linux/printk.h b/include/linux/printk.h
> > index fe7eb2351610..abe274305d79 100644
> > --- a/include/linux/printk.h
> > +++ b/include/linux/printk.h
> > @@ -206,6 +206,7 @@ void __init setup_log_buf(int early);
> >  __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
> >  void dump_stack_print_info(const char *log_lvl);
> >  void show_regs_print_info(const char *log_lvl);
> > +extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
> >  extern asmlinkage void dump_stack(void) __cold;
> >  extern void printk_safe_flush(void);
> >  extern void printk_safe_flush_on_panic(void);
> > diff --git a/lib/dump_stack.c b/lib/dump_stack.c
> > index f5a33b6f773f..3d2c324a4929 100644
> > --- a/lib/dump_stack.c
> > +++ b/lib/dump_stack.c
> > @@ -73,10 +73,10 @@ void show_regs_print_info(const char *log_lvl)
> >         dump_stack_print_info(log_lvl);
> >  }
> >
> > -static void __dump_stack(void)
> > +static void __dump_stack(const char *log_lvl)
> >  {
> > -       dump_stack_print_info(KERN_DEFAULT);
> > -       show_stack(NULL, NULL, KERN_DEFAULT);
> > +       dump_stack_print_info(log_lvl);
> > +       show_stack(NULL, NULL, log_lvl);
> >  }
> >
> >  /**
> > @@ -87,7 +87,7 @@ static void __dump_stack(void)
> >  #ifdef CONFIG_SMP
> >  static atomic_t dump_lock = ATOMIC_INIT(-1);
> >
> > -asmlinkage __visible void dump_stack(void)
> > +asmlinkage __visible void dump_stack_lvl(const char *log_lvl)
> >  {
> >         unsigned long flags;
> >         int was_locked;
> > @@ -117,7 +117,7 @@ asmlinkage __visible void dump_stack(void)
> >                 goto retry;
> >         }
> >
> > -       __dump_stack();
> > +       __dump_stack(log_lvl);
> >
> >         if (!was_locked)
> >                 atomic_set(&dump_lock, -1);
> > @@ -125,9 +125,14 @@ asmlinkage __visible void dump_stack(void)
> >         local_irq_restore(flags);
> >  }
> >  #else
> > -asmlinkage __visible void dump_stack(void)
> > +asmlinkage __visible void dump_stack_lvl(const char *log_lvl)
> >  {
> > -       __dump_stack();
> > +       __dump_stack(log_lvl);
> >  }
> >  #endif
>
> +EXPORT_SYMBOL(dump_stack_lvl);
>
> is missing here?

You are right, will fix in v2.

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

end of thread, other threads:[~2021-05-05 10:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05  9:22 [PATCH 1/2] printk: introduce dump_stack_lvl() Alexander Potapenko
2021-05-05  9:22 ` [PATCH 2/2] kasan: use dump_stack_lvl(KERN_ERR) to print stacks Alexander Potapenko
2021-05-05 10:37 ` [PATCH 1/2] printk: introduce dump_stack_lvl() Marco Elver
2021-05-05 10:58   ` Alexander Potapenko

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