From patchwork Tue Aug 19 14:49:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Jensen X-Patchwork-Id: 4743661 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 21CEA9F375 for ; Tue, 19 Aug 2014 14:52:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0CD6E20154 for ; Tue, 19 Aug 2014 14:52:53 +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 D7A17200F0 for ; Tue, 19 Aug 2014 14:52:51 +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 1XJkkT-0003Gn-Fl; Tue, 19 Aug 2014 14:50:57 +0000 Received: from mail-la0-x22b.google.com ([2a00:1450:4010:c03::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XJkk3-0002PD-Ld for linux-arm-kernel@lists.infradead.org; Tue, 19 Aug 2014 14:50:32 +0000 Received: by mail-la0-f43.google.com with SMTP id gi9so3512890lab.30 for ; Tue, 19 Aug 2014 07:50: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=t/sJ4aaX13xgp4BmcXhwPcNl07RbMMbQA7pIppTm+24=; b=fTG4uDPuL5DLcyE4w0c1PSHWIOM/Zq/XVIOiIoVo641soGmahuWOtKWVuUSSpXOwsP FbLf3HidAdTiOA/kU7Z4vv3P1LlwvrOAKGrzRhnpO8l4AhfEc+pJD+lbOzESNVhNnbr+ ImKFbff7CkDfqmf4yReiW1ssafgqwkf/qBRo5r6liP4X3eoSF6ID5jRztLcUvsG3EKod F2d/IlPTVS4wcTEZkaeOo1dl0C99rBHHVBO8V2pyBxwlwA82DUaViisy4JO9PyIjfzdY Haly5CJh0deeT29avAI9YEO+Py6dJuonySKYy8GRL91LVXU0rC8LfbGaezjSMNaTdSN0 sEHw== X-Received: by 10.152.30.100 with SMTP id r4mr15374173lah.87.1408459808841; Tue, 19 Aug 2014 07:50: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 o15sm12620111laa.44.2014.08.19.07.50.07 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 19 Aug 2014 07:50:08 -0700 (PDT) From: Jonas Jensen To: netdev@vger.kernel.org Subject: [PATCH v4 2/2] net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy() Date: Tue, 19 Aug 2014 16:49:44 +0200 Message-Id: <1408459784-9385-2-git-send-email-jonas.jensen@gmail.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1408459784-9385-1-git-send-email-jonas.jensen@gmail.com> References: <1408459784-9385-1-git-send-email-jonas.jensen@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140819_075031_918069_D7FD75BB X-CRM114-Status: GOOD ( 12.05 ) X-Spam-Score: -0.8 (/) Cc: f.fainelli@gmail.com, linux-kernel@vger.kernel.org, Jonas Jensen , bhutchings@solarflare.com, 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() and use memcpy(). Also, synchronize DMA memory before passing skb to napi_gro_receive(). Addresses https://bugzilla.kernel.org/show_bug.cgi?id=69041 Signed-off-by: Jonas Jensen --- Notes: The original motivation was to avoid memcpy(), since the memory is already allocated, why make a copy. Maybe the copy can be avoided updating RX ring descriptor addresses; new memory must be allocated just the same, the only difference that the controller could write directly to it. This fixes errors due to memory corruption, such as the following, seen on wget download (or ncftp): "read error: Bad address" On receiving error, wget exits without resuming (busybox default). Changes since v3: 1. commit message reworded Applies to next-20140818 drivers/net/ethernet/moxa/moxart_ether.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c index aa45607..17c9f0e 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++;