From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46BB9C433EF for ; Fri, 20 May 2022 12:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349643AbiETMmw convert rfc822-to-8bit (ORCPT ); Fri, 20 May 2022 08:42:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349498AbiETMmh (ORCPT ); Fri, 20 May 2022 08:42:37 -0400 X-Greylist: delayed 390 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 20 May 2022 05:42:21 PDT Received: from unicorn.mansr.com (unicorn.mansr.com [81.2.72.234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 402B61901A; Fri, 20 May 2022 05:42:20 -0700 (PDT) Received: from raven.mansr.com (raven.mansr.com [IPv6:2001:8b0:ca0d:1::3]) by unicorn.mansr.com (Postfix) with ESMTPS id 6406615361; Fri, 20 May 2022 13:35:48 +0100 (BST) Received: by raven.mansr.com (Postfix, from userid 51770) id 4D31721A3D6; Fri, 20 May 2022 13:35:48 +0100 (BST) From: =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= To: Christophe Leroy Cc: Pantelis Antoniou , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vitaly Bordug , Dan Malek , Joakim Tjernlund , "linuxppc-dev@lists.ozlabs.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] net: fs_enet: sync rx dma buffer before reading References: <20220519192443.28681-1-mans@mansr.com> <03f24864-9d4d-b4f9-354a-f3b271c0ae66@csgroup.eu> Date: Fri, 20 May 2022 13:35:48 +0100 In-Reply-To: <03f24864-9d4d-b4f9-354a-f3b271c0ae66@csgroup.eu> (Christophe Leroy's message of "Fri, 20 May 2022 05:39:38 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Christophe Leroy writes: > Le 19/05/2022 à 21:24, Mans Rullgard a écrit : >> The dma_sync_single_for_cpu() call must precede reading the received >> data. Fix this. > > See original commit 070e1f01827c. It explicitely says that the cache > must be invalidate _AFTER_ the copy. > > The cache is initialy invalidated by dma_map_single(), so before the > copy the cache is already clean. > > After the copy, data is in the cache. In order to allow re-use of the > skb, it must be put back in the same condition as before, in extenso the > cache must be invalidated in order to be in the same situation as after > dma_map_single(). > > So I think your change is wrong. OK, looking at it more closely, the change is at least unnecessary since there will be a cache invalidation between each use of the buffer either way. Please disregard the patch. Sorry for the noise. >> >> Fixes: 070e1f01827c ("net: fs_enet: don't unmap DMA when packet len is below copybreak") >> Signed-off-by: Mans Rullgard >> --- >> drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c | 8 ++++---- >> 1 file changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c >> index b3dae17e067e..432ce10cbfd0 100644 >> --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c >> +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c >> @@ -240,14 +240,14 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) >> /* +2 to make IP header L1 cache aligned */ >> skbn = netdev_alloc_skb(dev, pkt_len + 2); >> if (skbn != NULL) { >> + dma_sync_single_for_cpu(fep->dev, >> + CBDR_BUFADDR(bdp), >> + L1_CACHE_ALIGN(pkt_len), >> + DMA_FROM_DEVICE); >> skb_reserve(skbn, 2); /* align IP header */ >> skb_copy_from_linear_data(skb, >> skbn->data, pkt_len); >> swap(skb, skbn); >> - dma_sync_single_for_cpu(fep->dev, >> - CBDR_BUFADDR(bdp), >> - L1_CACHE_ALIGN(pkt_len), >> - DMA_FROM_DEVICE); >> } >> } else { >> skbn = netdev_alloc_skb(dev, ENET_RX_FRSIZE); >> -- >> 2.35.1 >> -- Måns Rullgård From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41187C433EF for ; Fri, 20 May 2022 12:42:49 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4L4RFz5QpRz3cdb for ; Fri, 20 May 2022 22:42:47 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=permerror (SPF Permanent Error: Void lookup limit of 2 exceeded) smtp.mailfrom=mansr.com (client-ip=2001:8b0:ca0d:1::2; helo=unicorn.mansr.com; envelope-from=mans@mansr.com; receiver=) X-Greylist: delayed 380 seconds by postgrey-1.36 at boromir; Fri, 20 May 2022 22:42:22 AEST Received: from unicorn.mansr.com (unicorn.mansr.com [IPv6:2001:8b0:ca0d:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4L4RFV3N15z2yWr for ; Fri, 20 May 2022 22:42:21 +1000 (AEST) Received: from raven.mansr.com (raven.mansr.com [IPv6:2001:8b0:ca0d:1::3]) by unicorn.mansr.com (Postfix) with ESMTPS id 6406615361; Fri, 20 May 2022 13:35:48 +0100 (BST) Received: by raven.mansr.com (Postfix, from userid 51770) id 4D31721A3D6; Fri, 20 May 2022 13:35:48 +0100 (BST) From: =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= To: Christophe Leroy Subject: Re: [PATCH] net: fs_enet: sync rx dma buffer before reading References: <20220519192443.28681-1-mans@mansr.com> <03f24864-9d4d-b4f9-354a-f3b271c0ae66@csgroup.eu> Date: Fri, 20 May 2022 13:35:48 +0100 In-Reply-To: <03f24864-9d4d-b4f9-354a-f3b271c0ae66@csgroup.eu> (Christophe Leroy's message of "Fri, 20 May 2022 05:39:38 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "linuxppc-dev@lists.ozlabs.org" , Dan Malek , "linux-kernel@vger.kernel.org" , Eric Dumazet , "netdev@vger.kernel.org" , Vitaly Bordug , Jakub Kicinski , Paolo Abeni , Joakim Tjernlund , "David S. Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Christophe Leroy writes: > Le 19/05/2022 =E0 21:24, Mans Rullgard a =E9crit=A0: >> The dma_sync_single_for_cpu() call must precede reading the received >> data. Fix this. > > See original commit 070e1f01827c. It explicitely says that the cache=20 > must be invalidate _AFTER_ the copy. > > The cache is initialy invalidated by dma_map_single(), so before the=20 > copy the cache is already clean. > > After the copy, data is in the cache. In order to allow re-use of the=20 > skb, it must be put back in the same condition as before, in extenso the= =20 > cache must be invalidated in order to be in the same situation as after=20 > dma_map_single(). > > So I think your change is wrong. OK, looking at it more closely, the change is at least unnecessary since there will be a cache invalidation between each use of the buffer either way. Please disregard the patch. Sorry for the noise. >>=20 >> Fixes: 070e1f01827c ("net: fs_enet: don't unmap DMA when packet len is b= elow copybreak") >> Signed-off-by: Mans Rullgard >> --- >> drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c | 8 ++++---- >> 1 file changed, 4 insertions(+), 4 deletions(-) >>=20 >> diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c b/dri= vers/net/ethernet/freescale/fs_enet/fs_enet-main.c >> index b3dae17e067e..432ce10cbfd0 100644 >> --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c >> +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c >> @@ -240,14 +240,14 @@ static int fs_enet_napi(struct napi_struct *napi, = int budget) >> /* +2 to make IP header L1 cache aligne= d */ >> skbn =3D netdev_alloc_skb(dev, pkt_len = + 2); >> if (skbn !=3D NULL) { >> + dma_sync_single_for_cpu(fep->dev, >> + CBDR_BUFADDR(bdp), >> + L1_CACHE_ALIGN(pkt_len), >> + DMA_FROM_DEVICE); >> skb_reserve(skbn, 2); /* alig= n IP header */ >> skb_copy_from_linear_data(skb, >> skbn->data, pkt_l= en); >> swap(skb, skbn); >> - dma_sync_single_for_cpu(fep->dev, >> - CBDR_BUFADDR(bdp), >> - L1_CACHE_ALIGN(pkt_len), >> - DMA_FROM_DEVICE); >> } >> } else { >> skbn =3D netdev_alloc_skb(dev, ENET_RX_= FRSIZE); >> -- >> 2.35.1 >>=20 --=20 M=E5ns Rullg=E5rd