All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] can: rx-offload: Break loop on queue full
@ 2022-08-10 14:45 Uwe Kleine-König
  2022-08-11  8:30 ` Marc Kleine-Budde
  0 siblings, 1 reply; 3+ messages in thread
From: Uwe Kleine-König @ 2022-08-10 14:45 UTC (permalink / raw)
  To: Wolfgang Grandegger, Marc Kleine-Budde; +Cc: linux-can, netdev, kernel

The following happend on an i.MX25 using flexcan with many packets on
the bus:

The rx-offload queue reached a length more than skb_queue_len_max. So in
can_rx_offload_offload_one() the drop variable was set to true which
made the call to .mailbox_read() (here: flexcan_mailbox_read()) just
return ERR_PTR(-ENOBUFS) (plus some irrelevant hardware interaction) and
so can_rx_offload_offload_one() returned ERR_PTR(-ENOBUFS), too.

Now can_rx_offload_irq_offload_fifo() looks as follows:

	while (1) {
		skb = can_rx_offload_offload_one(offload, 0);
		if (IS_ERR(skb))
			continue;
		...
	}

As the i.MX25 is a single core CPU while the rx-offload processing is
active there is no thread to process packets from the offload queue and
so it doesn't get shorter.

The result is a tight loop: can_rx_offload_offload_one() does nothing
relevant and returns an error code and so
can_rx_offload_irq_offload_fifo() calls can_rx_offload_offload_one()
again.

To break that loop don't continue calling can_rx_offload_offload_one()
after it reported an error.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

this patch just implements the obvious change to break the loop. I'm not
100% certain that there is no corner case where the break is wrong. The
problem exists at least since v5.6, didn't go back further to check.

This fixes a hard hang on said i.MX25.

Best regards
Uwe

 drivers/net/can/dev/rx-offload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/dev/rx-offload.c b/drivers/net/can/dev/rx-offload.c
index a32a01c172d4..d5d33692bb6a 100644
--- a/drivers/net/can/dev/rx-offload.c
+++ b/drivers/net/can/dev/rx-offload.c
@@ -207,7 +207,7 @@ int can_rx_offload_irq_offload_fifo(struct can_rx_offload *offload)
 	while (1) {
 		skb = can_rx_offload_offload_one(offload, 0);
 		if (IS_ERR(skb))
-			continue;
+			break;
 		if (!skb)
 			break;
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] can: rx-offload: Break loop on queue full
  2022-08-10 14:45 [PATCH] can: rx-offload: Break loop on queue full Uwe Kleine-König
@ 2022-08-11  8:30 ` Marc Kleine-Budde
  2022-08-11  9:43   ` Marc Kleine-Budde
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Kleine-Budde @ 2022-08-11  8:30 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Wolfgang Grandegger, linux-can, netdev, kernel

[-- Attachment #1: Type: text/plain, Size: 1983 bytes --]

On 10.08.2022 16:45:36, Uwe Kleine-König wrote:
> The following happend on an i.MX25 using flexcan with many packets on
> the bus:
> 
> The rx-offload queue reached a length more than skb_queue_len_max. So in
> can_rx_offload_offload_one() the drop variable was set to true which
> made the call to .mailbox_read() (here: flexcan_mailbox_read()) just
> return ERR_PTR(-ENOBUFS) (plus some irrelevant hardware interaction) and
> so can_rx_offload_offload_one() returned ERR_PTR(-ENOBUFS), too.
> 
> Now can_rx_offload_irq_offload_fifo() looks as follows:
> 
> 	while (1) {
> 		skb = can_rx_offload_offload_one(offload, 0);
> 		if (IS_ERR(skb))
> 			continue;
> 		...
> 	}
> 
> As the i.MX25 is a single core CPU while the rx-offload processing is
> active there is no thread to process packets from the offload queue and
> so it doesn't get shorter.
> 
> The result is a tight loop: can_rx_offload_offload_one() does nothing
> relevant and returns an error code and so
> can_rx_offload_irq_offload_fifo() calls can_rx_offload_offload_one()
> again.
> 
> To break that loop don't continue calling can_rx_offload_offload_one()
> after it reported an error.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
> 
> this patch just implements the obvious change to break the loop. I'm not
> 100% certain that there is no corner case where the break is wrong. The
> problem exists at least since v5.6, didn't go back further to check.
> 
> This fixes a hard hang on said i.MX25.

As Uwe suggested in an IRC conversation, the correct fix for the flexcan
driver is to return NULL if there is no CAN frame pending.

I'll send a -v2.

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] 3+ messages in thread

* Re: [PATCH] can: rx-offload: Break loop on queue full
  2022-08-11  8:30 ` Marc Kleine-Budde
@ 2022-08-11  9:43   ` Marc Kleine-Budde
  0 siblings, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2022-08-11  9:43 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Wolfgang Grandegger, linux-can, netdev, kernel

[-- Attachment #1: Type: text/plain, Size: 2208 bytes --]

On 11.08.2022 10:30:39, Marc Kleine-Budde wrote:
> On 10.08.2022 16:45:36, Uwe Kleine-König wrote:
> > The following happend on an i.MX25 using flexcan with many packets on
> > the bus:
> > 
> > The rx-offload queue reached a length more than skb_queue_len_max. So in
> > can_rx_offload_offload_one() the drop variable was set to true which
> > made the call to .mailbox_read() (here: flexcan_mailbox_read()) just
> > return ERR_PTR(-ENOBUFS) (plus some irrelevant hardware interaction) and
> > so can_rx_offload_offload_one() returned ERR_PTR(-ENOBUFS), too.
> > 
> > Now can_rx_offload_irq_offload_fifo() looks as follows:
> > 
> > 	while (1) {
> > 		skb = can_rx_offload_offload_one(offload, 0);
> > 		if (IS_ERR(skb))
> > 			continue;
> > 		...
> > 	}
> > 
> > As the i.MX25 is a single core CPU while the rx-offload processing is
> > active there is no thread to process packets from the offload queue and
> > so it doesn't get shorter.
> > 
> > The result is a tight loop: can_rx_offload_offload_one() does nothing
> > relevant and returns an error code and so
> > can_rx_offload_irq_offload_fifo() calls can_rx_offload_offload_one()
> > again.
> > 
> > To break that loop don't continue calling can_rx_offload_offload_one()
> > after it reported an error.
> > 
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > ---
> > Hello,
> > 
> > this patch just implements the obvious change to break the loop. I'm not
> > 100% certain that there is no corner case where the break is wrong. The
> > problem exists at least since v5.6, didn't go back further to check.
> > 
> > This fixes a hard hang on said i.MX25.
> 
> As Uwe suggested in an IRC conversation, the correct fix for the flexcan
> driver is to return NULL if there is no CAN frame pending.
> 
> I'll send a -v2.

https://lore.kernel.org/all/20220811094254.1864367-1-mkl@pengutronix.de

regards,
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] 3+ messages in thread

end of thread, other threads:[~2022-08-11  9:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-10 14:45 [PATCH] can: rx-offload: Break loop on queue full Uwe Kleine-König
2022-08-11  8:30 ` Marc Kleine-Budde
2022-08-11  9:43   ` 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.