* pull-request: can 2016-09-22
@ 2016-09-22 12:42 Marc Kleine-Budde
2016-09-22 12:42 ` [PATCH] can: dev: fix deadlock reported after bus-off Marc Kleine-Budde
2016-09-23 11:15 ` pull-request: can 2016-09-22 David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2016-09-22 12:42 UTC (permalink / raw)
To: netdev; +Cc: davem, linux-can, kernel
Hello David,
this is a pull request of one patch for the upcoming linux-4.8 release.
The patch by Sergei Miroshnichenko fixes a potential deadlock in the generic
CAN device code that cann occour after a bus-off.
regards,
Marc
---
The following changes since commit 7e32b44361abc77fbc01f2b97b045c405b2583e5:
tcp: properly account Fast Open SYN-ACK retrans (2016-09-22 03:33:01 -0400)
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-4.8-20160922
for you to fetch changes up to 9abefcb1aaa58b9d5aa40a8bb12c87d02415e4c8:
can: dev: fix deadlock reported after bus-off (2016-09-22 10:01:21 +0200)
----------------------------------------------------------------
linux-can-fixes-for-4.8-20160922
----------------------------------------------------------------
Sergei Miroshnichenko (1):
can: dev: fix deadlock reported after bus-off
drivers/net/can/dev.c | 27 +++++++++++++++++----------
include/linux/can/dev.h | 3 ++-
2 files changed, 19 insertions(+), 11 deletions(-)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] can: dev: fix deadlock reported after bus-off
2016-09-22 12:42 pull-request: can 2016-09-22 Marc Kleine-Budde
@ 2016-09-22 12:42 ` Marc Kleine-Budde
2016-09-23 11:15 ` pull-request: can 2016-09-22 David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2016-09-22 12:42 UTC (permalink / raw)
To: netdev
Cc: davem, linux-can, kernel, Sergei Miroshnichenko, linux-stable,
Marc Kleine-Budde
From: Sergei Miroshnichenko <sergeimir@emcraft.com>
A timer was used to restart after the bus-off state, leading to a
relatively large can_restart() executed in an interrupt context,
which in turn sets up pinctrl. When this happens during system boot,
there is a high probability of grabbing the pinctrl_list_mutex,
which is locked already by the probe() of other device, making the
kernel suspect a deadlock condition [1].
To resolve this issue, the restart_timer is replaced by a delayed
work.
[1] https://github.com/victronenergy/venus/issues/24
Signed-off-by: Sergei Miroshnichenko <sergeimir@emcraft.com>
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/dev.c | 27 +++++++++++++++++----------
include/linux/can/dev.h | 3 ++-
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index e21f7cc5ae4d..8d6208c0b400 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -21,6 +21,7 @@
#include <linux/slab.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
+#include <linux/workqueue.h>
#include <linux/can.h>
#include <linux/can/dev.h>
#include <linux/can/skb.h>
@@ -501,9 +502,8 @@ EXPORT_SYMBOL_GPL(can_free_echo_skb);
/*
* CAN device restart for bus-off recovery
*/
-static void can_restart(unsigned long data)
+static void can_restart(struct net_device *dev)
{
- struct net_device *dev = (struct net_device *)data;
struct can_priv *priv = netdev_priv(dev);
struct net_device_stats *stats = &dev->stats;
struct sk_buff *skb;
@@ -543,6 +543,14 @@ restart:
netdev_err(dev, "Error %d during restart", err);
}
+static void can_restart_work(struct work_struct *work)
+{
+ struct delayed_work *dwork = to_delayed_work(work);
+ struct can_priv *priv = container_of(dwork, struct can_priv, restart_work);
+
+ can_restart(priv->dev);
+}
+
int can_restart_now(struct net_device *dev)
{
struct can_priv *priv = netdev_priv(dev);
@@ -556,8 +564,8 @@ int can_restart_now(struct net_device *dev)
if (priv->state != CAN_STATE_BUS_OFF)
return -EBUSY;
- /* Runs as soon as possible in the timer context */
- mod_timer(&priv->restart_timer, jiffies);
+ cancel_delayed_work_sync(&priv->restart_work);
+ can_restart(dev);
return 0;
}
@@ -578,8 +586,8 @@ void can_bus_off(struct net_device *dev)
netif_carrier_off(dev);
if (priv->restart_ms)
- mod_timer(&priv->restart_timer,
- jiffies + (priv->restart_ms * HZ) / 1000);
+ schedule_delayed_work(&priv->restart_work,
+ msecs_to_jiffies(priv->restart_ms));
}
EXPORT_SYMBOL_GPL(can_bus_off);
@@ -688,6 +696,7 @@ struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max)
return NULL;
priv = netdev_priv(dev);
+ priv->dev = dev;
if (echo_skb_max) {
priv->echo_skb_max = echo_skb_max;
@@ -697,7 +706,7 @@ struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max)
priv->state = CAN_STATE_STOPPED;
- init_timer(&priv->restart_timer);
+ INIT_DELAYED_WORK(&priv->restart_work, can_restart_work);
return dev;
}
@@ -778,8 +787,6 @@ int open_candev(struct net_device *dev)
if (!netif_carrier_ok(dev))
netif_carrier_on(dev);
- setup_timer(&priv->restart_timer, can_restart, (unsigned long)dev);
-
return 0;
}
EXPORT_SYMBOL_GPL(open_candev);
@@ -794,7 +801,7 @@ void close_candev(struct net_device *dev)
{
struct can_priv *priv = netdev_priv(dev);
- del_timer_sync(&priv->restart_timer);
+ cancel_delayed_work_sync(&priv->restart_work);
can_flush_echo_skb(dev);
}
EXPORT_SYMBOL_GPL(close_candev);
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 5261751f6bd4..5f5270941ba0 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -32,6 +32,7 @@ enum can_mode {
* CAN common private data
*/
struct can_priv {
+ struct net_device *dev;
struct can_device_stats can_stats;
struct can_bittiming bittiming, data_bittiming;
@@ -47,7 +48,7 @@ struct can_priv {
u32 ctrlmode_static; /* static enabled options for driver/hardware */
int restart_ms;
- struct timer_list restart_timer;
+ struct delayed_work restart_work;
int (*do_set_bittiming)(struct net_device *dev);
int (*do_set_data_bittiming)(struct net_device *dev);
--
2.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: pull-request: can 2016-09-22
2016-09-22 12:42 pull-request: can 2016-09-22 Marc Kleine-Budde
2016-09-22 12:42 ` [PATCH] can: dev: fix deadlock reported after bus-off Marc Kleine-Budde
@ 2016-09-23 11:15 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2016-09-23 11:15 UTC (permalink / raw)
To: mkl; +Cc: netdev, linux-can, kernel
From: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Thu, 22 Sep 2016 14:42:21 +0200
> this is a pull request of one patch for the upcoming linux-4.8 release.
>
> The patch by Sergei Miroshnichenko fixes a potential deadlock in the generic
> CAN device code that cann occour after a bus-off.
Applied, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-09-23 11:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-22 12:42 pull-request: can 2016-09-22 Marc Kleine-Budde
2016-09-22 12:42 ` [PATCH] can: dev: fix deadlock reported after bus-off Marc Kleine-Budde
2016-09-23 11:15 ` pull-request: can 2016-09-22 David Miller
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.