linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/5] pull-request: can 2022-04-29
@ 2022-04-29 12:56 Marc Kleine-Budde
  2022-04-29 12:56 ` [PATCH net 1/5] can: isotp: remove re-binding of bound socket Marc Kleine-Budde
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2022-04-29 12:56 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel

Hello Jakub, hello David,

this is a pull request of 5 patches for net/master.

The first patch is by Oliver Hartkopp and removes the ability to
re-binding bounds sockets from the ISOTP. It turned out to be not
needed and brings unnecessary complexity.

The last 4 patches all target the grcan driver. Duoming Zhou's patch
fixes a potential dead lock in the grcan_close() function. Daniel
Hellstrom's patch fixes the dma_alloc_coherent() to use the correct
device. Andreas Larsson's 1st patch fixes a broken system id check,
the 2nd patch fixes the NAPI poll budget usage.

regards,
Marc

---

The following changes since commit d9157f6806d1499e173770df1f1b234763de5c79:

  tcp: fix F-RTO may not work correctly when receiving DSACK (2022-04-28 10:35:38 -0700)

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-5.18-20220429

for you to fetch changes up to 2873d4d52f7c52d60b316ba6c47bd7122b5a9861:

  can: grcan: only use the NAPI poll budget for RX (2022-04-29 12:09:32 +0200)

----------------------------------------------------------------
linux-can-fixes-for-5.18-20220429

----------------------------------------------------------------
Andreas Larsson (2):
      can: grcan: grcan_probe(): fix broken system id check for errata workaround needs
      can: grcan: only use the NAPI poll budget for RX

Daniel Hellstrom (1):
      can: grcan: use ofdev->dev when allocating DMA memory

Duoming Zhou (1):
      can: grcan: grcan_close(): fix deadlock

Oliver Hartkopp (1):
      can: isotp: remove re-binding of bound socket

 drivers/net/can/grcan.c | 46 ++++++++++++++++++++++++----------------------
 net/can/isotp.c         | 25 +++++--------------------
 2 files changed, 29 insertions(+), 42 deletions(-)



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

* [PATCH net 1/5] can: isotp: remove re-binding of bound socket
  2022-04-29 12:56 [PATCH net 0/5] pull-request: can 2022-04-29 Marc Kleine-Budde
@ 2022-04-29 12:56 ` Marc Kleine-Budde
  2022-04-29 19:40   ` patchwork-bot+netdevbpf
  2022-04-29 12:56 ` [PATCH net 2/5] can: grcan: grcan_close(): fix deadlock Marc Kleine-Budde
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Marc Kleine-Budde @ 2022-04-29 12:56 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Oliver Hartkopp, stable,
	Marc Kleine-Budde

From: Oliver Hartkopp <socketcan@hartkopp.net>

As a carry over from the CAN_RAW socket (which allows to change the CAN
interface while mantaining the filter setup) the re-binding of the
CAN_ISOTP socket needs to take care about CAN ID address information and
subscriptions. It turned out that this feature is so limited (e.g. the
sockopts remain fix) that it finally has never been needed/used.

In opposite to the stateless CAN_RAW socket the switching of the CAN ID
subscriptions might additionally lead to an interrupted ongoing PDU
reception. So better remove this unneeded complexity.

Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Link: https://lore.kernel.org/all/20220422082337.1676-1-socketcan@hartkopp.net
Cc: stable@vger.kernel.org
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 net/can/isotp.c | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/net/can/isotp.c b/net/can/isotp.c
index ff5d7870294e..1e7c6a460ef9 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1189,6 +1189,11 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)
 
 	lock_sock(sk);
 
+	if (so->bound) {
+		err = -EINVAL;
+		goto out;
+	}
+
 	/* do not register frame reception for functional addressing */
 	if (so->opt.flags & CAN_ISOTP_SF_BROADCAST)
 		do_rx_reg = 0;
@@ -1199,10 +1204,6 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)
 		goto out;
 	}
 
-	if (so->bound && addr->can_ifindex == so->ifindex &&
-	    rx_id == so->rxid && tx_id == so->txid)
-		goto out;
-
 	dev = dev_get_by_index(net, addr->can_ifindex);
 	if (!dev) {
 		err = -ENODEV;
@@ -1237,22 +1238,6 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)
 
 	dev_put(dev);
 
-	if (so->bound && do_rx_reg) {
-		/* unregister old filter */
-		if (so->ifindex) {
-			dev = dev_get_by_index(net, so->ifindex);
-			if (dev) {
-				can_rx_unregister(net, dev, so->rxid,
-						  SINGLE_MASK(so->rxid),
-						  isotp_rcv, sk);
-				can_rx_unregister(net, dev, so->txid,
-						  SINGLE_MASK(so->txid),
-						  isotp_rcv_echo, sk);
-				dev_put(dev);
-			}
-		}
-	}
-
 	/* switch to new settings */
 	so->ifindex = ifindex;
 	so->rxid = rx_id;

base-commit: d9157f6806d1499e173770df1f1b234763de5c79
-- 
2.35.1



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

* [PATCH net 2/5] can: grcan: grcan_close(): fix deadlock
  2022-04-29 12:56 [PATCH net 0/5] pull-request: can 2022-04-29 Marc Kleine-Budde
  2022-04-29 12:56 ` [PATCH net 1/5] can: isotp: remove re-binding of bound socket Marc Kleine-Budde
@ 2022-04-29 12:56 ` Marc Kleine-Budde
  2022-04-29 12:56 ` [PATCH net 3/5] can: grcan: use ofdev->dev when allocating DMA memory Marc Kleine-Budde
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2022-04-29 12:56 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Duoming Zhou, stable,
	Andreas Larsson, Marc Kleine-Budde

From: Duoming Zhou <duoming@zju.edu.cn>

There are deadlocks caused by del_timer_sync(&priv->hang_timer) and
del_timer_sync(&priv->rr_timer) in grcan_close(), one of the deadlocks
are shown below:

   (Thread 1)              |      (Thread 2)
                           | grcan_reset_timer()
grcan_close()              |  mod_timer()
 spin_lock_irqsave() //(1) |  (wait a time)
 ...                       | grcan_initiate_running_reset()
 del_timer_sync()          |  spin_lock_irqsave() //(2)
 (wait timer to stop)      |  ...

We hold priv->lock in position (1) of thread 1 and use
del_timer_sync() to wait timer to stop, but timer handler also need
priv->lock in position (2) of thread 2. As a result, grcan_close()
will block forever.

This patch extracts del_timer_sync() from the protection of
spin_lock_irqsave(), which could let timer handler to obtain the
needed lock.

Link: https://lore.kernel.org/all/20220425042400.66517-1-duoming@zju.edu.cn
Fixes: 6cec9b07fe6a ("can: grcan: Add device driver for GRCAN and GRHCAN cores")
Cc: stable@vger.kernel.org
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Reviewed-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/grcan.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c
index d0c5a7a60daf..1189057b5d68 100644
--- a/drivers/net/can/grcan.c
+++ b/drivers/net/can/grcan.c
@@ -1102,8 +1102,10 @@ static int grcan_close(struct net_device *dev)
 
 	priv->closing = true;
 	if (priv->need_txbug_workaround) {
+		spin_unlock_irqrestore(&priv->lock, flags);
 		del_timer_sync(&priv->hang_timer);
 		del_timer_sync(&priv->rr_timer);
+		spin_lock_irqsave(&priv->lock, flags);
 	}
 	netif_stop_queue(dev);
 	grcan_stop_hardware(dev);
-- 
2.35.1



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

* [PATCH net 3/5] can: grcan: use ofdev->dev when allocating DMA memory
  2022-04-29 12:56 [PATCH net 0/5] pull-request: can 2022-04-29 Marc Kleine-Budde
  2022-04-29 12:56 ` [PATCH net 1/5] can: isotp: remove re-binding of bound socket Marc Kleine-Budde
  2022-04-29 12:56 ` [PATCH net 2/5] can: grcan: grcan_close(): fix deadlock Marc Kleine-Budde
@ 2022-04-29 12:56 ` Marc Kleine-Budde
  2022-04-29 12:56 ` [PATCH net 4/5] can: grcan: grcan_probe(): fix broken system id check for errata workaround needs Marc Kleine-Budde
  2022-04-29 12:56 ` [PATCH net 5/5] can: grcan: only use the NAPI poll budget for RX Marc Kleine-Budde
  4 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2022-04-29 12:56 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Daniel Hellstrom, stable,
	Andreas Larsson, Marc Kleine-Budde

From: Daniel Hellstrom <daniel@gaisler.com>

Use the device of the device tree node should be rather than the
device of the struct net_device when allocating DMA buffers.

The driver got away with it on sparc32 until commit 53b7670e5735
("sparc: factor the dma coherent mapping into helper") after which the
driver oopses.

Fixes: 6cec9b07fe6a ("can: grcan: Add device driver for GRCAN and GRHCAN cores")
Link: https://lore.kernel.org/all/20220429084656.29788-2-andreas@gaisler.com
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/grcan.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c
index 1189057b5d68..f8860900575b 100644
--- a/drivers/net/can/grcan.c
+++ b/drivers/net/can/grcan.c
@@ -248,6 +248,7 @@ struct grcan_device_config {
 struct grcan_priv {
 	struct can_priv can;	/* must be the first member */
 	struct net_device *dev;
+	struct device *ofdev_dev;
 	struct napi_struct napi;
 
 	struct grcan_registers __iomem *regs;	/* ioremap'ed registers */
@@ -921,7 +922,7 @@ static void grcan_free_dma_buffers(struct net_device *dev)
 	struct grcan_priv *priv = netdev_priv(dev);
 	struct grcan_dma *dma = &priv->dma;
 
-	dma_free_coherent(&dev->dev, dma->base_size, dma->base_buf,
+	dma_free_coherent(priv->ofdev_dev, dma->base_size, dma->base_buf,
 			  dma->base_handle);
 	memset(dma, 0, sizeof(*dma));
 }
@@ -946,7 +947,7 @@ static int grcan_allocate_dma_buffers(struct net_device *dev,
 
 	/* Extra GRCAN_BUFFER_ALIGNMENT to allow for alignment */
 	dma->base_size = lsize + ssize + GRCAN_BUFFER_ALIGNMENT;
-	dma->base_buf = dma_alloc_coherent(&dev->dev,
+	dma->base_buf = dma_alloc_coherent(priv->ofdev_dev,
 					   dma->base_size,
 					   &dma->base_handle,
 					   GFP_KERNEL);
@@ -1589,6 +1590,7 @@ static int grcan_setup_netdev(struct platform_device *ofdev,
 	memcpy(&priv->config, &grcan_module_config,
 	       sizeof(struct grcan_device_config));
 	priv->dev = dev;
+	priv->ofdev_dev = &ofdev->dev;
 	priv->regs = base;
 	priv->can.bittiming_const = &grcan_bittiming_const;
 	priv->can.do_set_bittiming = grcan_set_bittiming;
-- 
2.35.1



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

* [PATCH net 4/5] can: grcan: grcan_probe(): fix broken system id check for errata workaround needs
  2022-04-29 12:56 [PATCH net 0/5] pull-request: can 2022-04-29 Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2022-04-29 12:56 ` [PATCH net 3/5] can: grcan: use ofdev->dev when allocating DMA memory Marc Kleine-Budde
@ 2022-04-29 12:56 ` Marc Kleine-Budde
  2022-04-29 12:56 ` [PATCH net 5/5] can: grcan: only use the NAPI poll budget for RX Marc Kleine-Budde
  4 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2022-04-29 12:56 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Andreas Larsson, stable,
	Marc Kleine-Budde

From: Andreas Larsson <andreas@gaisler.com>

The systemid property was checked for in the wrong place of the device
tree and compared to the wrong value.

Fixes: 6cec9b07fe6a ("can: grcan: Add device driver for GRCAN and GRHCAN cores")
Link: https://lore.kernel.org/all/20220429084656.29788-3-andreas@gaisler.com
Cc: stable@vger.kernel.org
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/grcan.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c
index f8860900575b..4ca3da56d3aa 100644
--- a/drivers/net/can/grcan.c
+++ b/drivers/net/can/grcan.c
@@ -241,7 +241,7 @@ struct grcan_device_config {
 		.rxsize		= GRCAN_DEFAULT_BUFFER_SIZE,	\
 		}
 
-#define GRCAN_TXBUG_SAFE_GRLIB_VERSION	0x4100
+#define GRCAN_TXBUG_SAFE_GRLIB_VERSION	4100
 #define GRLIB_VERSION_MASK		0xffff
 
 /* GRCAN private data structure */
@@ -1643,6 +1643,7 @@ static int grcan_setup_netdev(struct platform_device *ofdev,
 static int grcan_probe(struct platform_device *ofdev)
 {
 	struct device_node *np = ofdev->dev.of_node;
+	struct device_node *sysid_parent;
 	u32 sysid, ambafreq;
 	int irq, err;
 	void __iomem *base;
@@ -1651,10 +1652,15 @@ static int grcan_probe(struct platform_device *ofdev)
 	/* Compare GRLIB version number with the first that does not
 	 * have the tx bug (see start_xmit)
 	 */
-	err = of_property_read_u32(np, "systemid", &sysid);
-	if (!err && ((sysid & GRLIB_VERSION_MASK)
-		     >= GRCAN_TXBUG_SAFE_GRLIB_VERSION))
-		txbug = false;
+	sysid_parent = of_find_node_by_path("/ambapp0");
+	if (sysid_parent) {
+		of_node_get(sysid_parent);
+		err = of_property_read_u32(sysid_parent, "systemid", &sysid);
+		if (!err && ((sysid & GRLIB_VERSION_MASK) >=
+			     GRCAN_TXBUG_SAFE_GRLIB_VERSION))
+			txbug = false;
+		of_node_put(sysid_parent);
+	}
 
 	err = of_property_read_u32(np, "freq", &ambafreq);
 	if (err) {
-- 
2.35.1



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

* [PATCH net 5/5] can: grcan: only use the NAPI poll budget for RX
  2022-04-29 12:56 [PATCH net 0/5] pull-request: can 2022-04-29 Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2022-04-29 12:56 ` [PATCH net 4/5] can: grcan: grcan_probe(): fix broken system id check for errata workaround needs Marc Kleine-Budde
@ 2022-04-29 12:56 ` Marc Kleine-Budde
  4 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2022-04-29 12:56 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Andreas Larsson, stable,
	Marc Kleine-Budde

From: Andreas Larsson <andreas@gaisler.com>

The previous split budget between TX and RX made it return not using
the entire budget but at the same time not having calling called
napi_complete. This sometimes led to the poll to not be called, and at
the same time having TX and RX interrupts disabled resulting in the
driver getting stuck.

Fixes: 6cec9b07fe6a ("can: grcan: Add device driver for GRCAN and GRHCAN cores")
Link: https://lore.kernel.org/all/20220429084656.29788-4-andreas@gaisler.com
Cc: stable@vger.kernel.org
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/grcan.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c
index 4ca3da56d3aa..5215bd9b2c80 100644
--- a/drivers/net/can/grcan.c
+++ b/drivers/net/can/grcan.c
@@ -1125,7 +1125,7 @@ static int grcan_close(struct net_device *dev)
 	return 0;
 }
 
-static int grcan_transmit_catch_up(struct net_device *dev, int budget)
+static void grcan_transmit_catch_up(struct net_device *dev)
 {
 	struct grcan_priv *priv = netdev_priv(dev);
 	unsigned long flags;
@@ -1133,7 +1133,7 @@ static int grcan_transmit_catch_up(struct net_device *dev, int budget)
 
 	spin_lock_irqsave(&priv->lock, flags);
 
-	work_done = catch_up_echo_skb(dev, budget, true);
+	work_done = catch_up_echo_skb(dev, -1, true);
 	if (work_done) {
 		if (!priv->resetting && !priv->closing &&
 		    !(priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY))
@@ -1147,8 +1147,6 @@ static int grcan_transmit_catch_up(struct net_device *dev, int budget)
 	}
 
 	spin_unlock_irqrestore(&priv->lock, flags);
-
-	return work_done;
 }
 
 static int grcan_receive(struct net_device *dev, int budget)
@@ -1230,19 +1228,13 @@ static int grcan_poll(struct napi_struct *napi, int budget)
 	struct net_device *dev = priv->dev;
 	struct grcan_registers __iomem *regs = priv->regs;
 	unsigned long flags;
-	int tx_work_done, rx_work_done;
-	int rx_budget = budget / 2;
-	int tx_budget = budget - rx_budget;
+	int work_done;
 
-	/* Half of the budget for receiving messages */
-	rx_work_done = grcan_receive(dev, rx_budget);
+	work_done = grcan_receive(dev, budget);
 
-	/* Half of the budget for transmitting messages as that can trigger echo
-	 * frames being received
-	 */
-	tx_work_done = grcan_transmit_catch_up(dev, tx_budget);
+	grcan_transmit_catch_up(dev);
 
-	if (rx_work_done < rx_budget && tx_work_done < tx_budget) {
+	if (work_done < budget) {
 		napi_complete(napi);
 
 		/* Guarantee no interference with a running reset that otherwise
@@ -1259,7 +1251,7 @@ static int grcan_poll(struct napi_struct *napi, int budget)
 		spin_unlock_irqrestore(&priv->lock, flags);
 	}
 
-	return rx_work_done + tx_work_done;
+	return work_done;
 }
 
 /* Work tx bug by waiting while for the risky situation to clear. If that fails,
-- 
2.35.1



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

* Re: [PATCH net 1/5] can: isotp: remove re-binding of bound socket
  2022-04-29 12:56 ` [PATCH net 1/5] can: isotp: remove re-binding of bound socket Marc Kleine-Budde
@ 2022-04-29 19:40   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-04-29 19:40 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: netdev, davem, kuba, linux-can, kernel, socketcan, stable

Hello:

This series was applied to netdev/net.git (master)
by Marc Kleine-Budde <mkl@pengutronix.de>:

On Fri, 29 Apr 2022 14:56:08 +0200 you wrote:
> From: Oliver Hartkopp <socketcan@hartkopp.net>
> 
> As a carry over from the CAN_RAW socket (which allows to change the CAN
> interface while mantaining the filter setup) the re-binding of the
> CAN_ISOTP socket needs to take care about CAN ID address information and
> subscriptions. It turned out that this feature is so limited (e.g. the
> sockopts remain fix) that it finally has never been needed/used.
> 
> [...]

Here is the summary with links:
  - [net,1/5] can: isotp: remove re-binding of bound socket
    https://git.kernel.org/netdev/net/c/72ed3ee9fa0b
  - [net,2/5] can: grcan: grcan_close(): fix deadlock
    https://git.kernel.org/netdev/net/c/47f070a63e73
  - [net,3/5] can: grcan: use ofdev->dev when allocating DMA memory
    https://git.kernel.org/netdev/net/c/101da4268626
  - [net,4/5] can: grcan: grcan_probe(): fix broken system id check for errata workaround needs
    https://git.kernel.org/netdev/net/c/1e93ed26acf0
  - [net,5/5] can: grcan: only use the NAPI poll budget for RX
    https://git.kernel.org/netdev/net/c/2873d4d52f7c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-04-29 19:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29 12:56 [PATCH net 0/5] pull-request: can 2022-04-29 Marc Kleine-Budde
2022-04-29 12:56 ` [PATCH net 1/5] can: isotp: remove re-binding of bound socket Marc Kleine-Budde
2022-04-29 19:40   ` patchwork-bot+netdevbpf
2022-04-29 12:56 ` [PATCH net 2/5] can: grcan: grcan_close(): fix deadlock Marc Kleine-Budde
2022-04-29 12:56 ` [PATCH net 3/5] can: grcan: use ofdev->dev when allocating DMA memory Marc Kleine-Budde
2022-04-29 12:56 ` [PATCH net 4/5] can: grcan: grcan_probe(): fix broken system id check for errata workaround needs Marc Kleine-Budde
2022-04-29 12:56 ` [PATCH net 5/5] can: grcan: only use the NAPI poll budget for RX Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).