[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VcTyubQFXyKA1RoYkpWowfKYwA1N_zZtmvGTeCmDG89Ow@mail.gmail.com>
Date: Wed, 3 Aug 2022 18:50:13 +0200
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Sebastian Würl <sebastian.wuerl@...ratech.com>
Cc: Wolfgang Grandegger <wg@...ndegger.com>,
Marc Kleine-Budde <mkl@...gutronix.de>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Vincent Mailhol <mailhol.vincent@...adoo.fr>,
Stefan Mätje <stefan.maetje@....eu>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Oliver Hartkopp <socketcan@...tkopp.net>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Uwe Kleine-König
<u.kleine-koenig@...gutronix.de>, linux-can@...r.kernel.org,
netdev <netdev@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] drivers/net/can/spi/mcp251x.c: Fix race condition on
receive interrupt
On Wed, Aug 3, 2022 at 6:48 PM Andy Shevchenko
<andy.shevchenko@...il.com> wrote:
>
> On Wed, Aug 3, 2022 at 5:36 PM Sebastian Würl
> <sebastian.wuerl@...ratech.com> wrote:
> >
> > The mcp251x driver uses both receiving mailboxes of the can controller
>
> CAN
>
> > chips. For retrieving the CAN frames from the controller via SPI, it checks
> > once per interrupt which mailboxes have been filled, an will retrieve the
> > messages accordingly.
> >
> > This introduces a race condition, as another CAN frame can enter mailbox 1
> > while mailbox 0 is emptied. If now another CAN frame enters mailbox 0 until
> > the interrupt handler is called next, mailbox 0 is emptied before
> > mailbox 1, leading to out-of-order CAN frames in the network device.
> >
> > This is fixed by checking the interrupt flags once again after freeing
> > mailbox 0, to correctly also empty mailbox 1 before leaving the handler.
> >
> > For reproducing the bug I created the following setup:
> > - Two CAN devices, one Raspberry Pi with MCP2515, the other can be any.
> > - Setup CAN to 1 MHz
> > - Spam bursts of 5 CAN-messages with increasing CAN-ids
> > - Continue sending the bursts while sleeping a second between the bursts
> > - Check on the RPi whether the received messages have increasing CAN-ids
> > - Without this patch, every burst of messages will contain a flipped pair
>
> Fixes tag?
Also fix the Subject prefix (you may see the most used ones by running
`git log --no-merges --oneline -- drivers/net/can/spi/mcp251x.c`).
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists