提交 d3a56931 编写于 作者: M Magnus Karlsson 提交者: Alexei Starovoitov

xsk: Support allocations of large umems

When registering a umem area that is sufficiently large (>1G on an
x86), kmalloc cannot be used to allocate one of the internal data
structures, as the size requested gets too large. Use kvmalloc instead
that falls back on vmalloc if the allocation is too large for kmalloc.

Also add accounting for this structure as it is triggered by a user
space action (the XDP_UMEM_REG setsockopt) and it is by far the
largest structure of kernel allocated memory in xsk.
Reported-by: NRyan Goodfellow <rgoodfel@isi.edu>
Signed-off-by: NMagnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Acked-by: NJonathan Lemon <jonathan.lemon@gmail.com>
Link: https://lore.kernel.org/bpf/1578995365-7050-1-git-send-email-magnus.karlsson@intel.com
上级 0a29275b
...@@ -249,7 +249,7 @@ static void xdp_umem_release(struct xdp_umem *umem) ...@@ -249,7 +249,7 @@ static void xdp_umem_release(struct xdp_umem *umem)
xdp_umem_unmap_pages(umem); xdp_umem_unmap_pages(umem);
xdp_umem_unpin_pages(umem); xdp_umem_unpin_pages(umem);
kfree(umem->pages); kvfree(umem->pages);
umem->pages = NULL; umem->pages = NULL;
xdp_umem_unaccount_pages(umem); xdp_umem_unaccount_pages(umem);
...@@ -409,7 +409,8 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) ...@@ -409,7 +409,8 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
if (err) if (err)
goto out_account; goto out_account;
umem->pages = kcalloc(umem->npgs, sizeof(*umem->pages), GFP_KERNEL); umem->pages = kvcalloc(umem->npgs, sizeof(*umem->pages),
GFP_KERNEL_ACCOUNT);
if (!umem->pages) { if (!umem->pages) {
err = -ENOMEM; err = -ENOMEM;
goto out_pin; goto out_pin;
...@@ -419,7 +420,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) ...@@ -419,7 +420,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
if (!err) if (!err)
return 0; return 0;
kfree(umem->pages); kvfree(umem->pages);
out_pin: out_pin:
xdp_umem_unpin_pages(umem); xdp_umem_unpin_pages(umem);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册