From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D86B92820D5 for ; Mon, 22 Sep 2025 08:50:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758531038; cv=none; b=aTEnCkMiVL9fQ0jJ2XCiCWQzD7GSvPduPHymAUECaZpHCEF8fonh6wd/+/KkVUQfv1wCJlGIztHZ+L2IgvNO9gwaoHzI2qABMdG0znSDjzo3fqudFKIes9B/nIuhvCSOeFKPcimzBMz51AA8+F3u7s9DNKRpbKQO+oect0xo6Eo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758531038; c=relaxed/simple; bh=SS6O8XSqKO1v7x49viaL2rsbT8oAdhGU7jIfpFIDFuU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=q2xqJLkV09shHJlaG1RwX7T3QRlxmCWC96bTRZ1aXXogNCbWTnl5nOG63UcOQEYTdT6Zdxn8CKw17bOqhEZwKDMZmnQh8hZMIjQ1KTh6ySA24cmGXvMr0yrQJcReKqT2JfDPGu1qzUmuZdP0GVo2IYU8dOp0fUUXDTVONNpDGbQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1v0cFd-0004Qf-Ka; Mon, 22 Sep 2025 10:50:25 +0200 Received: from moin.white.stw.pengutronix.de ([2a0a:edc0:0:b01:1d::7b] helo=bjornoya.blackshift.org) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v0cFc-002Yte-1E; Mon, 22 Sep 2025 10:50:24 +0200 Received: from pengutronix.de (p54b152ce.dip0.t-ipconnect.de [84.177.82.206]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 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 0A079476BEF; Mon, 22 Sep 2025 08:50:24 +0000 (UTC) Date: Mon, 22 Sep 2025 10:50:23 +0200 From: Marc Kleine-Budde To: Andrea Daoud Cc: Heiko Stuebner , Elaine Zhang , kernel@pengutronix.de, linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Alexander Shiyan Subject: Re: Possible race condition of the rockchip_canfd driver Message-ID: <20250922-eccentric-rustling-gorilla-d2606f-mkl@pengutronix.de> References: <20250919-lurking-agama-of-genius-96b832-mkl@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="2ruxaxste5kyxrlz" Content-Disposition: inline In-Reply-To: X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org --2ruxaxste5kyxrlz Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: Possible race condition of the rockchip_canfd driver MIME-Version: 1.0 On 20.09.2025 18:08:03, Andrea Daoud wrote: > > On 18.09.2025 20:58:33, Andrea Daoud wrote: > > > I'm using the rockchip_canfd driver on an RK3568. When under high bus > > > load, I get > > > the following logs [1] in rkcanfd_tx_tail_is_eff, and the CAN bus is = unable to > > > communicate properly under this condition. The exact cause is current= ly not > > > entirely clear, and it's not reliably reproducible. > > > > Our customer is using a v3 silicon revision of the chip, which doesn't > > this workaround. >=20 > Could you please let me know how to check whether my RK3568 is v2 or v3? Alexander Shiyan (Cc'ed) reads the information from an nvmem cell: | https://github.com/MacroGroup/barebox/blob/macro/arch/arm/boards/diasom-r= k3568/board.c#L239-L257 The idea is to fixup the device tree in the bootloader depending on the SoC revision, so that the CAN driver uses only the needed workarounds. > > > In the logs we can spot some strange points: > > > > > > 1. Line 24, tx_head =3D=3D tx_tail. This should have been rejected by= the if > > > (!rkcanfd_get_tx_pending) clause. > > > > > > 2. Line 26, the last bit of priv->tx_tail (0x0185dbb3) is 1. This mea= ns that the > > > tx_tail should be 1, because rkcanfd_get_tx_tail is essentially mod t= he > > > priv->tx_tail by two. But the printed tx_tail is 0. > > > > > > I believe these problems could mean that the code is suffering from s= ome race > > > condition. It seems that, in the whole IRQ processing chain of the dr= iver, > > > there's no lock protection. Maybe some IRQ happens within the executi= on of > > > rkcanfd_tx_tail_is_eff, and touches the state of the tx_head and tx_t= ail? > > > > > > Could you please have a look at the code, and check if some locking i= s needed? > > > > My time for community support is currently a bit limited. I think this > > has to wait a bit, apologies :/ >=20 > No worries, I will debug myself, and hopefully send a PR if I found > something out. Great, I have a both a v2 and a v3 SoC here to test. regards, Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung N=C3=BCrnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 | --2ruxaxste5kyxrlz Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEn/sM2K9nqF/8FWzzDHRl3/mQkZwFAmjRDcwACgkQDHRl3/mQ kZwG6gf/b8xcXy5C2kLudCka3PJOOw8V+b51k7TIkzcjIxDUW0tY3KHlJLawnugC V0DKwzPNG0v6bCHgfBA2IaH49W1MxVNvqsTDvQWf2udAUzGu5BYRN9bvs8qpFYpF Pj6zlEUf0lO+Df68nqIEAekuwoXdout8CkTX6US6lgSZYe8uxPjWQ3T3fmFnzU44 iWTwK/nGOg7wUqZryuTsrmc1rkKmI2XjBek2PQSyTQxcgzMlESOuj11nhfXAVafa BI32c6nsFwcLx8nH/KwjVGBQKkcrS3IUP//Dw0/R36nNlqiqG4lmgvsJ4y8PhCIF ZNr9zrnmeflbjfKvZ9GdsswnKeNW5Q== =hiC1 -----END PGP SIGNATURE----- --2ruxaxste5kyxrlz--