* [PATCH RFC] can: m_can: m_can_tx_work_queue(): fix tx_skb race condition
@ 2021-05-05 11:43 Marc Kleine-Budde
2021-05-05 12:06 ` Torin Cooper-Bennun
0 siblings, 1 reply; 5+ messages in thread
From: Marc Kleine-Budde @ 2021-05-05 11:43 UTC (permalink / raw)
To: linux-can; +Cc: Marc Kleine-Budde
The m_can_start_xmit() function checks if the cdev->tx_skb is NULL and
returns with NETDEV_TX_BUSY in case tx_sbk is not NULL.
There is a race condition in the m_can_tx_work_queue(), where first
the skb is send to the driver and then the case tx_sbk is set to NULL.
A TX complete IRQ might come in between and wake the queue, which
results in tx_skb not being cleared yet.
Fixes: f524f829b75a ("can: m_can: Create a m_can platform framework")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
Hello,
compile time tested only.
Marc
drivers/net/can/m_can/m_can.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 2fa10bc0befe..bba2a449ac70 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1544,6 +1544,8 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
int i;
int putidx;
+ cdev->tx_skb = NULL;
+
/* Generate ID field for TX buffer Element */
/* Common to all supported M_CAN versions */
if (cf->can_id & CAN_EFF_FLAG) {
@@ -1660,7 +1662,6 @@ static void m_can_tx_work_queue(struct work_struct *ws)
tx_work);
m_can_tx_handler(cdev);
- cdev->tx_skb = NULL;
}
static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH RFC] can: m_can: m_can_tx_work_queue(): fix tx_skb race condition
2021-05-05 11:43 [PATCH RFC] can: m_can: m_can_tx_work_queue(): fix tx_skb race condition Marc Kleine-Budde
@ 2021-05-05 12:06 ` Torin Cooper-Bennun
2021-05-05 12:35 ` Marc Kleine-Budde
0 siblings, 1 reply; 5+ messages in thread
From: Torin Cooper-Bennun @ 2021-05-05 12:06 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can
On Wed, May 05, 2021 at 01:43:02PM +0200, Marc Kleine-Budde wrote:
> The m_can_start_xmit() function checks if the cdev->tx_skb is NULL and
> returns with NETDEV_TX_BUSY in case tx_sbk is not NULL.
>
> There is a race condition in the m_can_tx_work_queue(), where first
> the skb is send to the driver and then the case tx_sbk is set to NULL.
> A TX complete IRQ might come in between and wake the queue, which
> results in tx_skb not being cleared yet.
>
> Fixes: f524f829b75a ("can: m_can: Create a m_can platform framework")
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
> Hello,
>
> compile time tested only.
>
> Marc
Thanks a lot for spotting this Marc, after initial testing this is
working very well. I don't see that error message at all now, even at
very high transmit rates, and dropped frames are reduced considerably.
(Test setup: RPi CM4, TCAN4550, 500 kbit/s CAN-FD.)
--
Regards,
Torin Cooper-Bennun
Software Engineer | maxiluxsystems.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RFC] can: m_can: m_can_tx_work_queue(): fix tx_skb race condition
2021-05-05 12:06 ` Torin Cooper-Bennun
@ 2021-05-05 12:35 ` Marc Kleine-Budde
2021-05-05 12:46 ` Torin Cooper-Bennun
0 siblings, 1 reply; 5+ messages in thread
From: Marc Kleine-Budde @ 2021-05-05 12:35 UTC (permalink / raw)
To: Torin Cooper-Bennun; +Cc: linux-can
[-- Attachment #1: Type: text/plain, Size: 1333 bytes --]
On 05.05.2021 13:06:59, Torin Cooper-Bennun wrote:
> On Wed, May 05, 2021 at 01:43:02PM +0200, Marc Kleine-Budde wrote:
> > The m_can_start_xmit() function checks if the cdev->tx_skb is NULL and
> > returns with NETDEV_TX_BUSY in case tx_sbk is not NULL.
> >
> > There is a race condition in the m_can_tx_work_queue(), where first
> > the skb is send to the driver and then the case tx_sbk is set to NULL.
> > A TX complete IRQ might come in between and wake the queue, which
> > results in tx_skb not being cleared yet.
> >
> > Fixes: f524f829b75a ("can: m_can: Create a m_can platform framework")
> > Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> > ---
> > Hello,
> >
> > compile time tested only.
> >
> > Marc
>
> Thanks a lot for spotting this Marc, after initial testing this is
> working very well. I don't see that error message at all now, even at
> very high transmit rates, and dropped frames are reduced considerably.
>
> (Test setup: RPi CM4, TCAN4550, 500 kbit/s CAN-FD.)
Can I add your Tested-by?
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RFC] can: m_can: m_can_tx_work_queue(): fix tx_skb race condition
2021-05-05 12:35 ` Marc Kleine-Budde
@ 2021-05-05 12:46 ` Torin Cooper-Bennun
2021-05-05 12:50 ` Marc Kleine-Budde
0 siblings, 1 reply; 5+ messages in thread
From: Torin Cooper-Bennun @ 2021-05-05 12:46 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can
On Wed, May 05, 2021 at 02:35:01PM +0200, Marc Kleine-Budde wrote:
> > Thanks a lot for spotting this Marc, after initial testing this is
> > working very well. I don't see that error message at all now, even at
> > very high transmit rates, and dropped frames are reduced considerably.
> >
> > (Test setup: RPi CM4, TCAN4550, 500 kbit/s CAN-FD.)
>
> Can I add your Tested-by?
>
> Marc
>
> --
> Pengutronix e.K. | Marc Kleine-Budde |
> Embedded Linux | https://www.pengutronix.de |
> Vertretung West/Dortmund | Phone: +49-231-2826-924 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Yes, please do!
--
Regards,
Torin Cooper-Bennun
Software Engineer | maxiluxsystems.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RFC] can: m_can: m_can_tx_work_queue(): fix tx_skb race condition
2021-05-05 12:46 ` Torin Cooper-Bennun
@ 2021-05-05 12:50 ` Marc Kleine-Budde
0 siblings, 0 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2021-05-05 12:50 UTC (permalink / raw)
To: Torin Cooper-Bennun; +Cc: linux-can
[-- Attachment #1: Type: text/plain, Size: 773 bytes --]
On 05.05.2021 13:46:14, Torin Cooper-Bennun wrote:
> On Wed, May 05, 2021 at 02:35:01PM +0200, Marc Kleine-Budde wrote:
> > > Thanks a lot for spotting this Marc, after initial testing this is
> > > working very well. I don't see that error message at all now, even at
> > > very high transmit rates, and dropped frames are reduced considerably.
> > >
> > > (Test setup: RPi CM4, TCAN4550, 500 kbit/s CAN-FD.)
> >
> > Can I add your Tested-by?
> Yes, please do!
Done.
Thanks,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-05-05 12:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05 11:43 [PATCH RFC] can: m_can: m_can_tx_work_queue(): fix tx_skb race condition Marc Kleine-Budde
2021-05-05 12:06 ` Torin Cooper-Bennun
2021-05-05 12:35 ` Marc Kleine-Budde
2021-05-05 12:46 ` Torin Cooper-Bennun
2021-05-05 12:50 ` 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.