From patchwork Thu May 3 14:56:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 156714 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id C564BB6FA5 for ; Fri, 4 May 2012 00:59:34 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757427Ab2ECO7Z (ORCPT ); Thu, 3 May 2012 10:59:25 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:37758 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757102Ab2ECO7W (ORCPT ); Thu, 3 May 2012 10:59:22 -0400 X-IronPort-AV: E=Sophos;i="4.75,523,1330923600"; d="scan'208";a="193248765" Received: from ftlpmailmx02.citrite.net ([10.13.107.66]) by FTLPIPO02.CITRIX.COM with ESMTP/TLS/RC4-MD5; 03 May 2012 10:56:12 -0400 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.66) with Microsoft SMTP Server id 8.3.213.0; Thu, 3 May 2012 10:56:12 -0400 Received: from cosworth.uk.xensource.com ([10.80.16.52] ident=ianc) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1SPxRz-0002nJ-R7; Thu, 03 May 2012 15:56:11 +0100 From: Ian Campbell To: netdev@vger.kernel.org CC: David Miller , Eric Dumazet , "Michael S. Tsirkin" , Ian Campbell Subject: [PATCH 4/9] skb: add skb_shinfo_init and use for both alloc_skb, build_skb and skb_recycle Date: Thu, 3 May 2012 15:56:06 +0100 Message-ID: <1336056971-7839-4-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1336056915.20716.96.camel@zakaz.uk.xensource.com> References: <1336056915.20716.96.camel@zakaz.uk.xensource.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There is only one semantic change here which is that skb_recycle now does: kmemcheck_annotate_variable(shinfo->destructor_arg) I don't think it was erroneously missing before (since in the skb_recycle case it will have happened previously) but I beleive it is harmless to do it again and this saves having a different copy of the same code for the recycle case. Signed-off-by: Ian Campbell --- net/core/skbuff.c | 30 +++++++++++++----------------- 1 files changed, 13 insertions(+), 17 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index c60b603..e96f68b 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -145,6 +145,16 @@ static void skb_under_panic(struct sk_buff *skb, int sz, void *here) BUG(); } +static void skb_shinfo_init(struct sk_buff *skb) +{ + struct skb_shared_info *shinfo = skb_shinfo(skb); + + /* make sure we initialize shinfo sequentially */ + memset(shinfo, 0, offsetof(struct skb_shared_info, dataref)); + atomic_set(&shinfo->dataref, 1); + kmemcheck_annotate_variable(shinfo->destructor_arg); +} + /* Allocate a new skbuff. We do this ourselves so we can fill in a few * 'private' fields and also do memory statistics to find all the * [BEEP] leaks. @@ -170,7 +180,6 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask, int fclone, int node) { struct kmem_cache *cache; - struct skb_shared_info *shinfo; struct sk_buff *skb; u8 *data; @@ -210,11 +219,7 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask, skb->mac_header = ~0U; #endif - /* make sure we initialize shinfo sequentially */ - shinfo = skb_shinfo(skb); - memset(shinfo, 0, offsetof(struct skb_shared_info, dataref)); - atomic_set(&shinfo->dataref, 1); - kmemcheck_annotate_variable(shinfo->destructor_arg); + skb_shinfo_init(skb); if (fclone) { struct sk_buff *child = skb + 1; @@ -255,7 +260,6 @@ EXPORT_SYMBOL(__alloc_skb); */ struct sk_buff *build_skb(void *data, unsigned int frag_size) { - struct skb_shared_info *shinfo; struct sk_buff *skb; unsigned int size = frag_size ? : ksize(data); @@ -277,11 +281,7 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size) skb->mac_header = ~0U; #endif - /* make sure we initialize shinfo sequentially */ - shinfo = skb_shinfo(skb); - memset(shinfo, 0, offsetof(struct skb_shared_info, dataref)); - atomic_set(&shinfo->dataref, 1); - kmemcheck_annotate_variable(shinfo->destructor_arg); + skb_shinfo_init(skb); return skb; } @@ -546,13 +546,9 @@ EXPORT_SYMBOL(consume_skb); */ void skb_recycle(struct sk_buff *skb) { - struct skb_shared_info *shinfo; - skb_release_head_state(skb); - shinfo = skb_shinfo(skb); - memset(shinfo, 0, offsetof(struct skb_shared_info, dataref)); - atomic_set(&shinfo->dataref, 1); + skb_shinfo_init(skb); memset(skb, 0, offsetof(struct sk_buff, tail)); skb->data = skb->head + NET_SKB_PAD;