* [PATCH 0/2] can: mcp251xfd: fix TEF vs TX race condition introduced in UINC improvements
@ 2021-01-05 21:41 Marc Kleine-Budde
2021-01-05 21:41 ` [PATCH 1/2] can: mcp251xfd: mcp251xfd_handle_tefif(): fix TEF vs. TX race condition Marc Kleine-Budde
2021-01-05 21:41 ` [PATCH 2/2] can: mcp251xfd: mcp251xfd_handle_rxif_ring(): first increment RX tail pointer in HW, then in driver Marc Kleine-Budde
0 siblings, 2 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2021-01-05 21:41 UTC (permalink / raw)
To: kernel, linux-can; +Cc: Manivannan Sadhasivam, Thomas Kopp
Hello,
during the TEF readout UINC improvements, I introduced a TEF vs TX race
condition to the driver. The first patch fixes the problem. The second patch
fixes the same issue in the RX-path, which causes no problem, but now the code
path look the same.
regards,
Marc
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] can: mcp251xfd: mcp251xfd_handle_tefif(): fix TEF vs. TX race condition
2021-01-05 21:41 [PATCH 0/2] can: mcp251xfd: fix TEF vs TX race condition introduced in UINC improvements Marc Kleine-Budde
@ 2021-01-05 21:41 ` Marc Kleine-Budde
2021-01-05 21:41 ` [PATCH 2/2] can: mcp251xfd: mcp251xfd_handle_rxif_ring(): first increment RX tail pointer in HW, then in driver Marc Kleine-Budde
1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2021-01-05 21:41 UTC (permalink / raw)
To: kernel, linux-can; +Cc: Manivannan Sadhasivam, Thomas Kopp, Marc Kleine-Budde
The mcp251xfd driver uses a TX FIFO for sending CAN frames and a TX Event FIFO
(TEF) for completed TX-requests.
The TEF event handling in the mcp251xfd_handle_tefif() function has a race
condition. It first increments the tx-ring's tail counter to signal that
there's room in the TX and TEF FIFO, then it increments the TEF FIFO in
hardware.
A running mcp251xfd_start_xmit() on a different CPU might not stop the txqueue
(as the tx-ring still shows free space). The next mcp251xfd_start_xmit() will
push a message into the chip and the TX complete event might overflow the TEF
FIFO.
This patch changes the order to fix the problem.
Fixes: 68c0c1c7f966 ("can: mcp251xfd: tef-path: reduce number of SPI core requests to set UINC bit")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
index 77129d5f410b..85a1a8b7c0e7 100644
--- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
+++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
@@ -1368,13 +1368,10 @@ static int mcp251xfd_handle_tefif(struct mcp251xfd_priv *priv)
struct mcp251xfd_tx_ring *tx_ring = priv->tx;
struct spi_transfer *last_xfer;
- tx_ring->tail += len;
-
/* Increment the TEF FIFO tail pointer 'len' times in
* a single SPI message.
- */
-
- /* Note:
+ *
+ * Note:
*
* "cs_change == 1" on the last transfer results in an
* active chip select after the complete SPI
@@ -1391,6 +1388,8 @@ static int mcp251xfd_handle_tefif(struct mcp251xfd_priv *priv)
if (err)
return err;
+ tx_ring->tail += len;
+
err = mcp251xfd_check_tef_tail(priv);
if (err)
return err;
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] can: mcp251xfd: mcp251xfd_handle_rxif_ring(): first increment RX tail pointer in HW, then in driver
2021-01-05 21:41 [PATCH 0/2] can: mcp251xfd: fix TEF vs TX race condition introduced in UINC improvements Marc Kleine-Budde
2021-01-05 21:41 ` [PATCH 1/2] can: mcp251xfd: mcp251xfd_handle_tefif(): fix TEF vs. TX race condition Marc Kleine-Budde
@ 2021-01-05 21:41 ` Marc Kleine-Budde
1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2021-01-05 21:41 UTC (permalink / raw)
To: kernel, linux-can; +Cc: Manivannan Sadhasivam, Thomas Kopp, Marc Kleine-Budde
The previous patch fixes a TEF vs. TX race condition, by first updating the TEF
tail pointer in hardware, and then updating the driver internal pointer.
The same pattern exists in the RX-path, too. This should be no problem, as the
driver accesses the RX-FIFO from the interrupt handler only, thus the access is
properly serialized. Fix the order here, too, so that the TEF- and RX-path look
similar.
Fixes: 1f652bb6bae7 ("can: mcp25xxfd: rx-path: reduce number of SPI core requests to set UINC bit")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
index 85a1a8b7c0e7..36235afb0bc6 100644
--- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
+++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
@@ -1552,10 +1552,8 @@ mcp251xfd_handle_rxif_ring(struct mcp251xfd_priv *priv,
/* Increment the RX FIFO tail pointer 'len' times in a
* single SPI message.
- */
- ring->tail += len;
-
- /* Note:
+ *
+ * Note:
*
* "cs_change == 1" on the last transfer results in an
* active chip select after the complete SPI
@@ -1571,6 +1569,8 @@ mcp251xfd_handle_rxif_ring(struct mcp251xfd_priv *priv,
last_xfer->cs_change = 1;
if (err)
return err;
+
+ ring->tail += len;
}
return 0;
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-05 21:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 21:41 [PATCH 0/2] can: mcp251xfd: fix TEF vs TX race condition introduced in UINC improvements Marc Kleine-Budde
2021-01-05 21:41 ` [PATCH 1/2] can: mcp251xfd: mcp251xfd_handle_tefif(): fix TEF vs. TX race condition Marc Kleine-Budde
2021-01-05 21:41 ` [PATCH 2/2] can: mcp251xfd: mcp251xfd_handle_rxif_ring(): first increment RX tail pointer in HW, then in driver Marc Kleine-Budde
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.