FAILED: patch "[PATCH] can: mcp251xfd: fix infinite loop when xmit fails" failed to apply to 5.15-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x d8fb63e46c884c898a38f061c2330f7729e75510
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2024070105-reformat-gallantly-7ae0@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^..
Possible dependencies:
d8fb63e46c88 ("can: mcp251xfd: fix infinite loop when xmit fails")9263c2e92be9 ("can: mcp251xfd: ring: add support for runtime configurable RX/TX ring parameters") c9e6b80dfd48 ("can: mcp251xfd: update macros describing ring, FIFO and RAM layout")0a1f2e6502a1 ("can: mcp251xfd: ring: prepare support for runtime configurable RX/TX ring parameters") d86ba8db6af3 ("can: mcp251xfd: ethtool: add support")a1439a5add62 ("can: mcp251xfd: ram: add helper function for runtime ring size calculation") aada74220f00 ("can: mcp251xfd: mcp251xfd_priv: introduce macros specifying the number of supported TEF/RX/TX rings") fa0b68df7c95 ("can: mcp251xfd: ring: mcp251xfd_ring_init(): checked RAM usage of ring setup") 62713f0d9a38 ("can: mcp251xfd: ring: change order of TX and RX FIFOs")617283b9c4db ("can: mcp251xfd: ring: prepare to change order of TX and RX FIFOs")d2d5397fcae1 ("can: mcp251xfd: mcp251xfd_ring_init(): split ring_init into separate functions") c912f19ee382 ("can: mcp251xfd: introduce struct mcp251xfd_tx_ring::nr and ::fifo_nr and make use of it") 2a68dd8663ea ("can: mcp251xfd: add support for internal PLL")e39ea1360ca7 ("can: mcp251xfd: mcp251xfd_chip_clock_init(): prepare for PLL support, wait for OSC ready") 14193ea2bfee ("can: mcp251xfd: mcp251xfd_chip_timestamp_init(): factor out into separate function") 1ba3690fa2c6 ("can: mcp251xfd: mcp251xfd_chip_sleep(): introduce function to bring chip into sleep mode") 3044a4f271d2 ("can: mcp251xfd: introduce and make use of mcp251xfd_is_fd_mode()")55bc37c85587 ("can: mcp251xfd: move ring init into separate function")335c818c5a7a ("can: mcp251xfd: move chip FIFO init into separate file")1e846c7aeb06 ("can: mcp251xfd: move TEF handling into separate file")
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From d8fb63e46c884c898a38f061c2330f7729e75510 Mon Sep 17 00:00:00 2001
From: Vitor Soares <[email protected]>
Date: Fri, 17 May 2024 14:43:55 +0100
Subject: [PATCH] can: mcp251xfd: fix infinite loop when xmit fails
When the mcp251xfd_start_xmit() function fails, the driver stops processing messages, and the interrupt routine does not return, running indefinitely even after killing the running application.
Error messages:
[ 441.298819] mcp251xfd spi2.0 can0: ERROR in mcp251xfd_start_xmit: -16 [ 441.306498] mcp251xfd spi2.0 can0: Transmit Event FIFO buffer not empty. (seq=0x000017c7, tef_tail=0x000017cf, tef_head=0x000017d0, tx_head=0x000017d3).
... and repeat forever.
The issue can be triggered when multiple devices share the same SPI interface. And there is concurrent access to the bus.
The problem occurs because tx_ring->head increments even if mcp251xfd_start_xmit() fails. Consequently, the driver skips one TX package while still expecting a response in mcp251xfd_handle_tefif_one().
Resolve the issue by starting a workqueue to write the tx obj synchronously if err = -EBUSY. In case of another error, decrement tx_ring->head, remove skb from the echo stack, and drop the message.
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +13 -1
@@ -1618,11 +1618,20 @@ static int mcp251xfd_open(struct net_device *ndev)clear_bit (MCP251XFD_FLAGS_DOWN , priv->flags);can_rx_offload_enable (&priv->offload); + priv->wq =alloc_ordered_workqueue ("%s-mcp251xfd_wq" , +WQ_FREEZABLE |WQ_MEM_RECLAIM , +dev_name (&spi->dev)); +if (!priv->wq) { + err = -ENOMEM ; + goto out_can_rx_offload_disable; + } +INIT_WORK (&priv->tx_work, mcp251xfd_tx_obj_write_sync); + err =request_threaded_irq (spi->irq,NULL , mcp251xfd_irq,IRQF_SHARED |IRQF_ONESHOT ,dev_name (&spi->dev), priv);if (err) - goto out_can_rx_offload_disable; + goto out_destroy_workqueue; err =mcp251xfd_chip_interrupts_enable (priv);if (err)
@@ -1634,6 +1643,8 @@ static int mcp251xfd_open(struct net_device *ndev) out_free_irq:free_irq (spi->irq, priv); + out_destroy_workqueue: +destroy_workqueue (priv->wq); out_can_rx_offload_disable:can_rx_offload_disable (&priv->offload);set_bit (MCP251XFD_FLAGS_DOWN , priv->flags);
@@ -1661,6 +1672,7 @@ static int mcp251xfd_stop(struct net_device *ndev)hrtimer_cancel (&priv->tx_irq_timer);mcp251xfd_chip_interrupts_disable (priv);free_irq (ndev->irq, priv); +destroy_workqueue (priv->wq);can_rx_offload_disable (&priv->offload);mcp251xfd_timestamp_stop (priv);mcp251xfd_chip_stop (priv,CAN_STATE_STOPPED );
drivers/net/can/spi/mcp251xfd/mcp251xfd-tx.c +47 -8
79 lines not on this page · raw message
drivers/net/can/spi/mcp251xfd/mcp251xfd.h +5 -0
@@ -633,6 +633,10 @@ struct mcp251xfd_priv {struct mcp251xfd_rx_ring *rx[MCP251XFD_FIFO_RX_NUM ];struct mcp251xfd_tx_ring tx[MCP251XFD_FIFO_TX_NUM ]; +struct workqueue_struct *wq; +struct work_struct tx_work; +struct mcp251xfd_tx_obj *tx_work_obj; +DECLARE_BITMAP (flags, __MCP251XFD_FLAGS_SIZE__);u8 rx_ring_num;
@@ -952,6 +956,7 @@ void mcp251xfd_skb_set_timestamp(const struct mcp251xfd_priv *priv,void mcp251xfd_timestamp_init (struct mcp251xfd_priv *priv);void mcp251xfd_timestamp_stop (struct mcp251xfd_priv *priv); +void mcp251xfd_tx_obj_write_sync (struct work_struct *work);netdev_tx_t mcp251xfd_start_xmit (struct sk_buff *skb,struct net_device *ndev);