Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp434846imn; Wed, 3 Aug 2022 10:03:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sUF+zjQJ2koubzk/s4h+TN34TfsvWUFbCuO1FrcSW0Ty5b5tbjCBPLsZN4TBzR6DB6BL/p X-Received: by 2002:a65:604f:0:b0:41b:558b:4be with SMTP id a15-20020a65604f000000b0041b558b04bemr22343855pgp.597.1659546178904; Wed, 03 Aug 2022 10:02:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659546178; cv=none; d=google.com; s=arc-20160816; b=Ese/YSBR/L1FiWzHOb8Spclvf0FSsa9ADyaa41tZiSCB0mWUUv9NYjxcp2uJfcACg/ 9rV8JtyIwKYrk2/delr114Gd0v4zT2hZn2O3HWoazsmKIO+P4zkLP8asJDlgdppkyuTY pWOj8BB1/za+GnyiCMvDGE94nkIYBVw/5TaSFcHvcSMtT9WXESh4l/QZHEJYlUe6W43g HrDojRvmg0TESHqGfb+LM05ldsa46+WL/EBhr8pGqOm48jeqmwXoaiuOeaRBsK5HeWg1 gTYYm5rLFhvaBQB7Xj4pdiSreOPAttmStcgpY8XpW0xkNbG1GNMLyf4KxfhI6ZR7elfp Cvcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=gMmZnysqAMDlPpkxFBQS+E8RqY1hDuJMvV7H1So3zZU=; b=mo0r+Nq3YqiWZhmbCGXUAWmVX+LIEkIe2lcMyvOmnWL3Q/ws1/vyMEX5Tt8MUAP2eo jU0ZVo1EjVS0Hb9V1oLnNMwHfRR67r1CmbZYsQWvhw0H2cFGz8YXf8nzV1TSTDXgi0FK gORsYsEc+kHerdSA/9GoCcPBN6KfnMMjL/5dfiujeWsydSWWeUeN692DED8AvMODLfov ydRIALs3SfVL4fcrX2xsRZ5IBC0XHhpr9gXnGvoBqxQowZUBNXLD7dvCgNpgieV+A279 OSAxI/kF2+HosW9Iwpo821RrrJ1RxKuajVfpabrUJ4rT35nMxdJD30mEq9w9UVvO12qh yMUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fhEdIhwT; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w68-20020a623047000000b0052e25aa19d0si2667021pfw.88.2022.08.03.10.02.44; Wed, 03 Aug 2022 10:02:58 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fhEdIhwT; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236382AbiHCQti (ORCPT + 99 others); Wed, 3 Aug 2022 12:49:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233102AbiHCQtg (ORCPT ); Wed, 3 Aug 2022 12:49:36 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 447E324F1C; Wed, 3 Aug 2022 09:49:35 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id e13so3281195edj.12; Wed, 03 Aug 2022 09:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc; bh=gMmZnysqAMDlPpkxFBQS+E8RqY1hDuJMvV7H1So3zZU=; b=fhEdIhwTAqr5KeMUsYt/g8y6eT/BUynpWSzIPFItnbEjKFFqMBLYTgs5XuAqfq3tyZ EYeZYA/AYwdnRfgqp+fgGhnOz/akfNg8ElRIcGgFLoM6P7Sh9PrfCqrPc4QGi0Ao63NA Ulf0teM0yTHHKi9LehM+or72eui6A1vu3+yPKFdH6EfbEizSdmJgEfyAdLwZBHfHH8Ia ve0/Bzg9LzCcnf+LvHi9mV+5ejPUvbfYgoOxnYUCe5jo2rPewOwJ7JU5vQciDUHqHXRz udkbu4ioZwhsPfGd9K2qJD5PlB2TreLjQ9ZSOmb4EUzeaTPeyTzcTqkpbdN73eGHBXDF xCdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=gMmZnysqAMDlPpkxFBQS+E8RqY1hDuJMvV7H1So3zZU=; b=DKPfQtXcFsM4XkUqaBNVYk6PMcWSOwb4BjKQI4AQH5tZGXwZP/qdwsQhKb85FA2dXA iJuLTWRxfZOZH8+2l1pH3DBum64Eq4t6kkHA2OS4GP1dbh71Ru+T3kbmarFs8FWmeYNy NnOsxSUXTc8kDdM+w0UUZrqruHxQsC62TxjC+mN/17HKoxBWcAFx/H4YcLYY+rxoyHYU V7Wx/YmUyTheT6mbkt0M67tb9LUA0EqtAO71TRRvRv1rzco9TA6RUPZnUfrfya+t/jzn lvudjFPgVqoS1fv9KD/bpxVXFxzoCCsmueOCma/c9xTXTQWuz8MocTNVwLmwsH1vBXyZ ZICA== X-Gm-Message-State: AJIora8b4X1stPGQc7dLli1CAvqP1aOF/rGZYr9JfueBbRqdcfl8xXy2 BrsIjLEWZ1YlxMYIF9FTGkLUOe5TROrmX6cau3w= X-Received: by 2002:a05:6402:4414:b0:434:f58c:ee2e with SMTP id y20-20020a056402441400b00434f58cee2emr26332209eda.362.1659545373846; Wed, 03 Aug 2022 09:49:33 -0700 (PDT) MIME-Version: 1.0 References: <20220803153300.58732-1-sebastian.wuerl@ororatech.com> In-Reply-To: <20220803153300.58732-1-sebastian.wuerl@ororatech.com> From: Andy Shevchenko Date: Wed, 3 Aug 2022 18:48:57 +0200 Message-ID: Subject: Re: [PATCH] drivers/net/can/spi/mcp251x.c: Fix race condition on receive interrupt To: =?UTF-8?Q?Sebastian_W=C3=BCrl?= Cc: Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vincent Mailhol , =?UTF-8?Q?Stefan_M=C3=A4tje?= , Andy Shevchenko , Oliver Hartkopp , Sebastian Andrzej Siewior , =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= , linux-can@vger.kernel.org, netdev , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 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 CAN > chips. For retrieving the CAN frames from the controller via SPI, it chec= ks > 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 unt= il > 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 pai= r Fixes tag? --=20 With Best Regards, Andy Shevchenko