Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1457425lqh; Mon, 6 May 2024 08:15:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX+at0xR632RyT5dIb87/SrRJRtW9oRWCHD6U/w/kKzPeJXvxWIStSauFtvooCdnpCllXv24LmzXsZfXeRclD+3VZaGrUVxSMuFpxhcfw== X-Google-Smtp-Source: AGHT+IEnuhXu4s33M4ci3Gxc+nJ3XVzHlD1tGvyCYNhpCWrb8qA2RFXVoHEcuUtHecJpyH50/A4G X-Received: by 2002:a05:6808:148e:b0:3c6:574:eb45 with SMTP id e14-20020a056808148e00b003c60574eb45mr14065896oiw.45.1715008519316; Mon, 06 May 2024 08:15:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715008519; cv=pass; d=google.com; s=arc-20160816; b=p83CAVmKQt6nPylQfBD1/ZVEUEMOyy69IhUxrQvJuGkKSmbpDWTwEgDkIntuCqrvnk zC5a93IeVX5a3EGNwu2uOXFXCTEhP0C07TqJHSh0tuP/9PLhXANCuOR5rRY0yEDk5iP3 HNr1xnMDthsUkOAQt28sqEemFgEgn+xM5H2eJ0jyfFjHDDdpEfe5nZhtaRGu2PyLhrEN Pfd9lAyZOU3f3NbrCcSvS1voOVq3Hhze/AIFgFsrHtd5GWksAZVGC5q39fOB90N48URw GxRDBMrGHsH6Xudo4kQlg+kcZmnSvxywXUVUta2wcAChM/bbJaJ0JJPx3g6pIYveP8rc mfZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=AXdDHLWtKz74VV+XrxuIFy1z47YGf8MdFYuL5uImoOA=; fh=NmCp12YzNBXesEUmcsp1UB4YM0Qeqq++42+MqOQaqUY=; b=nMCASgchvIsW+aSxXR549p70nUT2L2swpQUXgxMo3KeH4advLHR5wqOCE8R3nZR20x xYYpwCFMcCPCJZ5efBZ5e8HCE2cpL666ToO/VRehqZJtZcVo9X79GPXi7S43aT9lbNj1 WmXWymNUquawpD9zrHAtiq+ldVF0JAy+4FRfSegfUnVD6hoca2zdSqWlM5cU0wuSLSKE 6lrFIBE2a/s9YtbMkmLBYgWZHEwr4kKKKn69gGAm2SODEUSjvs9BQVAWwVN5n72vvgrD uATns1DuNsIo+sxQ3L+IoHE8lbdvu6kUW5vWej88Ahp2JabEbz9DWooZY9KN/QkrAcWC BPuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-170063-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170063-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b7-20020a67f847000000b0047c30340952si1678982vsp.828.2024.05.06.08.15.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 08:15:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170063-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-170063-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170063-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 606751C21866 for ; Mon, 6 May 2024 15:14:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25539155727; Mon, 6 May 2024 15:14:42 +0000 (UTC) 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 18EF91553A1 for ; Mon, 6 May 2024 15:14:38 +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=1715008481; cv=none; b=T1ubpbbI/x+yxM08pTfDEfZPJWn1WVNDpSf5kgZd9dYHglXzD76zqkNiUG8ODjElZ+jhg0LdYQJx8wfCRm6hKh/UP2G0/h7vE+cj5KQumpTmIetmQQI6xlJm1ZC4Gp5tIkHW25fbjDo0F5/TBVoMqUi7P1i0+a+cNQEuY5DoRYg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715008481; c=relaxed/simple; bh=jgGBM1di0T0Mxh3GNCKZQk+nKLdzZaWHV4xpYN6qKrI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=e0X7dPwuFbW1g3lYy54AGXhP31NAodAbI1JKY2TmpEB7U/O5j9EEnLTeEAGCSggGcF9ru6SWJkrqBQcd4rOLFuGnGFY9vInRVvJrEdBh7giJcB5gSBZdABXHNHRJvzu1ValiAglU2QwOzgBv/5kR1+KlDhxjV6dgG9cXo29Y1sA= 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 1s402l-0000sN-R5; Mon, 06 May 2024 17:14:19 +0200 Received: from [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.94.2) (envelope-from ) id 1s402j-00GHyB-Up; Mon, 06 May 2024 17:14:17 +0200 Received: from pengutronix.de (unknown [172.20.34.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) 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 89ACC2CB730; Mon, 06 May 2024 15:14:17 +0000 (UTC) Date: Mon, 6 May 2024 17:14:17 +0200 From: Marc Kleine-Budde To: Vitor Soares Cc: Manivannan Sadhasivam , Thomas Kopp , Vincent Mailhol , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vitor Soares , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v4] can: mcp251xfd: fix infinite loop when xmit fails Message-ID: <20240506-bronze-snake-of-imagination-1db027-mkl@pengutronix.de> References: <20240506144918.419536-1-ivitro@gmail.com> 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="6xvopgmhifp6pdtd" Content-Disposition: inline In-Reply-To: <20240506144918.419536-1-ivitro@gmail.com> 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 --6xvopgmhifp6pdtd Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 06.05.2024 15:49:18, Vitor Soares wrote: > From: Vitor Soares >=20 > When the mcp251xfd_start_xmit() function fails, the driver stops > processing messages, and the interrupt routine does not return, > running indefinitely even after killing the running application. >=20 > Error messages: > [ 441.298819] mcp251xfd spi2.0 can0: ERROR in mcp251xfd_start_xmit: -16 > [ 441.306498] mcp251xfd spi2.0 can0: Transmit Event FIFO buffer not empt= y. (seq=3D0x000017c7, tef_tail=3D0x000017cf, tef_head=3D0x000017d0, tx_head= =3D0x000017d3). > ... and repeat forever. >=20 > The issue can be triggered when multiple devices share the same > SPI interface. And there is concurrent access to the bus. >=20 > The problem occurs because tx_ring->head increments even if > mcp251xfd_start_xmit() fails. Consequently, the driver skips one > TX package while still expecting a response in > mcp251xfd_handle_tefif_one(). >=20 > This patch resolves the issue by decreasing tx_ring->head and removing > the skb from the echo stack if mcp251xfd_start_xmit() fails. > Consequently, the package is dropped not been possible to re-transmit. >=20 > Fixes: 55e5b97f003e ("can: mcp25xxfd: add driver for Microchip MCP25xxFD = SPI CAN") > Cc: stable@vger.kernel.org > Signed-off-by: Vitor Soares > --- > With this approach, some packages get lost in concurrent SPI bus access > due to can_put_echo_skb() being called before mcp251xfd_tx_obj_write(). > The can_put_echo_skb() calls can_create_echo_skb() that consumes the orig= inal skb > resulting in a Kernel NULL pointer dereference error if return NETDEV_TX_= BUSY on > mcp251xfd_tx_obj_write() failure. > A potential solution would be to change the code to use spi_sync(), which= would > wait for SPI bus to be unlocked. Any thoughts about this? This is not an option. I think you need a echo_skb function that does the necessary cleanup, something like: void can_remove_echo_skb(struct net_device *dev, unsigned int idx) { struct can_priv *priv =3D netdev_priv(dev); priv->echo_skb[idx] =3D NULL; } I think you can open-code the "priv->echo_skb[idx] =3D NULL;" directly in the driver. And you have to take care of calling netdev_completed_queue(priv->ndev, 1, frame_len); Another option would be to start a workqueue and use spi_sync() in case the spi_async() is busy. 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 | --6xvopgmhifp6pdtd Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEUEC6huC2BN0pvD5fKDiiPnotvG8FAmY488UACgkQKDiiPnot vG9FFggAit859fJ+935r7xsgkOImOZCO1B2qbEmNRJCx3IOcusNr1j74fL935i6a 0rAdqHU7qndcGynpBbClTarptUjDRy0OH7PS/WGhucNdwPpJqXat3uGqgMJw06WQ EsDrS2iYiXCbj9rgcxl5EMaW7RSRz2mOzrAMkPzWtpIRxNetha+PKa9fDc9iEq01 5J+8DlRIa4tMgy1Y1OOEkHvObg8iVg55e1v1+MKJ2wti/WS7dvU0m/QEwbPqXre+ k+TozqXogUNIMA8BuVwhrKjtfxQyCyyk9SIt+aLsXt8PwgvQTab3hiEwkd6B5B53 NPURQbFDCPVvTKX0aiJpchxMHCCZ2g== =/BDM -----END PGP SIGNATURE----- --6xvopgmhifp6pdtd--