From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3431CC282CC for ; Tue, 5 Feb 2019 17:36:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A9C620821 for ; Tue, 5 Feb 2019 17:36:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="G8DOHBIL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728083AbfBERgh (ORCPT ); Tue, 5 Feb 2019 12:36:37 -0500 Received: from mail-qk1-f201.google.com ([209.85.222.201]:41847 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726550AbfBERgg (ORCPT ); Tue, 5 Feb 2019 12:36:36 -0500 Received: by mail-qk1-f201.google.com with SMTP id u197so3816675qka.8 for ; Tue, 05 Feb 2019 09:36:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=aAgPOITxTyntMxbL1HEI6nunbKyidxM0urHtffXP4L8=; b=G8DOHBILGJyLXKyzjAihi4e7C6U3RVu0xqWc1dEPahDQSst2IJhV65L0WuRQ00QOyO 9GnhR/IFXu3UL3TLvKTGzaA55trjuc1BbK8yTQnEgYr6u8T49oq+Z3hSWrQb6VFYHHzR sPpyZn0zQ4/nFTtRxZM40HlKZrXV3XHVVPxgvrmmk5Ow+221kq68GDSxBp07h/kp4oe6 f+PIfzvxNdRRSrZPI2aZZ1uH9NTN/2BDlOpIK4jO+byAFSLPACm5pCCe+4eWDN9OKI3H axOmXlEI6mc5phPR65HXTU0xZdkEanBPc7RIJi9XaIj+i2W1j0PYA0GicG1KJ4BlrsCE OvIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=aAgPOITxTyntMxbL1HEI6nunbKyidxM0urHtffXP4L8=; b=jXfgYTBqmaj/wMMUC7QgLq7tdQl+LNGF8B+tj3LlmQRk4UXPN5S3leMV29M/fxTMDN 1eGimUOMcqR69k8OEW4AhGYrP612/15EAm1tUbRNOq968R4ZrS+0ilOh5ltcZ4iGIT/S fIR16Gh836HbVVTTFg+xvxrHCcsU9Seyi0ER9wtBDGvTlZZjWr9wQMikS1lYZoI8FsDq Pwy15KIuuthDpD6elWOC4CLJtcoZ0Xewxnd5uOm3XaTCZhcxOyMmRBLdi134q3d911bv HlRG/RzhDdFIS/FDB0WMPPubisx96zc4sxhwpYWGt03fveGzClL83AomA/GtJznAnoXl LQ8g== X-Gm-Message-State: AHQUAualzrxYT1acwI7VDCGhqfXTOcYN1+Qmh7PnfRag/mM1/UMm9gaG P+3adu/TcHgsBYsRv4hnBvVGQHUDeKvuKO6lGSJNTOQPWzorBSjoT+9Mx3Q/d8luw60FJlldEq6 V3MaL6BzzXyyWrFr8gREtUixLa8RJjC1cZZUQdyrtoVOVXywE93MgFw== X-Google-Smtp-Source: AHgI3IYk+iW4IX6bOat/Jk5eCMAaXyES3NMLyVyW+3rGflrHI0r9YOeGGSuZ+4aWBwbgRSaTfdXy1n0= X-Received: by 2002:ac8:1382:: with SMTP id h2mr2444021qtj.56.1549388195038; Tue, 05 Feb 2019 09:36:35 -0800 (PST) Date: Tue, 5 Feb 2019 09:36:23 -0800 In-Reply-To: <20190205173629.160717-1-sdf@google.com> Message-Id: <20190205173629.160717-2-sdf@google.com> Mime-Version: 1.0 References: <20190205173629.160717-1-sdf@google.com> X-Mailer: git-send-email 2.20.1.611.gfbb209baf1-goog Subject: [RFC bpf-next 1/7] net: introduce __init_skb and __init_skb_shinfo helpers From: Stanislav Fomichev To: netdev@vger.kernel.org Cc: davem@davemloft.net, ast@kernel.org, daniel@iogearbox.net, simon.horman@netronome.com, willemb@google.com, Stanislav Fomichev Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org __init_skb is essentially a version of __build_skb which accepts skb as an argument (instead of doing kmem_cache_alloc to allocate it). __init_skb_shinfo initializes shinfo. No functional changes. Signed-off-by: Stanislav Fomichev --- include/linux/skbuff.h | 1 + net/core/skbuff.c | 68 ++++++++++++++++++++---------------------- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 831846617d07..ad883ab2762c 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1001,6 +1001,7 @@ void kfree_skb_partial(struct sk_buff *skb, bool head_stolen); bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, bool *fragstolen, int *delta_truesize); +void __init_skb(struct sk_buff *skb, u8 *data, unsigned int size); struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags, int node); struct sk_buff *__build_skb(void *data, unsigned int frag_size); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 26d848484912..23c9cf100bd4 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -160,6 +160,34 @@ static void *__kmalloc_reserve(size_t size, gfp_t flags, int node, * */ +void __init_skb(struct sk_buff *skb, u8 *data, unsigned int size) +{ + /* Only clear those fields we need to clear, not those that we will + * actually initialise below. Hence, don't put any more fields after + * the tail pointer in struct sk_buff! + */ + memset(skb, 0, offsetof(struct sk_buff, tail)); + /* Account for allocated memory : skb + skb->head */ + skb->truesize = SKB_TRUESIZE(size); + refcount_set(&skb->users, 1); + skb->head = data; + skb->data = data; + skb_reset_tail_pointer(skb); + skb->end = skb->tail + size; + skb->mac_header = (typeof(skb->mac_header))~0U; + skb->transport_header = (typeof(skb->transport_header))~0U; +} + +static inline void __init_skb_shinfo(struct sk_buff *skb) +{ + struct skb_shared_info *shinfo; + + /* make sure we initialize shinfo sequentially */ + shinfo = skb_shinfo(skb); + memset(shinfo, 0, offsetof(struct skb_shared_info, dataref)); + atomic_set(&shinfo->dataref, 1); +} + /** * __alloc_skb - allocate a network buffer * @size: size to allocate @@ -181,7 +209,6 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask, int flags, int node) { struct kmem_cache *cache; - struct skb_shared_info *shinfo; struct sk_buff *skb; u8 *data; bool pfmemalloc; @@ -215,27 +242,9 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask, size = SKB_WITH_OVERHEAD(ksize(data)); prefetchw(data + size); - /* - * Only clear those fields we need to clear, not those that we will - * actually initialise below. Hence, don't put any more fields after - * the tail pointer in struct sk_buff! - */ - memset(skb, 0, offsetof(struct sk_buff, tail)); - /* Account for allocated memory : skb + skb->head */ - skb->truesize = SKB_TRUESIZE(size); + __init_skb(skb, data, size); + __init_skb_shinfo(skb); skb->pfmemalloc = pfmemalloc; - refcount_set(&skb->users, 1); - skb->head = data; - skb->data = data; - skb_reset_tail_pointer(skb); - skb->end = skb->tail + size; - skb->mac_header = (typeof(skb->mac_header))~0U; - skb->transport_header = (typeof(skb->transport_header))~0U; - - /* make sure we initialize shinfo sequentially */ - shinfo = skb_shinfo(skb); - memset(shinfo, 0, offsetof(struct skb_shared_info, dataref)); - atomic_set(&shinfo->dataref, 1); if (flags & SKB_ALLOC_FCLONE) { struct sk_buff_fclones *fclones; @@ -277,7 +286,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); @@ -287,20 +295,8 @@ struct sk_buff *__build_skb(void *data, unsigned int frag_size) size -= SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); - memset(skb, 0, offsetof(struct sk_buff, tail)); - skb->truesize = SKB_TRUESIZE(size); - refcount_set(&skb->users, 1); - skb->head = data; - skb->data = data; - skb_reset_tail_pointer(skb); - skb->end = skb->tail + size; - skb->mac_header = (typeof(skb->mac_header))~0U; - skb->transport_header = (typeof(skb->transport_header))~0U; - - /* make sure we initialize shinfo sequentially */ - shinfo = skb_shinfo(skb); - memset(shinfo, 0, offsetof(struct skb_shared_info, dataref)); - atomic_set(&shinfo->dataref, 1); + __init_skb(skb, data, size); + __init_skb_shinfo(skb); return skb; } -- 2.20.1.611.gfbb209baf1-goog