From patchwork Thu Dec 6 23:25:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesper Dangaard Brouer X-Patchwork-Id: 153070 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp11146159ljp; Thu, 6 Dec 2018 15:26:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vw8crJXD2qSHmKcXVAUwZ+rdaT+83x7WKOrUOzxXwrjjOp8rb5LwyVTUgGERT8Xg0kroUz X-Received: by 2002:a63:9c1a:: with SMTP id f26mr7324522pge.381.1544138764149; Thu, 06 Dec 2018 15:26:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544138764; cv=none; d=google.com; s=arc-20160816; b=QVHdNFVmSHW19+7hGIbgEHhk1lIu/pt5jDL9u/mkKRyR6otPuw9TMpZBuHeCbP8BKG AcyNb4pmiEdD3gBFGL62yw71lcwPlGaUttIfjK5mkP/KMhD7Nd6A1EputCiUxX94rOml 16/FxcJVxh3is6jUc8DoL8M5tItDjzGX0QijResE7pvFLsA741Llyzs/HyrtN6Qzms9W IwzXRKRpAzd+/QIFfJq2h4qW7U5lRfD3Qsi83/bf1+u1aaR3DKgNU5+WfJVUpTLwAwHw 59e/f3rQUtDUHw3UCuYMKQBRjg1W5505OONGWpgzFqDqhwATFsrgpNeZNBFYb2Yd2jBP U6iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject; bh=ZzUvN/YSbdJLYjLzDsUOz7nslSDIuuMDEEq5nf9wMLE=; b=YEak36piAVTl+/0LsfQXGF0jv5n0fE4AmlAzQLMYV+jyuBLNnb+6ZReozDIYB4n1iU W22KdgaokAWrpuILEmx3s3fePhQIq7HMcSapDXVL75tire7oZUJeOzc97K/QUNEkIVVA Sn04Dk/po3uCNvSi8A5t1zUe3EfGdrjcpR49reH+eLIyqCAsyHtwgQMyEK+cA3+uXfUU fdvnYUupzkr4XZSgggU6xmnSezaq7vurO7bpatLn2Qcdy8htg7fXtJmKgbNLXwuYT2N7 1J8MIdSq4Ndr2SQLsaQjxiVH+9l/9YoBNRKMCH4t2O4GUgzR4k2BoJcnB+V4ZzftTYaU ullw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m32si1337455pld.86.2018.12.06.15.26.03; Thu, 06 Dec 2018 15:26:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726253AbeLFXZz (ORCPT + 10 others); Thu, 6 Dec 2018 18:25:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:9085 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726069AbeLFXZz (ORCPT ); Thu, 6 Dec 2018 18:25:55 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF6AE30821A4; Thu, 6 Dec 2018 23:25:54 +0000 (UTC) Received: from firesoul.localdomain (ovpn-200-16.brq.redhat.com [10.40.200.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 303755D9D6; Thu, 6 Dec 2018 23:25:48 +0000 (UTC) Received: from [192.168.5.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id 5BE6830631A99; Fri, 7 Dec 2018 00:25:47 +0100 (CET) Subject: [net-next PATCH RFC 4/8] net: core: add recycle capabilities on skbs via page_pool API From: Jesper Dangaard Brouer To: netdev@vger.kernel.org, "David S. Miller" , Jesper Dangaard Brouer Cc: Toke =?utf-8?q?H=C3=B8iland-J=C3=B8rgensen?= , ard.biesheuvel@linaro.org, Jason Wang , ilias.apalodimas@linaro.org, =?utf-8?b?QmrDtnJuVMO2cGVs?= , w@1wt.eu, Saeed Mahameed , mykyta.iziumtsev@gmail.com, Daniel Borkmann , Alexei Starovoitov , Tariq Toukan Date: Fri, 07 Dec 2018 00:25:47 +0100 Message-ID: <154413874729.21735.10644578158550468689.stgit@firesoul> In-Reply-To: <154413868810.21735.572808840657728172.stgit@firesoul> References: <154413868810.21735.572808840657728172.stgit@firesoul> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 06 Dec 2018 23:25:54 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ilias Apalodimas This patch is changing struct sk_buff, and is thus per-definition controversial. Place a new member 'mem_info' of type struct xdp_mem_info, just after members (flags) head_frag and pfmemalloc, And not in between headers_start/end to ensure skb_copy() and pskb_copy() work as-is. Copying mem_info during skb_clone() is required. This makes sure that pages are correctly freed or recycled during the altered skb_free_head() invocation. The 'mem_info' name is chosen as this is not strictly tied to XDP, although the XDP return infrastructure is used. As a future plan, we could introduce a __u8 flags member to xdp_mem_info and move flags head_frag and pfmemalloc into this area. Signed-off-by: Ilias Apalodimas Signed-off-by: Jesper Dangaard Brouer --- include/linux/skbuff.h | 6 +++++- include/net/xdp.h | 1 + net/core/skbuff.c | 7 +++++++ net/core/xdp.c | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 7dcfb5591dc3..95dac0ba6947 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -40,6 +40,7 @@ #include #include #include +#include /* The interface for checksum offload between the stack and networking drivers * is as follows... @@ -744,6 +745,10 @@ struct sk_buff { head_frag:1, xmit_more:1, pfmemalloc:1; + /* TODO: Future idea, extend mem_info with __u8 flags, and + * move bits head_frag and pfmemalloc there. + */ + struct xdp_mem_info mem_info; /* fields enclosed in headers_start/headers_end are copied * using a single memcpy() in __copy_skb_header() @@ -827,7 +832,6 @@ struct sk_buff { #ifdef CONFIG_NETWORK_SECMARK __u32 secmark; #endif - union { __u32 mark; __u32 reserved_tailroom; diff --git a/include/net/xdp.h b/include/net/xdp.h index 5c33b9e0efab..4a0ca7a3d5e5 100644 --- a/include/net/xdp.h +++ b/include/net/xdp.h @@ -128,6 +128,7 @@ struct xdp_frame *convert_to_xdp_frame(struct xdp_buff *xdp) void xdp_return_frame(struct xdp_frame *xdpf); void xdp_return_frame_rx_napi(struct xdp_frame *xdpf); void xdp_return_buff(struct xdp_buff *xdp); +void xdp_return_skb_page(void *data, struct xdp_mem_info *mem_info); int xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq, struct net_device *dev, u32 queue_index); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index b4ee5c8b928f..71aca186e44c 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -70,6 +70,7 @@ #include #include #include +#include #include #include @@ -544,6 +545,11 @@ static void skb_free_head(struct sk_buff *skb) { unsigned char *head = skb->head; + if (skb->mem_info.type == MEM_TYPE_PAGE_POOL) { + xdp_return_skb_page(head, &skb->mem_info); + return; + } + if (skb->head_frag) skb_free_frag(head); else @@ -859,6 +865,7 @@ static struct sk_buff *__skb_clone(struct sk_buff *n, struct sk_buff *skb) n->nohdr = 0; n->peeked = 0; C(pfmemalloc); + C(mem_info); n->destructor = NULL; C(tail); C(end); diff --git a/net/core/xdp.c b/net/core/xdp.c index e79526314864..1703be4c2611 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -379,6 +379,12 @@ void xdp_return_buff(struct xdp_buff *xdp) } EXPORT_SYMBOL_GPL(xdp_return_buff); +void xdp_return_skb_page(void *data, struct xdp_mem_info *mem_info) +{ + __xdp_return(data, mem_info, false, 0); +} +EXPORT_SYMBOL(xdp_return_skb_page); + int xdp_attachment_query(struct xdp_attachment_info *info, struct netdev_bpf *bpf) {