irq_work: record irq_work_queue() call stack
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
@@ -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
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.Signed-off-by Zqiang <[email protected]>
Quoted 39 lines
--- kernel/irq_work.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)kernel/irq_work.c +6
-2@@ -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
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.Signed-off-by Zqiang <[email protected]>--- kernel/irq_work.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)kernel/irq_work.c +6
-2@@ -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
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.
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 *worif (!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);
[tip: perf/urgent] irq_work: Make irq_work_queue() NMI-safe again
In reply to Peter ZijlstraThe 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
@@ -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);
[tip: perf/urgent] irq_work: Make irq_work_queue() NMI-safe again
In reply to Peter ZijlstraThe 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.
--- 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 *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);