From patchwork Fri Apr 22 05:59:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Duan X-Patchwork-Id: 8905921 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 22F339F1C1 for ; Fri, 22 Apr 2016 06:01:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A2DD320254 for ; Fri, 22 Apr 2016 06:01:27 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4D58020221 for ; Fri, 22 Apr 2016 06:01:26 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1atU7q-0004IQ-EM; Fri, 22 Apr 2016 05:59:34 +0000 Received: from mail-am1on0091.outbound.protection.outlook.com ([157.56.112.91] helo=emea01-am1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1atU7n-0004Ey-1p for linux-arm-kernel@lists.infradead.org; Fri, 22 Apr 2016 05:59:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-nxp-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ff4XC4U6h0J2Qo5YKSSV+S1B/vH/cTFXpLpmlpFBCMM=; b=E50qwbHnHwjjnoZq1M+6+soqP+GzzqIse+mrJrb3BBT9Y4MRSy/yZqL5GcIWDuKcjA/KOHWkeFuAXSDF9/+gg95jji7HlyajjwelDnk+DXtM40jhV5wZFU6YyBDS5hSCFEeNfZb7GC6tqjdK+1NQSbcec0Dpo6x8NiUr6A7qJxU= Received: from VI1PR0401MB1855.eurprd04.prod.outlook.com (10.165.235.21) by VI1PR0401MB2046.eurprd04.prod.outlook.com (10.166.141.26) with Microsoft SMTP Server (TLS) id 15.1.466.19; Fri, 22 Apr 2016 05:59:07 +0000 Received: from VI1PR0401MB1855.eurprd04.prod.outlook.com ([10.165.235.21]) by VI1PR0401MB1855.eurprd04.prod.outlook.com ([10.165.235.21]) with mapi id 15.01.0466.023; Fri, 22 Apr 2016 05:59:08 +0000 From: Fugang Duan To: Troy Kisky , "netdev@vger.kernel.org" , "davem@davemloft.net" , "lznuaa@gmail.com" Subject: RE: [PATCH net 1/1] net: fec: update dirty_tx even if no skb Thread-Topic: [PATCH net 1/1] net: fec: update dirty_tx even if no skb Thread-Index: AQHRnDrSX9pvZ6fNB02V+nvW2Eyq6J+VdJ2A Date: Fri, 22 Apr 2016 05:59:07 +0000 Message-ID: References: <1461290434-18462-1-git-send-email-troy.kisky@boundarydevices.com> In-Reply-To: <1461290434-18462-1-git-send-email-troy.kisky@boundarydevices.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: boundarydevices.com; dkim=none (message not signed) header.d=none; boundarydevices.com; dmarc=none action=none header.from=nxp.com; x-originating-ip: [123.151.195.53] x-ms-office365-filtering-correlation-id: fbf95578-fbcb-4099-7e0e-08d36a7337d7 x-microsoft-exchange-diagnostics: 1; VI1PR0401MB2046; 5:+qWDdfqRfyYTTmA0wl7Omd9rZqMBOHh8S8r9yGDicVzur4NRi6A2kUuD9pux2UWr2QWRP5aEB/He0EWCP8Ch61YRaNoIkCI+Dt40Vwm/AL18j4vvHycy2dIg5zaMmQ6mx4YNsWYGYKbSIzsKoXquMfW1z2p5oejzevU4QYyw7q17hhsRLkXb4GW6tNmn5w4f; 24:o9qDZ27lqai6bmvCQiPvHNaay6ik/skHhRuNlsKGfKn8cZvfyPZk+W3DgblRPkZVEITVJnQ6D9Bo2RJ+06CYJ/AjewjyMDSn3is83Q3GEYE=; 7:ORyRl8TLZIzGaaDxsXY2iylXSYg6hr8LCrszsII8kL0BxAUpCAZNNuqvj9RKV1HXO4MMEIeOLkUe7VyMlblAXLPR4CKBO4B6ht3lhm8PA0qbbKPRDxpfuySp2GK6MtyUKkeQWFFGTAS5o+iMXM9YLKpaSZLTlNSPyG5EhVyO4A6YveiUXJ4vYrQKubqQ2/AWTWP9D1ic0bk9euaTTicvDpCkDWPQAlTJ9I+pBvUKgVw= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0401MB2046; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(9101521026)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:VI1PR0401MB2046; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0401MB2046; x-forefront-prvs: 0920602B08 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(377454003)(2950100001)(1220700001)(5004730100002)(19580405001)(19580395003)(4326007)(2900100001)(76576001)(92566002)(189998001)(102836003)(15650500001)(86362001)(5001770100001)(3846002)(87936001)(6116002)(5002640100001)(5003600100002)(3900700001)(586003)(10400500002)(3280700002)(1096002)(122556002)(76176999)(106116001)(77096005)(33656002)(66066001)(2906002)(50986999)(2501003)(54356999)(5008740100001)(3660700001)(2201001)(9686002)(81166005)(74316001)(14143004); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0401MB2046; H:VI1PR0401MB1855.eurprd04.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Apr 2016 05:59:07.7993 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2046 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160421_225931_589284_39C2E76C X-CRM114-Status: GOOD ( 19.34 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "andrew@lunn.ch" , "stillcompiling@gmail.com" , "arnd@arndb.de" , "sergei.shtylyov@cogentembedded.com" , "gerg@uclinux.org" , Fabio Estevam , "johannes@sipsolutions.net" , "l.stach@pengutronix.de" , "holgerschurig@gmail.com" , "linux-arm-kernel@lists.infradead.org" , "tremyfr@gmail.com" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Troy Kisky Sent: Friday, April 22, 2016 10:01 AM > To: netdev@vger.kernel.org; davem@davemloft.net; Fugang Duan > ; lznuaa@gmail.com > Cc: Fabio Estevam ; l.stach@pengutronix.de; > andrew@lunn.ch; tremyfr@gmail.com; gerg@uclinux.org; linux-arm- > kernel@lists.infradead.org; johannes@sipsolutions.net; > stillcompiling@gmail.com; sergei.shtylyov@cogentembedded.com; > arnd@arndb.de; holgerschurig@gmail.com; Troy Kisky > > Subject: [PATCH net 1/1] net: fec: update dirty_tx even if no skb > > If dirty_tx isn't updated, then dma_unmap_single will be called twice. > > This fixes a > [ 58.420980] ------------[ cut here ]------------ > [ 58.425667] WARNING: CPU: 0 PID: 377 at /home/schurig/d/mkarm/linux- > 4.5/lib/dma-debug.c:1096 check_unmap+0x9d0/0xab8() > [ 58.436405] fec 2188000.ethernet: DMA-API: device driver tries to free DMA > memory it has not allocated [device address=0x0000000000000000] [size=66 > bytes] > > encountered by Holger > > Signed-off-by: Troy Kisky > Tested-by: > --- > drivers/net/ethernet/freescale/fec_main.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/ethernet/freescale/fec_main.c > b/drivers/net/ethernet/freescale/fec_main.c > index 08243c2..b71654c 100644 > --- a/drivers/net/ethernet/freescale/fec_main.c > +++ b/drivers/net/ethernet/freescale/fec_main.c > @@ -1197,10 +1197,8 @@ fec_enet_tx_queue(struct net_device *ndev, u16 > queue_id) > fec16_to_cpu(bdp->cbd_datlen), > DMA_TO_DEVICE); > bdp->cbd_bufaddr = cpu_to_fec32(0); > - if (!skb) { > - bdp = fec_enet_get_nextdesc(bdp, &txq->bd); > - continue; > - } > + if (!skb) > + goto skb_done; > > /* Check for errors. */ > if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC | @@ -1239,7 > +1237,7 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id) > > /* Free the sk buffer associated with this last transmit */ > dev_kfree_skb_any(skb); > - > +skb_done: > /* Make sure the update to bdp and tx_skbuff are performed > * before dirty_tx > */ > -- > 2.5.0 The patch is fine for me. Can you review below patch that also fix the issue. It can take much effort due to less rmb() and READ_ONCE() operation that is very sensitive for duplex Gbps test for i.MX6SX/i.MX7d SOC. (i.MX6SX can reach at 1.4Gbps, i.MX7D can reach at 1.8Gbps.) Andy --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -1160,12 +1160,13 @@ static void fec_enet_tx_queue(struct net_device *ndev, u16 queue_id) { struct fec_enet_private *fep; - struct bufdesc *bdp; + struct bufdesc *bdp, *bdp_t; unsigned short status; struct sk_buff *skb; struct fec_enet_priv_tx_q *txq; struct netdev_queue *nq; int index = 0; + int i, bdnum; int entries_free; fep = netdev_priv(ndev); @@ -1187,20 +1188,28 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id) if (status & BD_ENET_TX_READY) break; - index = fec_enet_get_bd_index(bdp, &txq->bd); - + bdp_t = bdp; + bdnum = 1; + index = fec_enet_get_bd_index(txq->tx_bd_base, bdp_t, fep); skb = txq->tx_skbuff[index]; - txq->tx_skbuff[index] = NULL; - if (!IS_TSO_HEADER(txq, fec32_to_cpu(bdp->cbd_bufaddr))) - dma_unmap_single(&fep->pdev->dev, - fec32_to_cpu(bdp->cbd_bufaddr), - fec16_to_cpu(bdp->cbd_datlen), - DMA_TO_DEVICE); - bdp->cbd_bufaddr = cpu_to_fec32(0); - if (!skb) { - bdp = fec_enet_get_nextdesc(bdp, &txq->bd); - continue; + while (!skb) { + bdp_t = fec_enet_get_nextdesc(bdp_t, &txq->bd); + index = fec_enet_get_bd_index(txq->tx_bd_base, bdp_t, fep); + skb = txq->tx_skbuff[index]; + bdnum++; + } + status = fec16_to_cpu(READ_ONCE(bdp->cbd_sc)); + if (status & BD_ENET_TX_READY) + break; + + for (i = 0; i < bdnum; i++) { + if (!IS_TSO_HEADER(txq, bdp->cbd_bufaddr)) + dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr, + bdp->cbd_datlen, DMA_TO_DEVICE); + bdp->cbd_bufaddr = 0; + if (i < bdnum - 1) + bdp = fec_enet_get_nextdesc(bdp, &txq->bd); } + txq->tx_skbuff[index] = NULL; Regards,