Skip to content

Commit 7f7ffa4

Browse files
magnus-karlssonborkmann
authored andcommitted
xsk: Move addrs from buffer pool to umem
Replicate the addrs pointer in the buffer pool to the umem. This mapping will be the same for all buffer pools sharing the same umem. In the buffer pool we leave the addrs pointer for performance reasons. Signed-off-by: Magnus Karlsson <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Björn Töpel <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent a5aa8e5 commit 7f7ffa4

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

include/net/xdp_sock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct xsk_queue;
1818
struct xdp_buff;
1919

2020
struct xdp_umem {
21+
void *addrs;
2122
u64 size;
2223
u32 headroom;
2324
u32 chunk_size;

net/xdp/xdp_umem.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,27 @@ static void xdp_umem_unaccount_pages(struct xdp_umem *umem)
3939
}
4040
}
4141

42+
static void xdp_umem_addr_unmap(struct xdp_umem *umem)
43+
{
44+
vunmap(umem->addrs);
45+
umem->addrs = NULL;
46+
}
47+
48+
static int xdp_umem_addr_map(struct xdp_umem *umem, struct page **pages,
49+
u32 nr_pages)
50+
{
51+
umem->addrs = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
52+
if (!umem->addrs)
53+
return -ENOMEM;
54+
return 0;
55+
}
56+
4257
static void xdp_umem_release(struct xdp_umem *umem)
4358
{
4459
umem->zc = false;
4560
ida_simple_remove(&umem_ida, umem->id);
4661

62+
xdp_umem_addr_unmap(umem);
4763
xdp_umem_unpin_pages(umem);
4864

4965
xdp_umem_unaccount_pages(umem);
@@ -192,8 +208,14 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
192208
if (err)
193209
goto out_account;
194210

211+
err = xdp_umem_addr_map(umem, umem->pgs, umem->npgs);
212+
if (err)
213+
goto out_unpin;
214+
195215
return 0;
196216

217+
out_unpin:
218+
xdp_umem_unpin_pages(umem);
197219
out_account:
198220
xdp_umem_unaccount_pages(umem);
199221
return err;

net/xdp/xsk_buff_pool.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,11 @@ void xp_del_xsk(struct xsk_buff_pool *pool, struct xdp_sock *xs)
3535
spin_unlock_irqrestore(&pool->xsk_tx_list_lock, flags);
3636
}
3737

38-
static void xp_addr_unmap(struct xsk_buff_pool *pool)
39-
{
40-
vunmap(pool->addrs);
41-
}
42-
43-
static int xp_addr_map(struct xsk_buff_pool *pool,
44-
struct page **pages, u32 nr_pages)
45-
{
46-
pool->addrs = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
47-
if (!pool->addrs)
48-
return -ENOMEM;
49-
return 0;
50-
}
51-
5238
void xp_destroy(struct xsk_buff_pool *pool)
5339
{
5440
if (!pool)
5541
return;
5642

57-
xp_addr_unmap(pool);
5843
kvfree(pool->heads);
5944
kvfree(pool);
6045
}
@@ -64,7 +49,6 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
6449
{
6550
struct xsk_buff_pool *pool;
6651
struct xdp_buff_xsk *xskb;
67-
int err;
6852
u32 i;
6953

7054
pool = kvzalloc(struct_size(pool, free_heads, umem->chunks),
@@ -86,6 +70,7 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
8670
pool->frame_len = umem->chunk_size - umem->headroom -
8771
XDP_PACKET_HEADROOM;
8872
pool->umem = umem;
73+
pool->addrs = umem->addrs;
8974
INIT_LIST_HEAD(&pool->free_list);
9075
INIT_LIST_HEAD(&pool->xsk_tx_list);
9176
spin_lock_init(&pool->xsk_tx_list_lock);
@@ -103,9 +88,7 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
10388
pool->free_heads[i] = xskb;
10489
}
10590

106-
err = xp_addr_map(pool, umem->pgs, umem->npgs);
107-
if (!err)
108-
return pool;
91+
return pool;
10992

11093
out:
11194
xp_destroy(pool);

0 commit comments

Comments
 (0)