All of lore.kernel.org
 help / color / mirror / Atom feed
* pull-request: can 2015-01-27
@ 2015-01-27  8:01 Marc Kleine-Budde
  2015-01-27  8:01 ` [PATCH 1/4] can: kvaser_usb: Do not sleep in atomic context Marc Kleine-Budde
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2015-01-27  8:01 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel

Hello David,

this is another pull request for net/master which consists of 4 patches.

All 4 patches are contributed by Ahmed S. Darwish, he fixes more problems in
the kvaser_usb driver.

David, please merge net/master to net-next/master, as we have more kvaser_usb
patches in the queue, that target net-next.

regards,
Marc

The following changes since commit 600ddd6825543962fb807884169e57b580dba208:

  net: sctp: fix slab corruption from use after free on INIT collisions (2015-01-26 17:02:05 -0800)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git tags/linux-can-fixes-for-3.19-20150127

for you to fetch changes up to e638642b08c170d2021b706f0b1c4f4ae93d8cbd:

  can: kvaser_usb: Fix state handling upon BUS_ERROR events (2015-01-27 08:55:09 +0100)

----------------------------------------------------------------
linux-can-fixes-for-3.19-20150127

----------------------------------------------------------------
Ahmed S. Darwish (4):
      can: kvaser_usb: Do not sleep in atomic context
      can: kvaser_usb: Send correct context to URB completion
      can: kvaser_usb: Retry the first bulk transfer on -ETIMEDOUT
      can: kvaser_usb: Fix state handling upon BUS_ERROR events

 drivers/net/can/usb/kvaser_usb.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] can: kvaser_usb: Do not sleep in atomic context
  2015-01-27  8:01 pull-request: can 2015-01-27 Marc Kleine-Budde
@ 2015-01-27  8:01 ` Marc Kleine-Budde
  2015-01-27  8:01 ` [PATCH 2/4] can: kvaser_usb: Send correct context to URB completion Marc Kleine-Budde
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2015-01-27  8:01 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Ahmed S. Darwish, linux-stable,
	Marc Kleine-Budde

From: "Ahmed S. Darwish" <ahmed.darwish@valeo.com>

Upon receiving a hardware event with the BUS_RESET flag set,
the driver kills all of its anchored URBs and resets all of
its transmit URB contexts.

Unfortunately it does so under the context of URB completion
handler `kvaser_usb_read_bulk_callback()', which is often
called in an atomic context.

While the device is flooded with many received error packets,
usb_kill_urb() typically sleeps/reschedules till the transfer
request of each killed URB in question completes, leading to
the sleep in atomic bug. [3]

In v2 submission of the original driver patch [1], it was
stated that the URBs kill and tx contexts reset was needed
since we don't receive any tx acknowledgments later and thus
such resources will be locked down forever. Fortunately this
is no longer needed since an earlier bugfix in this patch
series is now applied: all tx URB contexts are reset upon CAN
channel close. [2]

Moreover, a BUS_RESET is now treated _exactly_ like a BUS_OFF
event, which is the recommended handling method advised by
the device manufacturer.

[1] http://article.gmane.org/gmane.linux.network/239442
    http://www.webcitation.org/6Vr2yagAQ

[2] can: kvaser_usb: Reset all URB tx contexts upon channel close
    889b77f7fd2bcc922493d73a4c51d8a851505815

[3] Stacktrace:

 <IRQ>  [<ffffffff8158de87>] dump_stack+0x45/0x57
 [<ffffffff8158b60c>] __schedule_bug+0x41/0x4f
 [<ffffffff815904b1>] __schedule+0x5f1/0x700
 [<ffffffff8159360a>] ? _raw_spin_unlock_irqrestore+0xa/0x10
 [<ffffffff81590684>] schedule+0x24/0x70
 [<ffffffff8147d0a5>] usb_kill_urb+0x65/0xa0
 [<ffffffff81077970>] ? prepare_to_wait_event+0x110/0x110
 [<ffffffff8147d7d8>] usb_kill_anchored_urbs+0x48/0x80
 [<ffffffffa01f4028>] kvaser_usb_unlink_tx_urbs+0x18/0x50 [kvaser_usb]
 [<ffffffffa01f45d0>] kvaser_usb_rx_error+0xc0/0x400 [kvaser_usb]
 [<ffffffff8108b14a>] ? vprintk_default+0x1a/0x20
 [<ffffffffa01f5241>] kvaser_usb_read_bulk_callback+0x4c1/0x5f0 [kvaser_usb]
 [<ffffffff8147a73e>] __usb_hcd_giveback_urb+0x5e/0xc0
 [<ffffffff8147a8a1>] usb_hcd_giveback_urb+0x41/0x110
 [<ffffffffa0008748>] finish_urb+0x98/0x180 [ohci_hcd]
 [<ffffffff810cd1a7>] ? acct_account_cputime+0x17/0x20
 [<ffffffff81069f65>] ? local_clock+0x15/0x30
 [<ffffffffa000a36b>] ohci_work+0x1fb/0x5a0 [ohci_hcd]
 [<ffffffff814fbb31>] ? process_backlog+0xb1/0x130
 [<ffffffffa000cd5b>] ohci_irq+0xeb/0x270 [ohci_hcd]
 [<ffffffff81479fc1>] usb_hcd_irq+0x21/0x30
 [<ffffffff8108bfd3>] handle_irq_event_percpu+0x43/0x120
 [<ffffffff8108c0ed>] handle_irq_event+0x3d/0x60
 [<ffffffff8108ec84>] handle_fasteoi_irq+0x74/0x110
 [<ffffffff81004dfd>] handle_irq+0x1d/0x30
 [<ffffffff81004727>] do_IRQ+0x57/0x100
 [<ffffffff8159482a>] common_interrupt+0x6a/0x6a

Signed-off-by: Ahmed S. Darwish <ahmed.darwish@valeo.com>
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/kvaser_usb.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index c32cd61073bc..978a25e9cd3c 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -662,11 +662,6 @@ static void kvaser_usb_rx_error(const struct kvaser_usb *dev,
 	priv = dev->nets[channel];
 	stats = &priv->netdev->stats;
 
-	if (status & M16C_STATE_BUS_RESET) {
-		kvaser_usb_unlink_tx_urbs(priv);
-		return;
-	}
-
 	skb = alloc_can_err_skb(priv->netdev, &cf);
 	if (!skb) {
 		stats->rx_dropped++;
@@ -677,7 +672,7 @@ static void kvaser_usb_rx_error(const struct kvaser_usb *dev,
 
 	netdev_dbg(priv->netdev, "Error status: 0x%02x\n", status);
 
-	if (status & M16C_STATE_BUS_OFF) {
+	if (status & (M16C_STATE_BUS_OFF | M16C_STATE_BUS_RESET)) {
 		cf->can_id |= CAN_ERR_BUSOFF;
 
 		priv->can.can_stats.bus_off++;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] can: kvaser_usb: Send correct context to URB completion
  2015-01-27  8:01 pull-request: can 2015-01-27 Marc Kleine-Budde
  2015-01-27  8:01 ` [PATCH 1/4] can: kvaser_usb: Do not sleep in atomic context Marc Kleine-Budde
@ 2015-01-27  8:01 ` Marc Kleine-Budde
  2015-01-27  8:01 ` [PATCH 3/4] can: kvaser_usb: Retry the first bulk transfer on -ETIMEDOUT Marc Kleine-Budde
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2015-01-27  8:01 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Ahmed S. Darwish, linux-stable,
	Marc Kleine-Budde

From: "Ahmed S. Darwish" <ahmed.darwish@valeo.com>

Send expected argument to the URB completion hander: a CAN
netdevice instead of the network interface private context
`kvaser_usb_net_priv'.

This was discovered by having some garbage in the kernel
log in place of the netdevice names: can0 and can1.

Signed-off-by: Ahmed S. Darwish <ahmed.darwish@valeo.com>
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/kvaser_usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index 978a25e9cd3c..f0c62075df0a 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -587,7 +587,7 @@ static int kvaser_usb_simple_msg_async(struct kvaser_usb_net_priv *priv,
 			  usb_sndbulkpipe(dev->udev,
 					  dev->bulk_out->bEndpointAddress),
 			  buf, msg->len,
-			  kvaser_usb_simple_msg_callback, priv);
+			  kvaser_usb_simple_msg_callback, netdev);
 	usb_anchor_urb(urb, &priv->tx_submitted);
 
 	err = usb_submit_urb(urb, GFP_ATOMIC);
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] can: kvaser_usb: Retry the first bulk transfer on -ETIMEDOUT
  2015-01-27  8:01 pull-request: can 2015-01-27 Marc Kleine-Budde
  2015-01-27  8:01 ` [PATCH 1/4] can: kvaser_usb: Do not sleep in atomic context Marc Kleine-Budde
  2015-01-27  8:01 ` [PATCH 2/4] can: kvaser_usb: Send correct context to URB completion Marc Kleine-Budde
@ 2015-01-27  8:01 ` Marc Kleine-Budde
  2015-01-27  8:01 ` [PATCH 4/4] can: kvaser_usb: Fix state handling upon BUS_ERROR events Marc Kleine-Budde
  2015-01-27  8:13 ` pull-request: can 2015-01-27 David Miller
  4 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2015-01-27  8:01 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Ahmed S. Darwish, linux-stable,
	Marc Kleine-Budde

From: "Ahmed S. Darwish" <ahmed.darwish@valeo.com>

On some x86 laptops, plugging a Kvaser device again after an
unplug makes the firmware always ignore the very first command.
For such a case, provide some room for retries instead of
completely exiting the driver init code.

Signed-off-by: Ahmed S. Darwish <ahmed.darwish@valeo.com>
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/kvaser_usb.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index f0c62075df0a..55407b9663a6 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -1585,7 +1585,7 @@ static int kvaser_usb_probe(struct usb_interface *intf,
 {
 	struct kvaser_usb *dev;
 	int err = -ENOMEM;
-	int i;
+	int i, retry = 3;
 
 	dev = devm_kzalloc(&intf->dev, sizeof(*dev), GFP_KERNEL);
 	if (!dev)
@@ -1603,7 +1603,15 @@ static int kvaser_usb_probe(struct usb_interface *intf,
 
 	usb_set_intfdata(intf, dev);
 
-	err = kvaser_usb_get_software_info(dev);
+	/* On some x86 laptops, plugging a Kvaser device again after
+	 * an unplug makes the firmware always ignore the very first
+	 * command. For such a case, provide some room for retries
+	 * instead of completely exiting the driver.
+	 */
+	do {
+		err = kvaser_usb_get_software_info(dev);
+	} while (--retry && err == -ETIMEDOUT);
+
 	if (err) {
 		dev_err(&intf->dev,
 			"Cannot get software infos, error %d\n", err);
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] can: kvaser_usb: Fix state handling upon BUS_ERROR events
  2015-01-27  8:01 pull-request: can 2015-01-27 Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2015-01-27  8:01 ` [PATCH 3/4] can: kvaser_usb: Retry the first bulk transfer on -ETIMEDOUT Marc Kleine-Budde
@ 2015-01-27  8:01 ` Marc Kleine-Budde
  2015-01-27  8:13 ` pull-request: can 2015-01-27 David Miller
  4 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2015-01-27  8:01 UTC (permalink / raw)
  To: netdev
  Cc: davem, linux-can, kernel, Ahmed S. Darwish, linux-stable,
	Marc Kleine-Budde

From: "Ahmed S. Darwish" <ahmed.darwish@valeo.com>

While being in an ERROR_WARNING state, and receiving further
bus error events with error counters still in the ERROR_WARNING
range of 97-127 inclusive, the state handling code erroneously
reverts back to ERROR_ACTIVE.

Per the CAN standard, only revert to ERROR_ACTIVE when the
error counters are less than 96.

Moreover, in certain Kvaser models, the BUS_ERROR flag is
always set along with undefined bits in the M16C status
register. Thus use bitwise operators instead of full equality
for checking that register against bus errors.

Signed-off-by: Ahmed S. Darwish <ahmed.darwish@valeo.com>
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/kvaser_usb.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index 55407b9663a6..7af379ca861b 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -698,9 +698,7 @@ static void kvaser_usb_rx_error(const struct kvaser_usb *dev,
 		}
 
 		new_state = CAN_STATE_ERROR_PASSIVE;
-	}
-
-	if (status == M16C_STATE_BUS_ERROR) {
+	} else if (status & M16C_STATE_BUS_ERROR) {
 		if ((priv->can.state < CAN_STATE_ERROR_WARNING) &&
 		    ((txerr >= 96) || (rxerr >= 96))) {
 			cf->can_id |= CAN_ERR_CRTL;
@@ -710,7 +708,8 @@ static void kvaser_usb_rx_error(const struct kvaser_usb *dev,
 
 			priv->can.can_stats.error_warning++;
 			new_state = CAN_STATE_ERROR_WARNING;
-		} else if (priv->can.state > CAN_STATE_ERROR_ACTIVE) {
+		} else if ((priv->can.state > CAN_STATE_ERROR_ACTIVE) &&
+			   ((txerr < 96) && (rxerr < 96))) {
 			cf->can_id |= CAN_ERR_PROT;
 			cf->data[2] = CAN_ERR_PROT_ACTIVE;
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: pull-request: can 2015-01-27
  2015-01-27  8:01 pull-request: can 2015-01-27 Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2015-01-27  8:01 ` [PATCH 4/4] can: kvaser_usb: Fix state handling upon BUS_ERROR events Marc Kleine-Budde
@ 2015-01-27  8:13 ` David Miller
  2015-01-27  8:14   ` Marc Kleine-Budde
  4 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2015-01-27  8:13 UTC (permalink / raw)
  To: mkl; +Cc: netdev, linux-can, kernel

From: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Tue, 27 Jan 2015 09:01:23 +0100

> this is another pull request for net/master which consists of 4 patches.
> 
> All 4 patches are contributed by Ahmed S. Darwish, he fixes more problems in
> the kvaser_usb driver.

Pulled, thanks.

> David, please merge net/master to net-next/master, as we have more kvaser_usb
> patches in the queue, that target net-next.

I will do so after I send a pull request for 'net' to Linus and he takes it
in, thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: pull-request: can 2015-01-27
  2015-01-27  8:13 ` pull-request: can 2015-01-27 David Miller
@ 2015-01-27  8:14   ` Marc Kleine-Budde
  0 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2015-01-27  8:14 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, linux-can, kernel

[-- Attachment #1: Type: text/plain, Size: 909 bytes --]

On 01/27/2015 09:13 AM, David Miller wrote:
> From: Marc Kleine-Budde <mkl@pengutronix.de>
> Date: Tue, 27 Jan 2015 09:01:23 +0100
> 
>> this is another pull request for net/master which consists of 4 patches.
>>
>> All 4 patches are contributed by Ahmed S. Darwish, he fixes more problems in
>> the kvaser_usb driver.
> 
> Pulled, thanks.

That was fast :)

>> David, please merge net/master to net-next/master, as we have more kvaser_usb
>> patches in the queue, that target net-next.
> 
> I will do so after I send a pull request for 'net' to Linus and he takes it
> in, thanks.

Thanks, I'll notice.

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-01-27  8:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-27  8:01 pull-request: can 2015-01-27 Marc Kleine-Budde
2015-01-27  8:01 ` [PATCH 1/4] can: kvaser_usb: Do not sleep in atomic context Marc Kleine-Budde
2015-01-27  8:01 ` [PATCH 2/4] can: kvaser_usb: Send correct context to URB completion Marc Kleine-Budde
2015-01-27  8:01 ` [PATCH 3/4] can: kvaser_usb: Retry the first bulk transfer on -ETIMEDOUT Marc Kleine-Budde
2015-01-27  8:01 ` [PATCH 4/4] can: kvaser_usb: Fix state handling upon BUS_ERROR events Marc Kleine-Budde
2015-01-27  8:13 ` pull-request: can 2015-01-27 David Miller
2015-01-27  8:14   ` Marc Kleine-Budde

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.