All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kloetzke Jan <Jan.Kloetzke@preh.de>
To: "oneukum@suse.com" <oneukum@suse.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"jan@kloetzke.net" <jan@kloetzke.net>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH] usbnet: fix kernel crash after disconnect
Date: Thu, 18 Apr 2019 08:02:59 +0000	[thread overview]
Message-ID: <1555574578.4173.215.camel@preh.de> (raw)
In-Reply-To: <1555569464.7835.4.camel@suse.com>

Hi,

Am Donnerstag, den 18.04.2019, 08:37 +0200 schrieb Oliver Neukum:
> On Mi, 2019-04-17 at 09:19 +0000, Kloetzke Jan wrote:
> > When disconnecting cdc_ncm the kernel sporadically crashes shortly
> > after the disconnect:
> > 
> >   [   57.868812] Unable to handle kernel NULL pointer dereference
> > at virtual address 00000000
> >   ...
> >   [   58.006653] PC is at 0x0
> >   [   58.009202] LR is at call_timer_fn+0xec/0x1b4
> >   [   58.013567] pc : [<0000000000000000>] lr :
> > [<ffffff80080f5130>] pstate: 00000145
> >   [   58.020976] sp : ffffff8008003da0
> >   [   58.024295] x29: ffffff8008003da0 x28: 0000000000000001
> >   [   58.029618] x27: 000000000000000a x26: 0000000000000100
> >   [   58.034941] x25: 0000000000000000 x24: ffffff8008003e68
> >   [   58.040263] x23: 0000000000000000 x22: 0000000000000000
> >   [   58.045587] x21: 0000000000000000 x20: ffffffc68fac1808
> >   [   58.050910] x19: 0000000000000100 x18: 0000000000000000
> >   [   58.056232] x17: 0000007f885aff8c x16: 0000007f883a9f10
> >   [   58.061556] x15: 0000000000000001 x14: 000000000000006e
> >   [   58.066878] x13: 0000000000000000 x12: 00000000000000ba
> >   [   58.072201] x11: ffffffc69ff1db30 x10: 0000000000000020
> >   [   58.077524] x9 : 8000100008001000 x8 : 0000000000000001
> >   [   58.082847] x7 : 0000000000000800 x6 : ffffff8008003e70
> >   [   58.088169] x5 : ffffffc69ff17a28 x4 : 00000000ffff138b
> >   [   58.093492] x3 : 0000000000000000 x2 : 0000000000000000
> >   [   58.098814] x1 : 0000000000000000 x0 : 0000000000000000
> >   ...
> >   [   58.205800] [<          (null)>]           (null)
> >   [   58.210521] [<ffffff80080f5298>] expire_timers+0xa0/0x14c
> >   [   58.215937] [<ffffff80080f542c>] run_timer_softirq+0xe8/0x128
> >   [   58.221702] [<ffffff8008081120>] __do_softirq+0x298/0x348
> >   [   58.227118] [<ffffff80080a6304>] irq_exit+0x74/0xbc
> >   [   58.232009] [<ffffff80080e17dc>] __handle_domain_irq+0x78/0xac
> >   [   58.237857] [<ffffff8008080cf4>] gic_handle_irq+0x80/0xac
> >   ...
> > 
> > The crash happens roughly 125..130ms after the disconnect. This
> > correlates with the 'delay' timer that is started on certain USB
> > tx/rx
> > errors in the URB completion handler.
> > 
> > The suspected problem is a race of usbnet_stop() with
> > usbnet_start_xmit(). In usbnet_stop() we call
> > usbnet_terminate_urbs()
> > to cancel all URBs in flight. This only makes sense if no new URBs
> > are
> > submitted concurrently, though. But the usbnet_start_xmit() can run
> > at
> > the same time on another CPU which almost unconditionally submits
> > an
> > URB. The error callback of the new URB will then schedule the timer
> > after it was already stopped.
> 
> Hi,
> 
> interesting. How sure are you of the details of your analysis?

We have seen the issue sporadically, maybe once a month, on our IVI
system with dozens of units being tested all day long. We have the fix
in the field since three months and got no further reports so far. So
I'm relatively optimistic that the patch solves the problem.

> I am asking because usbnet_stop() does a del_timer_sync().
> It is indeed written under the assumption that the upper layer
> will have ceased transmission when it stops an interface.

I think this assumption is not correct. As far as I understand the
networking code it is still possible that the ndo_start_xmit callback
is called while ndo_stop is running and even after ndo_stop has
returned. You can only be sure after unregister_netdev() has returned.
Maybe some networking folks can comment on that.

> So I am wondering whether the correct fix would not be to make
> sure the timer is started.

I think the real problem is that new URBs are submitted concurrently.
The timer is just a secondary problem that blows up later. But if my
above assumption wrt. ndo_stop/ndo_start_xmit is not correct then the
patch would be indeed wrong.

Regards,
Jan

WARNING: multiple messages have this Message-ID (diff)
From: Kloetzke Jan <Jan.Kloetzke@preh.de>
To: "oneukum@suse.com" <oneukum@suse.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"jan@kloetzke.net" <jan@kloetzke.net>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: usbnet: fix kernel crash after disconnect
Date: Thu, 18 Apr 2019 08:02:59 +0000	[thread overview]
Message-ID: <1555574578.4173.215.camel@preh.de> (raw)

Hi,

Am Donnerstag, den 18.04.2019, 08:37 +0200 schrieb Oliver Neukum:
> On Mi, 2019-04-17 at 09:19 +0000, Kloetzke Jan wrote:
> > When disconnecting cdc_ncm the kernel sporadically crashes shortly
> > after the disconnect:
> > 
> >   [   57.868812] Unable to handle kernel NULL pointer dereference
> > at virtual address 00000000
> >   ...
> >   [   58.006653] PC is at 0x0
> >   [   58.009202] LR is at call_timer_fn+0xec/0x1b4
> >   [   58.013567] pc : [<0000000000000000>] lr :
> > [<ffffff80080f5130>] pstate: 00000145
> >   [   58.020976] sp : ffffff8008003da0
> >   [   58.024295] x29: ffffff8008003da0 x28: 0000000000000001
> >   [   58.029618] x27: 000000000000000a x26: 0000000000000100
> >   [   58.034941] x25: 0000000000000000 x24: ffffff8008003e68
> >   [   58.040263] x23: 0000000000000000 x22: 0000000000000000
> >   [   58.045587] x21: 0000000000000000 x20: ffffffc68fac1808
> >   [   58.050910] x19: 0000000000000100 x18: 0000000000000000
> >   [   58.056232] x17: 0000007f885aff8c x16: 0000007f883a9f10
> >   [   58.061556] x15: 0000000000000001 x14: 000000000000006e
> >   [   58.066878] x13: 0000000000000000 x12: 00000000000000ba
> >   [   58.072201] x11: ffffffc69ff1db30 x10: 0000000000000020
> >   [   58.077524] x9 : 8000100008001000 x8 : 0000000000000001
> >   [   58.082847] x7 : 0000000000000800 x6 : ffffff8008003e70
> >   [   58.088169] x5 : ffffffc69ff17a28 x4 : 00000000ffff138b
> >   [   58.093492] x3 : 0000000000000000 x2 : 0000000000000000
> >   [   58.098814] x1 : 0000000000000000 x0 : 0000000000000000
> >   ...
> >   [   58.205800] [<          (null)>]           (null)
> >   [   58.210521] [<ffffff80080f5298>] expire_timers+0xa0/0x14c
> >   [   58.215937] [<ffffff80080f542c>] run_timer_softirq+0xe8/0x128
> >   [   58.221702] [<ffffff8008081120>] __do_softirq+0x298/0x348
> >   [   58.227118] [<ffffff80080a6304>] irq_exit+0x74/0xbc
> >   [   58.232009] [<ffffff80080e17dc>] __handle_domain_irq+0x78/0xac
> >   [   58.237857] [<ffffff8008080cf4>] gic_handle_irq+0x80/0xac
> >   ...
> > 
> > The crash happens roughly 125..130ms after the disconnect. This
> > correlates with the 'delay' timer that is started on certain USB
> > tx/rx
> > errors in the URB completion handler.
> > 
> > The suspected problem is a race of usbnet_stop() with
> > usbnet_start_xmit(). In usbnet_stop() we call
> > usbnet_terminate_urbs()
> > to cancel all URBs in flight. This only makes sense if no new URBs
> > are
> > submitted concurrently, though. But the usbnet_start_xmit() can run
> > at
> > the same time on another CPU which almost unconditionally submits
> > an
> > URB. The error callback of the new URB will then schedule the timer
> > after it was already stopped.
> 
> Hi,
> 
> interesting. How sure are you of the details of your analysis?

We have seen the issue sporadically, maybe once a month, on our IVI
system with dozens of units being tested all day long. We have the fix
in the field since three months and got no further reports so far. So
I'm relatively optimistic that the patch solves the problem.

> I am asking because usbnet_stop() does a del_timer_sync().
> It is indeed written under the assumption that the upper layer
> will have ceased transmission when it stops an interface.

I think this assumption is not correct. As far as I understand the
networking code it is still possible that the ndo_start_xmit callback
is called while ndo_stop is running and even after ndo_stop has
returned. You can only be sure after unregister_netdev() has returned.
Maybe some networking folks can comment on that.

> So I am wondering whether the correct fix would not be to make
> sure the timer is started.

I think the real problem is that new URBs are submitted concurrently.
The timer is just a secondary problem that blows up later. But if my
above assumption wrt. ndo_stop/ndo_start_xmit is not correct then the
patch would be indeed wrong.

Regards,
Jan

  reply	other threads:[~2019-04-18  8:03 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-17  9:19 [PATCH] usbnet: fix kernel crash after disconnect Kloetzke Jan
2019-04-17  9:19 ` Kloetzke Jan
2019-04-18  6:37 ` [PATCH] " Oliver Neukum
2019-04-18  6:37   ` Oliver Neukum
2019-04-18  8:02   ` Kloetzke Jan [this message]
2019-04-18  8:02     ` Kloetzke Jan
2019-04-18 23:35     ` [PATCH] " David Miller
2019-04-18 23:35       ` David Miller
2019-04-19  7:17       ` [PATCH] " Jan Klötzke
2019-04-19  7:17         ` Jan Klötzke
2019-04-29 18:48         ` [PATCH] " Oliver Neukum
2019-04-29 18:48           ` Oliver Neukum
2019-04-30 14:08           ` [PATCH] " Kloetzke Jan
2019-04-30 14:08             ` Kloetzke Jan
2019-04-30 14:15           ` [PATCH v2] " Kloetzke Jan
2019-04-30 14:15             ` [v2] " Kloetzke Jan
2019-05-05  7:45             ` [PATCH v2] " David Miller
2019-05-05  7:45               ` [v2] " David Miller
2019-05-06  8:17               ` [PATCH v2] " Oliver Neukum
2019-05-16  7:10                 ` Kloetzke Jan
2019-05-21  0:09                   ` David Miller
2019-05-21  9:48                   ` Oliver Neukum
2019-05-21 10:12                     ` Kloetzke Jan
2019-05-21 11:42                       ` Oliver Neukum
2019-05-21 13:18                         ` [PATCH v3] " Kloetzke Jan
2019-05-21 20:47                           ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1555574578.4173.215.camel@preh.de \
    --to=jan.kloetzke@preh.de \
    --cc=jan@kloetzke.net \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oneukum@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.