On 06.05.2024 15:49:18, Vitor Soares wrote: > From: Vitor Soares <vitor.soares@xxxxxxxxxxx> > > 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(). > > This patch resolves the issue by decreasing tx_ring->head and removing > the skb from the echo stack if mcp251xfd_start_xmit() fails. > Consequently, the package is dropped not been possible to re-transmit. > > Fixes: 55e5b97f003e ("can: mcp25xxfd: add driver for Microchip MCP25xxFD SPI CAN") > Cc: stable@xxxxxxxxxxxxxxx > Signed-off-by: Vitor Soares <vitor.soares@xxxxxxxxxxx> > --- > With this approach, some packages get lost in concurrent SPI bus access > due to can_put_echo_skb() being called before mcp251xfd_tx_obj_write(). > The can_put_echo_skb() calls can_create_echo_skb() that consumes the original skb > resulting in a Kernel NULL pointer dereference error if return NETDEV_TX_BUSY on > mcp251xfd_tx_obj_write() failure. > A potential solution would be to change the code to use spi_sync(), which would > wait for SPI bus to be unlocked. Any thoughts about this? This is not an option. I think you need a echo_skb function that does the necessary cleanup, something like: void can_remove_echo_skb(struct net_device *dev, unsigned int idx) { struct can_priv *priv = netdev_priv(dev); priv->echo_skb[idx] = NULL; } I think you can open-code the "priv->echo_skb[idx] = NULL;" directly in the driver. And you have to take care of calling netdev_completed_queue(priv->ndev, 1, frame_len); Another option would be to start a workqueue and use spi_sync() in case the spi_async() is busy. regards, Marc -- Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Attachment:
signature.asc
Description: PGP signature