History

xsk: add umem completion queue support and mmap

Here, we add another setsockopt for registered user memory (umem) called XDP_UMEM_COMPLETION_QUEUE. Using this socket option, the process can ask the kernel to allocate a queue (ring buffer) and also mmap it (XDP_UMEM_PGOFF_COMPLETION_QUEUE) into the process. The queue is used to explicitly pass ownership of umem frames from the kernel to user process. This will be used by the TX path to tell user space that a certain frame has been transmitted and user space can use it for something else, if it wishes.

Magnus Karlsson committed 8 years ago

Commit fe230831 parent 02671e24 files · +15 −2Browse files

Unified · Split

4 files
  1. include/uapi/linux/if_xdp.h +2 −0
  2. net/xdp/xdp_umem.c +6 −1
  3. net/xdp/xdp_umem.h +1 −0
  4. net/xdp/xsk.c +6 −1
include/uapi/linux/if_xdp.h+2−0
@@ -36,6 +36,7 @@ struct sockaddr_xdp { · 35 unmodified lines
36#define XDP_RX_RING 136#define XDP_RX_RING 1
37#define XDP_UMEM_REG 337#define XDP_UMEM_REG 3
38#define XDP_UMEM_FILL_RING 438#define XDP_UMEM_FILL_RING 4
39#define XDP_UMEM_COMPLETION_RING 5
39 40
40struct xdp_umem_reg {41struct xdp_umem_reg {
41 __u64 addr; /* Start of packet data area */42 __u64 addr; /* Start of packet data area */
@@ -47,6 +48,7 @@ struct xdp_umem_reg { · 5 unmodified lines
47/* Pgoff for mmaping the rings */48/* Pgoff for mmaping the rings */
48#define XDP_PGOFF_RX_RING 049#define XDP_PGOFF_RX_RING 0
49#define XDP_UMEM_PGOFF_FILL_RING 0x10000000050#define XDP_UMEM_PGOFF_FILL_RING 0x100000000
51#define XDP_UMEM_PGOFF_COMPLETION_RING 0x180000000
50 52
51struct xdp_desc {53struct xdp_desc {
52 __u32 idx;54 __u32 idx;
net/xdp/xdp_umem.c+6−1
@@ -70,6 +70,11 @@ static void xdp_umem_release(struct xdp_umem *umem) · 69 unmodified lines
70 umem->fq = NULL;70 umem->fq = NULL;
71 }71 }
72 72
73 if (umem->cq) {
74 xskq_destroy(umem->cq);
75 umem->cq = NULL;
76 }
77
73 if (umem->pgs) {78 if (umem->pgs) {
74 xdp_umem_unpin_pages(umem);79 xdp_umem_unpin_pages(umem);
75 80
@@ -251,5 +256,5 @@ out: · 175 unmodified lines
251 256
252bool xdp_umem_validate_queues(struct xdp_umem *umem)257bool xdp_umem_validate_queues(struct xdp_umem *umem)
253{258{
254 return umem->fq;259 return (umem->fq && umem->cq);
255}260}
net/xdp/xdp_umem.h+1−0
@@ -24,6 +24,7 @@ · 23 unmodified lines
24 24
25struct xdp_umem {25struct xdp_umem {
26 struct xsk_queue *fq;26 struct xsk_queue *fq;
27 struct xsk_queue *cq;
27 struct page **pgs;28 struct page **pgs;
28 struct xdp_umem_props props;29 struct xdp_umem_props props;
29 u32 npgs;30 u32 npgs;
net/xdp/xsk.c+6−1
@@ -255,6 +255,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) · 254 unmodified lines
255 } else {255 } else {
256 /* This xsk has its own umem. */256 /* This xsk has its own umem. */
257 xskq_set_umem(xs->umem->fq, &xs->umem->props);257 xskq_set_umem(xs->umem->fq, &xs->umem->props);
258 xskq_set_umem(xs->umem->cq, &xs->umem->props);
258 }259 }
259 260
260 /* Rebind? */261 /* Rebind? */
@@ -334,6 +335,7 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname, · 73 unmodified lines
334 return 0;335 return 0;
335 }336 }
336 case XDP_UMEM_FILL_RING:337 case XDP_UMEM_FILL_RING:
338 case XDP_UMEM_COMPLETION_RING:
337 {339 {
338 struct xsk_queue **q;340 struct xsk_queue **q;
339 int entries;341 int entries;
@@ -345,7 +347,8 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname, · 5 unmodified lines
345 return -EFAULT;347 return -EFAULT;
346 348
347 mutex_lock(&xs->mutex);349 mutex_lock(&xs->mutex);
348 q = &xs->umem->fq;350 q = (optname == XDP_UMEM_FILL_RING) ? &xs->umem->fq :
351 &xs->umem->cq;
349 err = xsk_init_queue(entries, q, true);352 err = xsk_init_queue(entries, q, true);
350 mutex_unlock(&xs->mutex);353 mutex_unlock(&xs->mutex);
351 return err;354 return err;
@@ -375,6 +378,8 @@ static int xsk_mmap(struct file *file, struct socket *sock, · 23 unmodified lines
375 378
376 if (offset == XDP_UMEM_PGOFF_FILL_RING)379 if (offset == XDP_UMEM_PGOFF_FILL_RING)
377 q = xs->umem->fq;380 q = xs->umem->fq;
381 else if (offset == XDP_UMEM_PGOFF_COMPLETION_RING)
382 q = xs->umem->cq;
378 else383 else
379 return -EINVAL;384 return -EINVAL;
380 }385 }