From patchwork Mon Aug 25 14:22:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Jensen X-Patchwork-Id: 4775221 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 3EA969F38D for ; Mon, 25 Aug 2014 14:24:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2AA372012B for ; Mon, 25 Aug 2014 14:24:51 +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 2D01E20109 for ; Mon, 25 Aug 2014 14:24:50 +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 1XLvAc-00029X-KM; Mon, 25 Aug 2014 14:22:54 +0000 Received: from mail-la0-x22c.google.com ([2a00:1450:4010:c03::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XLvAW-00022i-Ku for linux-arm-kernel@lists.infradead.org; Mon, 25 Aug 2014 14:22:49 +0000 Received: by mail-la0-f44.google.com with SMTP id el20so13117790lab.31 for ; Mon, 25 Aug 2014 07:22:25 -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=R697NySRryZi5ijo4dH+r2ze8qc3XE6U0g9Amv4K5eo=; b=f3vOqGdp7BECS5/IXdQEfszvpfY6hQj1MRB1/bZn/j/ke1kub+1u+RLImjwLOW8Ib+ Gk6V58gp1yr2xQeIIweFjtBrvEmflzRn8Bz42TY5Ds/jrIv7TWRCnyl2X7bY7IMBltc8 KwszYxxmezZ6zr3oMOoEXF0jcZjWkEEHsFjD8mwP+x7mgX1jQaN0uZu9CCae0BuWWndD ArluIckUJBwJR+sZF/wpn+SBGGTU2ua0tW9syCH/+7Ef6opnaDBTN68JlHnS80iNgovn oFthV7ZrOD2QRibIg/gUDsHEq6Uxx29qNF16htkbaeIRln4SmZuShgIdFPWxPhGOpQjM 7TRA== X-Received: by 10.112.225.7 with SMTP id rg7mr20398506lbc.52.1408976545736; Mon, 25 Aug 2014 07:22:25 -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 s10sm6045012lal.34.2014.08.25.07.22.24 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 25 Aug 2014 07:22:25 -0700 (PDT) From: Jonas Jensen To: netdev@vger.kernel.org Subject: [PATCH v6 2/4] net: moxa: replace build_skb() with netdev_alloc_skb_ip_align() / memcpy() Date: Mon, 25 Aug 2014 16:22:22 +0200 Message-Id: <1408976542-15624-1-git-send-email-jonas.jensen@gmail.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1408544342-32058-1-git-send-email-jonas.jensen@gmail.com> References: <1408544342-32058-1-git-send-email-jonas.jensen@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140825_072248_877107_E22F0463 X-CRM114-Status: GOOD ( 11.96 ) X-Spam-Score: -0.8 (/) Cc: f.fainelli@gmail.com, eric.dumazet@gmail.com, linux-kernel@vger.kernel.org, Jonas Jensen , mirqus@gmail.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=-1.8 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=no 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(). 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 v5: 1. broke out DMA synchronization to separate patch Applies to next-20140825 drivers/net/ethernet/moxa/moxart_ether.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c index eed70d9..d66058d 100644 --- a/drivers/net/ethernet/moxa/moxart_ether.c +++ b/drivers/net/ethernet/moxa/moxart_ether.c @@ -226,13 +226,15 @@ 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); + 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); skb->protocol = eth_type_trans(skb, ndev); napi_gro_receive(&priv->napi, skb); @@ -464,8 +466,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,