Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1537308 > unrolled thread

[PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts on RT

Started bySteven Rostedt <rostedt@goodmis.org>
First post2016-12-07 00:00 +0100
Last post2016-12-07 16:40 +0100
Articles 5 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts on  RT Steven Rostedt <rostedt@goodmis.org> - 2016-12-07 00:00 +0100
    Re: [PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts  on RT Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-12-07 10:40 +0100
      Re: [PATCH RT] net: Have __napi_schedule_irqoff() disable  interrupts on RT Steven Rostedt <rostedt@goodmis.org> - 2016-12-07 14:10 +0100
        Re: [PATCH RT] net: Have __napi_schedule_irqoff() disable  interrupts on RT Steven Rostedt <rostedt@goodmis.org> - 2016-12-07 16:30 +0100
          Re: [PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts  on RT Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-12-07 16:40 +0100

#1537308 — [PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts on RT

FromSteven Rostedt <rostedt@goodmis.org>
Date2016-12-07 00:00 +0100
Subject[PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts on RT
Message-ID<sLwSm-8cn-17@gated-at.bofh.it>
A customer hit a crash where the napi sd->poll_list became corrupted.
The customer had the bnx2x driver, which does a
__napi_schedule_irqoff() in its interrupt handler. Unfortunately, when
running with CONFIG_PREEMPT_RT_FULL, this interrupt handler is run as a
thread and is preemptable. The call to ____napi_schedule() must be done
with interrupts disabled to protect the per cpu softnet_data's
poll_list, which is protected by disabling interrupts (disabling
preemption is enough when all interrupts are threaded and
local_bh_disable() can't preempt).

As bnx2x isn't the only driver that does this, the safest thing to do
is to make __napi_schedule_irqoff() call __napi_schedule() instead when
CONFIG_PREEMPT_RT_FULL is enabled, which will call local_irq_save()
before calling ____napi_schedule().

Cc: stable-rt@vger.kernel.org
Signed-off-by: Steven Rostedt (Red Hat) <rostedt@goodmis.org>
---
 include/linux/netdevice.h |   12 ++++++++++++
 net/core/dev.c            |    2 ++
 2 files changed, 14 insertions(+)

Index: linux-rt.git/include/linux/netdevice.h
===================================================================
--- linux-rt.git.orig/include/linux/netdevice.h	2016-11-18 14:59:01.679547362 -0500
+++ linux-rt.git/include/linux/netdevice.h	2016-12-06 17:35:38.506672042 -0500
@@ -395,7 +395,19 @@ typedef enum rx_handler_result rx_handle
 typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
 
 void __napi_schedule(struct napi_struct *n);
+
+/*
+ * When PREEMPT_RT_FULL is defined, all device interrupt handlers
+ * run as threads, and they can also be preempted (without PREEMPT_RT
+ * interrupt threads can not be preempted). Which means that calling
+ * __napi_schedule_irqoff() from an interrupt handler can be preempted
+ * and can corrupt the napi->poll_list.
+ */
+#ifdef CONFIG_PREEMPT_RT_FULL
+#define __napi_schedule_irqoff(n) __napi_schedule(n)
+#else
 void __napi_schedule_irqoff(struct napi_struct *n);
+#endif
 
 static inline bool napi_disable_pending(struct napi_struct *n)
 {
Index: linux-rt.git/net/core/dev.c
===================================================================
--- linux-rt.git.orig/net/core/dev.c	2016-11-18 14:59:02.876527251 -0500
+++ linux-rt.git/net/core/dev.c	2016-12-06 17:35:38.513672035 -0500
@@ -4910,6 +4910,7 @@ void __napi_schedule(struct napi_struct
 }
 EXPORT_SYMBOL(__napi_schedule);
 
+#ifndef CONFIG_PREEMPT_RT_FULL
 /**
  * __napi_schedule_irqoff - schedule for receive
  * @n: entry to schedule
@@ -4921,6 +4922,7 @@ void __napi_schedule_irqoff(struct napi_
 	____napi_schedule(this_cpu_ptr(&softnet_data), n);
 }
 EXPORT_SYMBOL(__napi_schedule_irqoff);
+#endif
 
 void __napi_complete(struct napi_struct *n)
 {

[toc] | [next] | [standalone]


#1537628 — Re: [PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts on RT

FromSebastian Andrzej Siewior <bigeasy@linutronix.de>
Date2016-12-07 10:40 +0100
SubjectRe: [PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts on RT
Message-ID<sLGRI-6H9-5@gated-at.bofh.it>
In reply to#1537308
On 2016-12-06 17:50:30 [-0500], Steven Rostedt wrote:
> A customer hit a crash where the napi sd->poll_list became corrupted.
> The customer had the bnx2x driver, which does a
> __napi_schedule_irqoff() in its interrupt handler. Unfortunately, when
> running with CONFIG_PREEMPT_RT_FULL, this interrupt handler is run as a
> thread and is preemptable. The call to ____napi_schedule() must be done
> with interrupts disabled to protect the per cpu softnet_data's
> poll_list, which is protected by disabling interrupts (disabling
> preemption is enough when all interrupts are threaded and
> local_bh_disable() can't preempt).
> 
> As bnx2x isn't the only driver that does this, the safest thing to do
> is to make __napi_schedule_irqoff() call __napi_schedule() instead when
> CONFIG_PREEMPT_RT_FULL is enabled, which will call local_irq_save()
> before calling ____napi_schedule().

It would work RT wise. But don't have the same problem if you boot the
kernel with threadirqs ?

Sebastian

[toc] | [prev] | [next] | [standalone]


#1537732 — Re: [PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts on RT

FromSteven Rostedt <rostedt@goodmis.org>
Date2016-12-07 14:10 +0100
SubjectRe: [PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts on RT
Message-ID<sLK8V-vo-21@gated-at.bofh.it>
In reply to#1537628
On Wed, 7 Dec 2016 10:10:40 +0100
Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:

> On 2016-12-06 17:50:30 [-0500], Steven Rostedt wrote:
> > A customer hit a crash where the napi sd->poll_list became corrupted.
> > The customer had the bnx2x driver, which does a
> > __napi_schedule_irqoff() in its interrupt handler. Unfortunately, when
> > running with CONFIG_PREEMPT_RT_FULL, this interrupt handler is run as a
> > thread and is preemptable. The call to ____napi_schedule() must be done
> > with interrupts disabled to protect the per cpu softnet_data's
> > poll_list, which is protected by disabling interrupts (disabling
> > preemption is enough when all interrupts are threaded and
> > local_bh_disable() can't preempt).
> > 
> > As bnx2x isn't the only driver that does this, the safest thing to do
> > is to make __napi_schedule_irqoff() call __napi_schedule() instead when
> > CONFIG_PREEMPT_RT_FULL is enabled, which will call local_irq_save()
> > before calling ____napi_schedule().  
> 
> It would work RT wise. But don't have the same problem if you boot the
> kernel with threadirqs ?
> 

I thought the same at first, but looking into the code for forced
threaded interrupts, I saw this:

        local_bh_disable();
        ret = action->thread_fn(action->irq, action->dev_id);
        irq_finalize_oneshot(desc, action);
        local_bh_enable();

Where without CONFIG_PREEMPT_RT_FULL, local_bh_disable() also disables
preemption. Then all the handlers still can not be preempted by another
handler. So it appears to be safe as well.

-- Steve

[toc] | [prev] | [next] | [standalone]


#1537839 — Re: [PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts on RT

FromSteven Rostedt <rostedt@goodmis.org>
Date2016-12-07 16:30 +0100
SubjectRe: [PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts on RT
Message-ID<sLMkq-1Oz-27@gated-at.bofh.it>
In reply to#1537732
On Wed, 7 Dec 2016 07:53:26 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Wed, 7 Dec 2016 10:10:40 +0100
> Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:
> 
> > On 2016-12-06 17:50:30 [-0500], Steven Rostedt wrote:  
> > > A customer hit a crash where the napi sd->poll_list became corrupted.
> > > The customer had the bnx2x driver, which does a
> > > __napi_schedule_irqoff() in its interrupt handler. Unfortunately, when
> > > running with CONFIG_PREEMPT_RT_FULL, this interrupt handler is run as a
> > > thread and is preemptable. The call to ____napi_schedule() must be done
> > > with interrupts disabled to protect the per cpu softnet_data's
> > > poll_list, which is protected by disabling interrupts (disabling
> > > preemption is enough when all interrupts are threaded and
> > > local_bh_disable() can't preempt).
> > > 
> > > As bnx2x isn't the only driver that does this, the safest thing to do
> > > is to make __napi_schedule_irqoff() call __napi_schedule() instead when
> > > CONFIG_PREEMPT_RT_FULL is enabled, which will call local_irq_save()
> > > before calling ____napi_schedule().    
> > 
> > It would work RT wise. But don't have the same problem if you boot the
> > kernel with threadirqs ?
> >   
> 
> I thought the same at first, but looking into the code for forced
> threaded interrupts, I saw this:
> 
>         local_bh_disable();
>         ret = action->thread_fn(action->irq, action->dev_id);
>         irq_finalize_oneshot(desc, action);
>         local_bh_enable();
> 
> Where without CONFIG_PREEMPT_RT_FULL, local_bh_disable() also disables
> preemption. Then all the handlers still can not be preempted by another
> handler. So it appears to be safe as well.
> 

Actually, I was hoping that the change log explained this. Should I
reword it better?

"poll_list, which is protected by disabling interrupts (disabling
 preemption is enough when all interrupts are threaded and
 local_bh_disable() can't preempt)."


-- Steve

[toc] | [prev] | [next] | [standalone]


#1537845 — Re: [PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts on RT

FromSebastian Andrzej Siewior <bigeasy@linutronix.de>
Date2016-12-07 16:40 +0100
SubjectRe: [PATCH RT] net: Have __napi_schedule_irqoff() disable interrupts on RT
Message-ID<sLMu5-1RI-9@gated-at.bofh.it>
In reply to#1537839
On 2016-12-07 10:28:34 [-0500], Steven Rostedt wrote:
> Actually, I was hoping that the change log explained this. Should I
> reword it better?
> 
> "poll_list, which is protected by disabling interrupts (disabling
>  preemption is enough when all interrupts are threaded and
>  local_bh_disable() can't preempt)."

That is fine, I merge it and add this piece. Thank you Steven.

> -- Steve

Sebastian

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web