Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp497042imn; Wed, 3 Aug 2022 12:52:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t7KwqcyQdT4cOcGzFLx4DMSCYNrvF7XMWHlzGWYRhpjC0Kz56lTZwtfim53bvCZg/zsbwW X-Received: by 2002:a05:6a00:1747:b0:52b:1cee:1384 with SMTP id j7-20020a056a00174700b0052b1cee1384mr26648726pfc.41.1659556359875; Wed, 03 Aug 2022 12:52:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659556359; cv=none; d=google.com; s=arc-20160816; b=ccdfagI8v4aF6x2E21rOXQllQj1FdWf7dMDcx7yKbKY/dR4c8Ub3Gvq/FVwDT4uWUU 5sAmmKAgSTBPq5ljOSCFhTVFKOBRqHX+9T9Xr8OUfB3ppvBSxIVzdEpVrCzs8/UrCCUs 67rKQV1tCkuYR4q7nrwFChQemRD0+fQmXDwdSt+4mCLBvAqMbMivnOHkS1MIGGbjTLXZ ucZ7qsAyBSCpfbkKoKSiOswQyjLCV6SDeC8GFXEAyoMDTuFKG1P4kGtEwCdJR6PZYXie 8PG8vxU+v4nU+/ZwpahYJtd/vfB/kPxxdPX1OP5kX3vm7q0MvQnZHKfZ9C3cjJGVHoPf rvXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=OHCPdQ2IXGiN7s1JE1UCRR0VNOnFNNeH9CXxbnotPDc=; b=yYu8yDVc8VyPwpwKwayQARnx42jkMhDzOtyZZSyouee8RmfICSpaExm9f5eq8rzTZ9 gMDxC93JFwwtxS76OW2FliGY7Ci8rJSHs/0n2TpNazDnVrG16Qn8KgIMZFbOI7BpYwz7 VXaHEO36FsAS+kRbTgTThvhSe/b1Hg2QJzkNEACaRoGaXL8Irff58UtT9I5etKsHW0ze HekWUFxBiKBEIrSrUNzu9ceABF5vS4qx8T6vFUPkFq46u7b6C1hP9c+9rwuewxsD7SyF 2yNA7Z0p3NAam7wvdetQgOhl0Yq98EecHwDDI+/kJv7n+TNH5vr42YZQ9imKIj8G1lKN UVrQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w3-20020a63c103000000b0041a6f5c4922si13514064pgf.407.2022.08.03.12.52.23; Wed, 03 Aug 2022 12:52:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238392AbiHCTIY (ORCPT + 99 others); Wed, 3 Aug 2022 15:08:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbiHCTIV (ORCPT ); Wed, 3 Aug 2022 15:08:21 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DBC45A2C2 for ; Wed, 3 Aug 2022 12:08:20 -0700 (PDT) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=bjornoya.blackshift.org) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJJiy-0004kG-3b; Wed, 03 Aug 2022 21:08:08 +0200 Received: from pengutronix.de (unknown [IPv6:2a01:4f8:1c1c:29e9:22:41ff:fe00:1400]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id 3035FC2431; Wed, 3 Aug 2022 19:08:06 +0000 (UTC) Date: Wed, 3 Aug 2022 21:08:04 +0200 From: Marc Kleine-Budde To: Andy Shevchenko Cc: Sebastian =?utf-8?B?V8O8cmw=?= , Wolfgang Grandegger , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vincent Mailhol , Stefan =?utf-8?B?TcOkdGpl?= , Andy Shevchenko , Oliver Hartkopp , Sebastian Andrzej Siewior , Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= , linux-can@vger.kernel.org, netdev , Linux Kernel Mailing List Subject: Re: [PATCH] drivers/net/can/spi/mcp251x.c: Fix race condition on receive interrupt Message-ID: <20220803190804.b3p4iugcz3yp6mtc@pengutronix.de> References: <20220803153300.58732-1-sebastian.wuerl@ororatech.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="5gaiw5anvnre55n2" Content-Disposition: inline In-Reply-To: X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --5gaiw5anvnre55n2 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 03.08.2022 18:48:57, Andy Shevchenko wrote: > On Wed, Aug 3, 2022 at 5:36 PM Sebastian W=C3=BCrl > wrote: > > > > The mcp251x driver uses both receiving mailboxes of the can controller >=20 > CAN >=20 > > chips. For retrieving the CAN frames from the controller via SPI, it ch= ecks > > once per interrupt which mailboxes have been filled, an will retrieve t= he > > messages accordingly. > > > > This introduces a race condition, as another CAN frame can enter mailbo= x 1 > > while mailbox 0 is emptied. If now another CAN frame enters mailbox 0 u= ntil > > 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 burs= ts > > - Check on the RPi whether the received messages have increasing CAN-i= ds > > - Without this patch, every burst of messages will contain a flipped p= air >=20 > Fixes tag? Should be: Fixes: bf66f3736a94 ("can: mcp251x: Move to threaded interrupts instead of = workqueues.") Marc --=20 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 | --5gaiw5anvnre55n2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEBsvAIBsPu6mG7thcrX5LkNig010FAmLqx5EACgkQrX5LkNig 010VYwf8CT/rSWhjeFgmdbbQt7DoVCZ8YkGWUSwHEcJX+j4cd2w1kBnpIeSLmOof BxT4dt/Oj4YLbeNRZV3ftD1zRPQX9Z9PqOjDvwstYKgvCOreIayI+ZR95jOZLH38 FZ3moRFD2m2uCPl+N4pC8wPd1MgVQVgwjSKzIiIR5KVp0cWuv8StMTbfnTHV8rDH +lROx4fwmYQk5iCSqWsMbtmfhEZtKmNXQpf3VGt95kLo51ManyG4A8ENIERT++vs 2ZkzfW7h5L0TRs48mbPBTyN0fZnr1MLFSGEQGETAF1W0LrHg2QVl4wIPUaebRjgS mDXRac1avL8frKzPTMp/b2dVWFx09A== =bst2 -----END PGP SIGNATURE----- --5gaiw5anvnre55n2--