Re: [PATCH] irq_work: Make irq_work_queue_on() NMI-safe again

1 view
Skip to first unread message

Jun Miao

unread,
Apr 26, 2022, 9:49:19 PM4/26/22
to ryabin...@gmail.com, Dmitry Vyukov, big...@linutronix.de, qiang1...@intel.com, pet...@infradead.org, ak...@linux-foundation.org, andre...@gmail.com, ying....@intel.com, kasa...@googlegroups.com, linux-...@vger.kernel.org
Add  To/Cc : KASAN/MEM , since I only used the scripts/get_maintainer.pl
to irq_work.c file.

Thanks
Jun Miao


On 2022/4/26 21:49, Jun Miao wrote:
> We should not put NMI unsafe code in irq_work_queue_on().
>
> The KASAN of kasan_record_aux_stack_noalloc() is not NMI safe. Because which
> will call the spinlock. While the irq_work_queue_on() is also very carefully
> carafted to be exactly that.
> When unable CONFIG_SM or local CPU, the irq_work_queue_on() is even same to
> irq_work_queue(). So delete KASAN instantly.
>
> Fixes: e2b5bcf9f5ba ("irq_work: record irq_work_queue() call stack")
> Suggested by: "Huang, Ying" <ying....@intel.com>
> Signed-off-by: Jun Miao <jun....@intel.com>
> ---
> kernel/irq_work.c | 3 ---
> 1 file changed, 3 deletions(-)
>
> diff --git a/kernel/irq_work.c b/kernel/irq_work.c
> index 7afa40fe5cc4..e7f48aa8d8af 100644
> --- a/kernel/irq_work.c
> +++ b/kernel/irq_work.c
> @@ -20,7 +20,6 @@
> #include <linux/smp.h>
> #include <linux/smpboot.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);
> @@ -137,8 +136,6 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
> if (!irq_work_claim(work))
> return false;
>
> - kasan_record_aux_stack_noalloc(work);
> -
> preempt_disable();
> if (cpu != smp_processor_id()) {
> /* Arch remote IPI send/receive backend aren't NMI safe */

Marco Elver

unread,
Apr 27, 2022, 8:27:35 AM4/27/22
to Jun Miao, ryabin...@gmail.com, Dmitry Vyukov, big...@linutronix.de, qiang1...@intel.com, pet...@infradead.org, ak...@linux-foundation.org, andre...@gmail.com, ying....@intel.com, kasa...@googlegroups.com, linux-...@vger.kernel.org
On Wed, 27 Apr 2022 at 03:49, Jun Miao <jun....@intel.com> wrote:
>
> Add To/Cc : KASAN/MEM , since I only used the scripts/get_maintainer.pl
> to irq_work.c file.
>
> Thanks
> Jun Miao
>
>
> On 2022/4/26 21:49, Jun Miao wrote:
> > We should not put NMI unsafe code in irq_work_queue_on().
> >
> > The KASAN of kasan_record_aux_stack_noalloc() is not NMI safe. Because which
> > will call the spinlock. While the irq_work_queue_on() is also very carefully
> > carafted to be exactly that.

"crafted"

> > When unable CONFIG_SM or local CPU, the irq_work_queue_on() is even same to

CONFIG_SM -> CONFIG_SMP

> > irq_work_queue(). So delete KASAN instantly.
> >
> > Fixes: e2b5bcf9f5ba ("irq_work: record irq_work_queue() call stack")
> > Suggested by: "Huang, Ying" <ying....@intel.com>
> > Signed-off-by: Jun Miao <jun....@intel.com>

I thought this had already been removed, but apparently there were 2
places: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=156172a13ff0626d8e23276e741c7e2cb2f3b572

Acked-by: Marco Elver <el...@google.com>

> > ---
> > kernel/irq_work.c | 3 ---
> > 1 file changed, 3 deletions(-)
> >
> > diff --git a/kernel/irq_work.c b/kernel/irq_work.c
> > index 7afa40fe5cc4..e7f48aa8d8af 100644
> > --- a/kernel/irq_work.c
> > +++ b/kernel/irq_work.c
> > @@ -20,7 +20,6 @@
> > #include <linux/smp.h>
> > #include <linux/smpboot.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);
> > @@ -137,8 +136,6 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
> > if (!irq_work_claim(work))
> > return false;
> >
> > - kasan_record_aux_stack_noalloc(work);
> > -
> > preempt_disable();
> > if (cpu != smp_processor_id()) {
> > /* Arch remote IPI send/receive backend aren't NMI safe */
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/9c951fe6-d354-5870-e91b-83d8346ac162%40intel.com.

Jun Miao

unread,
Apr 27, 2022, 9:17:56 AM4/27/22
to Marco Elver, ryabin...@gmail.com, Dmitry Vyukov, big...@linutronix.de, qiang1...@intel.com, pet...@infradead.org, ak...@linux-foundation.org, andre...@gmail.com, ying....@intel.com, kasa...@googlegroups.com, linux-...@vger.kernel.org

On 2022/4/27 20:26, Marco Elver wrote:
> On Wed, 27 Apr 2022 at 03:49, Jun Miao <jun....@intel.com> wrote:
>> Add To/Cc : KASAN/MEM , since I only used the scripts/get_maintainer.pl
>> to irq_work.c file.
>>
>> Thanks
>> Jun Miao
>>
>>
>> On 2022/4/26 21:49, Jun Miao wrote:
>>> We should not put NMI unsafe code in irq_work_queue_on().
>>>
>>> The KASAN of kasan_record_aux_stack_noalloc() is not NMI safe. Because which
>>> will call the spinlock. While the irq_work_queue_on() is also very carefully
>>> carafted to be exactly that.
> "crafted"
>
>>> When unable CONFIG_SM or local CPU, the irq_work_queue_on() is even same to
> CONFIG_SM -> CONFIG_SMP
>
>>> irq_work_queue(). So delete KASAN instantly.
>>>
>>> Fixes: e2b5bcf9f5ba ("irq_work: record irq_work_queue() call stack")
>>> Suggested by: "Huang, Ying" <ying....@intel.com>
>>> Signed-off-by: Jun Miao <jun....@intel.com>
> I thought this had already been removed, but apparently there were 2
> places: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=156172a13ff0626d8e23276e741c7e2cb2f3b572
>
> Acked-by: Marco Elver <el...@google.com>

Sure, I also found this patch which is the same reason, maybe Peter Z
forgot it. Let me make up a little.😉

Send V2 later.

Thanks
Jun Miao

Jun Miao

unread,
Apr 27, 2022, 9:50:44 AM4/27/22
to el...@google.com, dvy...@google.com, ryabin...@gmail.com, pet...@infradead.org, big...@linutronix.de, qiang1...@intel.com, andre...@gmail.com, kasa...@googlegroups.com, linux-...@vger.kernel.org, ak...@linux-foundation.org, jun....@intel.com
We should not put NMI unsafe code in irq_work_queue_on().

The KASAN of kasan_record_aux_stack_noalloc() is not NMI safe. Because which
will call the spinlock. While the irq_work_queue_on() is also very carefully
carfted to be exactly that.
When unable CONFIG_SMP or local CPU, the irq_work_queue_on() is even same to
irq_work_queue(). So delete KASAN instantly.

Fixes: e2b5bcf9f5ba ("irq_work: record irq_work_queue() call stack")
Suggested by: "Huang, Ying" <ying....@intel.com>
Signed-off-by: Jun Miao <jun....@intel.com>
Acked-by: Marco Elver <el...@google.com>
---
kernel/irq_work.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/kernel/irq_work.c b/kernel/irq_work.c
index 7afa40fe5cc4..e7f48aa8d8af 100644
--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -20,7 +20,6 @@
#include <linux/smp.h>
#include <linux/smpboot.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);
@@ -137,8 +136,6 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
if (!irq_work_claim(work))
return false;

- kasan_record_aux_stack_noalloc(work);
-
preempt_disable();
if (cpu != smp_processor_id()) {
/* Arch remote IPI send/receive backend aren't NMI safe */
--
2.32.0

Jun Miao

unread,
Apr 27, 2022, 9:55:44 AM4/27/22
to el...@google.com, dvy...@google.com, ryabin...@gmail.com, pet...@infradead.org, big...@linutronix.de, qiang1...@intel.com, andre...@gmail.com, kasa...@googlegroups.com, linux-...@vger.kernel.org, ak...@linux-foundation.org, jun....@intel.com
We should not put NMI unsafe code in irq_work_queue_on().

The KASAN of kasan_record_aux_stack_noalloc() is not NMI safe. Because which
will call the spinlock. While the irq_work_queue_on() is also very carefully
crafted to be exactly that.

Jun Miao

unread,
Apr 27, 2022, 10:00:25 AM4/27/22
to el...@google.com, dvy...@google.com, ryabin...@gmail.com, pet...@infradead.org, big...@linutronix.de, qiang1...@intel.com, andre...@gmail.com, kasa...@googlegroups.com, linux-...@vger.kernel.org, ak...@linux-foundation.org
Sorry, please ignore!

Peter Zijlstra

unread,
Apr 28, 2022, 5:24:56 AM4/28/22
to Jun Miao, el...@google.com, dvy...@google.com, ryabin...@gmail.com, big...@linutronix.de, qiang1...@intel.com, andre...@gmail.com, kasa...@googlegroups.com, linux-...@vger.kernel.org, ak...@linux-foundation.org
On Wed, Apr 27, 2022 at 09:55:49PM +0800, Jun Miao wrote:
> We should not put NMI unsafe code in irq_work_queue_on().

Why not, irq_work_queue_on() is not NMI safe. Only irq_work_queue() is.

Reply all
Reply to author
Forward
0 new messages