xsk: fix destination buffer address when copying with metadata
Subsystems (3)
PATCH 1/1 xsk: fix destination buffer address when copying with metadata
While working on a simplified test for [0] it occurred to me that the following looks fishy:
data = xsk_umem__get_data(xsk->umem_area, rx_desc->addr); data_meta = data - sizeof(my metadata);
Since the data points to umem frame at addr X, data_mem points to the end of umem frame X-1.
I don't think it's by design?
0: https://lore.kernel.org/bpf/[email protected]/T/#t
--- net/xdp/xsk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/xdp/xsk.c +1 -1
@@ -163,7 +163,7 @@ static void xsk_copy_xdp(struct xdp_buff *to, struct xdp_buff *from, u32 len) }else { from_buf = from->data_meta; metalen = from->data - from->data_meta; - to_buf = to->data - metalen; + to_buf = to->data; }memcpy (to_buf, from_buf, len + metalen);
Signature · 1 line
2.38.1.431.g37b22c650d-goog
Quoted 10 lines · Stanislav Fomichev
While working on a simplified test for [0] it occurred to me that the following looks fishy:
data = xsk_umem__get_data(xsk->umem_area, rx_desc->addr); data_meta = data - sizeof(my metadata);Since the data points to umem frame at addr X,
data_mempoints to the end of umem frame X-1.I don't think it's by design?
It is by design. :-)
net/xdp/xsk.c static void xsk_copy_xdp(struct xdp_buff *to, struct xdp_buff *from, u32 len) · line 166
Quoted 9 lines
net/xdp/xsk.c +0
-1@@ -163,7 +163,7 @@ static void xsk_copy_xdp(struct xdp_buff *to, struct xdp_buff *from, u32 len) }else { from_buf = from->data_meta; metalen = from->data - from->data_meta; - to_buf = to->data - metalen;
This is to include the XDP meta data in the receive buffer. Note that AF_XDP descriptor that you get back on the RX ring points to the *data* not the metadata.
For the unaligned mode you can pass any address (umem offset) into the fill ring, and the kernel will simply mask it and setup headroom accordingly.
The buffer allocator guarantees that there's XDP_PACKET_HEADROOM available.
IOW your example userland code above is correct.
Björn
Quoted 9 lines · Björn Töpel
Quoted 6 lines · Stanislav Fomichev
While working on a simplified test for [0] it occurred to me that the following looks fishy:
data = xsk_umem__get_data(xsk->umem_area, rx_desc->addr); data_meta = data - sizeof(my metadata);
Quoted 6 lines
Quoted 4 lines
Since the data points to umem frame at addr X,
data_mempoints to the end of umem frame X-1.I don't think it's by design?
It is by design. :-)
Noted, thanks for clarifying!
Quoted 14 lines
net/xdp/xsk.c static void xsk_copy_xdp(struct xdp_buff *to, struct xdp_buff *from, u32 len) · line 166
Quoted 9 lines
net/xdp/xsk.c +0
-1@@ -163,7 +163,7 @@ static void xsk_copy_xdp(struct xdp_buff *to, struct xdp_buff *from, u32 len) }else { from_buf = from->data_meta; metalen = from->data - from->data_meta; - to_buf = to->data - metalen;This is to include the XDP meta data in the receive buffer. Note that
AF_XDPdescriptor that you get back on the RX ring points to the *data* not the metadata.
Quoted 3 lines
For the unaligned mode you can pass any address (umem offset) into the fill ring, and the kernel will simply mask it and setup headroom accordingly.
Thanks for the details! And what happens in the aligned case?
Looking purely from the user side:
tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, idx); tx_desc->addr = idx * UMEM_FRAME_SIZE; /* this has to be aligned to the frame size? */
data = xsk_umem__get_data(xsk->umem_area, tx_desc->addr);
data here is basically = umem_area + idx * UMEM_FRAM_SIZE, right? How do I make sure metadata is placed in the same umem chunk? Will passing umem headroom do the trick?
Quoted 9 lines
The buffer allocator guarantees that there's
XDP_PACKET_HEADROOMavailable.IOW your example userland code above is correct.
Björn
Quoted 42 lines · Stanislav Fomichev
Quoted 9 lines · Björn Töpel
Quoted 6 lines · Stanislav Fomichev
While working on a simplified test for [0] it occurred to me that the following looks fishy:
data = xsk_umem__get_data(xsk->umem_area, rx_desc->addr); data_meta = data - sizeof(my metadata);Quoted 6 lines
Quoted 4 lines
Since the data points to umem frame at addr X,
data_mempoints to the end of umem frame X-1.I don't think it's by design?
It is by design. :-)
Noted, thanks for clarifying!
Quoted 14 lines
net/xdp/xsk.c static void xsk_copy_xdp(struct xdp_buff *to, struct xdp_buff *from, u32 len) · line 166
Quoted 9 lines
net/xdp/xsk.c +0
-1@@ -163,7 +163,7 @@ static void xsk_copy_xdp(struct xdp_buff *to, struct xdp_buff *from, u32 len) }else { from_buf = from->data_meta; metalen = from->data - from->data_meta; - to_buf = to->data - metalen;This is to include the XDP meta data in the receive buffer. Note that
AF_XDPdescriptor that you get back on the RX ring points to the *data* not the metadata.Quoted 3 lines
For the unaligned mode you can pass any address (umem offset) into the fill ring, and the kernel will simply mask it and setup headroom accordingly.
Thanks for the details! And what happens in the aligned case?
Looking purely from the user side:
Quoted 8 lines
tx_desc=xsk_ring_prod__tx_desc(&xsk->tx, idx);tx_desc->addr= idx *UMEM_FRAME_SIZE; /* this has to be aligned to the frame size? */
data =xsk_umem__get_data(xsk->umem_area, tx_desc->addr);data here is basically =
umem_area+ idx *UMEM_FRAM_SIZE, right? How do I make sure metadata is placed in the same umem chunk? Will passing umem headroom do the trick?
Ignore me. I do see now that there is always XDP_PACKET_HEADROOM bytes of headroom in rx_desc.
Quoted 10 lines
Quoted 10 lines
The buffer allocator guarantees that there's
XDP_PACKET_HEADROOMavailable.IOW your example userland code above is correct.
Björn