From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Vitor Soares <ivitro@gmail.com>
Cc: manivannan.sadhasivam@linaro.org, thomas.kopp@microchip.com,
wg@grandegger.com, linux-can@vger.kernel,
linux-kernel@vger.kernel.org, vitor.soares@toradex.com,
stable@vger.kernel.org
Subject: Re: [PATCH] can: mcp251xfd: fix infinite loop when xmit fails
Date: Thu, 7 Mar 2024 13:21:08 +0100 [thread overview]
Message-ID: <20240307-drift-hate-0919e82ee341-mkl@pengutronix.de> (raw)
In-Reply-To: <20240307120442.12262-1-ivitro@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3443 bytes --]
On 07.03.2024 12:04:42, Vitor Soares wrote:
> From: Vitor Soares <vitor.soares@toradex.com>
>
> 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 if
> mcp251xfd_start_xmit() fails. With the fix, if we attempt to trigger
> the issue again, the driver prints an error and discard the message.
What about returning NETDEV_TX_BUSY, then the networking stack will
retry.
> Fixes: 55e5b97f003e ("can: mcp25xxfd: add driver for Microchip MCP25xxFD SPI CAN")
> Cc: stable@vger.kernel.org
> Signed-off-by: Vitor Soares <vitor.soares@toradex.com>
> ---
> drivers/net/can/spi/mcp251xfd/mcp251xfd-tx.c | 27 ++++++++++----------
> 1 file changed, 14 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-tx.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-tx.c
> index 160528d3cc26..a8eb941c1b95 100644
> --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-tx.c
> +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-tx.c
> @@ -181,25 +181,26 @@ netdev_tx_t mcp251xfd_start_xmit(struct sk_buff *skb,
> tx_obj = mcp251xfd_get_tx_obj_next(tx_ring);
> mcp251xfd_tx_obj_from_skb(priv, tx_obj, skb, tx_ring->head);
>
> - /* Stop queue if we occupy the complete TX FIFO */
> tx_head = mcp251xfd_get_tx_head(tx_ring);
> - tx_ring->head++;
> - if (mcp251xfd_get_tx_free(tx_ring) == 0)
> - netif_stop_queue(ndev);
> -
> frame_len = can_skb_get_frame_len(skb);
> - err = can_put_echo_skb(skb, ndev, tx_head, frame_len);
> - if (!err)
> - netdev_sent_queue(priv->ndev, frame_len);
> + can_put_echo_skb(skb, ndev, tx_head, frame_len);
> +
> + tx_ring->head++;
>
> err = mcp251xfd_tx_obj_write(priv, tx_obj);
> - if (err)
> - goto out_err;
> + if (err) {
> + can_free_echo_skb(ndev, tx_head, NULL);
>
> - return NETDEV_TX_OK;
> + tx_ring->head--;
> +
I'm not sure, if we want an error message for -EBUSY. We could add
proper ethtool statistics.
> + netdev_err(priv->ndev, "ERROR in %s: %d\n", __func__, err);
> + } else {
> + /* Stop queue if we occupy the complete TX FIFO */
> + if (mcp251xfd_get_tx_free(tx_ring) == 0)
> + netif_stop_queue(ndev);
>
> - out_err:
> - netdev_err(priv->ndev, "ERROR in %s: %d\n", __func__, err);
> + netdev_sent_queue(priv->ndev, frame_len);
> + }
>
> return NETDEV_TX_OK;
> }
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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2024-03-07 12:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-07 12:04 Vitor Soares
2024-03-07 12:21 ` Marc Kleine-Budde [this message]
2024-03-07 12:23 ` Marc Kleine-Budde
2024-03-07 16:54 ` vitor
2024-03-07 20:40 ` Marc Kleine-Budde
2024-03-11 11:37 Vitor Soares
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240307-drift-hate-0919e82ee341-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=ivitro@gmail.com \
--cc=linux-can@vger.kernel \
--cc=linux-kernel@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=stable@vger.kernel.org \
--cc=thomas.kopp@microchip.com \
--cc=vitor.soares@toradex.com \
--cc=wg@grandegger.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®