Add MEM_TYPE_ZERO_COPY_VDEV for supporting the veth AF_XDP.
For zero-copy veth, the memory comes from userspace and does
not need to be freed at kernel.  Thus, when xdp returns the
frame, detecting this type and doing nothing.

Signed-off-by: William Tu <u9012...@gmail.com>
---
 include/net/xdp.h | 1 +
 net/core/xdp.c    | 1 +
 net/xdp/xsk.c     | 3 ++-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/net/xdp.h b/include/net/xdp.h
index 0f25b3675c5c..010cb9efca90 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -38,6 +38,7 @@ enum xdp_mem_type {
        MEM_TYPE_PAGE_ORDER0,     /* Orig XDP full page model */
        MEM_TYPE_PAGE_POOL,
        MEM_TYPE_ZERO_COPY,
+       MEM_TYPE_ZERO_COPY_VDEV,
        MEM_TYPE_MAX,
 };
 
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 4b2b194f4f1f..d47f003714c4 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -355,6 +355,7 @@ static void __xdp_return(void *data, struct xdp_mem_info 
*mem, bool napi_direct,
                xa = rhashtable_lookup(mem_id_ht, &mem->id, mem_id_rht_params);
                xa->zc_alloc->free(xa->zc_alloc, handle);
                rcu_read_unlock();
+       case MEM_TYPE_ZERO_COPY_VDEV:
        default:
                /* Not possible, checked in xdp_rxq_info_reg_mem_model() */
                break;
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 0e252047f55f..3d151d64fc79 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -109,7 +109,8 @@ int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
 
        len = xdp->data_end - xdp->data;
 
-       return (xdp->rxq->mem.type == MEM_TYPE_ZERO_COPY) ?
+       return (xdp->rxq->mem.type == MEM_TYPE_ZERO_COPY ||
+               xdp->rxq->mem.type == MEM_TYPE_ZERO_COPY_VDEV) ?
                __xsk_rcv_zc(xs, xdp, len) : __xsk_rcv(xs, xdp, len);
 }
 
-- 
2.7.4

Reply via email to