xsk: Introduce AF_XDP buffer allocation API
In order to simplify AF_XDP zero-copy enablement for NIC driver developers, a new AF_XDP buffer allocation API is added. The implementation is based on a single core (single producer/consumer) buffer pool for the AF_XDP UMEM. A buffer is allocated using the xsk_buff_alloc() function, and returned using xsk_buff_free(). If a buffer is disassociated with the pool, e.g. when a buffer is passed to an AF_XDP socket, a buffer is said to be released. Currently, the release function is only used by the AF_XDP internals and not visible to the driver. Drivers using this API should register the XDP memory model with the new MEM_TYPE_XSK_BUFF_POOL type. The API is defined in net/xdp_sock_drv.h. The buffer type is struct xdp_buff, and follows the lifetime of regular xdp_buffs, i.e. the lifetime of an xdp_buff is restricted to a NAPI context. In other words, the API is not replacing xdp_frames. In addition to introducing the API and implementations, the AF_XDP core is migrated to use the new APIs. rfc->v1: Fixed build errors/warnings for m68k and riscv. (kbuild test robot) Added headroom/chunk size getter. (Maxim/Björn) v1->v2: Swapped SoBs. (Maxim) v2->v3: Initialize struct xdp_buff member frame_sz. (Björn) Add API to query the DMA address of a frame. (Maxim) Do DMA sync for CPU till the end of the frame to handle possible growth (frame_sz). (Maxim) Signed-off-by:Björn Töpel <bjorn.topel@intel.com> Signed-off-by:
Maxim Mikityanskiy <maximmi@mellanox.com> Signed-off-by:
Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200520192103.355233-6-bjorn.topel@gmail.com
Showing
- include/net/xdp.h 3 additions, 1 deletioninclude/net/xdp.h
- include/net/xdp_sock.h 2 additions, 0 deletionsinclude/net/xdp_sock.h
- include/net/xdp_sock_drv.h 164 additions, 0 deletionsinclude/net/xdp_sock_drv.h
- include/net/xsk_buff_pool.h 56 additions, 0 deletionsinclude/net/xsk_buff_pool.h
- include/trace/events/xdp.h 2 additions, 1 deletioninclude/trace/events/xdp.h
- net/core/xdp.c 10 additions, 4 deletionsnet/core/xdp.c
- net/xdp/Makefile 1 addition, 0 deletionsnet/xdp/Makefile
- net/xdp/xdp_umem.c 15 additions, 4 deletionsnet/xdp/xdp_umem.c
- net/xdp/xsk.c 54 additions, 93 deletionsnet/xdp/xsk.c
- net/xdp/xsk_buff_pool.c 467 additions, 0 deletionsnet/xdp/xsk_buff_pool.c
- net/xdp/xsk_diag.c 1 addition, 1 deletionnet/xdp/xsk_diag.c
- net/xdp/xsk_queue.h 44 additions, 15 deletionsnet/xdp/xsk_queue.h
Loading
Please register or sign in to comment