2019-05-31 08:09:24 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2018-01-03 10:25:13 +00:00
|
|
|
/* net/core/xdp.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Jesper Dangaard Brouer, Red Hat Inc.
|
|
|
|
*/
|
2018-07-12 03:36:40 +00:00
|
|
|
#include <linux/bpf.h>
|
2023-02-01 17:30:15 +00:00
|
|
|
#include <linux/btf.h>
|
2023-01-19 22:15:26 +00:00
|
|
|
#include <linux/btf_ids.h>
|
2018-07-12 03:36:40 +00:00
|
|
|
#include <linux/filter.h>
|
2018-01-03 10:25:13 +00:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/mm.h>
|
2018-07-12 03:36:40 +00:00
|
|
|
#include <linux/netdevice.h>
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/idr.h>
|
|
|
|
#include <linux/rhashtable.h>
|
xdp: Xdp_frame add member frame_sz and handle in convert_to_xdp_frame
Use hole in struct xdp_frame, when adding member frame_sz, which keeps
same sizeof struct (32 bytes)
Drivers ixgbe and sfc had bug cases where the necessary/expected
tailroom was not reserved. This can lead to some hard to catch memory
corruption issues. Having the drivers frame_sz this can be detected when
packet length/end via xdp->data_end exceed the xdp_data_hard_end
pointer, which accounts for the reserved the tailroom.
When detecting this driver issue, simply fail the conversion with NULL,
which results in feedback to driver (failing xdp_do_redirect()) causing
driver to drop packet. Given the lack of consistent XDP stats, this can
be hard to troubleshoot. And given this is a driver bug, we want to
generate some more noise in form of a WARN stack dump (to ID the driver
code that inlined convert_to_xdp_frame).
Inlining the WARN macro is problematic, because it adds an asm
instruction (on Intel CPUs ud2) what influence instruction cache
prefetching. Thus, introduce xdp_warn and macro XDP_WARN, to avoid this
and at the same time make identifying the function and line of this
inlined function easier.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/158945337313.97035.10015729316710496600.stgit@firesoul
2020-05-14 10:49:33 +00:00
|
|
|
#include <linux/bug.h>
|
2023-08-04 18:05:24 +00:00
|
|
|
#include <net/page_pool/helpers.h>
|
2018-01-03 10:25:13 +00:00
|
|
|
|
2024-03-06 16:00:23 +00:00
|
|
|
#include <net/hotdata.h>
|
2018-01-03 10:25:13 +00:00
|
|
|
#include <net/xdp.h>
|
2019-06-18 13:05:58 +00:00
|
|
|
#include <net/xdp_priv.h> /* struct xdp_mem_allocator */
|
|
|
|
#include <trace/events/xdp.h>
|
2020-05-20 19:20:53 +00:00
|
|
|
#include <net/xdp_sock_drv.h>
|
2018-01-03 10:25:13 +00:00
|
|
|
|
|
|
|
#define REG_STATE_NEW 0x0
|
|
|
|
#define REG_STATE_REGISTERED 0x1
|
|
|
|
#define REG_STATE_UNREGISTERED 0x2
|
|
|
|
#define REG_STATE_UNUSED 0x3
|
|
|
|
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
static DEFINE_IDA(mem_id_pool);
|
|
|
|
static DEFINE_MUTEX(mem_id_lock);
|
|
|
|
#define MEM_ID_MAX 0xFFFE
|
|
|
|
#define MEM_ID_MIN 1
|
|
|
|
static int mem_id_next = MEM_ID_MIN;
|
|
|
|
|
|
|
|
static bool mem_id_init; /* false */
|
|
|
|
static struct rhashtable *mem_id_ht;
|
|
|
|
|
|
|
|
static u32 xdp_mem_id_hashfn(const void *data, u32 len, u32 seed)
|
|
|
|
{
|
|
|
|
const u32 *k = data;
|
|
|
|
const u32 key = *k;
|
|
|
|
|
2019-12-09 18:31:43 +00:00
|
|
|
BUILD_BUG_ON(sizeof_field(struct xdp_mem_allocator, mem.id)
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
!= sizeof(u32));
|
|
|
|
|
2018-06-18 02:52:50 +00:00
|
|
|
/* Use cyclic increasing ID as direct hash key */
|
|
|
|
return key;
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int xdp_mem_id_cmp(struct rhashtable_compare_arg *arg,
|
|
|
|
const void *ptr)
|
|
|
|
{
|
|
|
|
const struct xdp_mem_allocator *xa = ptr;
|
|
|
|
u32 mem_id = *(u32 *)arg->key;
|
|
|
|
|
|
|
|
return xa->mem.id != mem_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct rhashtable_params mem_id_rht_params = {
|
|
|
|
.nelem_hint = 64,
|
|
|
|
.head_offset = offsetof(struct xdp_mem_allocator, node),
|
|
|
|
.key_offset = offsetof(struct xdp_mem_allocator, mem.id),
|
2019-12-09 18:31:43 +00:00
|
|
|
.key_len = sizeof_field(struct xdp_mem_allocator, mem.id),
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
.max_size = MEM_ID_MAX,
|
|
|
|
.min_size = 8,
|
|
|
|
.automatic_shrinking = true,
|
|
|
|
.hashfn = xdp_mem_id_hashfn,
|
|
|
|
.obj_cmpfn = xdp_mem_id_cmp,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void __xdp_mem_allocator_rcu_free(struct rcu_head *rcu)
|
|
|
|
{
|
|
|
|
struct xdp_mem_allocator *xa;
|
|
|
|
|
|
|
|
xa = container_of(rcu, struct xdp_mem_allocator, rcu);
|
|
|
|
|
|
|
|
/* Allow this ID to be reused */
|
2024-01-20 07:02:20 +00:00
|
|
|
ida_free(&mem_id_pool, xa->mem.id);
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
|
|
|
|
kfree(xa);
|
|
|
|
}
|
|
|
|
|
2019-11-14 22:13:00 +00:00
|
|
|
static void mem_xa_remove(struct xdp_mem_allocator *xa)
|
xdp: tracking page_pool resources and safe removal
This patch is needed before we can allow drivers to use page_pool for
DMA-mappings. Today with page_pool and XDP return API, it is possible to
remove the page_pool object (from rhashtable), while there are still
in-flight packet-pages. This is safely handled via RCU and failed lookups in
__xdp_return() fallback to call put_page(), when page_pool object is gone.
In-case page is still DMA mapped, this will result in page note getting
correctly DMA unmapped.
To solve this, the page_pool is extended with tracking in-flight pages. And
XDP disconnect system queries page_pool and waits, via workqueue, for all
in-flight pages to be returned.
To avoid killing performance when tracking in-flight pages, the implement
use two (unsigned) counters, that in placed on different cache-lines, and
can be used to deduct in-flight packets. This is done by mapping the
unsigned "sequence" counters onto signed Two's complement arithmetic
operations. This is e.g. used by kernel's time_after macros, described in
kernel commit 1ba3aab3033b and 5a581b367b5, and also explained in RFC1982.
The trick is these two incrementing counters only need to be read and
compared, when checking if it's safe to free the page_pool structure. Which
will only happen when driver have disconnected RX/alloc side. Thus, on a
non-fast-path.
It is chosen that page_pool tracking is also enabled for the non-DMA
use-case, as this can be used for statistics later.
After this patch, using page_pool requires more strict resource "release",
e.g. via page_pool_release_page() that was introduced in this patchset, and
previous patches implement/fix this more strict requirement.
Drivers no-longer call page_pool_destroy(). Drivers already call
xdp_rxq_info_unreg() which call xdp_rxq_info_unreg_mem_model(), which will
attempt to disconnect the mem id, and if attempt fails schedule the
disconnect for later via delayed workqueue.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-18 13:05:47 +00:00
|
|
|
{
|
2019-11-14 22:13:00 +00:00
|
|
|
trace_mem_disconnect(xa);
|
xdp: tracking page_pool resources and safe removal
This patch is needed before we can allow drivers to use page_pool for
DMA-mappings. Today with page_pool and XDP return API, it is possible to
remove the page_pool object (from rhashtable), while there are still
in-flight packet-pages. This is safely handled via RCU and failed lookups in
__xdp_return() fallback to call put_page(), when page_pool object is gone.
In-case page is still DMA mapped, this will result in page note getting
correctly DMA unmapped.
To solve this, the page_pool is extended with tracking in-flight pages. And
XDP disconnect system queries page_pool and waits, via workqueue, for all
in-flight pages to be returned.
To avoid killing performance when tracking in-flight pages, the implement
use two (unsigned) counters, that in placed on different cache-lines, and
can be used to deduct in-flight packets. This is done by mapping the
unsigned "sequence" counters onto signed Two's complement arithmetic
operations. This is e.g. used by kernel's time_after macros, described in
kernel commit 1ba3aab3033b and 5a581b367b5, and also explained in RFC1982.
The trick is these two incrementing counters only need to be read and
compared, when checking if it's safe to free the page_pool structure. Which
will only happen when driver have disconnected RX/alloc side. Thus, on a
non-fast-path.
It is chosen that page_pool tracking is also enabled for the non-DMA
use-case, as this can be used for statistics later.
After this patch, using page_pool requires more strict resource "release",
e.g. via page_pool_release_page() that was introduced in this patchset, and
previous patches implement/fix this more strict requirement.
Drivers no-longer call page_pool_destroy(). Drivers already call
xdp_rxq_info_unreg() which call xdp_rxq_info_unreg_mem_model(), which will
attempt to disconnect the mem id, and if attempt fails schedule the
disconnect for later via delayed workqueue.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-18 13:05:47 +00:00
|
|
|
|
2019-11-14 22:13:00 +00:00
|
|
|
if (!rhashtable_remove_fast(mem_id_ht, &xa->node, mem_id_rht_params))
|
xdp: tracking page_pool resources and safe removal
This patch is needed before we can allow drivers to use page_pool for
DMA-mappings. Today with page_pool and XDP return API, it is possible to
remove the page_pool object (from rhashtable), while there are still
in-flight packet-pages. This is safely handled via RCU and failed lookups in
__xdp_return() fallback to call put_page(), when page_pool object is gone.
In-case page is still DMA mapped, this will result in page note getting
correctly DMA unmapped.
To solve this, the page_pool is extended with tracking in-flight pages. And
XDP disconnect system queries page_pool and waits, via workqueue, for all
in-flight pages to be returned.
To avoid killing performance when tracking in-flight pages, the implement
use two (unsigned) counters, that in placed on different cache-lines, and
can be used to deduct in-flight packets. This is done by mapping the
unsigned "sequence" counters onto signed Two's complement arithmetic
operations. This is e.g. used by kernel's time_after macros, described in
kernel commit 1ba3aab3033b and 5a581b367b5, and also explained in RFC1982.
The trick is these two incrementing counters only need to be read and
compared, when checking if it's safe to free the page_pool structure. Which
will only happen when driver have disconnected RX/alloc side. Thus, on a
non-fast-path.
It is chosen that page_pool tracking is also enabled for the non-DMA
use-case, as this can be used for statistics later.
After this patch, using page_pool requires more strict resource "release",
e.g. via page_pool_release_page() that was introduced in this patchset, and
previous patches implement/fix this more strict requirement.
Drivers no-longer call page_pool_destroy(). Drivers already call
xdp_rxq_info_unreg() which call xdp_rxq_info_unreg_mem_model(), which will
attempt to disconnect the mem id, and if attempt fails schedule the
disconnect for later via delayed workqueue.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-18 13:05:47 +00:00
|
|
|
call_rcu(&xa->rcu, __xdp_mem_allocator_rcu_free);
|
|
|
|
}
|
|
|
|
|
2019-11-14 22:13:00 +00:00
|
|
|
static void mem_allocator_disconnect(void *allocator)
|
|
|
|
{
|
|
|
|
struct xdp_mem_allocator *xa;
|
|
|
|
struct rhashtable_iter iter;
|
|
|
|
|
2019-12-03 22:01:14 +00:00
|
|
|
mutex_lock(&mem_id_lock);
|
|
|
|
|
2019-11-14 22:13:00 +00:00
|
|
|
rhashtable_walk_enter(mem_id_ht, &iter);
|
|
|
|
do {
|
|
|
|
rhashtable_walk_start(&iter);
|
|
|
|
|
|
|
|
while ((xa = rhashtable_walk_next(&iter)) && !IS_ERR(xa)) {
|
|
|
|
if (xa->allocator == allocator)
|
|
|
|
mem_xa_remove(xa);
|
|
|
|
}
|
|
|
|
|
|
|
|
rhashtable_walk_stop(&iter);
|
xdp: tracking page_pool resources and safe removal
This patch is needed before we can allow drivers to use page_pool for
DMA-mappings. Today with page_pool and XDP return API, it is possible to
remove the page_pool object (from rhashtable), while there are still
in-flight packet-pages. This is safely handled via RCU and failed lookups in
__xdp_return() fallback to call put_page(), when page_pool object is gone.
In-case page is still DMA mapped, this will result in page note getting
correctly DMA unmapped.
To solve this, the page_pool is extended with tracking in-flight pages. And
XDP disconnect system queries page_pool and waits, via workqueue, for all
in-flight pages to be returned.
To avoid killing performance when tracking in-flight pages, the implement
use two (unsigned) counters, that in placed on different cache-lines, and
can be used to deduct in-flight packets. This is done by mapping the
unsigned "sequence" counters onto signed Two's complement arithmetic
operations. This is e.g. used by kernel's time_after macros, described in
kernel commit 1ba3aab3033b and 5a581b367b5, and also explained in RFC1982.
The trick is these two incrementing counters only need to be read and
compared, when checking if it's safe to free the page_pool structure. Which
will only happen when driver have disconnected RX/alloc side. Thus, on a
non-fast-path.
It is chosen that page_pool tracking is also enabled for the non-DMA
use-case, as this can be used for statistics later.
After this patch, using page_pool requires more strict resource "release",
e.g. via page_pool_release_page() that was introduced in this patchset, and
previous patches implement/fix this more strict requirement.
Drivers no-longer call page_pool_destroy(). Drivers already call
xdp_rxq_info_unreg() which call xdp_rxq_info_unreg_mem_model(), which will
attempt to disconnect the mem id, and if attempt fails schedule the
disconnect for later via delayed workqueue.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-18 13:05:47 +00:00
|
|
|
|
2019-11-14 22:13:00 +00:00
|
|
|
} while (xa == ERR_PTR(-EAGAIN));
|
|
|
|
rhashtable_walk_exit(&iter);
|
2019-12-03 22:01:14 +00:00
|
|
|
|
|
|
|
mutex_unlock(&mem_id_lock);
|
2019-11-14 22:13:00 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 15:08:06 +00:00
|
|
|
void xdp_unreg_mem_model(struct xdp_mem_info *mem)
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
{
|
|
|
|
struct xdp_mem_allocator *xa;
|
2022-01-03 15:08:06 +00:00
|
|
|
int type = mem->type;
|
|
|
|
int id = mem->id;
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
|
2021-06-25 22:16:12 +00:00
|
|
|
/* Reset mem info to defaults */
|
2022-01-03 15:08:06 +00:00
|
|
|
mem->id = 0;
|
|
|
|
mem->type = 0;
|
2018-08-28 12:44:26 +00:00
|
|
|
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
if (id == 0)
|
|
|
|
return;
|
|
|
|
|
2021-06-25 22:16:12 +00:00
|
|
|
if (type == MEM_TYPE_PAGE_POOL) {
|
2019-11-14 22:13:00 +00:00
|
|
|
rcu_read_lock();
|
|
|
|
xa = rhashtable_lookup(mem_id_ht, &id, mem_id_rht_params);
|
|
|
|
page_pool_destroy(xa->page_pool);
|
|
|
|
rcu_read_unlock();
|
xdp: tracking page_pool resources and safe removal
This patch is needed before we can allow drivers to use page_pool for
DMA-mappings. Today with page_pool and XDP return API, it is possible to
remove the page_pool object (from rhashtable), while there are still
in-flight packet-pages. This is safely handled via RCU and failed lookups in
__xdp_return() fallback to call put_page(), when page_pool object is gone.
In-case page is still DMA mapped, this will result in page note getting
correctly DMA unmapped.
To solve this, the page_pool is extended with tracking in-flight pages. And
XDP disconnect system queries page_pool and waits, via workqueue, for all
in-flight pages to be returned.
To avoid killing performance when tracking in-flight pages, the implement
use two (unsigned) counters, that in placed on different cache-lines, and
can be used to deduct in-flight packets. This is done by mapping the
unsigned "sequence" counters onto signed Two's complement arithmetic
operations. This is e.g. used by kernel's time_after macros, described in
kernel commit 1ba3aab3033b and 5a581b367b5, and also explained in RFC1982.
The trick is these two incrementing counters only need to be read and
compared, when checking if it's safe to free the page_pool structure. Which
will only happen when driver have disconnected RX/alloc side. Thus, on a
non-fast-path.
It is chosen that page_pool tracking is also enabled for the non-DMA
use-case, as this can be used for statistics later.
After this patch, using page_pool requires more strict resource "release",
e.g. via page_pool_release_page() that was introduced in this patchset, and
previous patches implement/fix this more strict requirement.
Drivers no-longer call page_pool_destroy(). Drivers already call
xdp_rxq_info_unreg() which call xdp_rxq_info_unreg_mem_model(), which will
attempt to disconnect the mem id, and if attempt fails schedule the
disconnect for later via delayed workqueue.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-18 13:05:47 +00:00
|
|
|
}
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
}
|
2022-01-03 15:08:06 +00:00
|
|
|
EXPORT_SYMBOL_GPL(xdp_unreg_mem_model);
|
|
|
|
|
|
|
|
void xdp_rxq_info_unreg_mem_model(struct xdp_rxq_info *xdp_rxq)
|
|
|
|
{
|
|
|
|
if (xdp_rxq->reg_state != REG_STATE_REGISTERED) {
|
|
|
|
WARN(1, "Missing register, driver bug");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xdp_unreg_mem_model(&xdp_rxq->mem);
|
|
|
|
}
|
2018-08-28 12:44:26 +00:00
|
|
|
EXPORT_SYMBOL_GPL(xdp_rxq_info_unreg_mem_model);
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
|
2018-01-03 10:25:13 +00:00
|
|
|
void xdp_rxq_info_unreg(struct xdp_rxq_info *xdp_rxq)
|
|
|
|
{
|
|
|
|
/* Simplify driver cleanup code paths, allow unreg "unused" */
|
|
|
|
if (xdp_rxq->reg_state == REG_STATE_UNUSED)
|
|
|
|
return;
|
|
|
|
|
2018-08-28 12:44:26 +00:00
|
|
|
xdp_rxq_info_unreg_mem_model(xdp_rxq);
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
|
2018-01-03 10:25:13 +00:00
|
|
|
xdp_rxq->reg_state = REG_STATE_UNREGISTERED;
|
|
|
|
xdp_rxq->dev = NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_rxq_info_unreg);
|
|
|
|
|
|
|
|
static void xdp_rxq_info_init(struct xdp_rxq_info *xdp_rxq)
|
|
|
|
{
|
|
|
|
memset(xdp_rxq, 0, sizeof(*xdp_rxq));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns 0 on success, negative on failure */
|
2022-01-21 10:09:55 +00:00
|
|
|
int __xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq,
|
|
|
|
struct net_device *dev, u32 queue_index,
|
|
|
|
unsigned int napi_id, u32 frag_size)
|
2018-01-03 10:25:13 +00:00
|
|
|
{
|
2021-12-17 09:25:45 +00:00
|
|
|
if (!dev) {
|
|
|
|
WARN(1, "Missing net_device from driver");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2018-01-03 10:25:13 +00:00
|
|
|
if (xdp_rxq->reg_state == REG_STATE_UNUSED) {
|
|
|
|
WARN(1, "Driver promised not to register this");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xdp_rxq->reg_state == REG_STATE_REGISTERED) {
|
|
|
|
WARN(1, "Missing unregister, handled but fix driver");
|
|
|
|
xdp_rxq_info_unreg(xdp_rxq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* State either UNREGISTERED or NEW */
|
|
|
|
xdp_rxq_info_init(xdp_rxq);
|
|
|
|
xdp_rxq->dev = dev;
|
|
|
|
xdp_rxq->queue_index = queue_index;
|
2020-11-30 18:52:01 +00:00
|
|
|
xdp_rxq->napi_id = napi_id;
|
2022-01-21 10:09:55 +00:00
|
|
|
xdp_rxq->frag_size = frag_size;
|
2018-01-03 10:25:13 +00:00
|
|
|
|
|
|
|
xdp_rxq->reg_state = REG_STATE_REGISTERED;
|
|
|
|
return 0;
|
|
|
|
}
|
2022-01-21 10:09:55 +00:00
|
|
|
EXPORT_SYMBOL_GPL(__xdp_rxq_info_reg);
|
2018-01-03 10:25:13 +00:00
|
|
|
|
|
|
|
void xdp_rxq_info_unused(struct xdp_rxq_info *xdp_rxq)
|
|
|
|
{
|
|
|
|
xdp_rxq->reg_state = REG_STATE_UNUSED;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_rxq_info_unused);
|
2018-01-03 10:25:34 +00:00
|
|
|
|
|
|
|
bool xdp_rxq_info_is_reg(struct xdp_rxq_info *xdp_rxq)
|
|
|
|
{
|
|
|
|
return (xdp_rxq->reg_state == REG_STATE_REGISTERED);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_rxq_info_is_reg);
|
2018-04-17 14:45:26 +00:00
|
|
|
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
static int __mem_id_init_hash_table(void)
|
|
|
|
{
|
|
|
|
struct rhashtable *rht;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (unlikely(mem_id_init))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rht = kzalloc(sizeof(*rht), GFP_KERNEL);
|
|
|
|
if (!rht)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = rhashtable_init(rht, &mem_id_rht_params);
|
|
|
|
if (ret < 0) {
|
|
|
|
kfree(rht);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
mem_id_ht = rht;
|
|
|
|
smp_mb(); /* mutex lock should provide enough pairing */
|
|
|
|
mem_id_init = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a cyclic ID that maps to allocator pointer.
|
|
|
|
* See: https://www.kernel.org/doc/html/latest/core-api/idr.html
|
|
|
|
*
|
|
|
|
* Caller must lock mem_id_lock.
|
|
|
|
*/
|
|
|
|
static int __mem_id_cyclic_get(gfp_t gfp)
|
|
|
|
{
|
|
|
|
int retries = 1;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
again:
|
2024-01-20 07:02:20 +00:00
|
|
|
id = ida_alloc_range(&mem_id_pool, mem_id_next, MEM_ID_MAX - 1, gfp);
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
if (id < 0) {
|
|
|
|
if (id == -ENOSPC) {
|
|
|
|
/* Cyclic allocator, reset next id */
|
|
|
|
if (retries--) {
|
|
|
|
mem_id_next = MEM_ID_MIN;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return id; /* errno */
|
|
|
|
}
|
|
|
|
mem_id_next = id + 1;
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:46:22 +00:00
|
|
|
static bool __is_supported_mem_type(enum xdp_mem_type type)
|
|
|
|
{
|
|
|
|
if (type == MEM_TYPE_PAGE_POOL)
|
|
|
|
return is_page_pool_compiled_in();
|
|
|
|
|
|
|
|
if (type >= MEM_TYPE_MAX)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-03 15:08:06 +00:00
|
|
|
static struct xdp_mem_allocator *__xdp_reg_mem_model(struct xdp_mem_info *mem,
|
|
|
|
enum xdp_mem_type type,
|
|
|
|
void *allocator)
|
2018-04-17 14:45:26 +00:00
|
|
|
{
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
struct xdp_mem_allocator *xdp_alloc;
|
|
|
|
gfp_t gfp = GFP_KERNEL;
|
|
|
|
int id, errno, ret;
|
|
|
|
void *ptr;
|
|
|
|
|
2018-04-17 14:46:22 +00:00
|
|
|
if (!__is_supported_mem_type(type))
|
2022-01-03 15:08:06 +00:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
2018-04-17 14:45:26 +00:00
|
|
|
|
2022-01-03 15:08:06 +00:00
|
|
|
mem->type = type;
|
2018-04-17 14:45:26 +00:00
|
|
|
|
2018-04-17 14:46:22 +00:00
|
|
|
if (!allocator) {
|
2020-05-20 19:21:00 +00:00
|
|
|
if (type == MEM_TYPE_PAGE_POOL)
|
2022-01-03 15:08:06 +00:00
|
|
|
return ERR_PTR(-EINVAL); /* Setup time check page_pool req */
|
|
|
|
return NULL;
|
2018-04-17 14:46:22 +00:00
|
|
|
}
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
|
|
|
|
/* Delay init of rhashtable to save memory if feature isn't used */
|
|
|
|
if (!mem_id_init) {
|
|
|
|
mutex_lock(&mem_id_lock);
|
|
|
|
ret = __mem_id_init_hash_table();
|
|
|
|
mutex_unlock(&mem_id_lock);
|
2024-06-24 08:07:47 +00:00
|
|
|
if (ret < 0)
|
2022-01-03 15:08:06 +00:00
|
|
|
return ERR_PTR(ret);
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xdp_alloc = kzalloc(sizeof(*xdp_alloc), gfp);
|
|
|
|
if (!xdp_alloc)
|
2022-01-03 15:08:06 +00:00
|
|
|
return ERR_PTR(-ENOMEM);
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
|
|
|
|
mutex_lock(&mem_id_lock);
|
|
|
|
id = __mem_id_cyclic_get(gfp);
|
|
|
|
if (id < 0) {
|
|
|
|
errno = id;
|
|
|
|
goto err;
|
|
|
|
}
|
2022-01-03 15:08:06 +00:00
|
|
|
mem->id = id;
|
|
|
|
xdp_alloc->mem = *mem;
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
xdp_alloc->allocator = allocator;
|
|
|
|
|
|
|
|
/* Insert allocator into ID lookup table */
|
|
|
|
ptr = rhashtable_insert_slow(mem_id_ht, &id, &xdp_alloc->node);
|
|
|
|
if (IS_ERR(ptr)) {
|
2024-01-20 07:02:20 +00:00
|
|
|
ida_free(&mem_id_pool, mem->id);
|
2022-01-03 15:08:06 +00:00
|
|
|
mem->id = 0;
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
errno = PTR_ERR(ptr);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2019-07-08 21:34:28 +00:00
|
|
|
if (type == MEM_TYPE_PAGE_POOL)
|
2022-01-03 15:08:08 +00:00
|
|
|
page_pool_use_xdp_mem(allocator, mem_allocator_disconnect, mem);
|
2019-07-08 21:34:28 +00:00
|
|
|
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
mutex_unlock(&mem_id_lock);
|
2018-04-17 14:45:26 +00:00
|
|
|
|
2022-01-03 15:08:06 +00:00
|
|
|
return xdp_alloc;
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
err:
|
|
|
|
mutex_unlock(&mem_id_lock);
|
|
|
|
kfree(xdp_alloc);
|
2022-01-03 15:08:06 +00:00
|
|
|
return ERR_PTR(errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
int xdp_reg_mem_model(struct xdp_mem_info *mem,
|
|
|
|
enum xdp_mem_type type, void *allocator)
|
|
|
|
{
|
|
|
|
struct xdp_mem_allocator *xdp_alloc;
|
|
|
|
|
|
|
|
xdp_alloc = __xdp_reg_mem_model(mem, type, allocator);
|
|
|
|
if (IS_ERR(xdp_alloc))
|
|
|
|
return PTR_ERR(xdp_alloc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_reg_mem_model);
|
|
|
|
|
|
|
|
int xdp_rxq_info_reg_mem_model(struct xdp_rxq_info *xdp_rxq,
|
|
|
|
enum xdp_mem_type type, void *allocator)
|
|
|
|
{
|
|
|
|
struct xdp_mem_allocator *xdp_alloc;
|
|
|
|
|
|
|
|
if (xdp_rxq->reg_state != REG_STATE_REGISTERED) {
|
|
|
|
WARN(1, "Missing register, driver bug");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
xdp_alloc = __xdp_reg_mem_model(&xdp_rxq->mem, type, allocator);
|
|
|
|
if (IS_ERR(xdp_alloc))
|
|
|
|
return PTR_ERR(xdp_alloc);
|
|
|
|
|
2022-03-09 22:13:45 +00:00
|
|
|
if (trace_mem_connect_enabled() && xdp_alloc)
|
|
|
|
trace_mem_connect(xdp_alloc, xdp_rxq);
|
2022-01-03 15:08:06 +00:00
|
|
|
return 0;
|
2018-04-17 14:45:26 +00:00
|
|
|
}
|
2022-01-03 15:08:06 +00:00
|
|
|
|
2018-04-17 14:45:26 +00:00
|
|
|
EXPORT_SYMBOL_GPL(xdp_rxq_info_reg_mem_model);
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
|
2018-05-24 14:46:07 +00:00
|
|
|
/* XDP RX runs under NAPI protection, and in different delivery error
|
|
|
|
* scenarios (e.g. queue full), it is possible to return the xdp_frame
|
2019-10-11 08:43:03 +00:00
|
|
|
* while still leveraging this protection. The @napi_direct boolean
|
2018-05-24 14:46:07 +00:00
|
|
|
* is used for those calls sites. Thus, allowing for faster recycling
|
2020-11-27 17:17:26 +00:00
|
|
|
* of xdp_frames/pages in those cases.
|
2018-05-24 14:46:07 +00:00
|
|
|
*/
|
2022-01-21 10:09:55 +00:00
|
|
|
void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
|
|
|
|
struct xdp_buff *xdp)
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
{
|
2018-04-17 14:46:22 +00:00
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
switch (mem->type) {
|
|
|
|
case MEM_TYPE_PAGE_POOL:
|
|
|
|
page = virt_to_head_page(data);
|
2021-03-31 13:25:03 +00:00
|
|
|
if (napi_direct && xdp_return_frame_no_direct())
|
|
|
|
napi_direct = false;
|
2022-09-21 17:05:32 +00:00
|
|
|
/* No need to check ((page->pp_magic & ~0x3UL) == PP_SIGNATURE)
|
|
|
|
* as mem->type knows this a page_pool page
|
|
|
|
*/
|
|
|
|
page_pool_put_full_page(page->pp, page, napi_direct);
|
2018-04-17 14:46:22 +00:00
|
|
|
break;
|
|
|
|
case MEM_TYPE_PAGE_SHARED:
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
page_frag_free(data);
|
2018-04-17 14:46:22 +00:00
|
|
|
break;
|
|
|
|
case MEM_TYPE_PAGE_ORDER0:
|
|
|
|
page = virt_to_page(data); /* Assumes order0 page*/
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
put_page(page);
|
2018-04-17 14:46:22 +00:00
|
|
|
break;
|
2020-11-27 17:17:26 +00:00
|
|
|
case MEM_TYPE_XSK_BUFF_POOL:
|
|
|
|
/* NB! Only valid from an xdp_buff! */
|
|
|
|
xsk_buff_free(xdp);
|
|
|
|
break;
|
2018-04-17 14:46:22 +00:00
|
|
|
default:
|
|
|
|
/* Not possible, checked in xdp_rxq_info_reg_mem_model() */
|
2020-05-20 19:21:01 +00:00
|
|
|
WARN(1, "Incorrect XDP memory type (%d) usage", mem->type);
|
2018-04-17 14:46:22 +00:00
|
|
|
break;
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-02 11:01:27 +00:00
|
|
|
|
|
|
|
void xdp_return_frame(struct xdp_frame *xdpf)
|
|
|
|
{
|
2022-01-21 10:09:50 +00:00
|
|
|
struct skb_shared_info *sinfo;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (likely(!xdp_frame_has_frags(xdpf)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sinfo = xdp_get_shared_info_from_frame(xdpf);
|
|
|
|
for (i = 0; i < sinfo->nr_frags; i++) {
|
|
|
|
struct page *page = skb_frag_page(&sinfo->frags[i]);
|
|
|
|
|
|
|
|
__xdp_return(page_address(page), &xdpf->mem, false, NULL);
|
|
|
|
}
|
|
|
|
out:
|
2020-11-27 17:17:26 +00:00
|
|
|
__xdp_return(xdpf->data, &xdpf->mem, false, NULL);
|
2018-05-02 11:01:27 +00:00
|
|
|
}
|
xdp: rhashtable with allocator ID to pointer mapping
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info. Instead of using the IDR infrastructure, which
uses a radix tree, use a dynamic rhashtable, for creating ID to
pointer lookup table, because this is faster.
The problem that is being solved here is that, the xdp_rxq_info
pointer (stored in xdp_buff) cannot be used directly, as the
guaranteed lifetime is too short. The info is needed on a
(potentially) remote CPU during DMA-TX completion time . In an
xdp_frame the xdp_mem_info is stored, when it got converted from an
xdp_buff, which is sufficient for the simple page refcnt based recycle
schemes.
For more advanced allocators there is a need to store a pointer to the
registered allocator. Thus, there is a need to guard the lifetime or
validity of the allocator pointer, which is done through this
rhashtable ID map to pointer. The removal and validity of of the
allocator and helper struct xdp_mem_allocator is guarded by RCU. The
allocator will be created by the driver, and registered with
xdp_rxq_info_reg_mem_model().
It is up-to debate who is responsible for freeing the allocator
pointer or invoking the allocator destructor function. In any case,
this must happen via RCU freeing.
Use the IDA infrastructure for getting a cyclic increasing ID number,
that is used for keeping track of each registered allocator per
RX-queue xdp_rxq_info.
V4: Per req of Jason Wang
- Use xdp_rxq_info_reg_mem_model() in all drivers implementing
XDP_REDIRECT, even-though it's not strictly necessary when
allocator==NULL for type MEM_TYPE_PAGE_SHARED (given it's zero).
V6: Per req of Alex Duyck
- Introduce rhashtable_lookup() call in later patch
V8: Address sparse should be static warnings (from kbuild test robot)
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-17 14:46:12 +00:00
|
|
|
EXPORT_SYMBOL_GPL(xdp_return_frame);
|
2018-05-02 11:01:27 +00:00
|
|
|
|
2018-05-24 14:46:07 +00:00
|
|
|
void xdp_return_frame_rx_napi(struct xdp_frame *xdpf)
|
|
|
|
{
|
2022-01-21 10:09:50 +00:00
|
|
|
struct skb_shared_info *sinfo;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (likely(!xdp_frame_has_frags(xdpf)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sinfo = xdp_get_shared_info_from_frame(xdpf);
|
|
|
|
for (i = 0; i < sinfo->nr_frags; i++) {
|
|
|
|
struct page *page = skb_frag_page(&sinfo->frags[i]);
|
|
|
|
|
|
|
|
__xdp_return(page_address(page), &xdpf->mem, true, NULL);
|
|
|
|
}
|
|
|
|
out:
|
2020-11-27 17:17:26 +00:00
|
|
|
__xdp_return(xdpf->data, &xdpf->mem, true, NULL);
|
2018-05-24 14:46:07 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_return_frame_rx_napi);
|
|
|
|
|
2020-11-13 11:48:28 +00:00
|
|
|
/* XDP bulk APIs introduce a defer/flush mechanism to return
|
|
|
|
* pages belonging to the same xdp_mem_allocator object
|
|
|
|
* (identified via the mem.id field) in bulk to optimize
|
|
|
|
* I-cache and D-cache.
|
|
|
|
* The bulk queue size is set to 16 to be aligned to how
|
|
|
|
* XDP_REDIRECT bulking works. The bulk is flushed when
|
|
|
|
* it is full or when mem.id changes.
|
|
|
|
* xdp_frame_bulk is usually stored/allocated on the function
|
|
|
|
* call-stack to avoid locking penalties.
|
|
|
|
*/
|
|
|
|
void xdp_flush_frame_bulk(struct xdp_frame_bulk *bq)
|
|
|
|
{
|
|
|
|
struct xdp_mem_allocator *xa = bq->xa;
|
|
|
|
|
2020-11-13 11:48:29 +00:00
|
|
|
if (unlikely(!xa || !bq->count))
|
2020-11-13 11:48:28 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-13 11:48:29 +00:00
|
|
|
page_pool_put_page_bulk(xa->page_pool, bq->q, bq->count);
|
2020-11-13 11:48:28 +00:00
|
|
|
/* bq->xa is not cleared to save lookup, if mem.id same in next bulk */
|
|
|
|
bq->count = 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_flush_frame_bulk);
|
|
|
|
|
|
|
|
/* Must be called with rcu_read_lock held */
|
|
|
|
void xdp_return_frame_bulk(struct xdp_frame *xdpf,
|
|
|
|
struct xdp_frame_bulk *bq)
|
|
|
|
{
|
|
|
|
struct xdp_mem_info *mem = &xdpf->mem;
|
|
|
|
struct xdp_mem_allocator *xa;
|
|
|
|
|
|
|
|
if (mem->type != MEM_TYPE_PAGE_POOL) {
|
2022-01-21 10:09:50 +00:00
|
|
|
xdp_return_frame(xdpf);
|
2020-11-13 11:48:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xa = bq->xa;
|
|
|
|
if (unlikely(!xa)) {
|
|
|
|
xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params);
|
|
|
|
bq->count = 0;
|
|
|
|
bq->xa = xa;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bq->count == XDP_BULK_QUEUE_SIZE)
|
|
|
|
xdp_flush_frame_bulk(bq);
|
|
|
|
|
|
|
|
if (unlikely(mem->id != xa->mem.id)) {
|
|
|
|
xdp_flush_frame_bulk(bq);
|
|
|
|
bq->xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params);
|
|
|
|
}
|
|
|
|
|
2022-01-21 10:09:50 +00:00
|
|
|
if (unlikely(xdp_frame_has_frags(xdpf))) {
|
|
|
|
struct skb_shared_info *sinfo;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sinfo = xdp_get_shared_info_from_frame(xdpf);
|
|
|
|
for (i = 0; i < sinfo->nr_frags; i++) {
|
|
|
|
skb_frag_t *frag = &sinfo->frags[i];
|
|
|
|
|
|
|
|
bq->q[bq->count++] = skb_frag_address(frag);
|
|
|
|
if (bq->count == XDP_BULK_QUEUE_SIZE)
|
|
|
|
xdp_flush_frame_bulk(bq);
|
|
|
|
}
|
|
|
|
}
|
2020-11-13 11:48:28 +00:00
|
|
|
bq->q[bq->count++] = xdpf->data;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_return_frame_bulk);
|
|
|
|
|
2018-05-02 11:01:27 +00:00
|
|
|
void xdp_return_buff(struct xdp_buff *xdp)
|
|
|
|
{
|
2022-01-21 10:09:50 +00:00
|
|
|
struct skb_shared_info *sinfo;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (likely(!xdp_buff_has_frags(xdp)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sinfo = xdp_get_shared_info_from_buff(xdp);
|
|
|
|
for (i = 0; i < sinfo->nr_frags; i++) {
|
|
|
|
struct page *page = skb_frag_page(&sinfo->frags[i]);
|
|
|
|
|
|
|
|
__xdp_return(page_address(page), &xdp->rxq->mem, true, xdp);
|
|
|
|
}
|
|
|
|
out:
|
2020-11-27 17:17:26 +00:00
|
|
|
__xdp_return(xdp->data, &xdp->rxq->mem, true, xdp);
|
2018-05-02 11:01:27 +00:00
|
|
|
}
|
2022-03-11 09:14:19 +00:00
|
|
|
EXPORT_SYMBOL_GPL(xdp_return_buff);
|
2018-07-12 03:36:40 +00:00
|
|
|
|
|
|
|
void xdp_attachment_setup(struct xdp_attachment_info *info,
|
|
|
|
struct netdev_bpf *bpf)
|
|
|
|
{
|
|
|
|
if (info->prog)
|
|
|
|
bpf_prog_put(info->prog);
|
|
|
|
info->prog = bpf->prog;
|
|
|
|
info->flags = bpf->flags;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_attachment_setup);
|
2018-08-28 12:44:25 +00:00
|
|
|
|
|
|
|
struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp)
|
|
|
|
{
|
2018-08-30 14:27:18 +00:00
|
|
|
unsigned int metasize, totsize;
|
2018-08-28 12:44:25 +00:00
|
|
|
void *addr, *data_to_copy;
|
|
|
|
struct xdp_frame *xdpf;
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
/* Clone into a MEM_TYPE_PAGE_ORDER0 xdp_frame. */
|
|
|
|
metasize = xdp_data_meta_unsupported(xdp) ? 0 :
|
|
|
|
xdp->data - xdp->data_meta;
|
|
|
|
totsize = xdp->data_end - xdp->data + metasize;
|
|
|
|
|
|
|
|
if (sizeof(*xdpf) + totsize > PAGE_SIZE)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
page = dev_alloc_page();
|
|
|
|
if (!page)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
addr = page_to_virt(page);
|
|
|
|
xdpf = addr;
|
|
|
|
memset(xdpf, 0, sizeof(*xdpf));
|
|
|
|
|
|
|
|
addr += sizeof(*xdpf);
|
|
|
|
data_to_copy = metasize ? xdp->data_meta : xdp->data;
|
|
|
|
memcpy(addr, data_to_copy, totsize);
|
|
|
|
|
|
|
|
xdpf->data = addr + metasize;
|
|
|
|
xdpf->len = totsize - metasize;
|
|
|
|
xdpf->headroom = 0;
|
|
|
|
xdpf->metasize = metasize;
|
2020-06-16 10:35:18 +00:00
|
|
|
xdpf->frame_sz = PAGE_SIZE;
|
2018-08-28 12:44:25 +00:00
|
|
|
xdpf->mem.type = MEM_TYPE_PAGE_ORDER0;
|
|
|
|
|
2020-05-20 19:21:01 +00:00
|
|
|
xsk_buff_free(xdp);
|
2018-08-28 12:44:25 +00:00
|
|
|
return xdpf;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_convert_zc_to_xdp_frame);
|
xdp: Xdp_frame add member frame_sz and handle in convert_to_xdp_frame
Use hole in struct xdp_frame, when adding member frame_sz, which keeps
same sizeof struct (32 bytes)
Drivers ixgbe and sfc had bug cases where the necessary/expected
tailroom was not reserved. This can lead to some hard to catch memory
corruption issues. Having the drivers frame_sz this can be detected when
packet length/end via xdp->data_end exceed the xdp_data_hard_end
pointer, which accounts for the reserved the tailroom.
When detecting this driver issue, simply fail the conversion with NULL,
which results in feedback to driver (failing xdp_do_redirect()) causing
driver to drop packet. Given the lack of consistent XDP stats, this can
be hard to troubleshoot. And given this is a driver bug, we want to
generate some more noise in form of a WARN stack dump (to ID the driver
code that inlined convert_to_xdp_frame).
Inlining the WARN macro is problematic, because it adds an asm
instruction (on Intel CPUs ud2) what influence instruction cache
prefetching. Thus, introduce xdp_warn and macro XDP_WARN, to avoid this
and at the same time make identifying the function and line of this
inlined function easier.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/158945337313.97035.10015729316710496600.stgit@firesoul
2020-05-14 10:49:33 +00:00
|
|
|
|
|
|
|
/* Used by XDP_WARN macro, to avoid inlining WARN() in fast-path */
|
|
|
|
void xdp_warn(const char *msg, const char *func, const int line)
|
|
|
|
{
|
|
|
|
WARN(1, "XDP_WARN: %s(line:%d): %s\n", func, line, msg);
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_warn);
|
2021-01-12 18:26:12 +00:00
|
|
|
|
2021-01-29 22:04:08 +00:00
|
|
|
int xdp_alloc_skb_bulk(void **skbs, int n_skb, gfp_t gfp)
|
|
|
|
{
|
2024-03-06 16:00:23 +00:00
|
|
|
n_skb = kmem_cache_alloc_bulk(net_hotdata.skbuff_cache, gfp, n_skb, skbs);
|
2021-01-29 22:04:08 +00:00
|
|
|
if (unlikely(!n_skb))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_alloc_skb_bulk);
|
|
|
|
|
2021-01-12 18:26:12 +00:00
|
|
|
struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
|
|
|
|
struct sk_buff *skb,
|
|
|
|
struct net_device *dev)
|
|
|
|
{
|
2022-01-21 10:09:48 +00:00
|
|
|
struct skb_shared_info *sinfo = xdp_get_shared_info_from_frame(xdpf);
|
2021-01-12 18:26:12 +00:00
|
|
|
unsigned int headroom, frame_size;
|
|
|
|
void *hard_start;
|
2022-01-21 10:09:48 +00:00
|
|
|
u8 nr_frags;
|
|
|
|
|
|
|
|
/* xdp frags frame */
|
|
|
|
if (unlikely(xdp_frame_has_frags(xdpf)))
|
|
|
|
nr_frags = sinfo->nr_frags;
|
2021-01-12 18:26:12 +00:00
|
|
|
|
|
|
|
/* Part of headroom was reserved to xdpf */
|
|
|
|
headroom = sizeof(*xdpf) + xdpf->headroom;
|
|
|
|
|
|
|
|
/* Memory size backing xdp_frame data already have reserved
|
|
|
|
* room for build_skb to place skb_shared_info in tailroom.
|
|
|
|
*/
|
|
|
|
frame_size = xdpf->frame_sz;
|
|
|
|
|
|
|
|
hard_start = xdpf->data - headroom;
|
|
|
|
skb = build_skb_around(skb, hard_start, frame_size);
|
|
|
|
if (unlikely(!skb))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
skb_reserve(skb, headroom);
|
|
|
|
__skb_put(skb, xdpf->len);
|
|
|
|
if (xdpf->metasize)
|
|
|
|
skb_metadata_set(skb, xdpf->metasize);
|
|
|
|
|
2022-01-21 10:09:48 +00:00
|
|
|
if (unlikely(xdp_frame_has_frags(xdpf)))
|
|
|
|
xdp_update_skb_shared_info(skb, nr_frags,
|
|
|
|
sinfo->xdp_frags_size,
|
|
|
|
nr_frags * xdpf->frame_sz,
|
|
|
|
xdp_frame_is_frag_pfmemalloc(xdpf));
|
|
|
|
|
2021-01-12 18:26:12 +00:00
|
|
|
/* Essential SKB info: protocol and skb->dev */
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
|
|
|
|
|
|
|
/* Optional SKB info, currently missing:
|
|
|
|
* - HW checksum info (skb->ip_summed)
|
|
|
|
* - HW RX hash (skb_set_hash)
|
|
|
|
* - RX ring dev queue index (skb_record_rx_queue)
|
|
|
|
*/
|
|
|
|
|
2023-03-13 21:55:52 +00:00
|
|
|
if (xdpf->mem.type == MEM_TYPE_PAGE_POOL)
|
|
|
|
skb_mark_for_recycle(skb);
|
2021-01-12 18:26:12 +00:00
|
|
|
|
|
|
|
/* Allow SKB to reuse area used by xdp_frame */
|
|
|
|
xdp_scrub_frame(xdpf);
|
|
|
|
|
|
|
|
return skb;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(__xdp_build_skb_from_frame);
|
2021-01-12 18:26:13 +00:00
|
|
|
|
|
|
|
struct sk_buff *xdp_build_skb_from_frame(struct xdp_frame *xdpf,
|
|
|
|
struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
2024-03-06 16:00:23 +00:00
|
|
|
skb = kmem_cache_alloc(net_hotdata.skbuff_cache, GFP_ATOMIC);
|
2021-01-12 18:26:13 +00:00
|
|
|
if (unlikely(!skb))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memset(skb, 0, offsetof(struct sk_buff, tail));
|
|
|
|
|
|
|
|
return __xdp_build_skb_from_frame(xdpf, skb, dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_build_skb_from_frame);
|
2021-05-19 09:07:45 +00:00
|
|
|
|
|
|
|
struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf)
|
|
|
|
{
|
|
|
|
unsigned int headroom, totalsize;
|
|
|
|
struct xdp_frame *nxdpf;
|
|
|
|
struct page *page;
|
|
|
|
void *addr;
|
|
|
|
|
|
|
|
headroom = xdpf->headroom + sizeof(*xdpf);
|
|
|
|
totalsize = headroom + xdpf->len;
|
|
|
|
|
|
|
|
if (unlikely(totalsize > PAGE_SIZE))
|
|
|
|
return NULL;
|
|
|
|
page = dev_alloc_page();
|
|
|
|
if (!page)
|
|
|
|
return NULL;
|
|
|
|
addr = page_to_virt(page);
|
|
|
|
|
|
|
|
memcpy(addr, xdpf, totalsize);
|
|
|
|
|
|
|
|
nxdpf = addr;
|
|
|
|
nxdpf->data = addr + headroom;
|
|
|
|
nxdpf->frame_sz = PAGE_SIZE;
|
|
|
|
nxdpf->mem.type = MEM_TYPE_PAGE_ORDER0;
|
|
|
|
nxdpf->mem.id = 0;
|
|
|
|
|
|
|
|
return nxdpf;
|
|
|
|
}
|
2023-01-19 22:15:26 +00:00
|
|
|
|
2023-10-31 21:56:24 +00:00
|
|
|
__bpf_kfunc_start_defs();
|
2023-01-19 22:15:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* bpf_xdp_metadata_rx_timestamp - Read XDP frame RX timestamp.
|
|
|
|
* @ctx: XDP context pointer.
|
|
|
|
* @timestamp: Return value pointer.
|
|
|
|
*
|
2023-03-21 13:52:31 +00:00
|
|
|
* Return:
|
|
|
|
* * Returns 0 on success or ``-errno`` on error.
|
|
|
|
* * ``-EOPNOTSUPP`` : means device driver does not implement kfunc
|
|
|
|
* * ``-ENODATA`` : means no RX-timestamp available for this frame
|
2023-01-19 22:15:26 +00:00
|
|
|
*/
|
2023-02-01 17:30:15 +00:00
|
|
|
__bpf_kfunc int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
|
2023-01-19 22:15:26 +00:00
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bpf_xdp_metadata_rx_hash - Read XDP frame RX hash.
|
|
|
|
* @ctx: XDP context pointer.
|
|
|
|
* @hash: Return value pointer.
|
2023-04-12 19:48:40 +00:00
|
|
|
* @rss_type: Return value pointer for RSS type.
|
|
|
|
*
|
|
|
|
* The RSS hash type (@rss_type) specifies what portion of packet headers NIC
|
|
|
|
* hardware used when calculating RSS hash value. The RSS type can be decoded
|
|
|
|
* via &enum xdp_rss_hash_type either matching on individual L3/L4 bits
|
|
|
|
* ``XDP_RSS_L*`` or by combined traditional *RSS Hashing Types*
|
|
|
|
* ``XDP_RSS_TYPE_L*``.
|
2023-01-19 22:15:26 +00:00
|
|
|
*
|
2023-03-21 13:52:31 +00:00
|
|
|
* Return:
|
|
|
|
* * Returns 0 on success or ``-errno`` on error.
|
|
|
|
* * ``-EOPNOTSUPP`` : means device driver doesn't implement kfunc
|
|
|
|
* * ``-ENODATA`` : means no RX-hash available for this frame
|
2023-01-19 22:15:26 +00:00
|
|
|
*/
|
2023-04-12 19:48:40 +00:00
|
|
|
__bpf_kfunc int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, u32 *hash,
|
|
|
|
enum xdp_rss_hash_type *rss_type)
|
2023-01-19 22:15:26 +00:00
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2023-12-05 21:08:38 +00:00
|
|
|
/**
|
|
|
|
* bpf_xdp_metadata_rx_vlan_tag - Get XDP packet outermost VLAN tag
|
|
|
|
* @ctx: XDP context pointer.
|
|
|
|
* @vlan_proto: Destination pointer for VLAN Tag protocol identifier (TPID).
|
|
|
|
* @vlan_tci: Destination pointer for VLAN TCI (VID + DEI + PCP)
|
|
|
|
*
|
|
|
|
* In case of success, ``vlan_proto`` contains *Tag protocol identifier (TPID)*,
|
|
|
|
* usually ``ETH_P_8021Q`` or ``ETH_P_8021AD``, but some networks can use
|
|
|
|
* custom TPIDs. ``vlan_proto`` is stored in **network byte order (BE)**
|
|
|
|
* and should be used as follows:
|
|
|
|
* ``if (vlan_proto == bpf_htons(ETH_P_8021Q)) do_something();``
|
|
|
|
*
|
|
|
|
* ``vlan_tci`` contains the remaining 16 bits of a VLAN tag.
|
|
|
|
* Driver is expected to provide those in **host byte order (usually LE)**,
|
|
|
|
* so the bpf program should not perform byte conversion.
|
|
|
|
* According to 802.1Q standard, *VLAN TCI (Tag control information)*
|
|
|
|
* is a bit field that contains:
|
|
|
|
* *VLAN identifier (VID)* that can be read with ``vlan_tci & 0xfff``,
|
|
|
|
* *Drop eligible indicator (DEI)* - 1 bit,
|
|
|
|
* *Priority code point (PCP)* - 3 bits.
|
|
|
|
* For detailed meaning of DEI and PCP, please refer to other sources.
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* * Returns 0 on success or ``-errno`` on error.
|
|
|
|
* * ``-EOPNOTSUPP`` : device driver doesn't implement kfunc
|
|
|
|
* * ``-ENODATA`` : VLAN tag was not stripped or is not available
|
|
|
|
*/
|
|
|
|
__bpf_kfunc int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
|
|
|
|
__be16 *vlan_proto, u16 *vlan_tci)
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2023-10-31 21:56:24 +00:00
|
|
|
__bpf_kfunc_end_defs();
|
2023-01-19 22:15:26 +00:00
|
|
|
|
2024-01-29 01:24:08 +00:00
|
|
|
BTF_KFUNCS_START(xdp_metadata_kfunc_ids)
|
2023-09-13 17:13:49 +00:00
|
|
|
#define XDP_METADATA_KFUNC(_, __, name, ___) BTF_ID_FLAGS(func, name, KF_TRUSTED_ARGS)
|
2023-01-19 22:15:26 +00:00
|
|
|
XDP_METADATA_KFUNC_xxx
|
|
|
|
#undef XDP_METADATA_KFUNC
|
2024-01-29 01:24:08 +00:00
|
|
|
BTF_KFUNCS_END(xdp_metadata_kfunc_ids)
|
2023-01-19 22:15:26 +00:00
|
|
|
|
|
|
|
static const struct btf_kfunc_id_set xdp_metadata_kfunc_set = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.set = &xdp_metadata_kfunc_ids,
|
|
|
|
};
|
|
|
|
|
|
|
|
BTF_ID_LIST(xdp_metadata_kfunc_ids_unsorted)
|
2023-09-13 17:13:49 +00:00
|
|
|
#define XDP_METADATA_KFUNC(name, _, str, __) BTF_ID(func, str)
|
2023-01-19 22:15:26 +00:00
|
|
|
XDP_METADATA_KFUNC_xxx
|
|
|
|
#undef XDP_METADATA_KFUNC
|
|
|
|
|
|
|
|
u32 bpf_xdp_metadata_kfunc_id(int id)
|
|
|
|
{
|
|
|
|
/* xdp_metadata_kfunc_ids is sorted and can't be used */
|
|
|
|
return xdp_metadata_kfunc_ids_unsorted[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bpf_dev_bound_kfunc_id(u32 btf_id)
|
|
|
|
{
|
|
|
|
return btf_id_set8_contains(&xdp_metadata_kfunc_ids, btf_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init xdp_metadata_init(void)
|
|
|
|
{
|
|
|
|
return register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &xdp_metadata_kfunc_set);
|
|
|
|
}
|
|
|
|
late_initcall(xdp_metadata_init);
|
drivers: net: turn on XDP features
A summary of the flags being set for various drivers is given below.
Note that XDP_F_REDIRECT_TARGET and XDP_F_FRAG_TARGET are features
that can be turned off and on at runtime. This means that these flags
may be set and unset under RTNL lock protection by the driver. Hence,
READ_ONCE must be used by code loading the flag value.
Also, these flags are not used for synchronization against the availability
of XDP resources on a device. It is merely a hint, and hence the read
may race with the actual teardown of XDP resources on the device. This
may change in the future, e.g. operations taking a reference on the XDP
resources of the driver, and in turn inhibiting turning off this flag.
However, for now, it can only be used as a hint to check whether device
supports becoming a redirection target.
Turn 'hw-offload' feature flag on for:
- netronome (nfp)
- netdevsim.
Turn 'native' and 'zerocopy' features flags on for:
- intel (i40e, ice, ixgbe, igc)
- mellanox (mlx5).
- stmmac
- netronome (nfp)
Turn 'native' features flags on for:
- amazon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2, enetc)
- funeth
- intel (igb)
- marvell (mvneta, mvpp2, octeontx2)
- mellanox (mlx4)
- mtk_eth_soc
- qlogic (qede)
- sfc
- socionext (netsec)
- ti (cpsw)
- tap
- tsnep
- veth
- xen
- virtio_net.
Turn 'basic' (tx, pass, aborted and drop) features flags on for:
- netronome (nfp)
- cavium (thunder)
- hyperv.
Turn 'redirect_target' feature flag on for:
- amanzon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2)
- intel (i40e, ice, igb, ixgbe)
- ti (cpsw)
- marvell (mvneta, mvpp2)
- sfc
- socionext (netsec)
- qlogic (qede)
- mellanox (mlx5)
- tap
- veth
- virtio_net
- xen
Reviewed-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Co-developed-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Marek Majtyka <alardam@gmail.com>
Link: https://lore.kernel.org/r/3eca9fafb308462f7edb1f58e451d59209aa07eb.1675245258.git.lorenzo@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-02-01 10:24:18 +00:00
|
|
|
|
2023-03-09 12:25:27 +00:00
|
|
|
void xdp_set_features_flag(struct net_device *dev, xdp_features_t val)
|
drivers: net: turn on XDP features
A summary of the flags being set for various drivers is given below.
Note that XDP_F_REDIRECT_TARGET and XDP_F_FRAG_TARGET are features
that can be turned off and on at runtime. This means that these flags
may be set and unset under RTNL lock protection by the driver. Hence,
READ_ONCE must be used by code loading the flag value.
Also, these flags are not used for synchronization against the availability
of XDP resources on a device. It is merely a hint, and hence the read
may race with the actual teardown of XDP resources on the device. This
may change in the future, e.g. operations taking a reference on the XDP
resources of the driver, and in turn inhibiting turning off this flag.
However, for now, it can only be used as a hint to check whether device
supports becoming a redirection target.
Turn 'hw-offload' feature flag on for:
- netronome (nfp)
- netdevsim.
Turn 'native' and 'zerocopy' features flags on for:
- intel (i40e, ice, ixgbe, igc)
- mellanox (mlx5).
- stmmac
- netronome (nfp)
Turn 'native' features flags on for:
- amazon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2, enetc)
- funeth
- intel (igb)
- marvell (mvneta, mvpp2, octeontx2)
- mellanox (mlx4)
- mtk_eth_soc
- qlogic (qede)
- sfc
- socionext (netsec)
- ti (cpsw)
- tap
- tsnep
- veth
- xen
- virtio_net.
Turn 'basic' (tx, pass, aborted and drop) features flags on for:
- netronome (nfp)
- cavium (thunder)
- hyperv.
Turn 'redirect_target' feature flag on for:
- amanzon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2)
- intel (i40e, ice, igb, ixgbe)
- ti (cpsw)
- marvell (mvneta, mvpp2)
- sfc
- socionext (netsec)
- qlogic (qede)
- mellanox (mlx5)
- tap
- veth
- virtio_net
- xen
Reviewed-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Co-developed-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Marek Majtyka <alardam@gmail.com>
Link: https://lore.kernel.org/r/3eca9fafb308462f7edb1f58e451d59209aa07eb.1675245258.git.lorenzo@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-02-01 10:24:18 +00:00
|
|
|
{
|
2023-03-09 12:25:27 +00:00
|
|
|
val &= NETDEV_XDP_ACT_MASK;
|
|
|
|
if (dev->xdp_features == val)
|
|
|
|
return;
|
drivers: net: turn on XDP features
A summary of the flags being set for various drivers is given below.
Note that XDP_F_REDIRECT_TARGET and XDP_F_FRAG_TARGET are features
that can be turned off and on at runtime. This means that these flags
may be set and unset under RTNL lock protection by the driver. Hence,
READ_ONCE must be used by code loading the flag value.
Also, these flags are not used for synchronization against the availability
of XDP resources on a device. It is merely a hint, and hence the read
may race with the actual teardown of XDP resources on the device. This
may change in the future, e.g. operations taking a reference on the XDP
resources of the driver, and in turn inhibiting turning off this flag.
However, for now, it can only be used as a hint to check whether device
supports becoming a redirection target.
Turn 'hw-offload' feature flag on for:
- netronome (nfp)
- netdevsim.
Turn 'native' and 'zerocopy' features flags on for:
- intel (i40e, ice, ixgbe, igc)
- mellanox (mlx5).
- stmmac
- netronome (nfp)
Turn 'native' features flags on for:
- amazon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2, enetc)
- funeth
- intel (igb)
- marvell (mvneta, mvpp2, octeontx2)
- mellanox (mlx4)
- mtk_eth_soc
- qlogic (qede)
- sfc
- socionext (netsec)
- ti (cpsw)
- tap
- tsnep
- veth
- xen
- virtio_net.
Turn 'basic' (tx, pass, aborted and drop) features flags on for:
- netronome (nfp)
- cavium (thunder)
- hyperv.
Turn 'redirect_target' feature flag on for:
- amanzon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2)
- intel (i40e, ice, igb, ixgbe)
- ti (cpsw)
- marvell (mvneta, mvpp2)
- sfc
- socionext (netsec)
- qlogic (qede)
- mellanox (mlx5)
- tap
- veth
- virtio_net
- xen
Reviewed-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Co-developed-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Marek Majtyka <alardam@gmail.com>
Link: https://lore.kernel.org/r/3eca9fafb308462f7edb1f58e451d59209aa07eb.1675245258.git.lorenzo@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-02-01 10:24:18 +00:00
|
|
|
|
2023-03-09 12:25:27 +00:00
|
|
|
dev->xdp_features = val;
|
2023-03-16 22:02:34 +00:00
|
|
|
|
|
|
|
if (dev->reg_state == NETREG_REGISTERED)
|
|
|
|
call_netdevice_notifiers(NETDEV_XDP_FEAT_CHANGE, dev);
|
drivers: net: turn on XDP features
A summary of the flags being set for various drivers is given below.
Note that XDP_F_REDIRECT_TARGET and XDP_F_FRAG_TARGET are features
that can be turned off and on at runtime. This means that these flags
may be set and unset under RTNL lock protection by the driver. Hence,
READ_ONCE must be used by code loading the flag value.
Also, these flags are not used for synchronization against the availability
of XDP resources on a device. It is merely a hint, and hence the read
may race with the actual teardown of XDP resources on the device. This
may change in the future, e.g. operations taking a reference on the XDP
resources of the driver, and in turn inhibiting turning off this flag.
However, for now, it can only be used as a hint to check whether device
supports becoming a redirection target.
Turn 'hw-offload' feature flag on for:
- netronome (nfp)
- netdevsim.
Turn 'native' and 'zerocopy' features flags on for:
- intel (i40e, ice, ixgbe, igc)
- mellanox (mlx5).
- stmmac
- netronome (nfp)
Turn 'native' features flags on for:
- amazon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2, enetc)
- funeth
- intel (igb)
- marvell (mvneta, mvpp2, octeontx2)
- mellanox (mlx4)
- mtk_eth_soc
- qlogic (qede)
- sfc
- socionext (netsec)
- ti (cpsw)
- tap
- tsnep
- veth
- xen
- virtio_net.
Turn 'basic' (tx, pass, aborted and drop) features flags on for:
- netronome (nfp)
- cavium (thunder)
- hyperv.
Turn 'redirect_target' feature flag on for:
- amanzon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2)
- intel (i40e, ice, igb, ixgbe)
- ti (cpsw)
- marvell (mvneta, mvpp2)
- sfc
- socionext (netsec)
- qlogic (qede)
- mellanox (mlx5)
- tap
- veth
- virtio_net
- xen
Reviewed-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Co-developed-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Marek Majtyka <alardam@gmail.com>
Link: https://lore.kernel.org/r/3eca9fafb308462f7edb1f58e451d59209aa07eb.1675245258.git.lorenzo@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-02-01 10:24:18 +00:00
|
|
|
}
|
2023-03-09 12:25:27 +00:00
|
|
|
EXPORT_SYMBOL_GPL(xdp_set_features_flag);
|
|
|
|
|
|
|
|
void xdp_features_set_redirect_target(struct net_device *dev, bool support_sg)
|
|
|
|
{
|
|
|
|
xdp_features_t val = (dev->xdp_features | NETDEV_XDP_ACT_NDO_XMIT);
|
|
|
|
|
|
|
|
if (support_sg)
|
|
|
|
val |= NETDEV_XDP_ACT_NDO_XMIT_SG;
|
|
|
|
xdp_set_features_flag(dev, val);
|
|
|
|
}
|
drivers: net: turn on XDP features
A summary of the flags being set for various drivers is given below.
Note that XDP_F_REDIRECT_TARGET and XDP_F_FRAG_TARGET are features
that can be turned off and on at runtime. This means that these flags
may be set and unset under RTNL lock protection by the driver. Hence,
READ_ONCE must be used by code loading the flag value.
Also, these flags are not used for synchronization against the availability
of XDP resources on a device. It is merely a hint, and hence the read
may race with the actual teardown of XDP resources on the device. This
may change in the future, e.g. operations taking a reference on the XDP
resources of the driver, and in turn inhibiting turning off this flag.
However, for now, it can only be used as a hint to check whether device
supports becoming a redirection target.
Turn 'hw-offload' feature flag on for:
- netronome (nfp)
- netdevsim.
Turn 'native' and 'zerocopy' features flags on for:
- intel (i40e, ice, ixgbe, igc)
- mellanox (mlx5).
- stmmac
- netronome (nfp)
Turn 'native' features flags on for:
- amazon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2, enetc)
- funeth
- intel (igb)
- marvell (mvneta, mvpp2, octeontx2)
- mellanox (mlx4)
- mtk_eth_soc
- qlogic (qede)
- sfc
- socionext (netsec)
- ti (cpsw)
- tap
- tsnep
- veth
- xen
- virtio_net.
Turn 'basic' (tx, pass, aborted and drop) features flags on for:
- netronome (nfp)
- cavium (thunder)
- hyperv.
Turn 'redirect_target' feature flag on for:
- amanzon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2)
- intel (i40e, ice, igb, ixgbe)
- ti (cpsw)
- marvell (mvneta, mvpp2)
- sfc
- socionext (netsec)
- qlogic (qede)
- mellanox (mlx5)
- tap
- veth
- virtio_net
- xen
Reviewed-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Co-developed-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Marek Majtyka <alardam@gmail.com>
Link: https://lore.kernel.org/r/3eca9fafb308462f7edb1f58e451d59209aa07eb.1675245258.git.lorenzo@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-02-01 10:24:18 +00:00
|
|
|
EXPORT_SYMBOL_GPL(xdp_features_set_redirect_target);
|
|
|
|
|
|
|
|
void xdp_features_clear_redirect_target(struct net_device *dev)
|
|
|
|
{
|
2023-03-09 12:25:27 +00:00
|
|
|
xdp_features_t val = dev->xdp_features;
|
|
|
|
|
|
|
|
val &= ~(NETDEV_XDP_ACT_NDO_XMIT | NETDEV_XDP_ACT_NDO_XMIT_SG);
|
|
|
|
xdp_set_features_flag(dev, val);
|
drivers: net: turn on XDP features
A summary of the flags being set for various drivers is given below.
Note that XDP_F_REDIRECT_TARGET and XDP_F_FRAG_TARGET are features
that can be turned off and on at runtime. This means that these flags
may be set and unset under RTNL lock protection by the driver. Hence,
READ_ONCE must be used by code loading the flag value.
Also, these flags are not used for synchronization against the availability
of XDP resources on a device. It is merely a hint, and hence the read
may race with the actual teardown of XDP resources on the device. This
may change in the future, e.g. operations taking a reference on the XDP
resources of the driver, and in turn inhibiting turning off this flag.
However, for now, it can only be used as a hint to check whether device
supports becoming a redirection target.
Turn 'hw-offload' feature flag on for:
- netronome (nfp)
- netdevsim.
Turn 'native' and 'zerocopy' features flags on for:
- intel (i40e, ice, ixgbe, igc)
- mellanox (mlx5).
- stmmac
- netronome (nfp)
Turn 'native' features flags on for:
- amazon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2, enetc)
- funeth
- intel (igb)
- marvell (mvneta, mvpp2, octeontx2)
- mellanox (mlx4)
- mtk_eth_soc
- qlogic (qede)
- sfc
- socionext (netsec)
- ti (cpsw)
- tap
- tsnep
- veth
- xen
- virtio_net.
Turn 'basic' (tx, pass, aborted and drop) features flags on for:
- netronome (nfp)
- cavium (thunder)
- hyperv.
Turn 'redirect_target' feature flag on for:
- amanzon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2)
- intel (i40e, ice, igb, ixgbe)
- ti (cpsw)
- marvell (mvneta, mvpp2)
- sfc
- socionext (netsec)
- qlogic (qede)
- mellanox (mlx5)
- tap
- veth
- virtio_net
- xen
Reviewed-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Co-developed-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Marek Majtyka <alardam@gmail.com>
Link: https://lore.kernel.org/r/3eca9fafb308462f7edb1f58e451d59209aa07eb.1675245258.git.lorenzo@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-02-01 10:24:18 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdp_features_clear_redirect_target);
|