From patchwork Wed Aug 20 14:19:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Jensen X-Patchwork-Id: 4752001 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 599EAC0338 for ; Wed, 20 Aug 2014 14:21:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7F6A52015E for ; Wed, 20 Aug 2014 14:21:50 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 61ACA20155 for ; Wed, 20 Aug 2014 14:21:49 +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 1XK6jh-0008KK-Rk; Wed, 20 Aug 2014 14:19:37 +0000 Received: from mail-lb0-x235.google.com ([2a00:1450:4010:c04::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XK6jf-0008An-Bp for linux-arm-kernel@lists.infradead.org; Wed, 20 Aug 2014 14:19:35 +0000 Received: by mail-lb0-f181.google.com with SMTP id 10so6928994lbg.12 for ; Wed, 20 Aug 2014 07:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wLeG8KRfm/ysdANo7ckE6SBiUb1YG6nAudHww3AcBmM=; b=jk5p1DUJAMH8NLPV5EHSwiqwDvbNvUTvBIz7yYi5vvr3qOMG/ivqZUg4krkr43u87o Ol18TidRDfpd6Jsz0p9lGEkKq1SIhP06H6Ce/WGYGYpXLI3ZQZzT82ArbyPJ82DNTyrf ObjRMd5mRgZ3LJlKRNqtSy7VzVstrp0xhuVqDrV/rUKrgxfGdUSeCaKT+/6yVEFE4Gqd Xi6ETLd1JtuBJHrMwKD849EHyit3O/wNZoBpyy3DvCweLx4EjD5rMjUdTej0LJjJD4Et 3fBEsm3by8nM2cDEr6gRkwX2UjO3wBZnm0mUbi7Pg630+jf85CBL6I+v1ghkTSLphZ71 em8A== X-Received: by 10.152.45.101 with SMTP id l5mr42736316lam.20.1408544348815; Wed, 20 Aug 2014 07:19:08 -0700 (PDT) Received: from Ildjarn.ath.cx (static-213-115-41-10.sme.bredbandsbolaget.se. [213.115.41.10]) by mx.google.com with ESMTPSA id zm10sm37308757lbb.17.2014.08.20.07.19.07 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 20 Aug 2014 07:19:07 -0700 (PDT) From: Jonas Jensen To: netdev@vger.kernel.org Subject: [PATCH v5 2/2] net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy() Date: Wed, 20 Aug 2014 16:19:02 +0200 Message-Id: <1408544342-32058-1-git-send-email-jonas.jensen@gmail.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1408459784-9385-2-git-send-email-jonas.jensen@gmail.com> References: <1408459784-9385-2-git-send-email-jonas.jensen@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140820_071935_587597_38EF7BB1 X-CRM114-Status: GOOD ( 11.41 ) X-Spam-Score: -0.1 (/) Cc: f.fainelli@gmail.com, eric.dumazet@gmail.com, linux-kernel@vger.kernel.org, Jonas Jensen , davem@davemloft.net, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 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.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, 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 build_skb() is used to make skbs out of existing RX ring memory which is bad because the RX ring is allocated only once, on probe. Memory corruption occur because said memory is reclaimed, i.e. __kfree_skb() (and eventually put_page()). Replace build_skb() with netdev_alloc_skb_ip_align(), use memcpy(), and synchronize DMA memory before passing skb to napi_gro_receive(). Remove SKB_DATA_ALIGN() from RX buffer size while we're at it. Addresses https://bugzilla.kernel.org/show_bug.cgi?id=69041 Signed-off-by: Jonas Jensen --- Notes: Changes since v4: 1. remove SKB_DATA_ALIGN() from RX buffer size Applies to next-20140820 drivers/net/ethernet/moxa/moxart_ether.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c index aa45607..06a6fce 100644 --- a/drivers/net/ethernet/moxa/moxart_ether.c +++ b/drivers/net/ethernet/moxa/moxart_ether.c @@ -226,14 +226,21 @@ static int moxart_rx_poll(struct napi_struct *napi, int budget) if (len > RX_BUF_SIZE) len = RX_BUF_SIZE; - skb = build_skb(priv->rx_buf[rx_head], priv->rx_buf_size); + dma_sync_single_for_cpu(&ndev->dev, + priv->rx_mapping[rx_head], + priv->rx_buf_size, DMA_FROM_DEVICE); + skb = netdev_alloc_skb_ip_align(ndev, len); if (unlikely(!skb)) { - net_dbg_ratelimited("build_skb failed\n"); + net_dbg_ratelimited("netdev_alloc_skb_ip_align failed\n"); priv->stats.rx_dropped++; priv->stats.rx_errors++; } - + memcpy(skb->data, priv->rx_buf[rx_head], len); skb_put(skb, len); + dma_sync_single_for_device(&ndev->dev, + priv->rx_mapping[rx_head], + priv->rx_buf_size, DMA_FROM_DEVICE); + skb->protocol = eth_type_trans(skb, ndev); napi_gro_receive(&priv->napi, skb); rx++; @@ -466,8 +473,7 @@ static int moxart_mac_probe(struct platform_device *pdev) spin_lock_init(&priv->txlock); priv->tx_buf_size = TX_BUF_SIZE; - priv->rx_buf_size = RX_BUF_SIZE + - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); + priv->rx_buf_size = RX_BUF_SIZE; priv->tx_desc_base = dma_alloc_coherent(NULL, TX_REG_DESC_SIZE * TX_DESC_NUM, &priv->tx_base,