From patchwork Fri Feb 1 09:12:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianhua Xie X-Patchwork-Id: 217389 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id B59CA2C03A7 for ; Fri, 1 Feb 2013 20:13:41 +1100 (EST) Received: from tx2outboundpool.messaging.microsoft.com (tx2ehsobe003.messaging.microsoft.com [65.55.88.13]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client CN "mail.global.frontbridge.com", Issuer "Microsoft Secure Server Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 3D7522C0086 for ; Fri, 1 Feb 2013 20:13:17 +1100 (EST) Received: from mail214-tx2-R.bigfish.com (10.9.14.248) by TX2EHSOBE001.bigfish.com (10.9.40.21) with Microsoft SMTP Server id 14.1.225.23; Fri, 1 Feb 2013 09:13:14 +0000 Received: from mail214-tx2 (localhost [127.0.0.1]) by mail214-tx2-R.bigfish.com (Postfix) with ESMTP id A1272C032A; Fri, 1 Feb 2013 09:13:14 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1ee6h1de0h1202h1e76h1d1ah1d2ahzz8275bhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h1155h) Received: from mail214-tx2 (localhost.localdomain [127.0.0.1]) by mail214-tx2 (MessageSwitch) id 135970999340476_20460; Fri, 1 Feb 2013 09:13:13 +0000 (UTC) Received: from TX2EHSMHS026.bigfish.com (unknown [10.9.14.241]) by mail214-tx2.bigfish.com (Postfix) with ESMTP id F22B33C0050; Fri, 1 Feb 2013 09:13:12 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS026.bigfish.com (10.9.99.126) with Microsoft SMTP Server (TLS) id 14.1.225.23; Fri, 1 Feb 2013 09:13:10 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server (TLS) id 14.2.318.3; Fri, 1 Feb 2013 09:13:10 +0000 Received: from xjhlab.ap.freescale.net (xjhlab.ap.freescale.net [10.192.208.221]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id r119D6Pl010604; Fri, 1 Feb 2013 02:13:07 -0700 From: Jianhua Xie To: , Subject: [PATCH 2/2] gianfar: Add a parameter to support allocation skb GFP_KERNEL and GFP_ATOMIC Date: Fri, 1 Feb 2013 17:12:49 +0800 Message-ID: <1359709969-18381-1-git-send-email-jianhua.xie@freescale.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-OriginatorOrg: freescale.com Cc: Jianhua Xie , linuxppc-dev@lists.ozlabs.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" While allocation skb in IRQ/SOFTIRQ, such as processing each frame in the rx ring, alloc skb should be ATOMIC based, should not sleep. When allocation skb is not in IRQ/SOFTIRQ, such as allocation skb when initializing a net driver, starting up the NIC from stopped status. In this case, it is not necessary to alloc memory base on GFP_ATOMIC, should use GFP_KERNEL. The second method also avoid kernel crash and reporting -ENOMEM when free low memory is near vm.min_free_kbytes as below: Signed-off-by: Jianhua Xie --- drivers/net/ethernet/freescale/gianfar.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c index 94d36ac..559a01c 100644 --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c @@ -110,7 +110,7 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev); static void gfar_reset_task(struct work_struct *work); static void gfar_timeout(struct net_device *dev); static int gfar_close(struct net_device *dev); -static struct sk_buff *gfar_alloc_skb(struct net_device *dev); +static struct sk_buff *gfar_alloc_skb(struct net_device *dev, gfp_t gfp_mask); static void gfar_new_rxbdp(struct gfar_priv_rx_q *rx_queue, struct rxbd8 *bdp, struct sk_buff *skb); static int gfar_set_mac_address(struct net_device *dev); @@ -207,7 +207,7 @@ static int gfar_init_bds(struct net_device *ndev) gfar_init_rxbdp(rx_queue, rxbdp, rxbdp->bufPtr); } else { - skb = gfar_alloc_skb(ndev); + skb = gfar_alloc_skb(ndev, GFP_KERNEL); if (!skb) { netdev_err(ndev, "Can't allocate RX buffers\n"); return -ENOMEM; @@ -2598,12 +2598,13 @@ static void gfar_new_rxbdp(struct gfar_priv_rx_q *rx_queue, struct rxbd8 *bdp, gfar_init_rxbdp(rx_queue, bdp, buf); } -static struct sk_buff *gfar_alloc_skb(struct net_device *dev) +static struct sk_buff *gfar_alloc_skb(struct net_device *dev, gfp_t gfp_mask) { struct gfar_private *priv = netdev_priv(dev); struct sk_buff *skb; - skb = netdev_alloc_skb(dev, priv->rx_buffer_size + RXBUF_ALIGNMENT); + skb = __netdev_alloc_skb(dev, priv->rx_buffer_size + RXBUF_ALIGNMENT, + gfp_mask); if (!skb) return NULL; @@ -2749,7 +2750,7 @@ int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit) rmb(); /* Add another skb for the future */ - newskb = gfar_alloc_skb(dev); + newskb = gfar_alloc_skb(dev, GFP_ATOMIC); skb = rx_queue->rx_skbuff[rx_queue->skb_currx];