xdp: xdp_umem: replace kmap on vmap for umem map
authorIvan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Thu, 15 Aug 2019 12:13:55 +0000 (15:13 +0300)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 21 Aug 2019 12:31:17 +0000 (14:31 +0200)
For 64-bit there is no reason to use vmap/vunmap, so use page_address
as it was initially. For 32 bits, in some apps, like in samples
xdpsock_user.c when number of pgs in use is quite big, the kmap
memory can be not enough, despite on this, kmap looks like is
deprecated in such cases as it can block and should be used rather
for dynamic mm.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
net/xdp/xdp_umem.c

index cda6feb..2d65779 100644 (file)
@@ -14,7 +14,7 @@
 #include <linux/netdevice.h>
 #include <linux/rtnetlink.h>
 #include <linux/idr.h>
-#include <linux/highmem.h>
+#include <linux/vmalloc.h>
 
 #include "xdp_umem.h"
 #include "xsk_queue.h"
@@ -178,7 +178,30 @@ static void xdp_umem_unmap_pages(struct xdp_umem *umem)
        unsigned int i;
 
        for (i = 0; i < umem->npgs; i++)
-               kunmap(umem->pgs[i]);
+               if (PageHighMem(umem->pgs[i]))
+                       vunmap(umem->pages[i].addr);
+}
+
+static int xdp_umem_map_pages(struct xdp_umem *umem)
+{
+       unsigned int i;
+       void *addr;
+
+       for (i = 0; i < umem->npgs; i++) {
+               if (PageHighMem(umem->pgs[i]))
+                       addr = vmap(&umem->pgs[i], 1, VM_MAP, PAGE_KERNEL);
+               else
+                       addr = page_address(umem->pgs[i]);
+
+               if (!addr) {
+                       xdp_umem_unmap_pages(umem);
+                       return -ENOMEM;
+               }
+
+               umem->pages[i].addr = addr;
+       }
+
+       return 0;
 }
 
 static void xdp_umem_unpin_pages(struct xdp_umem *umem)
@@ -320,7 +343,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, i;
+       int size_chk, err;
 
        if (chunk_size < XDP_UMEM_MIN_CHUNK_SIZE || chunk_size > PAGE_SIZE) {
                /* Strictly speaking we could support this, if:
@@ -386,10 +409,11 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
                goto out_account;
        }
 
-       for (i = 0; i < umem->npgs; i++)
-               umem->pages[i].addr = kmap(umem->pgs[i]);
+       err = xdp_umem_map_pages(umem);
+       if (!err)
+               return 0;
 
-       return 0;
+       kfree(umem->pages);
 
 out_account:
        xdp_umem_unaccount_pages(umem);