Commit 64995362 authored by Daniel Borkmann's avatar Daniel Borkmann

Merge branch 'bpf-af-xdp-fixes'

Björn Töpel says:

====================
An issue with the current AF_XDP uapi raised by Mykyta Iziumtsev (see
https://www.spinics.net/lists/netdev/msg503664.html) is that it does
not support NICs that have a "type-writer" model in an efficient
way. In this model, a memory window is passed to the hardware and
multiple frames might be filled into that window, instead of just one
that we have in the current fixed frame-size model.

This patch set fixes two bugs in the current implementation and then
changes the uapi so that the type-writer model can be supported
efficiently by a possible future extension of AF_XDP.

These are the uapi changes in this patch:

* Change the "u32 idx" in the descriptors to "u64 addr". The current
  idx based format does NOT work for the type-writer model (as packets
  can start anywhere within a frame) but that a relative address
  pointer (the u64 addr) works well for both models in the prototype
  code we have that supports both models. We increased it from u32 to
  u64 to support umems larger than 4G. We have also removed the u16
  offset when having a "u64 addr" since that information is already
  carried in the least significant bits of the address.

* We want to use "u8 padding[5]" for something useful in the future
  (since we are not allowed to change its name), so we now call it
  just options so it can be extended for various purposes in the
  future. It is an u32 as that it what is left of the 16 byte
  descriptor.

* We changed the name of frame_size in the UMEM_REG setsockopt to
  chunk_size since this naming also makes sense to the type-writer
  model.

With these changes to the uapi, we believe the type-writer model can
be supported without having to resort to a new descriptor format. The
type-writer model could then be supported, from the uapi point of
view, by setting a flag at bind time and providing a new flag bit in
the options field of the descriptor that signals to user space that
all packets have been written in a chunk. Or with a new chunk
completion queue as suggested by Mykyta in his latest feedback mail on
the list.

We based this patch set on bpf-next commit bd3a08aa ("bpf:
flowlabel in bpf_fib_lookup should be flowinfo")

The structure of the patch set is as follows:

Patches 1-2: Fixes two bugs in the current implementation.
Patches 3-4: Prepares the uapi for a "type-writer" model and modifies
             the sample application so that it works with the new
	     uapi.
Patch 5: Small performance improvement patch for the sample application.

Cheers: Magnus and Björn
====================
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parents bd3a08aa a65ea68b
...@@ -12,7 +12,7 @@ packet processing. ...@@ -12,7 +12,7 @@ packet processing.
This document assumes that the reader is familiar with BPF and XDP. If This document assumes that the reader is familiar with BPF and XDP. If
not, the Cilium project has an excellent reference guide at not, the Cilium project has an excellent reference guide at
http://cilium.readthedocs.io/en/doc-1.0/bpf/. http://cilium.readthedocs.io/en/latest/bpf/.
Using the XDP_REDIRECT action from an XDP program, the program can Using the XDP_REDIRECT action from an XDP program, the program can
redirect ingress frames to other XDP enabled netdevs, using the redirect ingress frames to other XDP enabled netdevs, using the
...@@ -33,22 +33,22 @@ for a while due to a possible retransmit, the descriptor that points ...@@ -33,22 +33,22 @@ for a while due to a possible retransmit, the descriptor that points
to that packet can be changed to point to another and reused right to that packet can be changed to point to another and reused right
away. This again avoids copying data. away. This again avoids copying data.
The UMEM consists of a number of equally size frames and each frame The UMEM consists of a number of equally sized chunks. A descriptor in
has a unique frame id. A descriptor in one of the rings references a one of the rings references a frame by referencing its addr. The addr
frame by referencing its frame id. The user space allocates memory for is simply an offset within the entire UMEM region. The user space
this UMEM using whatever means it feels is most appropriate (malloc, allocates memory for this UMEM using whatever means it feels is most
mmap, huge pages, etc). This memory area is then registered with the appropriate (malloc, mmap, huge pages, etc). This memory area is then
kernel using the new setsockopt XDP_UMEM_REG. The UMEM also has two registered with the kernel using the new setsockopt XDP_UMEM_REG. The
rings: the FILL ring and the COMPLETION ring. The fill ring is used by UMEM also has two rings: the FILL ring and the COMPLETION ring. The
the application to send down frame ids for the kernel to fill in with fill ring is used by the application to send down addr for the kernel
RX packet data. References to these frames will then appear in the RX to fill in with RX packet data. References to these frames will then
ring once each packet has been received. The completion ring, on the appear in the RX ring once each packet has been received. The
other hand, contains frame ids that the kernel has transmitted completion ring, on the other hand, contains frame addr that the
completely and can now be used again by user space, for either TX or kernel has transmitted completely and can now be used again by user
RX. Thus, the frame ids appearing in the completion ring are ids that space, for either TX or RX. Thus, the frame addrs appearing in the
were previously transmitted using the TX ring. In summary, the RX and completion ring are addrs that were previously transmitted using the
FILL rings are used for the RX path and the TX and COMPLETION rings TX ring. In summary, the RX and FILL rings are used for the RX path
are used for the TX path. and the TX and COMPLETION rings are used for the TX path.
The socket is then finally bound with a bind() call to a device and a The socket is then finally bound with a bind() call to a device and a
specific queue id on that device, and it is not until bind is specific queue id on that device, and it is not until bind is
...@@ -59,13 +59,13 @@ wants to do this, it simply skips the registration of the UMEM and its ...@@ -59,13 +59,13 @@ wants to do this, it simply skips the registration of the UMEM and its
corresponding two rings, sets the XDP_SHARED_UMEM flag in the bind corresponding two rings, sets the XDP_SHARED_UMEM flag in the bind
call and submits the XSK of the process it would like to share UMEM call and submits the XSK of the process it would like to share UMEM
with as well as its own newly created XSK socket. The new process will with as well as its own newly created XSK socket. The new process will
then receive frame id references in its own RX ring that point to this then receive frame addr references in its own RX ring that point to
shared UMEM. Note that since the ring structures are single-consumer / this shared UMEM. Note that since the ring structures are
single-producer (for performance reasons), the new process has to single-consumer / single-producer (for performance reasons), the new
create its own socket with associated RX and TX rings, since it cannot process has to create its own socket with associated RX and TX rings,
share this with the other process. This is also the reason that there since it cannot share this with the other process. This is also the
is only one set of FILL and COMPLETION rings per UMEM. It is the reason that there is only one set of FILL and COMPLETION rings per
responsibility of a single process to handle the UMEM. UMEM. It is the responsibility of a single process to handle the UMEM.
How is then packets distributed from an XDP program to the XSKs? There How is then packets distributed from an XDP program to the XSKs? There
is a BPF map called XSKMAP (or BPF_MAP_TYPE_XSKMAP in full). The is a BPF map called XSKMAP (or BPF_MAP_TYPE_XSKMAP in full). The
...@@ -102,10 +102,10 @@ UMEM ...@@ -102,10 +102,10 @@ UMEM
UMEM is a region of virtual contiguous memory, divided into UMEM is a region of virtual contiguous memory, divided into
equal-sized frames. An UMEM is associated to a netdev and a specific equal-sized frames. An UMEM is associated to a netdev and a specific
queue id of that netdev. It is created and configured (frame size, queue id of that netdev. It is created and configured (chunk size,
frame headroom, start address and size) by using the XDP_UMEM_REG headroom, start address and size) by using the XDP_UMEM_REG setsockopt
setsockopt system call. A UMEM is bound to a netdev and queue id, via system call. A UMEM is bound to a netdev and queue id, via the bind()
the bind() system call. system call.
An AF_XDP is socket linked to a single UMEM, but one UMEM can have An AF_XDP is socket linked to a single UMEM, but one UMEM can have
multiple AF_XDP sockets. To share an UMEM created via one socket A, multiple AF_XDP sockets. To share an UMEM created via one socket A,
...@@ -147,13 +147,17 @@ UMEM Fill Ring ...@@ -147,13 +147,17 @@ UMEM Fill Ring
~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
The Fill ring is used to transfer ownership of UMEM frames from The Fill ring is used to transfer ownership of UMEM frames from
user-space to kernel-space. The UMEM indicies are passed in the user-space to kernel-space. The UMEM addrs are passed in the ring. As
ring. As an example, if the UMEM is 64k and each frame is 4k, then the an example, if the UMEM is 64k and each chunk is 4k, then the UMEM has
UMEM has 16 frames and can pass indicies between 0 and 15. 16 chunks and can pass addrs between 0 and 64k.
Frames passed to the kernel are used for the ingress path (RX rings). Frames passed to the kernel are used for the ingress path (RX rings).
The user application produces UMEM indicies to this ring. The user application produces UMEM addrs to this ring. Note that the
kernel will mask the incoming addr. E.g. for a chunk size of 2k, the
log2(2048) LSB of the addr will be masked off, meaning that 2048, 2050
and 3000 refers to the same chunk.
UMEM Completetion Ring UMEM Completetion Ring
~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
...@@ -165,16 +169,15 @@ used. ...@@ -165,16 +169,15 @@ used.
Frames passed from the kernel to user-space are frames that has been Frames passed from the kernel to user-space are frames that has been
sent (TX ring) and can be used by user-space again. sent (TX ring) and can be used by user-space again.
The user application consumes UMEM indicies from this ring. The user application consumes UMEM addrs from this ring.
RX Ring RX Ring
~~~~~~~ ~~~~~~~
The RX ring is the receiving side of a socket. Each entry in the ring The RX ring is the receiving side of a socket. Each entry in the ring
is a struct xdp_desc descriptor. The descriptor contains UMEM index is a struct xdp_desc descriptor. The descriptor contains UMEM offset
(idx), the length of the data (len), the offset into the frame (addr) and the length of the data (len).
(offset).
If no frames have been passed to kernel via the Fill ring, no If no frames have been passed to kernel via the Fill ring, no
descriptors will (or can) appear on the RX ring. descriptors will (or can) appear on the RX ring.
...@@ -221,38 +224,50 @@ side is xdpsock_user.c and the XDP side xdpsock_kern.c. ...@@ -221,38 +224,50 @@ side is xdpsock_user.c and the XDP side xdpsock_kern.c.
Naive ring dequeue and enqueue could look like this:: Naive ring dequeue and enqueue could look like this::
// struct xdp_rxtx_ring {
// __u32 *producer;
// __u32 *consumer;
// struct xdp_desc *desc;
// };
// struct xdp_umem_ring {
// __u32 *producer;
// __u32 *consumer;
// __u64 *desc;
// };
// typedef struct xdp_rxtx_ring RING; // typedef struct xdp_rxtx_ring RING;
// typedef struct xdp_umem_ring RING; // typedef struct xdp_umem_ring RING;
// typedef struct xdp_desc RING_TYPE; // typedef struct xdp_desc RING_TYPE;
// typedef __u32 RING_TYPE; // typedef __u64 RING_TYPE;
int dequeue_one(RING *ring, RING_TYPE *item) int dequeue_one(RING *ring, RING_TYPE *item)
{ {
__u32 entries = ring->ptrs.producer - ring->ptrs.consumer; __u32 entries = *ring->producer - *ring->consumer;
if (entries == 0) if (entries == 0)
return -1; return -1;
// read-barrier! // read-barrier!
*item = ring->desc[ring->ptrs.consumer & (RING_SIZE - 1)]; *item = ring->desc[*ring->consumer & (RING_SIZE - 1)];
ring->ptrs.consumer++; (*ring->consumer)++;
return 0; return 0;
} }
int enqueue_one(RING *ring, const RING_TYPE *item) int enqueue_one(RING *ring, const RING_TYPE *item)
{ {
u32 free_entries = RING_SIZE - (ring->ptrs.producer - ring->ptrs.consumer); u32 free_entries = RING_SIZE - (*ring->producer - *ring->consumer);
if (free_entries == 0) if (free_entries == 0)
return -1; return -1;
ring->desc[ring->ptrs.producer & (RING_SIZE - 1)] = *item; ring->desc[*ring->producer & (RING_SIZE - 1)] = *item;
// write-barrier! // write-barrier!
ring->ptrs.producer++; (*ring->producer)++;
return 0; return 0;
} }
......
...@@ -48,8 +48,8 @@ struct xdp_mmap_offsets { ...@@ -48,8 +48,8 @@ struct xdp_mmap_offsets {
struct xdp_umem_reg { struct xdp_umem_reg {
__u64 addr; /* Start of packet data area */ __u64 addr; /* Start of packet data area */
__u64 len; /* Length of packet data area */ __u64 len; /* Length of packet data area */
__u32 frame_size; /* Frame size */ __u32 chunk_size;
__u32 frame_headroom; /* Frame head room */ __u32 headroom;
}; };
struct xdp_statistics { struct xdp_statistics {
...@@ -66,13 +66,11 @@ struct xdp_statistics { ...@@ -66,13 +66,11 @@ struct xdp_statistics {
/* Rx/Tx descriptor */ /* Rx/Tx descriptor */
struct xdp_desc { struct xdp_desc {
__u32 idx; __u64 addr;
__u32 len; __u32 len;
__u16 offset; __u32 options;
__u8 flags;
__u8 padding[5];
}; };
/* UMEM descriptor is __u32 */ /* UMEM descriptor is __u64 */
#endif /* _LINUX_IF_XDP_H */ #endif /* _LINUX_IF_XDP_H */
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "xdp_umem.h" #include "xdp_umem.h"
#define XDP_UMEM_MIN_FRAME_SIZE 2048 #define XDP_UMEM_MIN_CHUNK_SIZE 2048
static void xdp_umem_unpin_pages(struct xdp_umem *umem) static void xdp_umem_unpin_pages(struct xdp_umem *umem)
{ {
...@@ -151,12 +151,12 @@ static int xdp_umem_account_pages(struct xdp_umem *umem) ...@@ -151,12 +151,12 @@ static int xdp_umem_account_pages(struct xdp_umem *umem)
static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
{ {
u32 frame_size = mr->frame_size, frame_headroom = mr->frame_headroom; u32 chunk_size = mr->chunk_size, headroom = mr->headroom;
unsigned int chunks, chunks_per_page;
u64 addr = mr->addr, size = mr->len; u64 addr = mr->addr, size = mr->len;
unsigned int nframes, nfpp;
int size_chk, err; int size_chk, err;
if (frame_size < XDP_UMEM_MIN_FRAME_SIZE || frame_size > PAGE_SIZE) { if (chunk_size < XDP_UMEM_MIN_CHUNK_SIZE || chunk_size > PAGE_SIZE) {
/* Strictly speaking we could support this, if: /* Strictly speaking we could support this, if:
* - huge pages, or* * - huge pages, or*
* - using an IOMMU, or * - using an IOMMU, or
...@@ -166,7 +166,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) ...@@ -166,7 +166,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
return -EINVAL; return -EINVAL;
} }
if (!is_power_of_2(frame_size)) if (!is_power_of_2(chunk_size))
return -EINVAL; return -EINVAL;
if (!PAGE_ALIGNED(addr)) { if (!PAGE_ALIGNED(addr)) {
...@@ -179,33 +179,30 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) ...@@ -179,33 +179,30 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
if ((addr + size) < addr) if ((addr + size) < addr)
return -EINVAL; return -EINVAL;
nframes = (unsigned int)div_u64(size, frame_size); chunks = (unsigned int)div_u64(size, chunk_size);
if (nframes == 0 || nframes > UINT_MAX) if (chunks == 0)
return -EINVAL; return -EINVAL;
nfpp = PAGE_SIZE / frame_size; chunks_per_page = PAGE_SIZE / chunk_size;
if (nframes < nfpp || nframes % nfpp) if (chunks < chunks_per_page || chunks % chunks_per_page)
return -EINVAL; return -EINVAL;
frame_headroom = ALIGN(frame_headroom, 64); headroom = ALIGN(headroom, 64);
size_chk = frame_size - frame_headroom - XDP_PACKET_HEADROOM; size_chk = chunk_size - headroom - XDP_PACKET_HEADROOM;
if (size_chk < 0) if (size_chk < 0)
return -EINVAL; return -EINVAL;
umem->pid = get_task_pid(current, PIDTYPE_PID); umem->pid = get_task_pid(current, PIDTYPE_PID);
umem->size = (size_t)size;
umem->address = (unsigned long)addr; umem->address = (unsigned long)addr;
umem->props.frame_size = frame_size; umem->props.chunk_mask = ~((u64)chunk_size - 1);
umem->props.nframes = nframes; umem->props.size = size;
umem->frame_headroom = frame_headroom; umem->headroom = headroom;
umem->chunk_size_nohr = chunk_size - headroom;
umem->npgs = size / PAGE_SIZE; umem->npgs = size / PAGE_SIZE;
umem->pgs = NULL; umem->pgs = NULL;
umem->user = NULL; umem->user = NULL;
umem->frame_size_log2 = ilog2(frame_size);
umem->nfpp_mask = nfpp - 1;
umem->nfpplog2 = ilog2(nfpp);
refcount_set(&umem->users, 1); refcount_set(&umem->users, 1);
err = xdp_umem_account_pages(umem); err = xdp_umem_account_pages(umem);
......
...@@ -18,35 +18,20 @@ struct xdp_umem { ...@@ -18,35 +18,20 @@ struct xdp_umem {
struct xsk_queue *cq; struct xsk_queue *cq;
struct page **pgs; struct page **pgs;
struct xdp_umem_props props; struct xdp_umem_props props;
u32 npgs; u32 headroom;
u32 frame_headroom; u32 chunk_size_nohr;
u32 nfpp_mask;
u32 nfpplog2;
u32 frame_size_log2;
struct user_struct *user; struct user_struct *user;
struct pid *pid; struct pid *pid;
unsigned long address; unsigned long address;
size_t size;
refcount_t users; refcount_t users;
struct work_struct work; struct work_struct work;
u32 npgs;
}; };
static inline char *xdp_umem_get_data(struct xdp_umem *umem, u32 idx) static inline char *xdp_umem_get_data(struct xdp_umem *umem, u64 addr)
{
u64 pg, off;
char *data;
pg = idx >> umem->nfpplog2;
off = (idx & umem->nfpp_mask) << umem->frame_size_log2;
data = page_address(umem->pgs[pg]);
return data + off;
}
static inline char *xdp_umem_get_data_with_headroom(struct xdp_umem *umem,
u32 idx)
{ {
return xdp_umem_get_data(umem, idx) + umem->frame_headroom; return page_address(umem->pgs[addr >> PAGE_SHIFT]) +
(addr & (PAGE_SIZE - 1));
} }
bool xdp_umem_validate_queues(struct xdp_umem *umem); bool xdp_umem_validate_queues(struct xdp_umem *umem);
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#define XDP_UMEM_PROPS_H_ #define XDP_UMEM_PROPS_H_
struct xdp_umem_props { struct xdp_umem_props {
u32 frame_size; u64 chunk_mask;
u32 nframes; u64 size;
}; };
#endif /* XDP_UMEM_PROPS_H_ */ #endif /* XDP_UMEM_PROPS_H_ */
...@@ -41,23 +41,29 @@ bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs) ...@@ -41,23 +41,29 @@ bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs)
static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
{ {
u32 *id, len = xdp->data_end - xdp->data; u32 len = xdp->data_end - xdp->data;
void *buffer; void *buffer;
int err = 0; u64 addr;
int err;
if (xs->dev != xdp->rxq->dev || xs->queue_id != xdp->rxq->queue_index) if (xs->dev != xdp->rxq->dev || xs->queue_id != xdp->rxq->queue_index)
return -EINVAL; return -EINVAL;
id = xskq_peek_id(xs->umem->fq); if (!xskq_peek_addr(xs->umem->fq, &addr) ||
if (!id) len > xs->umem->chunk_size_nohr) {
xs->rx_dropped++;
return -ENOSPC; return -ENOSPC;
}
addr += xs->umem->headroom;
buffer = xdp_umem_get_data_with_headroom(xs->umem, *id); buffer = xdp_umem_get_data(xs->umem, addr);
memcpy(buffer, xdp->data, len); memcpy(buffer, xdp->data, len);
err = xskq_produce_batch_desc(xs->rx, *id, len, err = xskq_produce_batch_desc(xs->rx, addr, len);
xs->umem->frame_headroom);
if (!err) if (!err)
xskq_discard_id(xs->umem->fq); xskq_discard_addr(xs->umem->fq);
else
xs->rx_dropped++;
return err; return err;
} }
...@@ -69,8 +75,6 @@ int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) ...@@ -69,8 +75,6 @@ int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
err = __xsk_rcv(xs, xdp); err = __xsk_rcv(xs, xdp);
if (likely(!err)) if (likely(!err))
xdp_return_buff(xdp); xdp_return_buff(xdp);
else
xs->rx_dropped++;
return err; return err;
} }
...@@ -88,18 +92,16 @@ int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) ...@@ -88,18 +92,16 @@ int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
err = __xsk_rcv(xs, xdp); err = __xsk_rcv(xs, xdp);
if (!err) if (!err)
xsk_flush(xs); xsk_flush(xs);
else
xs->rx_dropped++;
return err; return err;
} }
static void xsk_destruct_skb(struct sk_buff *skb) static void xsk_destruct_skb(struct sk_buff *skb)
{ {
u32 id = (u32)(long)skb_shinfo(skb)->destructor_arg; u64 addr = (u64)(long)skb_shinfo(skb)->destructor_arg;
struct xdp_sock *xs = xdp_sk(skb->sk); struct xdp_sock *xs = xdp_sk(skb->sk);
WARN_ON_ONCE(xskq_produce_id(xs->umem->cq, id)); WARN_ON_ONCE(xskq_produce_addr(xs->umem->cq, addr));
sock_wfree(skb); sock_wfree(skb);
} }
...@@ -124,14 +126,15 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m, ...@@ -124,14 +126,15 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,
while (xskq_peek_desc(xs->tx, &desc)) { while (xskq_peek_desc(xs->tx, &desc)) {
char *buffer; char *buffer;
u32 id, len; u64 addr;
u32 len;
if (max_batch-- == 0) { if (max_batch-- == 0) {
err = -EAGAIN; err = -EAGAIN;
goto out; goto out;
} }
if (xskq_reserve_id(xs->umem->cq)) { if (xskq_reserve_addr(xs->umem->cq)) {
err = -EAGAIN; err = -EAGAIN;
goto out; goto out;
} }
...@@ -154,8 +157,8 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m, ...@@ -154,8 +157,8 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,
} }
skb_put(skb, len); skb_put(skb, len);
id = desc.idx; addr = desc.addr;
buffer = xdp_umem_get_data(xs->umem, id) + desc.offset; buffer = xdp_umem_get_data(xs->umem, addr);
err = skb_store_bits(skb, 0, buffer, len); err = skb_store_bits(skb, 0, buffer, len);
if (unlikely(err)) { if (unlikely(err)) {
kfree_skb(skb); kfree_skb(skb);
...@@ -165,7 +168,7 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m, ...@@ -165,7 +168,7 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,
skb->dev = xs->dev; skb->dev = xs->dev;
skb->priority = sk->sk_priority; skb->priority = sk->sk_priority;
skb->mark = sk->sk_mark; skb->mark = sk->sk_mark;
skb_shinfo(skb)->destructor_arg = (void *)(long)id; skb_shinfo(skb)->destructor_arg = (void *)(long)addr;
skb->destructor = xsk_destruct_skb; skb->destructor = xsk_destruct_skb;
err = dev_direct_xmit(skb, xs->queue_id); err = dev_direct_xmit(skb, xs->queue_id);
......
...@@ -17,7 +17,7 @@ void xskq_set_umem(struct xsk_queue *q, struct xdp_umem_props *umem_props) ...@@ -17,7 +17,7 @@ void xskq_set_umem(struct xsk_queue *q, struct xdp_umem_props *umem_props)
static u32 xskq_umem_get_ring_size(struct xsk_queue *q) static u32 xskq_umem_get_ring_size(struct xsk_queue *q)
{ {
return sizeof(struct xdp_umem_ring) + q->nentries * sizeof(u32); return sizeof(struct xdp_umem_ring) + q->nentries * sizeof(u64);
} }
static u32 xskq_rxtx_get_ring_size(struct xsk_queue *q) static u32 xskq_rxtx_get_ring_size(struct xsk_queue *q)
......
...@@ -27,7 +27,7 @@ struct xdp_rxtx_ring { ...@@ -27,7 +27,7 @@ struct xdp_rxtx_ring {
/* Used for the fill and completion queues for buffers */ /* Used for the fill and completion queues for buffers */
struct xdp_umem_ring { struct xdp_umem_ring {
struct xdp_ring ptrs; struct xdp_ring ptrs;
u32 desc[0] ____cacheline_aligned_in_smp; u64 desc[0] ____cacheline_aligned_in_smp;
}; };
struct xsk_queue { struct xsk_queue {
...@@ -76,23 +76,25 @@ static inline u32 xskq_nb_free(struct xsk_queue *q, u32 producer, u32 dcnt) ...@@ -76,23 +76,25 @@ static inline u32 xskq_nb_free(struct xsk_queue *q, u32 producer, u32 dcnt)
/* UMEM queue */ /* UMEM queue */
static inline bool xskq_is_valid_id(struct xsk_queue *q, u32 idx) static inline bool xskq_is_valid_addr(struct xsk_queue *q, u64 addr)
{ {
if (unlikely(idx >= q->umem_props.nframes)) { if (addr >= q->umem_props.size) {
q->invalid_descs++; q->invalid_descs++;
return false; return false;
} }
return true; return true;
} }
static inline u32 *xskq_validate_id(struct xsk_queue *q) static inline u64 *xskq_validate_addr(struct xsk_queue *q, u64 *addr)
{ {
while (q->cons_tail != q->cons_head) { while (q->cons_tail != q->cons_head) {
struct xdp_umem_ring *ring = (struct xdp_umem_ring *)q->ring; struct xdp_umem_ring *ring = (struct xdp_umem_ring *)q->ring;
unsigned int idx = q->cons_tail & q->ring_mask; unsigned int idx = q->cons_tail & q->ring_mask;
if (xskq_is_valid_id(q, ring->desc[idx])) *addr = READ_ONCE(ring->desc[idx]) & q->umem_props.chunk_mask;
return &ring->desc[idx]; if (xskq_is_valid_addr(q, *addr))
return addr;
q->cons_tail++; q->cons_tail++;
} }
...@@ -100,35 +102,29 @@ static inline u32 *xskq_validate_id(struct xsk_queue *q) ...@@ -100,35 +102,29 @@ static inline u32 *xskq_validate_id(struct xsk_queue *q)
return NULL; return NULL;
} }
static inline u32 *xskq_peek_id(struct xsk_queue *q) static inline u64 *xskq_peek_addr(struct xsk_queue *q, u64 *addr)
{ {
struct xdp_umem_ring *ring;
if (q->cons_tail == q->cons_head) { if (q->cons_tail == q->cons_head) {
WRITE_ONCE(q->ring->consumer, q->cons_tail); WRITE_ONCE(q->ring->consumer, q->cons_tail);
q->cons_head = q->cons_tail + xskq_nb_avail(q, RX_BATCH_SIZE); q->cons_head = q->cons_tail + xskq_nb_avail(q, RX_BATCH_SIZE);
/* Order consumer and data */ /* Order consumer and data */
smp_rmb(); smp_rmb();
return xskq_validate_id(q);
} }
ring = (struct xdp_umem_ring *)q->ring; return xskq_validate_addr(q, addr);
return &ring->desc[q->cons_tail & q->ring_mask];
} }
static inline void xskq_discard_id(struct xsk_queue *q) static inline void xskq_discard_addr(struct xsk_queue *q)
{ {
q->cons_tail++; q->cons_tail++;
(void)xskq_validate_id(q);
} }
static inline int xskq_produce_id(struct xsk_queue *q, u32 id) static inline int xskq_produce_addr(struct xsk_queue *q, u64 addr)
{ {
struct xdp_umem_ring *ring = (struct xdp_umem_ring *)q->ring; struct xdp_umem_ring *ring = (struct xdp_umem_ring *)q->ring;
ring->desc[q->prod_tail++ & q->ring_mask] = id; ring->desc[q->prod_tail++ & q->ring_mask] = addr;
/* Order producer and data */ /* Order producer and data */
smp_wmb(); smp_wmb();
...@@ -137,7 +133,7 @@ static inline int xskq_produce_id(struct xsk_queue *q, u32 id) ...@@ -137,7 +133,7 @@ static inline int xskq_produce_id(struct xsk_queue *q, u32 id)
return 0; return 0;
} }
static inline int xskq_reserve_id(struct xsk_queue *q) static inline int xskq_reserve_addr(struct xsk_queue *q)
{ {
if (xskq_nb_free(q, q->prod_head, 1) == 0) if (xskq_nb_free(q, q->prod_head, 1) == 0)
return -ENOSPC; return -ENOSPC;
...@@ -150,16 +146,11 @@ static inline int xskq_reserve_id(struct xsk_queue *q) ...@@ -150,16 +146,11 @@ static inline int xskq_reserve_id(struct xsk_queue *q)
static inline bool xskq_is_valid_desc(struct xsk_queue *q, struct xdp_desc *d) static inline bool xskq_is_valid_desc(struct xsk_queue *q, struct xdp_desc *d)
{ {
u32 buff_len; if (!xskq_is_valid_addr(q, d->addr))
if (unlikely(d->idx >= q->umem_props.nframes)) {
q->invalid_descs++;
return false; return false;
}
buff_len = q->umem_props.frame_size; if (((d->addr + d->len) & q->umem_props.chunk_mask) !=
if (unlikely(d->len > buff_len || d->len == 0 || (d->addr & q->umem_props.chunk_mask)) {
d->offset > buff_len || d->offset + d->len > buff_len)) {
q->invalid_descs++; q->invalid_descs++;
return false; return false;
} }
...@@ -174,11 +165,9 @@ static inline struct xdp_desc *xskq_validate_desc(struct xsk_queue *q, ...@@ -174,11 +165,9 @@ static inline struct xdp_desc *xskq_validate_desc(struct xsk_queue *q,
struct xdp_rxtx_ring *ring = (struct xdp_rxtx_ring *)q->ring; struct xdp_rxtx_ring *ring = (struct xdp_rxtx_ring *)q->ring;
unsigned int idx = q->cons_tail & q->ring_mask; unsigned int idx = q->cons_tail & q->ring_mask;
if (xskq_is_valid_desc(q, &ring->desc[idx])) { *desc = READ_ONCE(ring->desc[idx]);
if (desc) if (xskq_is_valid_desc(q, desc))
*desc = ring->desc[idx];
return desc; return desc;
}
q->cons_tail++; q->cons_tail++;
} }
...@@ -189,31 +178,24 @@ static inline struct xdp_desc *xskq_validate_desc(struct xsk_queue *q, ...@@ -189,31 +178,24 @@ static inline struct xdp_desc *xskq_validate_desc(struct xsk_queue *q,
static inline struct xdp_desc *xskq_peek_desc(struct xsk_queue *q, static inline struct xdp_desc *xskq_peek_desc(struct xsk_queue *q,
struct xdp_desc *desc) struct xdp_desc *desc)
{ {
struct xdp_rxtx_ring *ring;
if (q->cons_tail == q->cons_head) { if (q->cons_tail == q->cons_head) {
WRITE_ONCE(q->ring->consumer, q->cons_tail); WRITE_ONCE(q->ring->consumer, q->cons_tail);
q->cons_head = q->cons_tail + xskq_nb_avail(q, RX_BATCH_SIZE); q->cons_head = q->cons_tail + xskq_nb_avail(q, RX_BATCH_SIZE);
/* Order consumer and data */ /* Order consumer and data */
smp_rmb(); smp_rmb();
return xskq_validate_desc(q, desc);
} }
ring = (struct xdp_rxtx_ring *)q->ring; return xskq_validate_desc(q, desc);
*desc = ring->desc[q->cons_tail & q->ring_mask];
return desc;
} }
static inline void xskq_discard_desc(struct xsk_queue *q) static inline void xskq_discard_desc(struct xsk_queue *q)
{ {
q->cons_tail++; q->cons_tail++;
(void)xskq_validate_desc(q, NULL);
} }
static inline int xskq_produce_batch_desc(struct xsk_queue *q, static inline int xskq_produce_batch_desc(struct xsk_queue *q,
u32 id, u32 len, u16 offset) u64 addr, u32 len)
{ {
struct xdp_rxtx_ring *ring = (struct xdp_rxtx_ring *)q->ring; struct xdp_rxtx_ring *ring = (struct xdp_rxtx_ring *)q->ring;
unsigned int idx; unsigned int idx;
...@@ -222,9 +204,8 @@ static inline int xskq_produce_batch_desc(struct xsk_queue *q, ...@@ -222,9 +204,8 @@ static inline int xskq_produce_batch_desc(struct xsk_queue *q,
return -ENOSPC; return -ENOSPC;
idx = (q->prod_head++) & q->ring_mask; idx = (q->prod_head++) & q->ring_mask;
ring->desc[idx].idx = id; ring->desc[idx].addr = addr;
ring->desc[idx].len = len; ring->desc[idx].len = len;
ring->desc[idx].offset = offset;
return 0; return 0;
} }
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#define NUM_FRAMES 131072 #define NUM_FRAMES 131072
#define FRAME_HEADROOM 0 #define FRAME_HEADROOM 0
#define FRAME_SHIFT 11
#define FRAME_SIZE 2048 #define FRAME_SIZE 2048
#define NUM_DESCS 1024 #define NUM_DESCS 1024
#define BATCH_SIZE 16 #define BATCH_SIZE 16
...@@ -55,6 +56,7 @@ ...@@ -55,6 +56,7 @@
#define DEBUG_HEXDUMP 0 #define DEBUG_HEXDUMP 0
typedef __u64 u64;
typedef __u32 u32; typedef __u32 u32;
static unsigned long prev_time; static unsigned long prev_time;
...@@ -81,12 +83,12 @@ struct xdp_umem_uqueue { ...@@ -81,12 +83,12 @@ struct xdp_umem_uqueue {
u32 size; u32 size;
u32 *producer; u32 *producer;
u32 *consumer; u32 *consumer;
u32 *ring; u64 *ring;
void *map; void *map;
}; };
struct xdp_umem { struct xdp_umem {
char (*frames)[FRAME_SIZE]; char *frames;
struct xdp_umem_uqueue fq; struct xdp_umem_uqueue fq;
struct xdp_umem_uqueue cq; struct xdp_umem_uqueue cq;
int fd; int fd;
...@@ -155,15 +157,15 @@ static const char pkt_data[] = ...@@ -155,15 +157,15 @@ static const char pkt_data[] =
static inline u32 umem_nb_free(struct xdp_umem_uqueue *q, u32 nb) static inline u32 umem_nb_free(struct xdp_umem_uqueue *q, u32 nb)
{ {
u32 free_entries = q->size - (q->cached_prod - q->cached_cons); u32 free_entries = q->cached_cons - q->cached_prod;
if (free_entries >= nb) if (free_entries >= nb)
return free_entries; return free_entries;
/* Refresh the local tail pointer */ /* Refresh the local tail pointer */
q->cached_cons = *q->consumer; q->cached_cons = *q->consumer + q->size;
return q->size - (q->cached_prod - q->cached_cons); return q->cached_cons - q->cached_prod;
} }
static inline u32 xq_nb_free(struct xdp_uqueue *q, u32 ndescs) static inline u32 xq_nb_free(struct xdp_uqueue *q, u32 ndescs)
...@@ -214,7 +216,7 @@ static inline int umem_fill_to_kernel_ex(struct xdp_umem_uqueue *fq, ...@@ -214,7 +216,7 @@ static inline int umem_fill_to_kernel_ex(struct xdp_umem_uqueue *fq,
for (i = 0; i < nb; i++) { for (i = 0; i < nb; i++) {
u32 idx = fq->cached_prod++ & fq->mask; u32 idx = fq->cached_prod++ & fq->mask;
fq->ring[idx] = d[i].idx; fq->ring[idx] = d[i].addr;
} }
u_smp_wmb(); u_smp_wmb();
...@@ -224,7 +226,7 @@ static inline int umem_fill_to_kernel_ex(struct xdp_umem_uqueue *fq, ...@@ -224,7 +226,7 @@ static inline int umem_fill_to_kernel_ex(struct xdp_umem_uqueue *fq,
return 0; return 0;
} }
static inline int umem_fill_to_kernel(struct xdp_umem_uqueue *fq, u32 *d, static inline int umem_fill_to_kernel(struct xdp_umem_uqueue *fq, u64 *d,
size_t nb) size_t nb)
{ {
u32 i; u32 i;
...@@ -246,7 +248,7 @@ static inline int umem_fill_to_kernel(struct xdp_umem_uqueue *fq, u32 *d, ...@@ -246,7 +248,7 @@ static inline int umem_fill_to_kernel(struct xdp_umem_uqueue *fq, u32 *d,
} }
static inline size_t umem_complete_from_kernel(struct xdp_umem_uqueue *cq, static inline size_t umem_complete_from_kernel(struct xdp_umem_uqueue *cq,
u32 *d, size_t nb) u64 *d, size_t nb)
{ {
u32 idx, i, entries = umem_nb_avail(cq, nb); u32 idx, i, entries = umem_nb_avail(cq, nb);
...@@ -266,10 +268,9 @@ static inline size_t umem_complete_from_kernel(struct xdp_umem_uqueue *cq, ...@@ -266,10 +268,9 @@ static inline size_t umem_complete_from_kernel(struct xdp_umem_uqueue *cq,
return entries; return entries;
} }
static inline void *xq_get_data(struct xdpsock *xsk, __u32 idx, __u32 off) static inline void *xq_get_data(struct xdpsock *xsk, u64 addr)
{ {
lassert(idx < NUM_FRAMES); return &xsk->umem->frames[addr];
return &xsk->umem->frames[idx][off];
} }
static inline int xq_enq(struct xdp_uqueue *uq, static inline int xq_enq(struct xdp_uqueue *uq,
...@@ -285,9 +286,8 @@ static inline int xq_enq(struct xdp_uqueue *uq, ...@@ -285,9 +286,8 @@ static inline int xq_enq(struct xdp_uqueue *uq,
for (i = 0; i < ndescs; i++) { for (i = 0; i < ndescs; i++) {
u32 idx = uq->cached_prod++ & uq->mask; u32 idx = uq->cached_prod++ & uq->mask;
r[idx].idx = descs[i].idx; r[idx].addr = descs[i].addr;
r[idx].len = descs[i].len; r[idx].len = descs[i].len;
r[idx].offset = descs[i].offset;
} }
u_smp_wmb(); u_smp_wmb();
...@@ -297,7 +297,7 @@ static inline int xq_enq(struct xdp_uqueue *uq, ...@@ -297,7 +297,7 @@ static inline int xq_enq(struct xdp_uqueue *uq,
} }
static inline int xq_enq_tx_only(struct xdp_uqueue *uq, static inline int xq_enq_tx_only(struct xdp_uqueue *uq,
__u32 idx, unsigned int ndescs) unsigned int id, unsigned int ndescs)
{ {
struct xdp_desc *r = uq->ring; struct xdp_desc *r = uq->ring;
unsigned int i; unsigned int i;
...@@ -308,9 +308,8 @@ static inline int xq_enq_tx_only(struct xdp_uqueue *uq, ...@@ -308,9 +308,8 @@ static inline int xq_enq_tx_only(struct xdp_uqueue *uq,
for (i = 0; i < ndescs; i++) { for (i = 0; i < ndescs; i++) {
u32 idx = uq->cached_prod++ & uq->mask; u32 idx = uq->cached_prod++ & uq->mask;
r[idx].idx = idx + i; r[idx].addr = (id + i) << FRAME_SHIFT;
r[idx].len = sizeof(pkt_data) - 1; r[idx].len = sizeof(pkt_data) - 1;
r[idx].offset = 0;
} }
u_smp_wmb(); u_smp_wmb();
...@@ -357,17 +356,21 @@ static void swap_mac_addresses(void *data) ...@@ -357,17 +356,21 @@ static void swap_mac_addresses(void *data)
*dst_addr = tmp; *dst_addr = tmp;
} }
#if DEBUG_HEXDUMP static void hex_dump(void *pkt, size_t length, u64 addr)
static void hex_dump(void *pkt, size_t length, const char *prefix)
{ {
int i = 0;
const unsigned char *address = (unsigned char *)pkt; const unsigned char *address = (unsigned char *)pkt;
const unsigned char *line = address; const unsigned char *line = address;
size_t line_size = 32; size_t line_size = 32;
unsigned char c; unsigned char c;
char buf[32];
int i = 0;
if (!DEBUG_HEXDUMP)
return;
sprintf(buf, "addr=%llu", addr);
printf("length = %zu\n", length); printf("length = %zu\n", length);
printf("%s | ", prefix); printf("%s | ", buf);
while (length-- > 0) { while (length-- > 0) {
printf("%02X ", *address++); printf("%02X ", *address++);
if (!(++i % line_size) || (length == 0 && i % line_size)) { if (!(++i % line_size) || (length == 0 && i % line_size)) {
...@@ -382,12 +385,11 @@ static void hex_dump(void *pkt, size_t length, const char *prefix) ...@@ -382,12 +385,11 @@ static void hex_dump(void *pkt, size_t length, const char *prefix)
} }
printf("\n"); printf("\n");
if (length > 0) if (length > 0)
printf("%s | ", prefix); printf("%s | ", buf);
} }
} }
printf("\n"); printf("\n");
} }
#endif
static size_t gen_eth_frame(char *frame) static size_t gen_eth_frame(char *frame)
{ {
...@@ -412,8 +414,8 @@ static struct xdp_umem *xdp_umem_configure(int sfd) ...@@ -412,8 +414,8 @@ static struct xdp_umem *xdp_umem_configure(int sfd)
mr.addr = (__u64)bufs; mr.addr = (__u64)bufs;
mr.len = NUM_FRAMES * FRAME_SIZE; mr.len = NUM_FRAMES * FRAME_SIZE;
mr.frame_size = FRAME_SIZE; mr.chunk_size = FRAME_SIZE;
mr.frame_headroom = FRAME_HEADROOM; mr.headroom = FRAME_HEADROOM;
lassert(setsockopt(sfd, SOL_XDP, XDP_UMEM_REG, &mr, sizeof(mr)) == 0); lassert(setsockopt(sfd, SOL_XDP, XDP_UMEM_REG, &mr, sizeof(mr)) == 0);
lassert(setsockopt(sfd, SOL_XDP, XDP_UMEM_FILL_RING, &fq_size, lassert(setsockopt(sfd, SOL_XDP, XDP_UMEM_FILL_RING, &fq_size,
...@@ -426,7 +428,7 @@ static struct xdp_umem *xdp_umem_configure(int sfd) ...@@ -426,7 +428,7 @@ static struct xdp_umem *xdp_umem_configure(int sfd)
&optlen) == 0); &optlen) == 0);
umem->fq.map = mmap(0, off.fr.desc + umem->fq.map = mmap(0, off.fr.desc +
FQ_NUM_DESCS * sizeof(u32), FQ_NUM_DESCS * sizeof(u64),
PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_POPULATE, sfd, MAP_SHARED | MAP_POPULATE, sfd,
XDP_UMEM_PGOFF_FILL_RING); XDP_UMEM_PGOFF_FILL_RING);
...@@ -437,9 +439,10 @@ static struct xdp_umem *xdp_umem_configure(int sfd) ...@@ -437,9 +439,10 @@ static struct xdp_umem *xdp_umem_configure(int sfd)
umem->fq.producer = umem->fq.map + off.fr.producer; umem->fq.producer = umem->fq.map + off.fr.producer;
umem->fq.consumer = umem->fq.map + off.fr.consumer; umem->fq.consumer = umem->fq.map + off.fr.consumer;
umem->fq.ring = umem->fq.map + off.fr.desc; umem->fq.ring = umem->fq.map + off.fr.desc;
umem->fq.cached_cons = FQ_NUM_DESCS;
umem->cq.map = mmap(0, off.cr.desc + umem->cq.map = mmap(0, off.cr.desc +
CQ_NUM_DESCS * sizeof(u32), CQ_NUM_DESCS * sizeof(u64),
PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_POPULATE, sfd, MAP_SHARED | MAP_POPULATE, sfd,
XDP_UMEM_PGOFF_COMPLETION_RING); XDP_UMEM_PGOFF_COMPLETION_RING);
...@@ -451,14 +454,14 @@ static struct xdp_umem *xdp_umem_configure(int sfd) ...@@ -451,14 +454,14 @@ static struct xdp_umem *xdp_umem_configure(int sfd)
umem->cq.consumer = umem->cq.map + off.cr.consumer; umem->cq.consumer = umem->cq.map + off.cr.consumer;
umem->cq.ring = umem->cq.map + off.cr.desc; umem->cq.ring = umem->cq.map + off.cr.desc;
umem->frames = (char (*)[FRAME_SIZE])bufs; umem->frames = bufs;
umem->fd = sfd; umem->fd = sfd;
if (opt_bench == BENCH_TXONLY) { if (opt_bench == BENCH_TXONLY) {
int i; int i;
for (i = 0; i < NUM_FRAMES; i++) for (i = 0; i < NUM_FRAMES * FRAME_SIZE; i += FRAME_SIZE)
(void)gen_eth_frame(&umem->frames[i][0]); (void)gen_eth_frame(&umem->frames[i]);
} }
return umem; return umem;
...@@ -472,7 +475,7 @@ static struct xdpsock *xsk_configure(struct xdp_umem *umem) ...@@ -472,7 +475,7 @@ static struct xdpsock *xsk_configure(struct xdp_umem *umem)
struct xdpsock *xsk; struct xdpsock *xsk;
bool shared = true; bool shared = true;
socklen_t optlen; socklen_t optlen;
u32 i; u64 i;
sfd = socket(PF_XDP, SOCK_RAW, 0); sfd = socket(PF_XDP, SOCK_RAW, 0);
lassert(sfd >= 0); lassert(sfd >= 0);
...@@ -508,7 +511,7 @@ static struct xdpsock *xsk_configure(struct xdp_umem *umem) ...@@ -508,7 +511,7 @@ static struct xdpsock *xsk_configure(struct xdp_umem *umem)
lassert(xsk->rx.map != MAP_FAILED); lassert(xsk->rx.map != MAP_FAILED);
if (!shared) { if (!shared) {
for (i = 0; i < NUM_DESCS / 2; i++) for (i = 0; i < NUM_DESCS * FRAME_SIZE; i += FRAME_SIZE)
lassert(umem_fill_to_kernel(&xsk->umem->fq, &i, 1) lassert(umem_fill_to_kernel(&xsk->umem->fq, &i, 1)
== 0); == 0);
} }
...@@ -533,6 +536,7 @@ static struct xdpsock *xsk_configure(struct xdp_umem *umem) ...@@ -533,6 +536,7 @@ static struct xdpsock *xsk_configure(struct xdp_umem *umem)
xsk->tx.producer = xsk->tx.map + off.tx.producer; xsk->tx.producer = xsk->tx.map + off.tx.producer;
xsk->tx.consumer = xsk->tx.map + off.tx.consumer; xsk->tx.consumer = xsk->tx.map + off.tx.consumer;
xsk->tx.ring = xsk->tx.map + off.tx.desc; xsk->tx.ring = xsk->tx.map + off.tx.desc;
xsk->tx.cached_cons = NUM_DESCS;
sxdp.sxdp_family = PF_XDP; sxdp.sxdp_family = PF_XDP;
sxdp.sxdp_ifindex = opt_ifindex; sxdp.sxdp_ifindex = opt_ifindex;
...@@ -727,7 +731,7 @@ static void kick_tx(int fd) ...@@ -727,7 +731,7 @@ static void kick_tx(int fd)
static inline void complete_tx_l2fwd(struct xdpsock *xsk) static inline void complete_tx_l2fwd(struct xdpsock *xsk)
{ {
u32 descs[BATCH_SIZE]; u64 descs[BATCH_SIZE];
unsigned int rcvd; unsigned int rcvd;
size_t ndescs; size_t ndescs;
...@@ -749,7 +753,7 @@ static inline void complete_tx_l2fwd(struct xdpsock *xsk) ...@@ -749,7 +753,7 @@ static inline void complete_tx_l2fwd(struct xdpsock *xsk)
static inline void complete_tx_only(struct xdpsock *xsk) static inline void complete_tx_only(struct xdpsock *xsk)
{ {
u32 descs[BATCH_SIZE]; u64 descs[BATCH_SIZE];
unsigned int rcvd; unsigned int rcvd;
if (!xsk->outstanding_tx) if (!xsk->outstanding_tx)
...@@ -774,17 +778,9 @@ static void rx_drop(struct xdpsock *xsk) ...@@ -774,17 +778,9 @@ static void rx_drop(struct xdpsock *xsk)
return; return;
for (i = 0; i < rcvd; i++) { for (i = 0; i < rcvd; i++) {
u32 idx = descs[i].idx; char *pkt = xq_get_data(xsk, descs[i].addr);
lassert(idx < NUM_FRAMES); hex_dump(pkt, descs[i].len, descs[i].addr);
#if DEBUG_HEXDUMP
char *pkt;
char buf[32];
pkt = xq_get_data(xsk, idx, descs[i].offset);
sprintf(buf, "idx=%d", idx);
hex_dump(pkt, descs[i].len, buf);
#endif
} }
xsk->rx_npkts += rcvd; xsk->rx_npkts += rcvd;
...@@ -867,17 +863,11 @@ static void l2fwd(struct xdpsock *xsk) ...@@ -867,17 +863,11 @@ static void l2fwd(struct xdpsock *xsk)
} }
for (i = 0; i < rcvd; i++) { for (i = 0; i < rcvd; i++) {
char *pkt = xq_get_data(xsk, descs[i].idx, char *pkt = xq_get_data(xsk, descs[i].addr);
descs[i].offset);
swap_mac_addresses(pkt); swap_mac_addresses(pkt);
#if DEBUG_HEXDUMP
char buf[32];
u32 idx = descs[i].idx;
sprintf(buf, "idx=%d", idx); hex_dump(pkt, descs[i].len, descs[i].addr);
hex_dump(pkt, descs[i].len, buf);
#endif
} }
xsk->rx_npkts += rcvd; xsk->rx_npkts += rcvd;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment