Skip to content

Commit

Permalink
xsk: introduce xdp_umem_page
Browse files Browse the repository at this point in the history
The xdp_umem_page holds the address for a page. Trade memory for
faster lookup. Later, we'll add DMA address here as well.

Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
  • Loading branch information
Björn Töpel authored and Daniel Borkmann committed Jun 5, 2018
1 parent e61e62b commit 8aef734
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 6 additions & 1 deletion include/net/xdp_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ struct xdp_umem_props {
u64 size;
};

struct xdp_umem_page {
void *addr;
};

struct xdp_umem {
struct xsk_queue *fq;
struct xsk_queue *cq;
struct page **pgs;
struct xdp_umem_page *pages;
struct xdp_umem_props props;
u32 headroom;
u32 chunk_size_nohr;
Expand All @@ -32,6 +36,7 @@ struct xdp_umem {
unsigned long address;
refcount_t users;
struct work_struct work;
struct page **pgs;
u32 npgs;
};

Expand Down
15 changes: 14 additions & 1 deletion net/xdp/xdp_umem.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ static void xdp_umem_release(struct xdp_umem *umem)
goto out;

mmput(mm);
kfree(umem->pages);
umem->pages = NULL;

xdp_umem_unaccount_pages(umem);
out:
kfree(umem);
Expand Down Expand Up @@ -155,7 +158,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
u32 chunk_size = mr->chunk_size, headroom = mr->headroom;
unsigned int chunks, chunks_per_page;
u64 addr = mr->addr, size = mr->len;
int size_chk, err;
int size_chk, err, i;

if (chunk_size < XDP_UMEM_MIN_CHUNK_SIZE || chunk_size > PAGE_SIZE) {
/* Strictly speaking we could support this, if:
Expand Down Expand Up @@ -213,6 +216,16 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
err = xdp_umem_pin_pages(umem);
if (err)
goto out_account;

umem->pages = kcalloc(umem->npgs, sizeof(*umem->pages), GFP_KERNEL);
if (!umem->pages) {
err = -ENOMEM;
goto out_account;
}

for (i = 0; i < umem->npgs; i++)
umem->pages[i].addr = page_address(umem->pgs[i]);

return 0;

out_account:
Expand Down
3 changes: 1 addition & 2 deletions net/xdp/xdp_umem.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

static inline char *xdp_umem_get_data(struct xdp_umem *umem, u64 addr)
{
return page_address(umem->pgs[addr >> PAGE_SHIFT]) +
(addr & (PAGE_SIZE - 1));
return umem->pages[addr >> PAGE_SHIFT].addr + (addr & (PAGE_SIZE - 1));
}

bool xdp_umem_validate_queues(struct xdp_umem *umem);
Expand Down

0 comments on commit 8aef734

Please sign in to comment.