Skip to contentSkip to conversation

irq_work: record irq_work_queue() call stack

PATCH Applied [email protected] 5 participants 7 messages Mar 31, 2021 – Jun 10, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irq_work: record irq_work_queue() call stack

From: Zqiang <[email protected]>

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.

---
 kernel/irq_work.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/irq_work.c +6 -1
index e8da1e71583a..23a7a0ba1388 100644
@@ -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 */
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · On Wed, Mar 31, 2021 at 8:32 AM <[email protected]> wrote:

From: Zqiang <[email protected]>

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.

Quoted 39 lines
---
 kernel/irq_work.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/irq_work.c +6 -2
index e8da1e71583a..23a7a0ba1388 100644
@@ -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 on v1 1/1
#2 lore raw
In reply to [email protected]
Quoted 45 lines · On Wed, Mar 31, 2021 at 8:32 AM <[email protected]> wrote:

From: Zqiang <[email protected]>

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.

---
 kernel/irq_work.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/irq_work.c +6 -2
index e8da1e71583a..23a7a0ba1388 100644
@@ -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 */
--
Quoted 1 line

2.17.1

#3 lore raw
In reply to [email protected]

kernel/irq_work.c bool irq_work_queue(struct irq_work *work) · line 78

Quoted 10 lines · On Wed, Mar 31, 2021 at 02:32:02PM +0800, [email protected] wrote:
kernel/irq_work.c +3 -0
@@ -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.

#4 lore raw

PATCH 1/1 irq_work: Make irq_work_queue() NMI-safe again

Quoted 15 lines · Peter Zijlstra

Review bool irq_work_queue(struct irq_work *work) · line 78

Quoted 10 lines · On Wed, Mar 31, 2021 at 02:32:02PM +0800, [email protected] wrote:
(quoted diff) +3 -0
@@ -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.

Quoted 2 lines

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 <[email protected]>
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.

---
 kernel/irq_work.c |    3 ---
 1 file changed, 3 deletions(-)
kernel/irq_work.c +0 -3
@@ -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);
merge bot Applied
#5 lore raw

[tip: perf/urgent] irq_work: Make irq_work_queue() NMI-safe again

In reply to Peter Zijlstra
The following commit has been merged into the perf/urgent branch of tip:

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 <[email protected]>
AuthorDate:    Tue, 08 Jun 2021 19:54:15 +02:00
Committer:     Peter Zijlstra <[email protected]>
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.

---
 kernel/irq_work.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/irq_work.c +0 -3
index 23a7a0b..db8c248 100644
@@ -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);
merge bot Applied
#6 lore raw

[tip: perf/urgent] irq_work: Make irq_work_queue() NMI-safe again

In reply to Peter Zijlstra
The following commit has been merged into the perf/urgent branch of tip:

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 <[email protected]>
AuthorDate:    Tue, 08 Jun 2021 19:54:15 +02:00
Committer:     Peter Zijlstra <[email protected]>
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")
---
 kernel/irq_work.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/irq_work.c +0 -3
index 23a7a0b..db8c248 100644
@@ -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);