From patchwork Sun Jan 28 14:20:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13534481 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD3B524B2C; Sun, 28 Jan 2024 14:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706451729; cv=none; b=O3qEophc9gWbmmBDojc6Rg9k+YAuWh30+eRdcQeUrWvsM+Ks9ef8iPCYN+nIfXq9JA4CeXlqpKMgXqFtpOWOS6/pw7oAXY4HnlQSRVaZ9jJETcKrDhS5vKsuNs6j5aEB1jORDNprY2jwuz3Rmu+jB60ofnZ68S+cxWpAy2bsGHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706451729; c=relaxed/simple; bh=smRcOPt7Bh+Cyjqvn72Zg9vAozaKKpftgkhBlmG9Qtw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=njpGvyoUnOYAEThZ6tONMgr0IhcvXN5ABuMBGsQg8mV9JZUStQBkvz68Q+WgNTz0ZwpQQgwCCraxuOqgKdvdUijty2+9b7Ror3g/YWOyLEWXWeuObhHpBqF7/5PgbNYpXzK649cdMP/gCMwNtt87BkCEgPL+8XPulgCQQjeJtEs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GnRDxpCl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GnRDxpCl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE33DC433C7; Sun, 28 Jan 2024 14:22:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706451729; bh=smRcOPt7Bh+Cyjqvn72Zg9vAozaKKpftgkhBlmG9Qtw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GnRDxpClOihheRgjjlT3ToEml/MdvAgHKSl2f/dl+82u36HqB4Ckrq4ToRHj8tt/J WTW+UQdOVN+D7tmKI4BD72w7CcaXtSiAjywd61FYSDs7O1aIRA0+atsDoztU6yqEIW /8t0+sf+cke9bLRJ5RFHA8o7D4TOyEJAToOTU1iyRoHb18kTBvLly0ppiWSBbpKDve FlZ6dv0Dao5Is5RHDAY5jo4O1ZcvWnNDL4yCFN0qYyBVOCFpy0Xt1kHp8DsNyhh0SO 3mMh/W3UsokFAeImo8qt8uPknlpft68rN3QJGN6JbgeIcMjr6/OF+7c5DIu1sEdo1v LiDQHNexj2sPA== From: Lorenzo Bianconi To: netdev@vger.kernel.org Cc: lorenzo.bianconi@redhat.com, davem@davemloft.net, kuba@kernel.org, edumazet@google.com, pabeni@redhat.com, bpf@vger.kernel.org, toke@redhat.com, willemdebruijn.kernel@gmail.com, jasowang@redhat.com, sdf@google.com, hawk@kernel.org, ilias.apalodimas@linaro.org Subject: [PATCH v6 net-next 1/5] net: add generic per-cpu page_pool allocator Date: Sun, 28 Jan 2024 15:20:37 +0100 Message-ID: <5b0222d3df382c22fe0fa96154ae7b27189f7ecd.1706451150.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Introduce generic percpu page_pools allocator. Moreover add page_pool_create_percpu() and cpuid filed in page_pool struct in order to recycle the page in the page_pool "hot" cache if napi_pp_put_page() is running on the same cpu. This is a preliminary patch to add xdp multi-buff support for xdp running in generic mode. Signed-off-by: Lorenzo Bianconi --- include/net/page_pool/types.h | 3 +++ net/core/dev.c | 40 +++++++++++++++++++++++++++++++++++ net/core/page_pool.c | 23 ++++++++++++++++---- net/core/skbuff.c | 5 +++-- 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h index 76481c465375..3828396ae60c 100644 --- a/include/net/page_pool/types.h +++ b/include/net/page_pool/types.h @@ -128,6 +128,7 @@ struct page_pool_stats { struct page_pool { struct page_pool_params_fast p; + int cpuid; bool has_init_callback; long frag_users; @@ -203,6 +204,8 @@ struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp); struct page *page_pool_alloc_frag(struct page_pool *pool, unsigned int *offset, unsigned int size, gfp_t gfp); struct page_pool *page_pool_create(const struct page_pool_params *params); +struct page_pool *page_pool_create_percpu(const struct page_pool_params *params, + int cpuid); struct xdp_mem_info; diff --git a/net/core/dev.c b/net/core/dev.c index cb2dab0feee0..bf9ec740b09a 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -153,6 +153,8 @@ #include #include #include +#include +#include #include "dev.h" #include "net-sysfs.h" @@ -442,6 +444,8 @@ static RAW_NOTIFIER_HEAD(netdev_chain); DEFINE_PER_CPU_ALIGNED(struct softnet_data, softnet_data); EXPORT_PER_CPU_SYMBOL(softnet_data); +DEFINE_PER_CPU_ALIGNED(struct page_pool *, page_pool); + #ifdef CONFIG_LOCKDEP /* * register_netdevice() inits txq->_xmit_lock and sets lockdep class @@ -11686,6 +11690,27 @@ static void __init net_dev_struct_check(void) * */ +#define SD_PAGE_POOL_RING_SIZE 256 +static int net_page_pool_alloc(int cpuid) +{ +#if IS_ENABLED(CONFIG_PAGE_POOL) + struct page_pool_params page_pool_params = { + .pool_size = SD_PAGE_POOL_RING_SIZE, + .nid = NUMA_NO_NODE, + }; + struct page_pool *pp_ptr; + + pp_ptr = page_pool_create_percpu(&page_pool_params, cpuid); + if (IS_ERR(pp_ptr)) { + pp_ptr = NULL; + return -ENOMEM; + } + + per_cpu(page_pool, cpuid) = pp_ptr; +#endif + return 0; +} + /* * This is called single threaded during boot, so no need * to take the rtnl semaphore. @@ -11738,6 +11763,9 @@ static int __init net_dev_init(void) init_gro_hash(&sd->backlog); sd->backlog.poll = process_backlog; sd->backlog.weight = weight_p; + + if (net_page_pool_alloc(i)) + goto out; } dev_boot_phase = 0; @@ -11765,6 +11793,18 @@ static int __init net_dev_init(void) WARN_ON(rc < 0); rc = 0; out: + if (rc < 0) { + for_each_possible_cpu(i) { + struct page_pool *pp_ptr = this_cpu_read(page_pool); + + if (!pp_ptr) + continue; + + page_pool_destroy(pp_ptr); + per_cpu(page_pool, i) = NULL; + } + } + return rc; } diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 4933762e5a6b..89c835fcf094 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -171,13 +171,16 @@ static void page_pool_producer_unlock(struct page_pool *pool, } static int page_pool_init(struct page_pool *pool, - const struct page_pool_params *params) + const struct page_pool_params *params, + int cpuid) { unsigned int ring_qsize = 1024; /* Default */ memcpy(&pool->p, ¶ms->fast, sizeof(pool->p)); memcpy(&pool->slow, ¶ms->slow, sizeof(pool->slow)); + pool->cpuid = cpuid; + /* Validate only known flags were used */ if (pool->p.flags & ~(PP_FLAG_ALL)) return -EINVAL; @@ -253,10 +256,12 @@ static void page_pool_uninit(struct page_pool *pool) } /** - * page_pool_create() - create a page pool. + * page_pool_create_percpu() - create a page pool for a given cpu. * @params: parameters, see struct page_pool_params + * @cpuid: cpu identifier */ -struct page_pool *page_pool_create(const struct page_pool_params *params) +struct page_pool * +page_pool_create_percpu(const struct page_pool_params *params, int cpuid) { struct page_pool *pool; int err; @@ -265,7 +270,7 @@ struct page_pool *page_pool_create(const struct page_pool_params *params) if (!pool) return ERR_PTR(-ENOMEM); - err = page_pool_init(pool, params); + err = page_pool_init(pool, params, cpuid); if (err < 0) goto err_free; @@ -282,6 +287,16 @@ struct page_pool *page_pool_create(const struct page_pool_params *params) kfree(pool); return ERR_PTR(err); } +EXPORT_SYMBOL(page_pool_create_percpu); + +/** + * page_pool_create() - create a page pool + * @params: parameters, see struct page_pool_params + */ +struct page_pool *page_pool_create(const struct page_pool_params *params) +{ + return page_pool_create_percpu(params, -1); +} EXPORT_SYMBOL(page_pool_create); static void page_pool_return_page(struct page_pool *pool, struct page *page); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index edbbef563d4d..9e5eb47b4025 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -923,9 +923,10 @@ bool napi_pp_put_page(struct page *page, bool napi_safe) */ if (napi_safe || in_softirq()) { const struct napi_struct *napi = READ_ONCE(pp->p.napi); + unsigned int cpuid = smp_processor_id(); - allow_direct = napi && - READ_ONCE(napi->list_owner) == smp_processor_id(); + allow_direct = napi && READ_ONCE(napi->list_owner) == cpuid; + allow_direct |= (pp->cpuid == cpuid); } /* Driver set this to memory recycling info. Reset it on recycle. From patchwork Sun Jan 28 14:20:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13534482 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61B37288DD; Sun, 28 Jan 2024 14:22:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706451733; cv=none; b=qnNveL+zqSzKYhq4kIUjMtjyvvPYOEpGtclVYOuuFG4xRDZtcCxkSdNgbUEA225Nf9VyffdB+yExAlW6C7K2x5pA9whb3VCcNAGGcws0Xi97JDxIJQ5iyunws1YSD36Du5NxbtOkBELPHgQSh3pZJcBM2XiocdBlbo8O/zYg7Ls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706451733; c=relaxed/simple; bh=1OOLH7js8NjWz3tp7HldxyWc6SbFLgrAhGUX0VKyIR8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G5+Lu/9tpcN3EzNawlT6kZuYctre0nXsq/SFI7Pg+gyEh1UzLpmCOyC2WG5kqJP9JdcL3FBdMqQKnCKfSc9VmY4QKmzlzJTuVwJPzTIO2NU8QgGdJG/d6EhpNP6QS6nns4e8fds7TqXgJ9ZyevYixQRwh0lDCxVRkAFWFWylpb0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IDxF+UOI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IDxF+UOI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73D8CC433F1; Sun, 28 Jan 2024 14:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706451732; bh=1OOLH7js8NjWz3tp7HldxyWc6SbFLgrAhGUX0VKyIR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IDxF+UOIdot/9RrXtq7eDDZAkdeGXztpVGZEhG6PrNJM/8LCr92A+PSy/7xeH08qR dVrc0A3mO0vcP3rdxwiQWMv1IGkP5YbWqxyP/8B30GxfQqJJqaX1FCaALIQDpEs7ty 9bhoI5dNzbTYaWFD09FIQCMWdQ1TICz/l8YJOzEgNMKJqTU1JdgnNQs3eBbs6mXZzx uGpm9UqxEp6QOXRT0qOvzEYcKAz8hqrG4WsvvhD16Uii6Ot5SRn2M/nOvdtTq88ufs Tfr83uDb6UybMVsns4Bib8hK3i4oENtpCFPpSmHg2PMjeZbE35Eb5hn1lXhK6BcbEY nwLqrOfD+f7dA== From: Lorenzo Bianconi To: netdev@vger.kernel.org Cc: lorenzo.bianconi@redhat.com, davem@davemloft.net, kuba@kernel.org, edumazet@google.com, pabeni@redhat.com, bpf@vger.kernel.org, toke@redhat.com, willemdebruijn.kernel@gmail.com, jasowang@redhat.com, sdf@google.com, hawk@kernel.org, ilias.apalodimas@linaro.org Subject: [PATCH v6 net-next 2/5] xdp: rely on skb pointer reference in do_xdp_generic and netif_receive_generic_xdp Date: Sun, 28 Jan 2024 15:20:38 +0100 Message-ID: <7fd76e88e2aadc03f14b040ffc762e88d05afc8c.1706451150.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Rely on skb pointer reference instead of the skb pointer in do_xdp_generic and netif_receive_generic_xdp routine signatures. This is a preliminary patch to add multi-buff support for xdp running in generic mode. Acked-by: Jesper Dangaard Brouer Signed-off-by: Lorenzo Bianconi --- drivers/net/tun.c | 4 ++-- include/linux/netdevice.h | 2 +- net/core/dev.c | 16 +++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 4a4f8c8e79fa..5bd98bdaddf2 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1927,7 +1927,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, rcu_read_lock(); xdp_prog = rcu_dereference(tun->xdp_prog); if (xdp_prog) { - ret = do_xdp_generic(xdp_prog, skb); + ret = do_xdp_generic(xdp_prog, &skb); if (ret != XDP_PASS) { rcu_read_unlock(); local_bh_enable(); @@ -2517,7 +2517,7 @@ static int tun_xdp_one(struct tun_struct *tun, skb_record_rx_queue(skb, tfile->queue_index); if (skb_xdp) { - ret = do_xdp_generic(xdp_prog, skb); + ret = do_xdp_generic(xdp_prog, &skb); if (ret != XDP_PASS) { ret = 0; goto out; diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 118c40258d07..7eee99a58200 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3958,7 +3958,7 @@ static inline void dev_consume_skb_any(struct sk_buff *skb) u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, struct bpf_prog *xdp_prog); void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog); -int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb); +int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff **pskb); int netif_rx(struct sk_buff *skb); int __netif_rx(struct sk_buff *skb); diff --git a/net/core/dev.c b/net/core/dev.c index bf9ec740b09a..960f39ac5e33 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4924,10 +4924,11 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, return act; } -static u32 netif_receive_generic_xdp(struct sk_buff *skb, +static u32 netif_receive_generic_xdp(struct sk_buff **pskb, struct xdp_buff *xdp, struct bpf_prog *xdp_prog) { + struct sk_buff *skb = *pskb; u32 act = XDP_DROP; /* Reinjected packets coming from act_mirred or similar should @@ -5008,24 +5009,24 @@ void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog) static DEFINE_STATIC_KEY_FALSE(generic_xdp_needed_key); -int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb) +int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff **pskb) { if (xdp_prog) { struct xdp_buff xdp; u32 act; int err; - act = netif_receive_generic_xdp(skb, &xdp, xdp_prog); + act = netif_receive_generic_xdp(pskb, &xdp, xdp_prog); if (act != XDP_PASS) { switch (act) { case XDP_REDIRECT: - err = xdp_do_generic_redirect(skb->dev, skb, + err = xdp_do_generic_redirect((*pskb)->dev, *pskb, &xdp, xdp_prog); if (err) goto out_redir; break; case XDP_TX: - generic_xdp_tx(skb, xdp_prog); + generic_xdp_tx(*pskb, xdp_prog); break; } return XDP_DROP; @@ -5033,7 +5034,7 @@ int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb) } return XDP_PASS; out_redir: - kfree_skb_reason(skb, SKB_DROP_REASON_XDP); + kfree_skb_reason(*pskb, SKB_DROP_REASON_XDP); return XDP_DROP; } EXPORT_SYMBOL_GPL(do_xdp_generic); @@ -5356,7 +5357,8 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, int ret2; migrate_disable(); - ret2 = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog), skb); + ret2 = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog), + &skb); migrate_enable(); if (ret2 != XDP_PASS) { From patchwork Sun Jan 28 14:20:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13534483 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA6E324208; Sun, 28 Jan 2024 14:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706451736; cv=none; b=BcmzOpsiKW8cA/o/dIZHIG4kfVLxL3ZrPneHlngsOvSBDvzL99rPZJlDhN6HU3MOXo9wEeKsDylKs7fAPJn42ybggWgHALnBCBeKCW7h0WK9SpeeobZUyoeIyZ67rW7mVr9BGj4hVkr0FLG72uHMTD/ti4EFsx0PtaEwRfgZ9Vw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706451736; c=relaxed/simple; bh=JLsVjDwv4U9XRkH6tXDLlha24RZBYQV0xD3WrVD51lo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=csp+wWxXuCHwUq2p7oGf5+v17uJWsawdr9dmjlALTilTg/5m/crfdh8k8IYituzbx4dEhIAkbdn9mofmHPy+GFEqC2m5GwetLi7I5hSfGzEUPaJeMOVmDNBIMnu0n/ePvj6mfMx1ThleIEDJowQWanFTjiJr67G6TK78rIABcCo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b2DVhC5a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b2DVhC5a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04275C433C7; Sun, 28 Jan 2024 14:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706451736; bh=JLsVjDwv4U9XRkH6tXDLlha24RZBYQV0xD3WrVD51lo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b2DVhC5agQiFGFxl32tkKen55MO1E3Va1IOoTYk0ouFrOD4hIM4MlKBTOX1hbKo13 D2g8wDtoddry6TUvRfMQhYzhjvk4mTd3MYM/b6YeYPVFZqypTNZdXLK18OTScJtZHu b+cHgKaRWBHpMQndCmILyl+SRgAHUsvl5fUJMcI4oQ18BJVq1xyMYd2xqXg7DW1/Cc +cploIlH2VZq0fq/EO1/iR+8J2KLt/nmKXmI7vPQCGzOBDeQ4aeRD6/Ypy25yRVhhE kfiL67kPhBf66+ALpMJC+vFEOqAoNhMR5zC0AEejqWwYjFHy4G4gQCXWdymVqHH3gF Nt4903cP7i9Qw== From: Lorenzo Bianconi To: netdev@vger.kernel.org Cc: lorenzo.bianconi@redhat.com, davem@davemloft.net, kuba@kernel.org, edumazet@google.com, pabeni@redhat.com, bpf@vger.kernel.org, toke@redhat.com, willemdebruijn.kernel@gmail.com, jasowang@redhat.com, sdf@google.com, hawk@kernel.org, ilias.apalodimas@linaro.org Subject: [PATCH v6 net-next 3/5] xdp: add multi-buff support for xdp running in generic mode Date: Sun, 28 Jan 2024 15:20:39 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Similar to native xdp, do not always linearize the skb in netif_receive_generic_xdp routine but create a non-linear xdp_buff to be processed by the eBPF program. This allow to add multi-buffer support for xdp running in generic mode. Signed-off-by: Lorenzo Bianconi --- net/core/dev.c | 152 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 133 insertions(+), 19 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 960f39ac5e33..19f92ba90e49 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4862,6 +4862,12 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, xdp_init_buff(xdp, frame_sz, &rxqueue->xdp_rxq); xdp_prepare_buff(xdp, hard_start, skb_headroom(skb) - mac_len, skb_headlen(skb) + mac_len, true); + if (skb_is_nonlinear(skb)) { + skb_shinfo(skb)->xdp_frags_size = skb->data_len; + xdp_buff_set_frags_flag(xdp); + } else { + xdp_buff_clear_frags_flag(xdp); + } orig_data_end = xdp->data_end; orig_data = xdp->data; @@ -4891,6 +4897,14 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, skb->len += off; /* positive on grow, negative on shrink */ } + /* XDP frag metadata (e.g. nr_frags) are updated in eBPF helpers + * (e.g. bpf_xdp_adjust_tail), we need to update data_len here. + */ + if (xdp_buff_has_frags(xdp)) + skb->data_len = skb_shinfo(skb)->xdp_frags_size; + else + skb->data_len = 0; + /* check if XDP changed eth hdr such SKB needs update */ eth = (struct ethhdr *)xdp->data; if ((orig_eth_type != eth->h_proto) || @@ -4924,12 +4938,117 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, return act; } +#if IS_ENABLED(CONFIG_PAGE_POOL) +static int +netif_skb_segment_for_xdp(struct page_pool *pool, struct sk_buff **pskb, + struct bpf_prog *prog) +{ + u32 size, truesize, len, max_head_size, off; + struct sk_buff *skb = *pskb, *nskb; + int err, i, head_off; + void *data; + + /* XDP does not support fraglist so we need to linearize + * the skb. + */ + if (skb_has_frag_list(skb) || !prog->aux->xdp_has_frags) + return -EOPNOTSUPP; + + max_head_size = SKB_WITH_OVERHEAD(PAGE_SIZE - XDP_PACKET_HEADROOM); + if (skb->len > max_head_size + MAX_SKB_FRAGS * PAGE_SIZE) + return -ENOMEM; + + size = min_t(u32, skb->len, max_head_size); + truesize = SKB_HEAD_ALIGN(size) + XDP_PACKET_HEADROOM; + data = page_pool_dev_alloc_va(pool, &truesize); + if (!data) + return -ENOMEM; + + nskb = napi_build_skb(data, truesize); + if (!nskb) { + page_pool_free_va(pool, data, true); + return -ENOMEM; + } + + skb_reserve(nskb, XDP_PACKET_HEADROOM); + skb_copy_header(nskb, skb); + skb_mark_for_recycle(nskb); + + err = skb_copy_bits(skb, 0, nskb->data, size); + if (err) { + consume_skb(nskb); + return err; + } + skb_put(nskb, size); + + head_off = skb_headroom(nskb) - skb_headroom(skb); + skb_headers_offset_update(nskb, head_off); + + off = size; + len = skb->len - off; + for (i = 0; i < MAX_SKB_FRAGS && off < skb->len; i++) { + struct page *page; + u32 page_off; + + size = min_t(u32, len, PAGE_SIZE); + truesize = size; + + page = page_pool_dev_alloc(pool, &page_off, &truesize); + if (!data) { + consume_skb(nskb); + return -ENOMEM; + } + + skb_add_rx_frag(nskb, i, page, page_off, size, truesize); + err = skb_copy_bits(skb, off, page_address(page) + page_off, + size); + if (err) { + consume_skb(nskb); + return err; + } + + len -= size; + off += size; + } + + consume_skb(skb); + *pskb = nskb; + + return 0; +} +#endif + +static int +netif_skb_check_for_xdp(struct sk_buff **pskb, struct bpf_prog *prog) +{ + struct sk_buff *skb = *pskb; + int err, hroom, troom; + +#if IS_ENABLED(CONFIG_PAGE_POOL) + if (!netif_skb_segment_for_xdp(this_cpu_read(page_pool), pskb, prog)) + return 0; +#endif + + /* In case we have to go down the path and also linearize, + * then lets do the pskb_expand_head() work just once here. + */ + hroom = XDP_PACKET_HEADROOM - skb_headroom(skb); + troom = skb->tail + skb->data_len - skb->end; + err = pskb_expand_head(skb, + hroom > 0 ? ALIGN(hroom, NET_SKB_PAD) : 0, + troom > 0 ? troom + 128 : 0, GFP_ATOMIC); + if (err) + return err; + + return skb_linearize(skb); +} + static u32 netif_receive_generic_xdp(struct sk_buff **pskb, struct xdp_buff *xdp, struct bpf_prog *xdp_prog) { struct sk_buff *skb = *pskb; - u32 act = XDP_DROP; + u32 mac_len, act = XDP_DROP; /* Reinjected packets coming from act_mirred or similar should * not get XDP generic processing. @@ -4937,41 +5056,36 @@ static u32 netif_receive_generic_xdp(struct sk_buff **pskb, if (skb_is_redirected(skb)) return XDP_PASS; - /* XDP packets must be linear and must have sufficient headroom - * of XDP_PACKET_HEADROOM bytes. This is the guarantee that also - * native XDP provides, thus we need to do it here as well. + /* XDP packets must have sufficient headroom of XDP_PACKET_HEADROOM + * bytes. This is the guarantee that also native XDP provides, + * thus we need to do it here as well. */ + mac_len = skb->data - skb_mac_header(skb); + __skb_push(skb, mac_len); + if (skb_cloned(skb) || skb_is_nonlinear(skb) || skb_headroom(skb) < XDP_PACKET_HEADROOM) { - int hroom = XDP_PACKET_HEADROOM - skb_headroom(skb); - int troom = skb->tail + skb->data_len - skb->end; - - /* In case we have to go down the path and also linearize, - * then lets do the pskb_expand_head() work just once here. - */ - if (pskb_expand_head(skb, - hroom > 0 ? ALIGN(hroom, NET_SKB_PAD) : 0, - troom > 0 ? troom + 128 : 0, GFP_ATOMIC)) - goto do_drop; - if (skb_linearize(skb)) + if (netif_skb_check_for_xdp(pskb, xdp_prog)) goto do_drop; } - act = bpf_prog_run_generic_xdp(skb, xdp, xdp_prog); + __skb_pull(*pskb, mac_len); + + act = bpf_prog_run_generic_xdp(*pskb, xdp, xdp_prog); switch (act) { case XDP_REDIRECT: case XDP_TX: case XDP_PASS: break; default: - bpf_warn_invalid_xdp_action(skb->dev, xdp_prog, act); + bpf_warn_invalid_xdp_action((*pskb)->dev, xdp_prog, act); fallthrough; case XDP_ABORTED: - trace_xdp_exception(skb->dev, xdp_prog, act); + trace_xdp_exception((*pskb)->dev, xdp_prog, act); fallthrough; case XDP_DROP: do_drop: - kfree_skb(skb); + kfree_skb(*pskb); break; } From patchwork Sun Jan 28 14:20:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13534484 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73DF31DA44; Sun, 28 Jan 2024 14:22:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706451740; cv=none; b=sxl/kP5HMWzgm4sPocfMu2ySTHERxGZ+4HOn1wihVJU+1aIJCX9j3oH3TiJ32uSBul7wzSzaopxF33zYG2lwDjYKZkcmhQnOVVVQfgyZRhiYFYHGoCI1etHoB1J6x12Jym2IA69Xe3yyJlC+Ig49k6vm1UB2zRCYs6/CuGMPV+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706451740; c=relaxed/simple; bh=O+YeuMB8+lN1QWS1jW/X6V/PjZZ4TGDBb2JpTZRa5gk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R66q/zU83qHIr/P5Wm/r7YET9o7ku6LFbC7DkMwiewITv8eVEEfeWGecbWFRWTtiCFOxTb0xnTUZGiPJNDt37lS/wJ8lp3RL5cFK3i6mKIabVQluVzsxkQDCJygn8puD2ktcbj/IiBa1sd83QHLLsA379EcgWGXXfiKB/RFKfWc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ET1JIOFN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ET1JIOFN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC9B3C433C7; Sun, 28 Jan 2024 14:22:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706451740; bh=O+YeuMB8+lN1QWS1jW/X6V/PjZZ4TGDBb2JpTZRa5gk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ET1JIOFNNX9QHMD2y4Fe4OHnjLipcrAcXdnpxilURkvl1M8H/0Ac1Ht2F27WxcGN7 pQ6mq7twb5h8HmXPyCR1/c4y+v0SfH7zmo0ByK5BVehLEC2D07Hu9KTE8X0EDol457 oBFGWrDB8tZuOwXYBx8fRiox+JSth/chM6rey/AaHNMVKyNSqXlLdSkWeZCJIe2fb9 dWdwGvX929XimAyFcrVnyFeRZBiNvqeMlXFUDsriwxB0KRg5ifszHoGZbqKPEgLHc0 /YRpY13pjfyZbC8nb3jzpjuWGLHKqGjpmTb0g4Yovm03lySQ26vC1ne0vnJqpo6sXp AgynIdg7kTagQ== From: Lorenzo Bianconi To: netdev@vger.kernel.org Cc: lorenzo.bianconi@redhat.com, davem@davemloft.net, kuba@kernel.org, edumazet@google.com, pabeni@redhat.com, bpf@vger.kernel.org, toke@redhat.com, willemdebruijn.kernel@gmail.com, jasowang@redhat.com, sdf@google.com, hawk@kernel.org, ilias.apalodimas@linaro.org Subject: [PATCH v6 net-next 4/5] net: page_pool: make stats available just for global pools Date: Sun, 28 Jan 2024 15:20:40 +0100 Message-ID: <9f0a571c1f322ff6c4e6facfd7d6d508e73a8f2f.1706451150.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Move page_pool stats allocation in page_pool_create routine and get rid of it for percpu page_pools. Signed-off-by: Lorenzo Bianconi --- net/core/page_pool.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 89c835fcf094..5278ffef6442 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -37,13 +37,15 @@ #define recycle_stat_inc(pool, __stat) \ do { \ struct page_pool_recycle_stats __percpu *s = pool->recycle_stats; \ - this_cpu_inc(s->__stat); \ + if (s) \ + this_cpu_inc(s->__stat); \ } while (0) #define recycle_stat_add(pool, __stat, val) \ do { \ struct page_pool_recycle_stats __percpu *s = pool->recycle_stats; \ - this_cpu_add(s->__stat, val); \ + if (s) \ + this_cpu_add(s->__stat, val); \ } while (0) static const char pp_stats[][ETH_GSTRING_LEN] = { @@ -79,6 +81,9 @@ bool page_pool_get_stats(const struct page_pool *pool, if (!stats) return false; + if (!pool->recycle_stats) + return false; + /* The caller is responsible to initialize stats. */ stats->alloc_stats.fast += pool->alloc_stats.fast; stats->alloc_stats.slow += pool->alloc_stats.slow; @@ -218,19 +223,8 @@ static int page_pool_init(struct page_pool *pool, } pool->has_init_callback = !!pool->slow.init_callback; - -#ifdef CONFIG_PAGE_POOL_STATS - pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats); - if (!pool->recycle_stats) + if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0) return -ENOMEM; -#endif - - if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0) { -#ifdef CONFIG_PAGE_POOL_STATS - free_percpu(pool->recycle_stats); -#endif - return -ENOMEM; - } atomic_set(&pool->pages_state_release_cnt, 0); @@ -295,7 +289,21 @@ EXPORT_SYMBOL(page_pool_create_percpu); */ struct page_pool *page_pool_create(const struct page_pool_params *params) { - return page_pool_create_percpu(params, -1); + struct page_pool *pool; + + pool = page_pool_create_percpu(params, -1); + if (IS_ERR(pool)) + return pool; + +#ifdef CONFIG_PAGE_POOL_STATS + pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats); + if (!pool->recycle_stats) { + page_pool_uninit(pool); + kfree(pool); + pool = ERR_PTR(-ENOMEM); + } +#endif + return pool; } EXPORT_SYMBOL(page_pool_create); From patchwork Sun Jan 28 14:20:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13534485 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 290192D044; Sun, 28 Jan 2024 14:22:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706451744; cv=none; b=UKkBxJiEqjG6VZoAg+neocsqqy0trF4hMA4K0rcI3Tvatc6mKnk3HZ1bRTJhcYpZ3WM4fTopch2m8YNlRlo2V2PF8Vu1qVv7QpqtrAoM/V8Rj838HOB4b1NZ63j6nx/dM5E+7sZKlgLeuNgK8B+Diz89Ig0UE15y4zwn0+VcBzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706451744; c=relaxed/simple; bh=eA07ywQOGA3josKKVG7GzOBzSj4bcU+K56EhXf7uxFI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LKpttSiBMXhmXc5bm5wrHUkBLsSHE05XsabmCSgVLCMf6qRXY86q7Q4drXLG9lJiOUFqMLRQB/Hp/fWIpDlEfOMsabYe+O6gsVcazgmU5ps8fXJVsPG6SPO/Xitvnw4f/yA2IyfOpcpYJSQ6wSOUDBhKciIZzhVCJ2jYnx6MPtU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vRdBYhcD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vRdBYhcD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 537C2C433F1; Sun, 28 Jan 2024 14:22:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706451743; bh=eA07ywQOGA3josKKVG7GzOBzSj4bcU+K56EhXf7uxFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vRdBYhcDgpySoAjcJETKyLMOfqFtFOC3pCkEj1/iXhSMuPe509Q4q9iv3TCv+/nFM BRCmzerzq4M8Ti+MdwfGBnMuVWL/6l0oNZEw5ZajttN9saeOtMBd2JvPUW5Osl5YL+ H4IkMVLxXJ31ja953FPObQwNT32D8FQqJAcVimDG8fuyJPC5ZF78JGdgC2DqMZepgU /1XyQsBruBd63cOaqrCWqaT1tldNNww4A3J92wnbGdyapFO8wgPVDP8o62kvrsx0Rn jKTR26zdgiyWvSbDAxQMEOqRHD2Cpfg7MnXAUN7GchAi3SZIyaFNXD2p+yM5cpKw/T M9gF9uIi+g49w== From: Lorenzo Bianconi To: netdev@vger.kernel.org Cc: lorenzo.bianconi@redhat.com, davem@davemloft.net, kuba@kernel.org, edumazet@google.com, pabeni@redhat.com, bpf@vger.kernel.org, toke@redhat.com, willemdebruijn.kernel@gmail.com, jasowang@redhat.com, sdf@google.com, hawk@kernel.org, ilias.apalodimas@linaro.org Subject: [PATCH v6 net-next 5/5] veth: rely on netif_skb_segment_for_xdp utility routine Date: Sun, 28 Jan 2024 15:20:41 +0100 Message-ID: <72aa14d2c15a4367d59ac232772d3bf08852bc30.1706451150.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Rely on netif_skb_segment_for_xdp utility routine and remove duplicated code. Signed-off-by: Lorenzo Bianconi --- drivers/net/veth.c | 79 +++------------------------------------ include/linux/netdevice.h | 4 ++ net/core/dev.c | 6 +-- 3 files changed, 12 insertions(+), 77 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 578e36ea1589..ddb163f134ea 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -721,7 +721,8 @@ static void veth_xdp_get(struct xdp_buff *xdp) static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, struct xdp_buff *xdp, - struct sk_buff **pskb) + struct sk_buff **pskb, + struct bpf_prog *prog) { struct sk_buff *skb = *pskb; u32 frame_sz; @@ -729,80 +730,10 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, if (skb_shared(skb) || skb_head_is_locked(skb) || skb_shinfo(skb)->nr_frags || skb_headroom(skb) < XDP_PACKET_HEADROOM) { - u32 size, len, max_head_size, off, truesize, page_offset; - struct sk_buff *nskb; - struct page *page; - int i, head_off; - void *va; - - /* We need a private copy of the skb and data buffers since - * the ebpf program can modify it. We segment the original skb - * into order-0 pages without linearize it. - * - * Make sure we have enough space for linear and paged area - */ - max_head_size = SKB_WITH_OVERHEAD(PAGE_SIZE - - VETH_XDP_HEADROOM); - if (skb->len > PAGE_SIZE * MAX_SKB_FRAGS + max_head_size) - goto drop; - - size = min_t(u32, skb->len, max_head_size); - truesize = SKB_HEAD_ALIGN(size) + VETH_XDP_HEADROOM; - - /* Allocate skb head */ - va = page_pool_dev_alloc_va(rq->page_pool, &truesize); - if (!va) - goto drop; - - nskb = napi_build_skb(va, truesize); - if (!nskb) { - page_pool_free_va(rq->page_pool, va, true); + if (netif_skb_segment_for_xdp(rq->page_pool, pskb, prog)) goto drop; - } - - skb_reserve(nskb, VETH_XDP_HEADROOM); - skb_copy_header(nskb, skb); - skb_mark_for_recycle(nskb); - - if (skb_copy_bits(skb, 0, nskb->data, size)) { - consume_skb(nskb); - goto drop; - } - skb_put(nskb, size); - head_off = skb_headroom(nskb) - skb_headroom(skb); - skb_headers_offset_update(nskb, head_off); - - /* Allocate paged area of new skb */ - off = size; - len = skb->len - off; - - for (i = 0; i < MAX_SKB_FRAGS && off < skb->len; i++) { - size = min_t(u32, len, PAGE_SIZE); - truesize = size; - - page = page_pool_dev_alloc(rq->page_pool, &page_offset, - &truesize); - if (!page) { - consume_skb(nskb); - goto drop; - } - - skb_add_rx_frag(nskb, i, page, page_offset, size, - truesize); - if (skb_copy_bits(skb, off, - page_address(page) + page_offset, - size)) { - consume_skb(nskb); - goto drop; - } - - len -= size; - off += size; - } - - consume_skb(skb); - skb = nskb; + skb = *pskb; } /* SKB "head" area always have tailroom for skb_shared_info */ @@ -850,7 +781,7 @@ static struct sk_buff *veth_xdp_rcv_skb(struct veth_rq *rq, } __skb_push(skb, skb->data - skb_mac_header(skb)); - if (veth_convert_skb_to_xdp_buff(rq, xdp, &skb)) + if (veth_convert_skb_to_xdp_buff(rq, xdp, &skb, xdp_prog)) goto drop; vxbuf.skb = skb; diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 7eee99a58200..8c1f6954de47 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3955,6 +3955,10 @@ static inline void dev_consume_skb_any(struct sk_buff *skb) dev_kfree_skb_any_reason(skb, SKB_CONSUMED); } +#if IS_ENABLED(CONFIG_PAGE_POOL) +int netif_skb_segment_for_xdp(struct page_pool *pool, struct sk_buff **pskb, + struct bpf_prog *prog); +#endif u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, struct bpf_prog *xdp_prog); void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog); diff --git a/net/core/dev.c b/net/core/dev.c index 19f92ba90e49..b2fc8f0683dd 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4939,9 +4939,8 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, } #if IS_ENABLED(CONFIG_PAGE_POOL) -static int -netif_skb_segment_for_xdp(struct page_pool *pool, struct sk_buff **pskb, - struct bpf_prog *prog) +int netif_skb_segment_for_xdp(struct page_pool *pool, struct sk_buff **pskb, + struct bpf_prog *prog) { u32 size, truesize, len, max_head_size, off; struct sk_buff *skb = *pskb, *nskb; @@ -5016,6 +5015,7 @@ netif_skb_segment_for_xdp(struct page_pool *pool, struct sk_buff **pskb, return 0; } +EXPORT_SYMBOL_GPL(netif_skb_segment_for_xdp); #endif static int