From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Tom Evans <tom.evans@motec.com.au>
Cc: lw@karo-electronics.de,
Scott Thomson <scott.thomson@motec.com.au>,
"linux-can@vger.kernel.org" <linux-can@vger.kernel.org>
Subject: Re: Possible infinite-loop bug in drivers/net/can/flexcan.c
Date: Fri, 23 Aug 2013 11:05:37 +0200 [thread overview]
Message-ID: <521725E1.2050001@pengutronix.de> (raw)
In-Reply-To: <52170C82.9070109@motec.com.au>
[-- Attachment #1: Type: text/plain, Size: 2546 bytes --]
On 08/23/2013 09:17 AM, Tom Evans wrote:
> I don't know where best to report this, so I'm sending it upstream to
> our Kernel supplier and to the last author in the file header.
Use the official linux-can mailinglist (Cc'ed).
> I'm changing the FlexCAN driver on our i.MX53 product as the kernel
> can't guarantee the NAPI service time and it is dropping CAN packets.
> I've been measuring 19 MILLISECONDS between the CAN interrupt and NAPI
> reading, so it is dropping a huge number of packets.
>
> Anyway, while rewriting, I think I spotted an "infinite loop" on a
> buffer allocation failure:
>
> /*
> * flexcan.c - FLEXCAN CAN controller driver
> *
> * Copyright (c) 2005-2006 Varma Electronics Oy
> * Copyright (c) 2009 Sascha Hauer, Pengutronix
> * Copyright (c) 2010 Marc Kleine-Budde, Pengutronix
> *
> * Based on code originally by Andrey Volkov <avolkov@varma-el.com>
> ...
> static int flexcan_poll(struct napi_struct *napi, int quota)
> {
> ...
> reg_iflag1 = flexcan_read(®s->iflag1);
> while (reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE &&
> work_done < quota) {
> work_done += flexcan_read_frame(dev);
> reg_iflag1 = flexcan_read(®s->iflag1);
> }
>
> where...
>
> static int flexcan_read_frame(struct net_device *dev)
> {
> struct net_device_stats *stats = &dev->stats;
> struct can_frame *cf;
> struct sk_buff *skb;
>
> skb = alloc_can_skb(dev, &cf);
> if (unlikely(!skb)) {
> stats->rx_dropped++;
> return 0;
> }
>
> So if alloc_can_skb() returns NULL, it fails to read the FlexCAN
> registers, doesn't clear FLEXCAN_IFLAG_RX_FIFO_AVAILABLE and returns ZERO.
>
> The "while" loop in flexcan_poll() only exits when the FlexCAN FIFO is
> empty or when "work_done" counts out.
>
> I've put some test code in flexcan_read_frame() to stop allocating skbs
> after 10,000 calls, and after than many CAN messages the whole thing
> resets as the watchdog resets it.
>
> The simplest fix is to have flexcan_read_frame() return "1" on drop.
How does the driver behave if flexcan_read_frame() returns "1" here?
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]
parent reply other threads:[~2013-08-23 9:06 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <52170C82.9070109@motec.com.au>]
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=521725E1.2050001@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=linux-can@vger.kernel.org \
--cc=lw@karo-electronics.de \
--cc=scott.thomson@motec.com.au \
--cc=tom.evans@motec.com.au \
/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;
as well as URLs for NNTP newsgroup(s).