All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] irq_work: record irq_work_queue() call stack
@ 2021-03-31  6:32 qiang.zhang
  2021-03-31 10:02 ` Dmitry Vyukov
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: qiang.zhang @ 2021-03-31  6:32 UTC (permalink / raw)
  To: ryabinin.a.a, glider, dvyukov, matthias.bgg, andreyknvl, akpm,
	oleg, walter-zh.wu, frederic
  Cc: kasan-dev, linux-kernel

From: Zqiang <qiang.zhang@windriver.com>

Add the irq_work_queue() call stack into the KASAN auxiliary
stack in order to improve KASAN reports. this will let us know
where the irq work be queued.

Signed-off-by: Zqiang <qiang.zhang@windriver.com>
---
 kernel/irq_work.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/irq_work.c b/kernel/irq_work.c
index e8da1e71583a..23a7a0ba1388 100644
--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -19,7 +19,7 @@
 #include <linux/notifier.h>
 #include <linux/smp.h>
 #include <asm/processor.h>
-
+#include <linux/kasan.h>
 
 static DEFINE_PER_CPU(struct llist_head, raised_list);
 static DEFINE_PER_CPU(struct llist_head, lazy_list);
@@ -70,6 +70,9 @@ bool irq_work_queue(struct irq_work *work)
 	if (!irq_work_claim(work))
 		return false;
 
+	/*record irq_work call stack in order to print it in KASAN reports*/
+	kasan_record_aux_stack(work);
+
 	/* Queue the entry and raise the IPI if needed. */
 	preempt_disable();
 	__irq_work_queue_local(work);
@@ -98,6 +101,8 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
 	if (!irq_work_claim(work))
 		return false;
 
+	kasan_record_aux_stack(work);
+
 	preempt_disable();
 	if (cpu != smp_processor_id()) {
 		/* Arch remote IPI send/receive backend aren't NMI safe */
-- 
2.17.1


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

* Re: [PATCH] irq_work: record irq_work_queue() call stack
  2021-03-31  6:32 [PATCH] irq_work: record irq_work_queue() call stack qiang.zhang
@ 2021-03-31 10:02 ` Dmitry Vyukov
  2021-04-02 14:52 ` Andrey Konovalov
  2021-06-08 17:51 ` Peter Zijlstra
  2 siblings, 0 replies; 7+ messages in thread
From: Dmitry Vyukov @ 2021-03-31 10:02 UTC (permalink / raw)
  To: Zhang, Qiang
  Cc: Andrey Ryabinin, Alexander Potapenko, Matthias Brugger,
	Andrey Konovalov, Andrew Morton, Oleg Nesterov, Walter Wu,
	Frederic Weisbecker, kasan-dev, LKML

On Wed, Mar 31, 2021 at 8:32 AM <qiang.zhang@windriver.com> wrote:
>
> From: Zqiang <qiang.zhang@windriver.com>
>
> Add the irq_work_queue() call stack into the KASAN auxiliary
> stack in order to improve KASAN reports. this will let us know
> where the irq work be queued.
>
> Signed-off-by: Zqiang <qiang.zhang@windriver.com>

Reviewed-by: Dmitry Vyukov <dvyukov@google.com>

> ---
>  kernel/irq_work.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/irq_work.c b/kernel/irq_work.c
> index e8da1e71583a..23a7a0ba1388 100644
> --- a/kernel/irq_work.c
> +++ b/kernel/irq_work.c
> @@ -19,7 +19,7 @@
>  #include <linux/notifier.h>
>  #include <linux/smp.h>
>  #include <asm/processor.h>
> -
> +#include <linux/kasan.h>
>
>  static DEFINE_PER_CPU(struct llist_head, raised_list);
>  static DEFINE_PER_CPU(struct llist_head, lazy_list);
> @@ -70,6 +70,9 @@ bool irq_work_queue(struct irq_work *work)
>         if (!irq_work_claim(work))
>                 return false;
>
> +       /*record irq_work call stack in order to print it in KASAN reports*/
> +       kasan_record_aux_stack(work);
> +
>         /* Queue the entry and raise the IPI if needed. */
>         preempt_disable();
>         __irq_work_queue_local(work);
> @@ -98,6 +101,8 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
>         if (!irq_work_claim(work))
>                 return false;
>
> +       kasan_record_aux_stack(work);
> +
>         preempt_disable();
>         if (cpu != smp_processor_id()) {
>                 /* Arch remote IPI send/receive backend aren't NMI safe */
> --
> 2.17.1
>

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

* Re: [PATCH] irq_work: record irq_work_queue() call stack
  2021-03-31  6:32 [PATCH] irq_work: record irq_work_queue() call stack qiang.zhang
  2021-03-31 10:02 ` Dmitry Vyukov
@ 2021-04-02 14:52 ` Andrey Konovalov
  2021-06-08 17:51 ` Peter Zijlstra
  2 siblings, 0 replies; 7+ messages in thread
From: Andrey Konovalov @ 2021-04-02 14:52 UTC (permalink / raw)
  To: qiang.zhang
  Cc: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov,
	matthias.bgg, Andrey Konovalov, Andrew Morton, oleg,
	walter-zh.wu, frederic, kasan-dev, LKML

On Wed, Mar 31, 2021 at 8:32 AM <qiang.zhang@windriver.com> wrote:
>
> From: Zqiang <qiang.zhang@windriver.com>
>
> Add the irq_work_queue() call stack into the KASAN auxiliary
> stack in order to improve KASAN reports. this will let us know
> where the irq work be queued.
>
> Signed-off-by: Zqiang <qiang.zhang@windriver.com>
> ---
>  kernel/irq_work.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/irq_work.c b/kernel/irq_work.c
> index e8da1e71583a..23a7a0ba1388 100644
> --- a/kernel/irq_work.c
> +++ b/kernel/irq_work.c
> @@ -19,7 +19,7 @@
>  #include <linux/notifier.h>
>  #include <linux/smp.h>
>  #include <asm/processor.h>
> -
> +#include <linux/kasan.h>
>
>  static DEFINE_PER_CPU(struct llist_head, raised_list);
>  static DEFINE_PER_CPU(struct llist_head, lazy_list);
> @@ -70,6 +70,9 @@ bool irq_work_queue(struct irq_work *work)
>         if (!irq_work_claim(work))
>                 return false;
>
> +       /*record irq_work call stack in order to print it in KASAN reports*/
> +       kasan_record_aux_stack(work);
> +
>         /* Queue the entry and raise the IPI if needed. */
>         preempt_disable();
>         __irq_work_queue_local(work);
> @@ -98,6 +101,8 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
>         if (!irq_work_claim(work))
>                 return false;
>
> +       kasan_record_aux_stack(work);
> +
>         preempt_disable();
>         if (cpu != smp_processor_id()) {
>                 /* Arch remote IPI send/receive backend aren't NMI safe */
> --
> 2.17.1

Acked-by: Andrey Konovalov <andreyknvl@gmail.com>

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

* Re: [PATCH] irq_work: record irq_work_queue() call stack
  2021-03-31  6:32 [PATCH] irq_work: record irq_work_queue() call stack qiang.zhang
  2021-03-31 10:02 ` Dmitry Vyukov
  2021-04-02 14:52 ` Andrey Konovalov
@ 2021-06-08 17:51 ` Peter Zijlstra
  2021-06-08 17:59   ` [PATCH] irq_work: Make irq_work_queue() NMI-safe again Peter Zijlstra
                     ` (2 more replies)
  2 siblings, 3 replies; 7+ messages in thread
From: Peter Zijlstra @ 2021-06-08 17:51 UTC (permalink / raw)
  To: qiang.zhang
  Cc: ryabinin.a.a, glider, dvyukov, matthias.bgg, andreyknvl, akpm,
	oleg, walter-zh.wu, frederic, kasan-dev, linux-kernel

On Wed, Mar 31, 2021 at 02:32:02PM +0800, qiang.zhang@windriver.com wrote:

> @@ -70,6 +70,9 @@ bool irq_work_queue(struct irq_work *work)
>  	if (!irq_work_claim(work))
>  		return false;
>  
> +	/*record irq_work call stack in order to print it in KASAN reports*/
> +	kasan_record_aux_stack(work);
> +
>  	/* Queue the entry and raise the IPI if needed. */
>  	preempt_disable();
>  	__irq_work_queue_local(work);

Thanks for the Cc :/ Also NAK.

I shall go revert this instantly. KASAN is not NMI safe, while
irq_work_queue() is very carefully crafted to be exactly that.

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

* [PATCH] irq_work: Make irq_work_queue() NMI-safe again
  2021-06-08 17:51 ` Peter Zijlstra
@ 2021-06-08 17:59   ` Peter Zijlstra
  2021-06-10  7:02   ` [tip: perf/urgent] " tip-bot2 for Peter Zijlstra
  2021-06-10  8:13   ` tip-bot2 for Peter Zijlstra
  2 siblings, 0 replies; 7+ messages in thread
From: Peter Zijlstra @ 2021-06-08 17:59 UTC (permalink / raw)
  To: qiang.zhang
  Cc: ryabinin.a.a, glider, dvyukov, matthias.bgg, andreyknvl, akpm,
	oleg, walter-zh.wu, frederic, kasan-dev, linux-kernel

On Tue, Jun 08, 2021 at 07:51:02PM +0200, Peter Zijlstra wrote:
> On Wed, Mar 31, 2021 at 02:32:02PM +0800, qiang.zhang@windriver.com wrote:
> 
> > @@ -70,6 +70,9 @@ bool irq_work_queue(struct irq_work *work)
> >  	if (!irq_work_claim(work))
> >  		return false;
> >  
> > +	/*record irq_work call stack in order to print it in KASAN reports*/
> > +	kasan_record_aux_stack(work);
> > +
> >  	/* Queue the entry and raise the IPI if needed. */
> >  	preempt_disable();
> >  	__irq_work_queue_local(work);
> 
> Thanks for the Cc :/ Also NAK.
> 
> I shall go revert this instantly. KASAN is not NMI safe, while
> irq_work_queue() is very carefully crafted to be exactly that.

The below goes in tip/perf/urgent ASAP.

---
Subject: irq_work: Make irq_work_queue() NMI-safe again
From: Peter Zijlstra <peterz@infradead.org>
Date: Tue Jun  8 19:54:15 CEST 2021

Someone carelessly put NMI unsafe code in irq_work_queue(), breaking
just about every single user. Also, someone has a terrible comment
style.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/irq_work.c |    3 ---
 1 file changed, 3 deletions(-)

--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -70,9 +70,6 @@ bool irq_work_queue(struct irq_work *wor
 	if (!irq_work_claim(work))
 		return false;
 
-	/*record irq_work call stack in order to print it in KASAN reports*/
-	kasan_record_aux_stack(work);
-
 	/* Queue the entry and raise the IPI if needed. */
 	preempt_disable();
 	__irq_work_queue_local(work);

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

* [tip: perf/urgent] irq_work: Make irq_work_queue() NMI-safe again
  2021-06-08 17:51 ` Peter Zijlstra
  2021-06-08 17:59   ` [PATCH] irq_work: Make irq_work_queue() NMI-safe again Peter Zijlstra
@ 2021-06-10  7:02   ` tip-bot2 for Peter Zijlstra
  2021-06-10  8:13   ` tip-bot2 for Peter Zijlstra
  2 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2021-06-10  7:02 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Alexander Shishkin, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     dc6be79444d82d5b9d679c7d6bd77c672f1e28ca
Gitweb:        https://git.kernel.org/tip/dc6be79444d82d5b9d679c7d6bd77c672f1e28ca
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Tue, 08 Jun 2021 19:54:15 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 08 Jun 2021 20:03:59 +02:00

irq_work: Make irq_work_queue() NMI-safe again

Someone carelessly put NMI unsafe code in irq_work_queue(), breaking
just about every single user. Also, someone has a terrible comment
style.

Reported-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/YL+uBq8LzXXZsYVf@hirez.programming.kicks-ass.net
---
 kernel/irq_work.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/kernel/irq_work.c b/kernel/irq_work.c
index 23a7a0b..db8c248 100644
--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -70,9 +70,6 @@ bool irq_work_queue(struct irq_work *work)
 	if (!irq_work_claim(work))
 		return false;
 
-	/*record irq_work call stack in order to print it in KASAN reports*/
-	kasan_record_aux_stack(work);
-
 	/* Queue the entry and raise the IPI if needed. */
 	preempt_disable();
 	__irq_work_queue_local(work);

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

* [tip: perf/urgent] irq_work: Make irq_work_queue() NMI-safe again
  2021-06-08 17:51 ` Peter Zijlstra
  2021-06-08 17:59   ` [PATCH] irq_work: Make irq_work_queue() NMI-safe again Peter Zijlstra
  2021-06-10  7:02   ` [tip: perf/urgent] " tip-bot2 for Peter Zijlstra
@ 2021-06-10  8:13   ` tip-bot2 for Peter Zijlstra
  2 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2021-06-10  8:13 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Alexander Shishkin, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     156172a13ff0626d8e23276e741c7e2cb2f3b572
Gitweb:        https://git.kernel.org/tip/156172a13ff0626d8e23276e741c7e2cb2f3b572
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Tue, 08 Jun 2021 19:54:15 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Thu, 10 Jun 2021 10:00:08 +02:00

irq_work: Make irq_work_queue() NMI-safe again

Someone carelessly put NMI unsafe code in irq_work_queue(), breaking
just about every single user. Also, someone has a terrible comment
style.

Fixes: e2b5bcf9f5ba ("irq_work: record irq_work_queue() call stack")
Reported-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/YL+uBq8LzXXZsYVf@hirez.programming.kicks-ass.net
---
 kernel/irq_work.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/kernel/irq_work.c b/kernel/irq_work.c
index 23a7a0b..db8c248 100644
--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -70,9 +70,6 @@ bool irq_work_queue(struct irq_work *work)
 	if (!irq_work_claim(work))
 		return false;
 
-	/*record irq_work call stack in order to print it in KASAN reports*/
-	kasan_record_aux_stack(work);
-
 	/* Queue the entry and raise the IPI if needed. */
 	preempt_disable();
 	__irq_work_queue_local(work);

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

end of thread, other threads:[~2021-06-10  8:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-31  6:32 [PATCH] irq_work: record irq_work_queue() call stack qiang.zhang
2021-03-31 10:02 ` Dmitry Vyukov
2021-04-02 14:52 ` Andrey Konovalov
2021-06-08 17:51 ` Peter Zijlstra
2021-06-08 17:59   ` [PATCH] irq_work: Make irq_work_queue() NMI-safe again Peter Zijlstra
2021-06-10  7:02   ` [tip: perf/urgent] " tip-bot2 for Peter Zijlstra
2021-06-10  8:13   ` tip-bot2 for Peter Zijlstra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.