xsk: multi-buffer support
Subsystems (11)
Maciej Fijalkowski
maintainerv4 cover xsk: multi-buffer support
v3->v4:
-rely on ynl for adding new xdp_features flag [Jakub]
- move xskb_list to xsk_buff_pool
v2->v3:
- Fix issue with the next valid packet getting dropped after an invalid packet with MAX_SKB_FRAGS + 1 frags [Magnus]
- query NETDEV_XDP_ACT_ZC_SG flag within xskxceiver and act on it
- remove redundant include in xsk.c [kernel test robot]
- s/NETDEV_XDP_ACT_NDO_ZC_SG/NETDEV_XDP_ACT_ZC_SG + kernel doc [Magnus, Simon]
v1->v2:
- fix spelling issues in commit messages [Simon]
- remove XSK_DESC_MAX_FRAGS, use MAX_SKB_FRAGS instead [Stan, Alexei]
- add documentation patch
- fix build error from kernel test robot on patch 10
This series of patches add multi-buffer support for AF_XDP. XDP and various NIC drivers already have support for multi-buffer packets. With this patch set, programs using AF_XDP sockets can now also receive and transmit multi-buffer packets both in copy as well as zero-copy mode. ZC multi-buffer implementation is based on ice driver.
Some definitions to put us all on the same page:
* A packet consists of one or more frames
* A descriptor in one of the AF_XDP rings always refers to a single frame. In the case the packet consists of a single frame, the descriptor refers to the whole packet.
To represent a packet consisting of multiple frames, we introduce a new flag called XDP_PKT_CONTD in the options field of the Rx and Tx descriptors. If it is true (1) the packet continues with the next descriptor and if it is false (0) it means this is the last descriptor of the packet. Why the reverse logic of end-of-packet (eop) flag found in many NICs? Just to preserve compatibility with non-multi-buffer applications that have this bit set to false for all packets on Rx, and the apps set the options field to zero for Tx, as anything else will be treated as an invalid descriptor.
These are the semantics for producing packets onto XSK Tx ring consisting of multiple frames:
* When an invalid descriptor is found, all the other descriptors/frames of this packet are marked as invalid and not completed. The next descriptor is treated as the start of a new packet, even if this was not the intent (because we cannot guess the intent). As before, if your program is producing invalid descriptors you have a bug that must be fixed.
* Zero length descriptors are treated as invalid descriptors.
* For copy mode, the maximum supported number of frames in a packet is equal to CONFIG_MAX_SKB_FRAGS + 1. If it is exceeded, all descriptors accumulated so far are dropped and treated as invalid. To produce an application that will work on any system regardless of this config setting, limit the number of frags to 18, as the minimum value of the config is 17.
* For zero-copy mode, the limit is up to what the NIC HW supports. Usually at least five on the NICs we have checked. We consciously chose to not enforce a rigid limit (such as CONFIG_MAX_SKB_FRAGS + 1) for zero-copy mode, as it would have resulted in copy actions under the hood to fit into what limit the NIC supports. Kind of defeats the purpose of zero-copy mode.
* ZC batch API guarantees that it will provide a batch of Tx descriptors that ends with full packet at the end. If not, ZC drivers would have to gather the full packet on their side. The approach we picked makes ZC drivers life much easier (at least on Tx side).
Here is an example Tx path pseudo-code (using libxdp interfaces for simplicity) ignoring that the umem is finite in size, and that we eventually will run out of packets to send. Also assumes pkts.addr points to a valid location in the umem.
void tx_packets(struct xsk_socket_info *xsk, struct pkt *pkts,
int batch_size)
{
u32 idx, i, pkt_nb = 0;
xsk_ring_prod__reserve(&xsk->tx, batch_size, &idx);
for (i = 0; i < batch_size;) {
u64 addr = pkts[pkt_nb].addr;
u32 len = pkts[pkt_nb].size;
do {
struct xdp_desc *tx_desc;
tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, idx + i++);
tx_desc->addr = addr;
if (len > xsk_frame_size) {
tx_desc->len = xsk_frame_size;
tx_desc->options |= XDP_PKT_CONTD;
} else {
tx_desc->len = len;
tx_desc->options = 0;
pkt_nb++;
}
len -= tx_desc->len;
addr += xsk_frame_size;
if (i == batch_size) {
/* Remember len, addr, pkt_nb for next
* iteration. Skipped for simplicity.
*/
break;
}
} while (len);
}
xsk_ring_prod__submit(&xsk->tx, i);
}On the Rx path in copy mode, the xsk core copies the XDP data into multiple descriptors, if needed, and sets the XDP_PKT_CONTD flag as detailed before. Zero-copy mode in order to avoid the copies has to maintain a chain of xdp_buff_xsk structs that represent whole packet. This is because what actually is redirected is the xdp_buff and we currently have no equivalent mechanism that is used for copy mode (embedded skb_shared_info in xdp_buff) to carry the frags. This means xdp_buff_xsk grows in size but these members are at the end and should not be touched when data path is not dealing with fragmented packets. This solution kept us within assumed performance impact, hence we decided to proceed with it.
When the application gets a descriptor with the XDP_PKT_CONTD flag set to one, it means that the packet consists of multiple buffers and it continues with the next buffer in the following descriptor. When a descriptor with XDP_PKT_CONTD == 0 is received, it means that this is the last buffer of the packet. AF_XDP guarantees that only a complete packet (all frames in the packet) is sent to the application.
If application reads a batch of descriptors, using for example the libxdp interfaces, it is not guaranteed that the batch will end with a full packet. It might end in the middle of a packet and the rest of the buffers of that packet will arrive at the beginning of the next batch, since the libxdp interface does not read the whole ring (unless you have an enormous batch size or a very small ring size).
Here is a simple Rx path pseudo-code example (using libxdp interfaces for simplicity). Error paths have been excluded for simplicity:
void rx_packets(struct xsk_socket_info *xsk)
{
static bool new_packet = true;
u32 idx_rx = 0, idx_fq = 0;
static char *pkt;
int rcvd = xsk_ring_cons__peek(&xsk->rx, opt_batch_size, &idx_rx);
xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq);
for (int i = 0; i < rcvd; i++) {
struct xdp_desc *desc = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++);
char *frag = xsk_umem__get_data(xsk->umem->buffer, desc->addr);
bool eop = !(desc->options & XDP_PKT_CONTD);
if (new_packet)
pkt = frag;
else
add_frag_to_pkt(pkt, frag);
if (eop)
process_pkt(pkt);
new_packet = eop;
*xsk_ring_prod__fill_addr(&xsk->umem->fq, idx_fq++) = desc->addr;
}
xsk_ring_prod__submit(&xsk->umem->fq, rcvd);
xsk_ring_cons__release(&xsk->rx, rcvd);
}Unfortunately, we had to introduce a new bind flag (XDP_USE_SG) on the AF_XDP level to enable multi-buffer support. It would be great if you have ideas on how to get rid of it. The reason we need to differentiate between non multi-buffer and multi-buffer is the behaviour when the kernel gets a packet that is larger than the frame size. Without multi-buffer, this packet is dropped and marked in the stats. With multi-buffer on, we want to split it up into multiple frames instead.
At the start, we thought that riding on the .frags section name of the XDP program was a good idea. You do not have to introduce yet another flag and all AF_XDP users must load an XDP program anyway to get any traffic up to the socket, so why not just say that the XDP program decides if the AF_XDP socket should get multi-buffer packets or not? The problem is that we can create an AF_XDP socket that is Tx only and that works without having to load an XDP program at all. Another problem is that the XDP program might change during the execution, so we would have to check this for every single packet.
Here is the observed throughput when compared without any multi-buffer changes and measured with xdpsock prog for 64B packets (+ is improvement) is about same with a small drop for rx_drop for copy mode, zero-copy mode is more sensitive and as shown below rxdrop gets around 5% performance drop. Note that this drop combines from core + driver support, whereas copy mode had already driver support in place.
Mode rxdrop l2fwd txonly
xdp-zc -5% -3% -2% xdp-drv -1.2% 0% +2% xdp-skb -0.6% -1% +2%
Thank you,
Tirthendu, Magnus and Maciej
Maciej Fijalkowski (8):
xsk: prepare both copy and zero-copy modes to co-exist
xsk: allow core/drivers to test EOP bit
xsk: support mbuf on ZC RX
ice: xsk: add RX multi-buffer support
xsk: support ZC Tx multi-buffer in batch API
xsk: report zero-copy multi-buffer capability via xdp_features
ice: xsk: Tx multi-buffer support
selftests/xsk: reset NIC settings to default after running test suite
Magnus Karlsson (7):
xsk: add multi-buffer documentation selftests/xsk: transmit and receive multi-buffer packets selftests/xsk: add basic multi-buffer test selftests/xsk: add unaligned mode test for multi-buffer selftests/xsk: add invalid descriptor test for multi-buffer selftests/xsk: add metadata copy test for multi-buff selftests/xsk: add test for too many frags
Tirthendu Sarkar (7):
xsk: prepare 'options' in xdp_desc for multi-buffer use
xsk: introduce XSK_USE_SG bind flag for xsk socket
xsk: move xdp_buff's data length check to xsk_rcv_check
xsk: add support for AF_XDP multi-buffer on Rx path
xsk: introduce wrappers and helpers for supporting multi-buffer in Tx
path
xsk: add support for AF_XDP multi-buffer on Tx path
xsk: discard zero length descriptors in Tx path
Documentation/netlink/specs/netdev.yaml | 5 + Documentation/networking/af_xdp.rst | 177 +++++++ drivers/net/ethernet/intel/ice/ice_base.c | 9 +- drivers/net/ethernet/intel/ice/ice_main.c | 2 +- drivers/net/ethernet/intel/ice/ice_xsk.c | 221 ++++++--- include/net/xdp_sock.h | 7 + include/net/xdp_sock_drv.h | 54 +++ include/net/xsk_buff_pool.h | 7 + include/uapi/linux/if_xdp.h | 13 + include/uapi/linux/netdev.h | 5 +- net/core/filter.c | 7 +- net/xdp/xsk.c | 362 ++++++++++---- net/xdp/xsk_buff_pool.c | 8 + net/xdp/xsk_queue.h | 91 ++-- tools/include/uapi/linux/if_xdp.h | 9 + tools/include/uapi/linux/netdev.h | 5 +- .../selftests/bpf/progs/xsk_xdp_progs.c | 6 +- tools/testing/selftests/bpf/test_xsk.sh | 5 + tools/testing/selftests/bpf/xsk.c | 136 +++++- tools/testing/selftests/bpf/xsk.h | 2 + tools/testing/selftests/bpf/xsk_prereqs.sh | 7 + tools/testing/selftests/bpf/xskxceiver.c | 447 +++++++++++++++--- tools/testing/selftests/bpf/xskxceiver.h | 20 +- 23 files changed, 1352 insertions(+), 253 deletions(-)
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 1/22 xsk: prepare 'options' in xdp_desc for multi-buffer use
From: Tirthendu Sarkar <[email protected]>
Use the 'options' field in xdp_desc as a packet continuity marker. Since 'options' field was unused till now and was expected to be set to 0, the 'eop' descriptor will have it set to 0, while the non-eop descriptors will have to set it to 1. This ensures legacy applications continue to work without needing any change for single-buffer packets.
Add helper functions and extend xskq_prod_reserve_desc() to use the 'options' field.
--- include/uapi/linux/if_xdp.h | 7 +++++++ net/xdp/xsk.c | 8 ++++---- net/xdp/xsk_queue.h | 12 +++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-)
include/uapi/linux/if_xdp.h +7 -0
@@ -108,4 +108,11 @@ struct xdp_desc {/* UMEM descriptor is __u64 */ +/* Flag indicating that the packet continues with the buffer pointed out by the +* next frame in the ring. The end of the packet is signalled by setting this +* bit to zero. For single buffer packets, every descriptor has 'options' set +* to 0 and this maintains backward compatibility. +*/ +#define XDP_PKT_CONTD (1 << 0) +#endif /* _LINUX_IF_XDP_H */
net/xdp/xsk.c +4 -4
@@ -135,14 +135,14 @@ int xsk_reg_pool_at_qid(struct net_device *dev, struct xsk_buff_pool *pool,return 0 ; } -static int __xsk_rcv_zc (struct xdp_sock *xs,struct xdp_buff *xdp,u32 len) +static int __xsk_rcv_zc (struct xdp_sock *xs,struct xdp_buff *xdp,u32 len,u32 flags) { struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);u64 addr;int err; addr =xp_get_handle (xskb); - err =xskq_prod_reserve_desc (xs->rx, addr, len); + err =xskq_prod_reserve_desc (xs->rx, addr, len, flags);if (err) { xs->rx_queue_full++;return err;
@@ -189,7 +189,7 @@ static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) }xsk_copy_xdp (xsk_xdp, xdp, len); - err =__xsk_rcv_zc (xs, xsk_xdp, len); + err =__xsk_rcv_zc (xs, xsk_xdp, len,0 );if (err) {xsk_buff_free (xsk_xdp);return err;
@@ -259,7 +259,7 @@ static int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)if (xdp->rxq->mem.type ==MEM_TYPE_XSK_BUFF_POOL ) { len = xdp->data_end - xdp->data; -return __xsk_rcv_zc (xs, xdp, len); +return __xsk_rcv_zc (xs, xdp, len,0 ); } err =__xsk_rcv (xs, xdp);
net/xdp/xsk_queue.h +9 -3
@@ -130,6 +130,11 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr)return false; } +static inline bool xp_unused_options_set (u16 options) +{ +return options & ~XDP_PKT_CONTD ; +} +static inline bool xp_aligned_validate_desc (struct xsk_buff_pool *pool,struct xdp_desc *desc) {
@@ -141,7 +146,7 @@ static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool,if (desc->addr >= pool->addrs_cnt)return false; -if (desc->options) +if (xp_unused_options_set (desc->options))return false;return true; }
@@ -158,7 +163,7 @@ static inline bool xp_unaligned_validate_desc(struct xsk_buff_pool *pool, xp_desc_crosses_non_contig_pg(pool, addr, desc->len))return false; -if (desc->options) +if (xp_unused_options_set (desc->options))return false;return true; }
@@ -360,7 +365,7 @@ static inline void xskq_prod_write_addr_batch(struct xsk_queue *q, struct xdp_de }static inline int xskq_prod_reserve_desc (struct xsk_queue *q, -u64 addr,u32 len) +u64 addr,u32 len,u32 flags) {struct xdp_rxtx_ring *ring = (struct xdp_rxtx_ring *)q->ring;u32 idx;
@@ -372,6 +377,7 @@ static inline int xskq_prod_reserve_desc(struct xsk_queue *q, idx = q->cached_prod++ & q->ring_mask; ring->desc[idx].addr = addr; ring->desc[idx].len = len; + ring->desc[idx].options = flags;return 0 ; }
Signature · 1 line
2.34.1
Re: [PATCH v4 bpf-next 01/22] xsk: prepare 'options' in xdp_desc for multi-buffer use
Quoted 18 lines · Maciej Fijalkowski
From: Tirthendu Sarkar <[email protected]>
Use the 'options' field in
xdp_descas a packet continuity marker. Since 'options' field was unused till now and was expected to be set to 0, the 'eop' descriptor will have it set to 0, while the non-eop descriptors will have to set it to 1. This ensures legacy applications continue to work without needing any change for single-buffer packets.Add helper functions and extend
xskq_prod_reserve_desc()to use the 'options' field.Signed-off-by Tirthendu Sarkar <[email protected]>--- include/uapi/linux/if_xdp.h | 7 +++++++ net/xdp/xsk.c | 8 ++++---- net/xdp/xsk_queue.h | 12 +++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-)
[...]
net/xdp/xsk_queue.h static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr) · line 133
Quoted 9 lines
net/xdp/xsk_queue.h +1
-0@@ -130,6 +130,11 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr)return false; } +static inline bool xp_unused_options_set (u16 options)
^
To match struct xdp_desc, this should be u32, no?
Maciej Fijalkowski
maintainerRe: [PATCH v4 bpf-next 01/22] xsk: prepare 'options' in xdp_desc for multi-buffer use
Quoted 28 lines · Benjamin Poirier
Quoted 18 lines · Maciej Fijalkowski
From: Tirthendu Sarkar <[email protected]>
Use the 'options' field in
xdp_descas a packet continuity marker. Since 'options' field was unused till now and was expected to be set to 0, the 'eop' descriptor will have it set to 0, while the non-eop descriptors will have to set it to 1. This ensures legacy applications continue to work without needing any change for single-buffer packets.Add helper functions and extend
xskq_prod_reserve_desc()to use the 'options' field.Signed-off-by Tirthendu Sarkar <[email protected]>--- include/uapi/linux/if_xdp.h | 7 +++++++ net/xdp/xsk.c | 8 ++++---- net/xdp/xsk_queue.h | 12 +++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-)[...]
Quoted 8 lines
net/xdp/xsk_queue.h +0
-0@@ -130,6 +130,11 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr)return false; }
Quoted 3 lines
net/xdp/xsk_queue.h static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr) · line 133
Quoted 1 line
net/xdp/xsk_queue.h +1
-0+static inline bool xp_unused_options_set (u16 options)^To match struct
xdp_desc, this should be u32, no?
Of course. Good catch. It's going to be fixed in next revision.
Maciej Fijalkowski
maintainerPATCH v4 2/22 xsk: introduce XSK_USE_SG bind flag for xsk socket
In reply to Maciej FijalkowskiFrom: Tirthendu Sarkar <[email protected]>
As of now xsk core drops any xdp_buff with data size greater than the xsk frame_size as set by the af_xdp application. With multi-buffer support introduced in the next patch xsk core can now split those buffers into multiple descriptors provided the af_xdp application can handle them. Such capability of the application needs to be independent of the xdp_prog's frag support capability since there are cases where even a single xdp_buffer may need to be split into multiple descriptors owing to a smaller xsk frame size.
For e.g., with NIC rx_buffer size set to 4kB, a 3kB packet will constitute of a single buffer and so will be sent as such to AF_XDP layer irrespective of 'xdp.frags' capability of the XDP program. Now if the xsk frame size is set to 2kB by the AF_XDP application, then the packet will need to be split into 2 descriptors if AF_XDP application can handle multi-buffer, else it needs to be dropped.
Applications can now advertise their frag handling capability to xsk core so that xsk core can decide if it should drop or split xdp_buffs that exceed xsk frame size. This is done using a new 'XSK_USE_SG' bind flag for the xdp socket.
--- include/net/xdp_sock.h | 1 + include/uapi/linux/if_xdp.h | 6 ++++++ net/xdp/xsk.c | 5 +++-- 3 files changed, 10 insertions(+), 2 deletions(-)
include/net/xdp_sock.h +1 -0
@@ -52,6 +52,7 @@ struct xdp_sock {struct xsk_buff_pool *pool;u16 queue_id;bool zc; +bool sg;enum {XSK_READY =0 ,XSK_BOUND ,
include/uapi/linux/if_xdp.h +6 -0
@@ -25,6 +25,12 @@* application. */ #define XDP_USE_NEED_WAKEUP (1 << 3) +/* By setting this option, userspace application indicates that it can +* handle multiple descriptors per packet thus enabling AF_XDP to split +* multi-buffer XDP frames into multiple Rx descriptors. Without this set +* such frames will be dropped. +*/ +#define XDP_USE_SG (1 << 4)/* Flags for xsk_umem_config flags */ #define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
net/xdp/xsk.c +3 -2
@@ -896,7 +896,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) flags = sxdp->sxdp_flags;if (flags & ~(XDP_SHARED_UMEM |XDP_COPY |XDP_ZEROCOPY | -XDP_USE_NEED_WAKEUP )) +XDP_USE_NEED_WAKEUP |XDP_USE_SG ))return -EINVAL ;rtnl_lock ();
@@ -924,7 +924,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)struct socket *sock;if ((flags &XDP_COPY ) || (flags &XDP_ZEROCOPY ) || - (flags &XDP_USE_NEED_WAKEUP )) { + (flags &XDP_USE_NEED_WAKEUP ) || (flags &XDP_USE_SG )) {/* Cannot specify flags for shared sockets. */ err = -EINVAL ; goto out_unlock;
@@ -1023,6 +1023,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) xs->dev = dev; xs->zc = xs->umem->zc; + xs->sg = !!(flags &XDP_USE_SG ); xs->queue_id = qid;xp_add_xsk (xs->pool, xs);
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 3/22 xsk: prepare both copy and zero-copy modes to co-exist
In reply to Maciej FijalkowskiCurrently, __xsk_rcv_zc() is a function that is responsible for producing AF_XDP Rx descriptors. It is used by both copy and zero-copy mode. Both of these modes are going to differ when multi-buffer support is going to be added. ZC will work on a chain of xdp_buff_xsk structs whereas copy-mode is going to utilize skb_shared_info contents. This means that ZC-specific changes would affect the copy mode.
Let's modify __xsk_rcv_zc() to work directly on xdp_buff_xsk so the callsites have to retrieve this from xdp_buff. Also, introduce xsk_rcv_zc() which will carry all the needed later changes for supporting multi-buffer on ZC side that do not apply to copy mode.
--- net/xdp/xsk.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
net/xdp/xsk.c +13 -4
@@ -135,9 +135,9 @@ int xsk_reg_pool_at_qid(struct net_device *dev, struct xsk_buff_pool *pool,return 0 ; } -static int __xsk_rcv_zc (struct xdp_sock *xs,struct xdp_buff *xdp,u32 len,u32 flags) +static int __xsk_rcv_zc (struct xdp_sock *xs,struct xdp_buff_xsk *xskb,u32 len, +u32 flags) { - struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);u64 addr;int err;
@@ -152,6 +152,13 @@ static int __xsk_rcv_zc(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len, u32return 0 ; } +static int xsk_rcv_zc (struct xdp_sock *xs,struct xdp_buff *xdp,u32 len) +{ + struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp); + +return __xsk_rcv_zc (xs, xskb, len,0 ); +} +static void xsk_copy_xdp (struct xdp_buff *to,struct xdp_buff *from,u32 len) {void *from_buf, *to_buf;
@@ -172,6 +179,7 @@ static void xsk_copy_xdp(struct xdp_buff *to, struct xdp_buff *from, u32 len)static int __xsk_rcv (struct xdp_sock *xs,struct xdp_buff *xdp) { +struct xdp_buff_xsk *xskb;struct xdp_buff *xsk_xdp;int err;u32 len;
@@ -189,7 +197,8 @@ static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) }xsk_copy_xdp (xsk_xdp, xdp, len); - err =__xsk_rcv_zc (xs, xsk_xdp, len,0 ); + xskb = container_of(xsk_xdp, struct xdp_buff_xsk, xdp); + err =__xsk_rcv_zc (xs, xskb, len,0 );if (err) {xsk_buff_free (xsk_xdp);return err;
@@ -259,7 +268,7 @@ static int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)if (xdp->rxq->mem.type ==MEM_TYPE_XSK_BUFF_POOL ) { len = xdp->data_end - xdp->data; -return __xsk_rcv_zc (xs, xdp, len,0 ); +return xsk_rcv_zc (xs, xdp, len); } err =__xsk_rcv (xs, xdp);
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 4/22 xsk: move xdp_buff's data length check to xsk_rcv_check
In reply to Maciej FijalkowskiFrom: Tirthendu Sarkar <[email protected]>
If the data in xdp_buff exceeds the xsk frame length, the packet needs to be dropped. This check is currently being done in __xsk_rcv(). Move the described logic to xsk_rcv_check() so that such a xdp_buff will only be dropped if the application does not support multi-buffer (absence of XDP_USE_SG bind flag). This is applicable for all cases:
copy mode, zero copy mode as well as skb mode.
--- net/xdp/xsk.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
net/xdp/xsk.c +13 -14
@@ -177,18 +177,11 @@ static void xsk_copy_xdp(struct xdp_buff *to, struct xdp_buff *from, u32 len)memcpy (to_buf, from_buf, len + metalen); } -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 len) {struct xdp_buff_xsk *xskb;struct xdp_buff *xsk_xdp;int err; -u32 len; - - len = xdp->data_end - xdp->data; -if (len >xsk_pool_get_rx_frame_size (xs->pool)) { - xs->rx_dropped++; -return -ENOSPC ; - } xsk_xdp =xsk_buff_alloc (xs->pool);if (!xsk_xdp) {
@@ -224,7 +217,7 @@ static bool xsk_is_bound(struct xdp_sock *xs)return false; } -static int xsk_rcv_check (struct xdp_sock *xs,struct xdp_buff *xdp) +static int xsk_rcv_check (struct xdp_sock *xs,struct xdp_buff *xdp,u32 len) {if (!xsk_is_bound (xs))return -ENXIO ;
@@ -232,6 +225,11 @@ static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp)if (xs->dev != xdp->rxq->dev || xs->queue_id != xdp->rxq->queue_index)return -EINVAL ; +if (len >xsk_pool_get_rx_frame_size (xs->pool)) { + xs->rx_dropped++; +return -ENOSPC ; + } +sk_mark_napi_id_once_xdp (&xs->sk, xdp);return 0 ; }
@@ -245,12 +243,13 @@ static void xsk_flush(struct xdp_sock *xs)int xsk_generic_rcv (struct xdp_sock *xs,struct xdp_buff *xdp) { +u32 len =xdp_get_buff_len (xdp);int err;spin_lock_bh (&xs->rx_lock); - err =xsk_rcv_check (xs, xdp); + err =xsk_rcv_check (xs, xdp, len);if (!err) { - err =__xsk_rcv (xs, xdp); + err =__xsk_rcv (xs, xdp, len);xsk_flush (xs); }spin_unlock_bh (&xs->rx_lock);
@@ -259,10 +258,10 @@ int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)static int xsk_rcv (struct xdp_sock *xs,struct xdp_buff *xdp) { +u32 len =xdp_get_buff_len (xdp);int err; -u32 len; - err =xsk_rcv_check (xs, xdp); + err =xsk_rcv_check (xs, xdp, len);if (err)return err;
@@ -271,7 +270,7 @@ static int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)return xsk_rcv_zc (xs, xdp, len); } - err =__xsk_rcv (xs, xdp); + err =__xsk_rcv (xs, xdp, len);if (!err)xdp_return_buff (xdp);return err;
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 5/22 xsk: add support for AF_XDP multi-buffer on Rx path
In reply to Maciej FijalkowskiFrom: Tirthendu Sarkar <[email protected]>
Add multi-buffer support for AF_XDP by extending the XDP multi-buffer support to be reflected in user-space when a packet is redirected to an AF_XDP socket.
In the XDP implementation, the NIC driver builds the xdp_buff from the first frag of the packet and adds any subsequent frags in the skb_shinfo area of the xdp_buff. In AF_XDP core, XDP buffers are allocated from xdp_sock's pool and data is copied from the driver's xdp_buff and frags.
Once an allocated XDP buffer is full and there is still data to be copied, the 'XDP_PKT_CONTD' flag in'options' field of the corresponding xdp ring descriptor is set and passed to the application. When application sees the aforementioned flag set it knows there is pending data for this packet that will be carried in the following descriptors. If there is no more data to be copied, the flag in 'options' field is cleared for that descriptor signalling EOP to the application.
If application reads a batch of descriptors using for example the libxdp interfaces, it is not guaranteed that the batch will end with a full packet. It might end in the middle of a packet and the rest of the frames of that packet will arrive at the beginning of the next batch.
AF_XDP ensures that only a complete packet (along with all its frags) is sent to application.
--- net/core/filter.c | 7 +-- net/xdp/xsk.c | 110 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 29 deletions(-)
net/core/filter.c +1 -6
@@ -4344,13 +4344,8 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,struct bpf_redirect_info *ri =this_cpu_ptr (&bpf_redirect_info);enum bpf_map_type map_type = ri->map_type; -if (map_type ==BPF_MAP_TYPE_XSKMAP ) { -/* XDP_REDIRECT is not supported AF_XDP yet. */ -if (unlikely (xdp_buff_has_frags (xdp))) -return -EOPNOTSUPP ; - +if (map_type ==BPF_MAP_TYPE_XSKMAP )return __xdp_do_redirect_xsk (ri, dev, xdp, xdp_prog); - }return __xdp_do_redirect_frame (ri, dev,xdp_convert_buff_to_frame (xdp), xdp_prog);
net/xdp/xsk.c +87 -23
137 lines not on this page · raw message
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 6/22 xsk: introduce wrappers and helpers for supporting multi-buffer in Tx path
In reply to Maciej FijalkowskiFrom: Tirthendu Sarkar <[email protected]>
In Tx path, xsk core reserves space for each desc to be transmitted in the completion queue and it's address contained in it is stored in the skb destructor arg. After successful transmission the skb destructor submits the addr marking completion.
To handle multiple descriptors per packet, now along with reserving space for each descriptor, the corresponding address is also stored in completion queue. The number of pending descriptors are stored in skb destructor arg and is used by the skb destructor to update completions.
Introduce 'skb' in xdp_sock to store a partially built packet when __xsk_generic_xmit() must return before it sees the EOP descriptor for the current packet so that packet building can resume in next call of __xsk_generic_xmit().
Helper functions are introduced to set and get the pending descriptors in the skb destructor arg. Also, wrappers are introduced for storing descriptor addresses, submitting and cancelling (for unsuccessful transmissions) the number of completions.
--- include/net/xdp_sock.h | 6 ++++ net/xdp/xsk.c | 74 ++++++++++++++++++++++++++++++------------ net/xdp/xsk_queue.h | 19 ++++------- 3 files changed, 67 insertions(+), 32 deletions(-)
include/net/xdp_sock.h +6 -0
@@ -68,6 +68,12 @@ struct xdp_sock {u64 rx_dropped;u64 rx_queue_full; +/* When __xsk_generic_xmit() must return before it sees the EOP descriptor for the current +* packet, the partially built skb is saved here so that packet building can resume in next +* call of __xsk_generic_xmit(). +*/ +struct sk_buff *skb; +struct list_head map_list;/* Protects map_list */ spinlock_t map_list_lock;
net/xdp/xsk.c +54 -20
119 lines not on this page · raw message
net/xdp/xsk_queue.h +7 -12
@@ -297,6 +297,11 @@ static inline void xskq_cons_release(struct xsk_queue *q) q->cached_cons++; } +static inline void xskq_cons_cancel_n (struct xsk_queue *q,u32 cnt) +{ + q->cached_cons -= cnt; +} +static inline u32 xskq_cons_present_entries (struct xsk_queue *q) {/* No barriers needed since data is not accessed */
@@ -324,9 +329,9 @@ static inline bool xskq_prod_is_full(struct xsk_queue *q)return xskq_prod_nb_free (q,1 ) ? false : true; } -static inline void xskq_prod_cancel (struct xsk_queue *q) +static inline void xskq_prod_cancel_n (struct xsk_queue *q,u32 cnt) { - q->cached_prod--; + q->cached_prod -= cnt; }static inline int xskq_prod_reserve (struct xsk_queue *q)
@@ -392,16 +397,6 @@ static inline void xskq_prod_submit(struct xsk_queue *q)__xskq_prod_submit (q, q->cached_prod); } -static inline void xskq_prod_submit_addr (struct xsk_queue *q,u64 addr) -{ -struct xdp_umem_ring *ring = (struct xdp_umem_ring *)q->ring; -u32 idx = q->ring->producer; - - ring->desc[idx++ & q->ring_mask] = addr; - -__xskq_prod_submit (q, idx); -} -static inline void xskq_prod_submit_n (struct xsk_queue *q,u32 nb_entries) {__xskq_prod_submit (q, q->ring->producer + nb_entries);
Signature · 1 line
2.34.1
Re: [PATCH v4 bpf-next 06/22] xsk: introduce wrappers and helpers for supporting multi-buffer in Tx path
Quoted 34 lines · Maciej Fijalkowski
From: Tirthendu Sarkar <[email protected]>
In Tx path, xsk core reserves space for each desc to be transmitted in the completion queue and it's address contained in it is stored in the skb destructor arg. After successful transmission the skb destructor submits the addr marking completion.
To handle multiple descriptors per packet, now along with reserving space for each descriptor, the corresponding address is also stored in completion queue. The number of pending descriptors are stored in skb destructor arg and is used by the skb destructor to update completions.
Introduce 'skb' in
xdp_sockto store a partially built packet when__xsk_generic_xmit()must return before it sees the EOP descriptor for the current packet so that packet building can resume in next call of__xsk_generic_xmit().Helper functions are introduced to set and get the pending descriptors in the skb destructor arg. Also, wrappers are introduced for storing descriptor addresses, submitting and cancelling (for unsuccessful transmissions) the number of completions.
Signed-off-by Tirthendu Sarkar <[email protected]>--- include/net/xdp_sock.h | 6 ++++ net/xdp/xsk.c | 74 ++++++++++++++++++++++++++++++------------ net/xdp/xsk_queue.h | 19 ++++------- 3 files changed, 67 insertions(+), 32 deletions(-)include/net/xdp_sock.h +0
-0
include/net/xdp_sock.h struct xdp_sock { · line 75
Quoted 8 lines
include/net/xdp_sock.h +5
-0@@ -68,6 +68,12 @@ struct xdp_sock {u64 rx_dropped;u64 rx_queue_full; +/* When __xsk_generic_xmit() must return before it sees the EOP descriptor for the current +* packet, the partially built skb is saved here so that packet building can resume in next +* call of __xsk_generic_xmit(). +*/ +struct sk_buff *skb;
What ensures this doesn't leak? IIUC, when the loop in __xsk_generic_xmit() gets to the end of a batch, userspace will get an EAGAIN error and be expected to retry the call later, right? But if userspace never retries, could the socket be torn down with this pointer still populated? I looked for something that would prevent this in subsequent patches, but couldn't find it; am I missing something?
-Toke
RE: [PATCH v4 bpf-next 06/22] xsk: introduce wrappers and helpers for supporting multi-buffer in Tx path
Quoted 61 lines
-----Original Message-----
From: Toke Høiland-Jørgensen <[email protected]>
Sent: Tuesday, June 20, 2023 10:56 PMQuoted 1 line
Subject: Re: [PATCH v4 bpf-next 06/22] xsk: introduce wrappers and helpers for supporting multi-buffer in Tx path
Quoted 34 lines · Maciej Fijalkowski
From: Tirthendu Sarkar <[email protected]>
In Tx path, xsk core reserves space for each desc to be transmitted in the completion queue and it's address contained in it is stored in the skb destructor arg. After successful transmission the skb destructor submits the addr marking completion.
To handle multiple descriptors per packet, now along with reserving space for each descriptor, the corresponding address is also stored in completion queue. The number of pending descriptors are stored in skb destructor arg and is used by the skb destructor to update completions.
Introduce 'skb' in
xdp_sockto store a partially built packet when__xsk_generic_xmit()must return before it sees the EOP descriptor for the current packet so that packet building can resume in next call of__xsk_generic_xmit().Helper functions are introduced to set and get the pending descriptors in the skb destructor arg. Also, wrappers are introduced for storing descriptor addresses, submitting and cancelling (for unsuccessful transmissions) the number of completions.
Signed-off-by Tirthendu Sarkar <[email protected]>--- include/net/xdp_sock.h | 6 ++++ net/xdp/xsk.c | 74 ++++++++++++++++++++++++++++++------------ net/xdp/xsk_queue.h | 19 ++++------- 3 files changed, 67 insertions(+), 32 deletions(-)include/net/xdp_sock.h +0
-0include/net/xdp_sock.h struct xdp_sock { · line 71
Quoted 4 lines
include/net/xdp_sock.h +1
-0@@ -68,6 +68,12 @@ struct xdp_sock {u64 rx_dropped;u64 rx_queue_full; +/* When __xsk_generic_xmit() must return before it sees the EOP descriptor for the current
include/net/xdp_sock.h struct xdp_sock { · line 72
Quoted 1 line
include/net/xdp_sock.h +1
-0+* packet, the partially built skb is saved here so that packet building can resume in next
include/net/xdp_sock.h struct xdp_sock { · line 75
Quoted 3 lines
include/net/xdp_sock.h +3
-0+* call of __xsk_generic_xmit(). +*/ +struct sk_buff *skb;What ensures this doesn't leak? IIUC, when the loop in
__xsk_generic_xmit()gets to the end of a batch, userspace will get an EAGAIN error and be expected to retry the call later, right? But if userspace never retries, could the socket be torn down with this pointer still populated? I looked for something that would prevent this in subsequent patches, but couldn't find it; am I missing something?
Quoted 2 lines
-Toke
Thanks for catching this. We will add cleanup during socket termination in v5.
RE: [PATCH v4 bpf-next 06/22] xsk: introduce wrappers and helpers for supporting multi-buffer in Tx path
Quoted 61 lines · Tirthendu
Quoted 61 lines
-----Original Message-----
From: Toke Høiland-Jørgensen <[email protected]>
Sent: Tuesday, June 20, 2023 10:56 PMQuoted 1 line
Subject: Re: [PATCH v4 bpf-next 06/22] xsk: introduce wrappers and helpers for supporting multi-buffer in Tx path
Quoted 34 lines · Maciej Fijalkowski
From: Tirthendu Sarkar <[email protected]>
In Tx path, xsk core reserves space for each desc to be transmitted in the completion queue and it's address contained in it is stored in the skb destructor arg. After successful transmission the skb destructor submits the addr marking completion.
To handle multiple descriptors per packet, now along with reserving space for each descriptor, the corresponding address is also stored in completion queue. The number of pending descriptors are stored in skb destructor arg and is used by the skb destructor to update completions.
Introduce 'skb' in
xdp_sockto store a partially built packet when__xsk_generic_xmit()must return before it sees the EOP descriptor for the current packet so that packet building can resume in next call of__xsk_generic_xmit().Helper functions are introduced to set and get the pending descriptors in the skb destructor arg. Also, wrappers are introduced for storing descriptor addresses, submitting and cancelling (for unsuccessful transmissions) the number of completions.
Signed-off-by Tirthendu Sarkar <[email protected]>--- include/net/xdp_sock.h | 6 ++++ net/xdp/xsk.c | 74 ++++++++++++++++++++++++++++++------------ net/xdp/xsk_queue.h | 19 ++++------- 3 files changed, 67 insertions(+), 32 deletions(-)include/net/xdp_sock.h +0
-0include/net/xdp_sock.h struct xdp_sock { · line 71
Quoted 4 lines
include/net/xdp_sock.h +1
-0@@ -68,6 +68,12 @@ struct xdp_sock {u64 rx_dropped;u64 rx_queue_full; +/* When __xsk_generic_xmit() must return before it sees the EOP descriptor for the current
include/net/xdp_sock.h struct xdp_sock { · line 72
Quoted 1 line
include/net/xdp_sock.h +1
-0+* packet, the partially built skb is saved here so that packet building can resume in next
include/net/xdp_sock.h struct xdp_sock { · line 75
Quoted 3 lines
include/net/xdp_sock.h +3
-0+* call of __xsk_generic_xmit(). +*/ +struct sk_buff *skb;What ensures this doesn't leak? IIUC, when the loop in
__xsk_generic_xmit()gets to the end of a batch, userspace will get an EAGAIN error and be expected to retry the call later, right? But if userspace never retries, could the socket be torn down with this pointer still populated? I looked for something that would prevent this in subsequent patches, but couldn't find it; am I missing something?
Quoted 4 lines
Quoted 2 lines
-Toke
Thanks for catching this. We will add cleanup during socket termination in v5.
Awesome! :)
-Toke
Maciej Fijalkowski
maintainerPATCH v4 7/22 xsk: allow core/drivers to test EOP bit
In reply to Maciej FijalkowskiDrivers are used to check for EOP bit whereas AF_XDP operates on inverted logic - user space indicates that current frag is not the last one and packet continues. For AF_XDP core needs, add xp_mb_desc() that will simply test XDP_PKT_CONTD from xdp_desc::options, but in order to preserve drivers default behavior, introduce an interface for ZC drivers that will negate xp_mb_desc() result and therefore make it easier to test EOP bit from during production of HW Tx descriptors.
--- include/net/xdp_sock_drv.h | 10 ++++++++++ include/net/xsk_buff_pool.h | 5 +++++ 2 files changed, 15 insertions(+)
include/net/xdp_sock_drv.h +10 -0
@@ -89,6 +89,11 @@ static inline struct xdp_buff *xsk_buff_alloc(struct xsk_buff_pool *pool)return xp_alloc (pool); } +static inline bool xsk_is_eop_desc (struct xdp_desc *desc) +{ +return !xp_mb_desc (desc); +} +/* Returns as many entries as possible up to max. 0 <= N <= max. */ static inline u32 xsk_buff_alloc_batch (struct xsk_buff_pool *pool,struct xdp_buff **xdp,u32 max) {
@@ -241,6 +246,11 @@ static inline struct xdp_buff *xsk_buff_alloc(struct xsk_buff_pool *pool)return NULL ; } +static inline bool xsk_is_eop_desc (struct xdp_desc *desc) +{ +return false; +} +static inline u32 xsk_buff_alloc_batch (struct xsk_buff_pool *pool,struct xdp_buff **xdp,u32 max) {return 0 ;
include/net/xsk_buff_pool.h +5 -0
@@ -184,6 +184,11 @@ static inline bool xp_desc_crosses_non_contig_pg(struct xsk_buff_pool *pool, !(pool->dma_pages[addr >>PAGE_SHIFT ] &XSK_NEXT_PG_CONTIG_MASK ); } +static inline bool xp_mb_desc (struct xdp_desc *desc) +{ +return desc->options &XDP_PKT_CONTD ; +} +static inline u64 xp_aligned_extract_addr (struct xsk_buff_pool *pool,u64 addr) {return addr & pool->chunk_mask;
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 8/22 xsk: add support for AF_XDP multi-buffer on Tx path
In reply to Maciej FijalkowskiFrom: Tirthendu Sarkar <[email protected]>
For transmitting an AF_XDP packet, allocate skb while processing the first desc and copy data to it. The 'XDP_PKT_CONTD' flag in 'options' field of the desc indicates the EOP status of the packet. If the current desc is not EOP, store the skb, release the current desc and go on to read the next descs.
Allocate a page for each subsequent desc, copy data to it and add it as a frag in the skb stored in xsk. On processing EOP, transmit the skb with frags. Addresses contained in descs have been already queued in consumer queue and skb destructor updated the completion count.
On transmit failure cancel the releases, clear the descs from the completion queue and consume the skb for retrying packet transmission.
For any invalid descriptor (invalid length/address/options) in the middle of a packet, all pending descriptors will be dropped by xsk core along with the invalid one and the next descriptor is treated as the start of a new packet.
Maximum supported frames for a packet is MAX_SKB_FRAGS + 1. If it is exceeded, all descriptors accumulated so far are dropped.
--- net/xdp/xsk.c | 117 +++++++++++++++++++++++++++++++++----------- net/xdp/xsk_queue.h | 13 +++-- 2 files changed, 97 insertions(+), 33 deletions(-)
net/xdp/xsk.c +89 -28
@@ -393,7 +393,8 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc)rcu_read_lock ();list_for_each_entry_rcu (xs, &pool->xsk_tx_list, tx_list) {if (!xskq_cons_peek_desc (xs->tx, desc, pool)) { - xs->tx->queue_empty_descs++; +if (xskq_has_descs (xs->tx)) +xskq_cons_release (xs->tx);continue ; }
@@ -539,24 +540,32 @@ static void xsk_consume_skb(struct sk_buff *skb) xs->skb =NULL ; } +static void xsk_drop_skb (struct sk_buff *skb) +{ +xdp_sk (skb->sk)->tx->invalid_descs +=xsk_get_num_desc (skb); +xsk_consume_skb (skb); +} +static struct sk_buff *xsk_build_skb_zerocopy (struct xdp_sock *xs,struct xdp_desc *desc) {struct xsk_buff_pool *pool = xs->pool;u32 hr, len, ts, offset, copy, copied; -struct sk_buff *skb; +struct sk_buff *skb = xs->skb;struct page *page;void *buffer;int err, i;u64 addr; - hr =max (NET_SKB_PAD ,L1_CACHE_ALIGN (xs->dev->needed_headroom)); +if (!skb) { + hr =max (NET_SKB_PAD ,L1_CACHE_ALIGN (xs->dev->needed_headroom)); - skb =sock_alloc_send_skb (&xs->sk, hr,1 , &err); -if (unlikely (!skb)) -return ERR_PTR (err); + skb =sock_alloc_send_skb (&xs->sk, hr,1 , &err); +if (unlikely (!skb)) +return ERR_PTR (err); -skb_reserve (skb, hr); +skb_reserve (skb, hr); + } addr = desc->addr; len = desc->len;
@@ -566,7 +575,10 @@ static struct sk_buff *xsk_build_skb_zerocopy(struct xdp_sock *xs, offset =offset_in_page (buffer); addr = buffer - pool->addrs; -for (copied =0 , i =0 ; copied < len; i++) { +for (copied =0 , i =skb_shinfo (skb)->nr_frags; copied < len; i++) { +if (unlikely (i >=MAX_SKB_FRAGS )) +return ERR_PTR (-EFAULT ); + page = pool->umem->pgs[addr >>PAGE_SHIFT ];get_page (page);
@@ -591,33 +603,56 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs, struct xdp_desc *desc) {struct net_device *dev = xs->dev; -struct sk_buff *skb; +struct sk_buff *skb = xs->skb; +int err;if (dev->priv_flags &IFF_TX_SKB_NO_LINEAR ) { skb =xsk_build_skb_zerocopy (xs, desc); -if (IS_ERR (skb)) -return skb; +if (IS_ERR (skb)) { + err =PTR_ERR (skb); + goto free_err; + } }else {u32 hr, tr, len;void *buffer; -int err; - hr =max (NET_SKB_PAD ,L1_CACHE_ALIGN (dev->needed_headroom)); - tr = dev->needed_tailroom; + buffer =xsk_buff_raw_get_data (xs->pool, desc->addr); len = desc->len; - skb =sock_alloc_send_skb (&xs->sk, hr + len + tr,1 , &err); -if (unlikely (!skb)) -return ERR_PTR (err); +if (!skb) { + hr =max (NET_SKB_PAD ,L1_CACHE_ALIGN (dev->needed_headroom)); + tr = dev->needed_tailroom; + skb =sock_alloc_send_skb (&xs->sk, hr + len + tr,1 , &err); +if (unlikely (!skb)) + goto free_err; -skb_reserve (skb, hr); -skb_put (skb, len); +skb_reserve (skb, hr); +skb_put (skb, len); - buffer =xsk_buff_raw_get_data (xs->pool, desc->addr); - err =skb_store_bits (skb,0 , buffer, len); -if (unlikely (err)) { -kfree_skb (skb); -return ERR_PTR (err); + err =skb_store_bits (skb,0 , buffer, len); +if (unlikely (err)) + goto free_err; + }else { +int nr_frags =skb_shinfo (skb)->nr_frags; +struct page *page; +u8 *vaddr; + +if (unlikely (nr_frags == (MAX_SKB_FRAGS -1 ) &&xp_mb_desc (desc))) { + err = -EFAULT ; + goto free_err; + } + + page =alloc_page (xs->sk.sk_allocation); +if (unlikely (!page)) { + err = -EAGAIN ; + goto free_err; + } + + vaddr =kmap_local_page (page); +memcpy (vaddr, buffer, len); +kunmap_local (vaddr); + +skb_add_rx_frag (skb, nr_frags, page,0 , len,0 ); } }
@@ -628,6 +663,17 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,xsk_set_destructor_arg (skb);return skb; + +free_err: +if (err == -EAGAIN ) { +xsk_cq_cancel_locked (xs,1 ); + }else { +xsk_set_destructor_arg (skb); +xsk_drop_skb (skb); +xskq_cons_release (xs->tx); + } + +return ERR_PTR (err); }static int __xsk_generic_xmit (struct sock *sk)
@@ -667,30 +713,45 @@ static int __xsk_generic_xmit(struct sock *sk) skb =xsk_build_skb (xs, &desc);if (IS_ERR (skb)) { err =PTR_ERR (skb); -xsk_cq_cancel_locked (xs,1 ); - goto out; +if (err == -EAGAIN ) + goto out; + err =0 ; +continue ; + } + +xskq_cons_release (xs->tx); + +if (xp_mb_desc (&desc)) { + xs->skb = skb; +continue ; } err =__dev_direct_xmit (skb, xs->queue_id);if (err ==NETDEV_TX_BUSY ) {/* Tell user-space to retry the send */ +xskq_cons_cancel_n (xs->tx,xsk_get_num_desc (skb));xsk_consume_skb (skb); err = -EAGAIN ; goto out; } -xskq_cons_release (xs->tx);/* Ignore NET_XMIT_CN as packet might have been sent */ if (err ==NET_XMIT_DROP ) {/* SKB completed but not sent */ err = -EBUSY ; + xs->skb =NULL ; goto out; } sent_frame = true; + xs->skb =NULL ; } - xs->tx->queue_empty_descs++; +if (xskq_has_descs (xs->tx)) { +if (xs->skb) +xsk_drop_skb (xs->skb); +xskq_cons_release (xs->tx); + } out:if (sent_frame)
net/xdp/xsk_queue.h +8 -5
@@ -175,6 +175,11 @@ static inline bool xp_validate_desc(struct xsk_buff_pool *pool,xp_aligned_validate_desc (pool, desc); } +static inline bool xskq_has_descs (struct xsk_queue *q) +{ +return q->cached_cons != q->cached_prod; +} +static inline bool xskq_cons_is_valid_desc (struct xsk_queue *q,struct xdp_desc *d,struct xsk_buff_pool *pool)
@@ -190,17 +195,15 @@ static inline bool xskq_cons_read_desc(struct xsk_queue *q, struct xdp_desc *desc, struct xsk_buff_pool *pool) { -while (q->cached_cons != q->cached_prod) { +if (q->cached_cons != q->cached_prod) {struct xdp_rxtx_ring *ring = (struct xdp_rxtx_ring *)q->ring;u32 idx = q->cached_cons & q->ring_mask; *desc = ring->desc[idx]; -if (xskq_cons_is_valid_desc (q, desc, pool)) -return true; - - q->cached_cons++; +return xskq_cons_is_valid_desc (q, desc, pool); } + q->queue_empty_descs++;return false; }
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 9/22 xsk: discard zero length descriptors in Tx path
In reply to Maciej FijalkowskiFrom: Tirthendu Sarkar <[email protected]>
Descriptors with zero length are not supported by many NICs. To preserve uniform behavior discard any zero length desc as invvalid desc.
--- net/xdp/xsk_queue.h | 6 ++++++ 1 file changed, 6 insertions(+)
net/xdp/xsk_queue.h +6 -0
@@ -140,6 +140,9 @@ static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool, {u64 offset = desc->addr & (pool->chunk_size -1 ); +if (!desc->len) +return false; +if (offset + desc->len > pool->chunk_size)return false;
@@ -156,6 +159,9 @@ static inline bool xp_unaligned_validate_desc(struct xsk_buff_pool *pool, {u64 addr =xp_unaligned_add_offset_to_addr (desc->addr); +if (!desc->len) +return false; +if (desc->len > pool->chunk_size)return false;
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 10/22 xsk: support mbuf on ZC RX
In reply to Maciej FijalkowskiGiven that skb_shared_info relies on skb_frag_t, in order to support xskb chaining, introduce xdp_buff_xsk::xskb_list_node and xsk_buff_pool::xskb_list.
This is needed so ZC drivers can add frags as xskb nodes which will make it possible to handle it both when producing AF_XDP Rx descriptors as well as freeing/recycling all the frags that a single frame carries.
Speaking of latter, update xsk_buff_free() to take care of list nodes. For the former (adding as frags), introduce xsk_buff_add_frag() for ZC drivers usage that is going to be used to add a frag to to xskb list from pool.
xsk_buff_get_frag() will be utilized by XDP_TX and, on contrary, will return xdp_buff.
One of the previous patches added a wrapper for ZC Rx so implement xskb list walk and production of Rx descriptors there.
--- include/net/xdp_sock_drv.h | 44 +++++++++++++++++++++++++++++++++++++ include/net/xsk_buff_pool.h | 2 ++ net/xdp/xsk.c | 26 +++++++++++++++++++++- net/xdp/xsk_buff_pool.c | 2 ++ 4 files changed, 73 insertions(+), 1 deletion(-)
include/net/xdp_sock_drv.h +44 -0
@@ -108,10 +108,45 @@ static inline bool xsk_buff_can_alloc(struct xsk_buff_pool *pool, u32 count)static inline void xsk_buff_free (struct xdp_buff *xdp) { struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp); +struct list_head *xskb_list = &xskb->pool->xskb_list; +struct xdp_buff_xsk *pos, *tmp; +if (likely (!xdp_buff_has_frags (xdp))) + goto out; + +list_for_each_entry_safe (pos, tmp, xskb_list, xskb_list_node) { +list_del (&pos->xskb_list_node); +xp_free (pos); + } + +xdp_get_shared_info_from_buff (xdp)->nr_frags =0 ; +out:xp_free (xskb); } +static inline void xsk_buff_add_frag (struct xdp_buff *xdp) +{ + struct xdp_buff_xsk *frag = container_of(xdp, struct xdp_buff_xsk, xdp); + +list_add_tail (&frag->xskb_list_node, &frag->pool->xskb_list); +} + +static inline struct xdp_buff *xsk_buff_get_frag (struct xdp_buff *first) +{ + struct xdp_buff_xsk *xskb = container_of(first, struct xdp_buff_xsk, xdp); +struct xdp_buff *ret =NULL ; +struct xdp_buff_xsk *frag; + + frag =list_first_entry_or_null (&xskb->pool->xskb_list, + struct xdp_buff_xsk, xskb_list_node); +if (frag) { +list_del (&frag->xskb_list_node); + ret = &frag->xdp; + } + +return ret; +} +static inline void xsk_buff_set_size (struct xdp_buff *xdp,u32 size) { xdp->data = xdp->data_hard_start +XDP_PACKET_HEADROOM ;
@@ -265,6 +300,15 @@ static inline void xsk_buff_free(struct xdp_buff *xdp) { } +static inline void xsk_buff_add_frag (struct xdp_buff *xdp) +{ +} + +static inline struct xdp_buff *xsk_buff_get_frag (struct xdp_buff *first) +{ +return NULL ; +} +static inline void xsk_buff_discard (struct xdp_buff *xdp) { }
include/net/xsk_buff_pool.h +2 -0
@@ -29,6 +29,7 @@ struct xdp_buff_xsk {struct xsk_buff_pool *pool;u64 orig_addr;struct list_head free_list_node; +struct list_head xskb_list_node; };#define XSK_CHECK_PRIV_TYPE (t) BUILD_BUG_ON(sizeof(t) > offsetofend(struct xdp_buff_xsk, cb))
@@ -54,6 +55,7 @@ struct xsk_buff_pool {struct xdp_umem *umem;struct work_struct work;struct list_head free_list; +struct list_head xskb_list;u32 heads_cnt;u16 queue_id;
net/xdp/xsk.c +25 -1
@@ -155,8 +155,32 @@ static int __xsk_rcv_zc(struct xdp_sock *xs, struct xdp_buff_xsk *xskb, u32 len,static int xsk_rcv_zc (struct xdp_sock *xs,struct xdp_buff *xdp,u32 len) { struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp); +u32 frags =xdp_buff_has_frags (xdp); +struct xdp_buff_xsk *pos, *tmp; +struct list_head *xskb_list; +u32 contd =0 ; +int err; + +if (frags) + contd =XDP_PKT_CONTD ; -return __xsk_rcv_zc (xs, xskb, len,0 ); + err =__xsk_rcv_zc (xs, xskb, len, contd); +if (err ||likely (!frags)) + goto out; + + xskb_list = &xskb->pool->xskb_list; +list_for_each_entry_safe (pos, tmp, xskb_list, xskb_list_node) { +if (list_is_singular (xskb_list)) + contd =0 ; + len = pos->xdp.data_end - pos->xdp.data; + err =__xsk_rcv_zc (xs, pos, len, contd); +if (err) +return err; +list_del (&pos->xskb_list_node); + } + +out: +return err; }static void *xsk_copy_xdp_start (struct xdp_buff *from)
net/xdp/xsk_buff_pool.c +2 -0
@@ -86,6 +86,7 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs, pool->umem = umem; pool->addrs = umem->addrs;INIT_LIST_HEAD (&pool->free_list); +INIT_LIST_HEAD (&pool->xskb_list);INIT_LIST_HEAD (&pool->xsk_tx_list);spin_lock_init (&pool->xsk_tx_list_lock);spin_lock_init (&pool->cq_lock);
@@ -99,6 +100,7 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs, xskb->pool = pool; xskb->xdp.frame_sz = umem->chunk_size - umem->headroom;INIT_LIST_HEAD (&xskb->free_list_node); +INIT_LIST_HEAD (&xskb->xskb_list_node);if (pool->unaligned) pool->free_heads[i] = xskb;else
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 11/22 ice: xsk: add RX multi-buffer support
In reply to Maciej FijalkowskiThis support is strongly inspired by work that introduced multi-buffer support to regular Rx data path in ice. There are some differences, though. When adding a frag, besides adding it to skb_shared_info, use also fresh xsk_buff_add_frag() helper. Reason for doing both things is that we can not rule out the fact that AF_XDP pipeline could use XDP program that needs to access frame fragments. Without them being in skb_shared_info it will not be possible. Another difference is that XDP_PASS has to allocate a new pages for each frags and copy contents from memory backed by xsk_buff_pool.
chain_len that is used for programming HW Rx descriptors no longer has to be limited to 1 when xsk_pool is present - remove this restriction.
--- drivers/net/ethernet/intel/ice/ice_base.c | 9 +- drivers/net/ethernet/intel/ice/ice_xsk.c | 136 ++++++++++++++++------ 2 files changed, 102 insertions(+), 43 deletions(-)
drivers/net/ethernet/intel/ice/ice_base.c +1 -8
@@ -408,7 +408,6 @@ static unsigned int ice_rx_offset(struct ice_rx_ring *rx_ring)*/ static int ice_setup_rx_ctx (struct ice_rx_ring *ring) { -int chain_len =ICE_MAX_CHAINED_RX_BUFS ;struct ice_vsi *vsi = ring->vsi;u32 rxdid =ICE_RXDID_FLEX_NIC ;struct ice_rlan_ctx rlan_ctx;
@@ -472,17 +471,11 @@ static int ice_setup_rx_ctx(struct ice_rx_ring *ring)*/ rlan_ctx.showiv =0 ; -/* For AF_XDP ZC, we disallow packets to span on -* multiple buffers, thus letting us skip that -* handling in the fast-path. -*/ -if (ring->xsk_pool) - chain_len =1 ;/* Max packet size for this queue - must not be set to a larger value * than 5 x DBUF */ rlan_ctx.rxmax =min_t (u32, vsi->max_frame, - chain_len * ring->rx_buf_len); +ICE_MAX_CHAINED_RX_BUFS * ring->rx_buf_len);/* Rx queue threshold in units of 64 */ rlan_ctx.lrxqthresh =1 ;
drivers/net/ethernet/intel/ice/ice_xsk.c +101 -35
231 lines not on this page · raw message
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 12/22 xsk: support ZC Tx multi-buffer in batch API
In reply to Maciej FijalkowskiModify xskq_cons_read_desc_batch() in a way that each processed descriptor will be checked if it is an EOP one or not and act accordingly to that.
Change the behavior of mentioned function to break the processing when stumbling upon invalid descriptor instead of skipping it. Furthermore, let us give only full packets down to ZC driver.
With these two assumptions ZC drivers will not have to take care of an intermediate state of incomplete frames, which will simplify its implementations a lot.
--- net/xdp/xsk_queue.h | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-)
net/xdp/xsk_queue.h +32 -9
@@ -48,6 +48,11 @@ struct xsk_queue {size_t ring_vmalloc_size; }; +struct parsed_desc { +u32 mb; +u32 valid; +}; +/* The structure of the shared state of the rings are a simple * circular buffer, as outlined in * Documentation/core-api/circular-buffers.rst. For the Rx and
@@ -218,30 +223,48 @@ static inline void xskq_cons_release_n(struct xsk_queue *q, u32 cnt) q->cached_cons += cnt; } -static inline u32 xskq_cons_read_desc_batch (struct xsk_queue *q,struct xsk_buff_pool *pool, -u32 max) +static inline void parse_desc (struct xsk_queue *q,struct xsk_buff_pool *pool, +struct xdp_desc *desc,struct parsed_desc *parsed) +{ + parsed->valid =xskq_cons_is_valid_desc (q, desc, pool); + parsed->mb =xp_mb_desc (desc); +} + +static inline +u32 xskq_cons_read_desc_batch (struct xsk_queue *q,struct xsk_buff_pool *pool, +u32 max) {u32 cached_cons = q->cached_cons, nb_entries =0 ;struct xdp_desc *descs = pool->tx_descs; +u32 total_descs =0 , nr_frags =0 ; +/* track first entry, if stumble upon *any* invalid descriptor, rewind +* current packet that consists of frags and stop the processing +*/ while (cached_cons != q->cached_prod && nb_entries < max) {struct xdp_rxtx_ring *ring = (struct xdp_rxtx_ring *)q->ring;u32 idx = cached_cons & q->ring_mask; +struct parsed_desc parsed; descs[nb_entries] = ring->desc[idx]; -if (unlikely (!xskq_cons_is_valid_desc (q, &descs[nb_entries], pool))) { -/* Skip the entry */ - cached_cons++; -continue ; - } + cached_cons++; +parse_desc (q, pool, &descs[nb_entries], &parsed); +if (unlikely (!parsed.valid)) +break ; nb_entries++; - cached_cons++; +if (likely (!parsed.mb)) { + total_descs += (nr_frags +1 ); + nr_frags =0 ; + }else { + nr_frags++; + } } + cached_cons -= nr_frags;/* Release valid plus any invalid entries */ xskq_cons_release_n (q, cached_cons - q->cached_cons); -return nb_entries; +return total_descs; }/* Functions for consumers */
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 13/22 xsk: report zero-copy multi-buffer capability via xdp_features
In reply to Maciej FijalkowskiIntroduce new xdp_feature NETDEV_XDP_ACT_ZC_SG that will be used to find out if user space that wants to do ZC multi-buffer will be able to do so against underlying ZC driver.
--- Documentation/netlink/specs/netdev.yaml | 5 +++++ include/uapi/linux/netdev.h | 5 ++++- net/xdp/xsk_buff_pool.c | 6 ++++++ tools/include/uapi/linux/netdev.h | 5 ++++- 4 files changed, 19 insertions(+), 2 deletions(-)
Documentation/netlink/specs/netdev.yaml +5 -0
@@ -42,6 +42,11 @@ definitions: doc: This feature informs if netdev implements non-linear XDP buffer support in ndo_xdp_xmit callback. + - + name: zc-sg + doc: + This feature informs if netdev implements non-linear XDP buffer + support in zero-copy mode. attribute-sets: -
include/uapi/linux/netdev.h +4 -1
@@ -24,6 +24,8 @@* XDP buffer support in the driver napi callback. * @NETDEV_XDP_ACT_NDO_XMIT_SG: This feature informs if netdev implements * non-linear XDP buffer support in ndo_xdp_xmit callback. +* @NETDEV_XDP_ACT_ZC_SG: This feature informs if netdev implements non-linear +* XDP buffer support in zero-copy mode. */ enum netdev_xdp_act {NETDEV_XDP_ACT_BASIC =1 ,
@@ -33,8 +35,9 @@ enum netdev_xdp_act {NETDEV_XDP_ACT_HW_OFFLOAD =16 ,NETDEV_XDP_ACT_RX_SG =32 ,NETDEV_XDP_ACT_NDO_XMIT_SG =64 , +NETDEV_XDP_ACT_ZC_SG =128 , - NETDEV_XDP_ACT_MASK = 127, + NETDEV_XDP_ACT_MASK = 255, }; enum {
net/xdp/xsk_buff_pool.c +6 -0
@@ -189,6 +189,12 @@ int xp_assign_dev(struct xsk_buff_pool *pool, goto err_unreg_pool; } +if (!(netdev->xdp_features &NETDEV_XDP_ACT_ZC_SG ) && + flags &XDP_USE_SG ) { + err = -EOPNOTSUPP ; + goto err_unreg_pool; + } + bpf.command =XDP_SETUP_XSK_POOL ; bpf.xsk.pool = pool; bpf.xsk.queue_id = queue_id;
tools/include/uapi/linux/netdev.h +4 -1
@@ -24,6 +24,8 @@* XDP buffer support in the driver napi callback. * @NETDEV_XDP_ACT_NDO_XMIT_SG: This feature informs if netdev implements * non-linear XDP buffer support in ndo_xdp_xmit callback. +* @NETDEV_XDP_ACT_ZC_SG: This feature informs if netdev implements non-linear +* XDP buffer support in zero-copy mode. */ enum netdev_xdp_act {NETDEV_XDP_ACT_BASIC =1 ,
@@ -33,8 +35,9 @@ enum netdev_xdp_act {NETDEV_XDP_ACT_HW_OFFLOAD =16 ,NETDEV_XDP_ACT_RX_SG =32 ,NETDEV_XDP_ACT_NDO_XMIT_SG =64 , +NETDEV_XDP_ACT_ZC_SG =128 , - NETDEV_XDP_ACT_MASK = 127, + NETDEV_XDP_ACT_MASK = 255, }; enum {
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 14/22 ice: xsk: Tx multi-buffer support
In reply to Maciej FijalkowskiMost of this patch is about actually supporting XDP_TX action. Pure Tx ZC support is only about looking at XDP_PKT_CONTD presence at options field and based on that generating EOP bit on Tx HW descriptor. This is that simple due to the implementation on xsk_tx_peek_release_desc_batch() where we are making sure that last produced descriptor is an EOP one.
Report via xdp_features that this driver is now capable of consuming multi-buffer packets on both Rx and Tx sides.
--- drivers/net/ethernet/intel/ice/ice_main.c | 2 +- drivers/net/ethernet/intel/ice/ice_xsk.c | 83 ++++++++++++++++------- 2 files changed, 61 insertions(+), 24 deletions(-)
drivers/net/ethernet/intel/ice/ice_main.c +1 -1
@@ -3377,7 +3377,7 @@ static void ice_set_ops(struct ice_vsi *vsi) netdev->xdp_features =NETDEV_XDP_ACT_BASIC |NETDEV_XDP_ACT_REDIRECT |NETDEV_XDP_ACT_XSK_ZEROCOPY | -NETDEV_XDP_ACT_RX_SG ; +NETDEV_XDP_ACT_RX_SG |NETDEV_XDP_ACT_ZC_SG ; }/**
drivers/net/ethernet/intel/ice/ice_xsk.c +60 -23
131 lines not on this page · raw message
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 15/22 xsk: add multi-buffer documentation
In reply to Maciej FijalkowskiFrom: Magnus Karlsson <[email protected]>
Add AF_XDP multi-buffer support documentation including two pseudo-code samples.
--- Documentation/networking/af_xdp.rst | 177 ++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+)
Documentation/networking/af_xdp.rst +177 -0
@@ -453,6 +453,93 @@ XDP_OPTIONS getsockopt Gets options from an XDP socket. The only one supported so far is XDP_OPTIONS_ZEROCOPY which tells you if zero-copy is on or not. +Multi-Buffer Support +-------------------- + +With multi-buffer support, programs using AF_XDP sockets can receive +and transmit packets consisting of multiple buffers both in copy and +zero-copy mode. For example, a packet can consist of two +frames/buffers, one with the header and the other one with the data, +or a 9K Ethernet jumbo frame can be constructed by chaining together +three 4K frames. + +Some definitions: + +* A packet consists of one or more frames + +* A descriptor in one of the AF_XDP rings always refers to a single + frame. In the case the packet consists of a single frame, the + descriptor refers to the whole packet. + +To enable multi-buffer support for an AF_XDP socket, use the new bind +flag XDP_USE_SG. If this is not provided, all multi-buffer packets +will be dropped just as before. Note that the XDP program loaded also +needs to be in multi-buffer mode. This can be accomplished by using +"xdp.frags" as the section name of the XDP program used. + +To represent a packet consisting of multiple frames, a new flag called +XDP_PKT_CONTD is introduced in the options field of the Rx and Tx +descriptors. If it is true (1) the packet continues with the next +descriptor and if it is false (0) it means this is the last descriptor +of the packet. Why the reverse logic of end-of-packet (eop) flag found +in many NICs? Just to preserve compatibility with non-multi-buffer +applications that have this bit set to false for all packets on Rx, +and the apps set the options field to zero for Tx, as anything else +will be treated as an invalid descriptor. + +These are the semantics for producing packets onto AF_XDP Tx ring +consisting of multiple frames: + +* When an invalid descriptor is found, all the other + descriptors/frames of this packet are marked as invalid and not + completed. The next descriptor is treated as the start of a new + packet, even if this was not the intent (because we cannot guess + the intent). As before, if your program is producing invalid + descriptors you have a bug that must be fixed. + +* Zero length descriptors are treated as invalid descriptors. + +* For copy mode, the maximum supported number of frames in a packet is + equal to CONFIG_MAX_SKB_FRAGS + 1. If it is exceeded, all + descriptors accumulated so far are dropped and treated as + invalid. To produce an application that will work on any system + regardless of this config setting, limit the number of frags to 18, + as the minimum value of the config is 17. + +* For zero-copy mode, the limit is up to what the NIC HW + supports. Usually at least five on the NICs we have checked. We + consciously chose to not enforce a rigid limit (such as + CONFIG_MAX_SKB_FRAGS + 1) for zero-copy mode, as it would have + resulted in copy actions under the hood to fit into what limit + the NIC supports. Kind of defeats the purpose of zero-copy mode. + +* The ZC batch API guarantees that it will provide a batch of Tx + descriptors that ends with full packet at the end. If not, ZC + drivers would have to gather the full packet on their side. The + approach we picked makes ZC drivers' life much easier (at least on + Tx side). + +On the Rx path in copy-mode, the xsk core copies the XDP data into +multiple descriptors, if needed, and sets the XDP_PKT_CONTD flag as +detailed before. Zero-copy mode works the same, though the data is not +copied. When the application gets a descriptor with the XDP_PKT_CONTD +flag set to one, it means that the packet consists of multiple buffers +and it continues with the next buffer in the following +descriptor. When a descriptor with XDP_PKT_CONTD == 0 is received, it +means that this is the last buffer of the packet. AF_XDP guarantees +that only a complete packet (all frames in the packet) is sent to the +application. + +If application reads a batch of descriptors, using for example the libxdp +interfaces, it is not guaranteed that the batch will end with a full +packet. It might end in the middle of a packet and the rest of the +buffers of that packet will arrive at the beginning of the next batch, +since the libxdp interface does not read the whole ring (unless you +have an enormous batch size or a very small ring size). + +An example program each for Rx and Tx multi-buffer support can be found +later in this document. + Usage =====
@@ -532,6 +619,96 @@ like this: But please use the libbpf functions as they are optimized and ready to use. Will make your life easier. +Usage Multi-Buffer Rx +===================== + +Here is a simple Rx path pseudo-code example (using libxdp interfaces +for simplicity). Error paths have been excluded to keep it short: + +.. code-block:: c + + void rx_packets(struct xsk_socket_info *xsk) + { + static bool new_packet = true; + u32 idx_rx = 0, idx_fq = 0; + static char *pkt; + + int rcvd = xsk_ring_cons__peek(&xsk->rx, opt_batch_size, &idx_rx); + + xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq); + + for (int i = 0; i < rcvd; i++) { + struct xdp_desc *desc = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++); + char *frag = xsk_umem__get_data(xsk->umem->buffer, desc->addr); + bool eop = !(desc->options & XDP_PKT_CONTD); + + if (new_packet) + pkt = frag; + else + add_frag_to_pkt(pkt, frag); + + if (eop) + process_pkt(pkt); + + new_packet = eop; + + *xsk_ring_prod__fill_addr(&xsk->umem->fq, idx_fq++) = desc->addr; + } + + xsk_ring_prod__submit(&xsk->umem->fq, rcvd); + xsk_ring_cons__release(&xsk->rx, rcvd); + } + +Usage Multi-Buffer Tx +===================== + +Here is an example Tx path pseudo-code (using libxdp interfaces for +simplicity) ignoring that the umem is finite in size, and that we +eventually will run out of packets to send. Also assumes pkts.addr +points to a valid location in the umem. + +.. code-block:: c + + void tx_packets(struct xsk_socket_info *xsk, struct pkt *pkts, + int batch_size) + { + u32 idx, i, pkt_nb = 0; + + xsk_ring_prod__reserve(&xsk->tx, batch_size, &idx); + + for (i = 0; i < batch_size;) { + u64 addr = pkts[pkt_nb].addr; + u32 len = pkts[pkt_nb].size; + + do { + struct xdp_desc *tx_desc; + + tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, idx + i++); + tx_desc->addr = addr; + + if (len > xsk_frame_size) { + tx_desc->len = xsk_frame_size; + tx_desc->options = XDP_PKT_CONTD; + } else { + tx_desc->len = len; + tx_desc->options = 0; + pkt_nb++; + } + len -= tx_desc->len; + addr += xsk_frame_size; + + if (i == batch_size) { + /* Remember len, addr, pkt_nb for next iteration. + * Skipped for simplicity. + */ + break; + } + } while (len); + } + + xsk_ring_prod__submit(&xsk->tx, i); + } + Sample application ==================
Signature · 1 line
2.34.1
Re: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
Quoted 67 lines · Maciej Fijalkowski
From: Magnus Karlsson <[email protected]>
Add
AF_XDPmulti-buffer support documentation including two pseudo-code samples.Signed-off-by Magnus Karlsson <[email protected]>--- Documentation/networking/af_xdp.rst | 177 ++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+)Documentation/networking/af_xdp.rst +49
-0@@ -453,6 +453,93 @@ XDP_OPTIONS getsockopt Gets options from an XDP socket. The only one supported so far is XDP_OPTIONS_ZEROCOPY which tells you if zero-copy is on or not. +Multi-Buffer Support +-------------------- + +With multi-buffer support, programs using AF_XDP sockets can receive +and transmit packets consisting of multiple buffers both in copy and +zero-copy mode. For example, a packet can consist of two +frames/buffers, one with the header and the other one with the data, +or a 9K Ethernet jumbo frame can be constructed by chaining together +three 4K frames. + +Some definitions: + +* A packet consists of one or more frames + +* A descriptor in one of the AF_XDP rings always refers to a single + frame. In the case the packet consists of a single frame, the + descriptor refers to the whole packet. + +To enable multi-buffer support for an AF_XDP socket, use the new bind +flag XDP_USE_SG. If this is not provided, all multi-buffer packets +will be dropped just as before. Note that the XDP program loaded also +needs to be in multi-buffer mode. This can be accomplished by using +"xdp.frags" as the section name of the XDP program used. + +To represent a packet consisting of multiple frames, a new flag called +XDP_PKT_CONTD is introduced in the options field of the Rx and Tx +descriptors. If it is true (1) the packet continues with the next +descriptor and if it is false (0) it means this is the last descriptor +of the packet. Why the reverse logic of end-of-packet (eop) flag found +in many NICs? Just to preserve compatibility with non-multi-buffer +applications that have this bit set to false for all packets on Rx, +and the apps set the options field to zero for Tx, as anything else +will be treated as an invalid descriptor. + +These are the semantics for producing packets onto AF_XDP Tx ring +consisting of multiple frames: + +* When an invalid descriptor is found, all the other + descriptors/frames of this packet are marked as invalid and not + completed. The next descriptor is treated as the start of a new + packet, even if this was not the intent (because we cannot guess + the intent). As before, if your program is producing invalid + descriptors you have a bug that must be fixed. + +* Zero length descriptors are treated as invalid descriptors. + +* For copy mode, the maximum supported number of frames in a packet is + equal to CONFIG_MAX_SKB_FRAGS + 1. If it is exceeded, all + descriptors accumulated so far are dropped and treated as
Documentation/networking/af_xdp.rst XDP_OPTIONS getsockopt · line 514
Quoted 10 lines
Documentation/networking/af_xdp.rst +10
-0+ invalid. To produce an application that will work on any system + regardless of this config setting, limit the number of frags to 18, + as the minimum value of the config is 17. + +* For zero-copy mode, the limit is up to what the NIC HW + supports. Usually at least five on the NICs we have checked. We + consciously chose to not enforce a rigid limit (such as + CONFIG_MAX_SKB_FRAGS + 1) for zero-copy mode, as it would have + resulted in copy actions under the hood to fit into what limit + the NIC supports. Kind of defeats the purpose of zero-copy mode.
How is an application supposed to discover the actual limit for a given NIC/driver?
Documentation/networking/af_xdp.rst XDP_OPTIONS getsockopt · line 520
Quoted 5 lines
Documentation/networking/af_xdp.rst +5
-0+* The ZC batch API guarantees that it will provide a batch of Tx + descriptors that ends with full packet at the end. If not, ZC + drivers would have to gather the full packet on their side. The + approach we picked makes ZC drivers' life much easier (at least on + Tx side).
This seems like it implies some constraint on how an application can use the APIs, but it's not quite clear to me what those constraints are, nor what happens if an application does something different. This should probably be spelled out...
Documentation/networking/af_xdp.rst XDP_OPTIONS getsockopt · line 531
Quoted 10 lines
Documentation/networking/af_xdp.rst +10
-0+On the Rx path in copy-mode, the xsk core copies the XDP data into +multiple descriptors, if needed, and sets the XDP_PKT_CONTD flag as +detailed before. Zero-copy mode works the same, though the data is not +copied. When the application gets a descriptor with the XDP_PKT_CONTD +flag set to one, it means that the packet consists of multiple buffers +and it continues with the next buffer in the following +descriptor. When a descriptor with XDP_PKT_CONTD == 0 is received, it +means that this is the last buffer of the packet. AF_XDP guarantees +that only a complete packet (all frames in the packet) is sent to the +application.
In light of the comment on batch size below, I think it would be useful to spell out what this means exactly. IIUC correctly, it means that the kernel will check the ringbuffer before starting to copy the data, and if there are not enough descriptors available, it will drop the packet instead of doing a partial copy, right? And this is the case for both ZC and copy mode?
Quoted 41 lines
Documentation/networking/af_xdp.rst +34
-0+If application reads a batch of descriptors, using for example the libxdp +interfaces, it is not guaranteed that the batch will end with a full +packet. It might end in the middle of a packet and the rest of the +buffers of that packet will arrive at the beginning of the next batch, +since the libxdp interface does not read the whole ring (unless you +have an enormous batch size or a very small ring size). + +An example program each for Rx and Tx multi-buffer support can be found +later in this document. + Usage =====@@ -532,6 +619,96 @@ like this: But please use the libbpf functions as they are optimized and ready to use. Will make your life easier. +Usage Multi-Buffer Rx +===================== + +Here is a simple Rx path pseudo-code example (using libxdp interfaces +for simplicity). Error paths have been excluded to keep it short: + +.. code-block:: c + + void rx_packets(struct xsk_socket_info *xsk) + { + static bool new_packet = true; + u32 idx_rx = 0, idx_fq = 0; + static char *pkt; + + int rcvd = xsk_ring_cons__peek(&xsk->rx, opt_batch_size, &idx_rx); + + xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq); + + for (int i = 0; i < rcvd; i++) { + struct xdp_desc *desc = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++); + char *frag = xsk_umem__get_data(xsk->umem->buffer, desc->addr); + bool eop = !(desc->options & XDP_PKT_CONTD); + + if (new_packet)
Documentation/networking/af_xdp.rst like this: · line 655
Quoted 10 lines
Documentation/networking/af_xdp.rst +10
-0+ pkt = frag; + else + add_frag_to_pkt(pkt, frag); + + if (eop) + process_pkt(pkt); + + new_packet = eop; + + *xsk_ring_prod__fill_addr(&xsk->umem->fq, idx_fq++) = desc->addr;
Indentation is off here...
-Toke
Re: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
Quoted 75 lines · Toke Høiland-Jørgensen
Quoted 72 lines · Maciej Fijalkowski
From: Magnus Karlsson <[email protected]>
Add
AF_XDPmulti-buffer support documentation including two pseudo-code samples.Signed-off-by Magnus Karlsson <[email protected]>--- Documentation/networking/af_xdp.rst | 177 ++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+)Documentation/networking/af_xdp.rst +54
-0@@ -453,6 +453,93 @@ XDP_OPTIONS getsockopt Gets options from an XDP socket. The only one supported so far is XDP_OPTIONS_ZEROCOPY which tells you if zero-copy is on or not. +Multi-Buffer Support +-------------------- + +With multi-buffer support, programs using AF_XDP sockets can receive +and transmit packets consisting of multiple buffers both in copy and +zero-copy mode. For example, a packet can consist of two +frames/buffers, one with the header and the other one with the data, +or a 9K Ethernet jumbo frame can be constructed by chaining together +three 4K frames. + +Some definitions: + +* A packet consists of one or more frames + +* A descriptor in one of the AF_XDP rings always refers to a single + frame. In the case the packet consists of a single frame, the + descriptor refers to the whole packet. + +To enable multi-buffer support for an AF_XDP socket, use the new bind +flag XDP_USE_SG. If this is not provided, all multi-buffer packets +will be dropped just as before. Note that the XDP program loaded also +needs to be in multi-buffer mode. This can be accomplished by using +"xdp.frags" as the section name of the XDP program used. + +To represent a packet consisting of multiple frames, a new flag called +XDP_PKT_CONTD is introduced in the options field of the Rx and Tx +descriptors. If it is true (1) the packet continues with the next +descriptor and if it is false (0) it means this is the last descriptor +of the packet. Why the reverse logic of end-of-packet (eop) flag found +in many NICs? Just to preserve compatibility with non-multi-buffer +applications that have this bit set to false for all packets on Rx, +and the apps set the options field to zero for Tx, as anything else +will be treated as an invalid descriptor. + +These are the semantics for producing packets onto AF_XDP Tx ring +consisting of multiple frames: + +* When an invalid descriptor is found, all the other + descriptors/frames of this packet are marked as invalid and not + completed. The next descriptor is treated as the start of a new + packet, even if this was not the intent (because we cannot guess + the intent). As before, if your program is producing invalid + descriptors you have a bug that must be fixed. + +* Zero length descriptors are treated as invalid descriptors. + +* For copy mode, the maximum supported number of frames in a packet is + equal to CONFIG_MAX_SKB_FRAGS + 1. If it is exceeded, all + descriptors accumulated so far are dropped and treated as + invalid. To produce an application that will work on any system + regardless of this config setting, limit the number of frags to 18, + as the minimum value of the config is 17. + +* For zero-copy mode, the limit is up to what the NIC HW
Quoted 8 lines
Documentation/networking/af_xdp.rst XDP_OPTIONS getsockopt · line 514
Quoted 5 lines
Documentation/networking/af_xdp.rst +5
-0+ supports. Usually at least five on the NICs we have checked. We + consciously chose to not enforce a rigid limit (such as + CONFIG_MAX_SKB_FRAGS + 1) for zero-copy mode, as it would have + resulted in copy actions under the hood to fit into what limit + the NIC supports. Kind of defeats the purpose of zero-copy mode.How is an application supposed to discover the actual limit for a given NIC/driver?
Thanks for your comments Toke. I will add an example here of how to discover this. Basically you can send a packet with N frags (N = 2 to start with), check the error stats through the getsockopt. If no invalid_tx_desc error, increase N with one and send this new packet. If you get an error, then the max number of frags is N-1.
Quoted 20 lines
Documentation/networking/af_xdp.rst XDP_OPTIONS getsockopt · line 520
Quoted 5 lines
Documentation/networking/af_xdp.rst +5
-0+* The ZC batch API guarantees that it will provide a batch of Tx + descriptors that ends with full packet at the end. If not, ZC + drivers would have to gather the full packet on their side. The + approach we picked makes ZC drivers' life much easier (at least on + Tx side).This seems like it implies some constraint on how an application can use the APIs, but it's not quite clear to me what those constraints are, nor what happens if an application does something different. This should probably be spelled out...
Quoted 9 lines
Documentation/networking/af_xdp.rst +9
-0+On the Rx path in copy-mode, the xsk core copies the XDP data into +multiple descriptors, if needed, and sets the XDP_PKT_CONTD flag as +detailed before. Zero-copy mode works the same, though the data is not +copied. When the application gets a descriptor with the XDP_PKT_CONTD +flag set to one, it means that the packet consists of multiple buffers +and it continues with the next buffer in the following +descriptor. When a descriptor with XDP_PKT_CONTD == 0 is received, it +means that this is the last buffer of the packet. AF_XDP guarantees +that only a complete packet (all frames in the packet) is sent to the
Quoted 8 lines
Documentation/networking/af_xdp.rst XDP_OPTIONS getsockopt · line 531
Quoted 1 line
Documentation/networking/af_xdp.rst +1
-0+application.In light of the comment on batch size below, I think it would be useful to spell out what this means exactly. IIUC correctly, it means that the kernel will check the ringbuffer before starting to copy the data, and if there are not enough descriptors available, it will drop the packet instead of doing a partial copy, right? And this is the case for both ZC and copy mode?
I will make this paragraph and the previous one clearer. And yes, copy mode and zc mode have the same behaviour.
Quoted 45 lines
Quoted 45 lines
Documentation/networking/af_xdp.rst +38
-0+If application reads a batch of descriptors, using for example the libxdp +interfaces, it is not guaranteed that the batch will end with a full +packet. It might end in the middle of a packet and the rest of the +buffers of that packet will arrive at the beginning of the next batch, +since the libxdp interface does not read the whole ring (unless you +have an enormous batch size or a very small ring size). + +An example program each for Rx and Tx multi-buffer support can be found +later in this document. + Usage =====@@ -532,6 +619,96 @@ like this: But please use the libbpf functions as they are optimized and ready to use. Will make your life easier. +Usage Multi-Buffer Rx +===================== + +Here is a simple Rx path pseudo-code example (using libxdp interfaces +for simplicity). Error paths have been excluded to keep it short: + +.. code-block:: c + + void rx_packets(struct xsk_socket_info *xsk) + { + static bool new_packet = true; + u32 idx_rx = 0, idx_fq = 0; + static char *pkt; + + int rcvd = xsk_ring_cons__peek(&xsk->rx, opt_batch_size, &idx_rx); + + xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq); + + for (int i = 0; i < rcvd; i++) { + struct xdp_desc *desc = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++); + char *frag = xsk_umem__get_data(xsk->umem->buffer, desc->addr); + bool eop = !(desc->options & XDP_PKT_CONTD); + + if (new_packet) + pkt = frag; + else + add_frag_to_pkt(pkt, frag); +
Quoted 8 lines
Documentation/networking/af_xdp.rst like this: · line 655
Quoted 6 lines
Documentation/networking/af_xdp.rst +6
-0+ if (eop) + process_pkt(pkt); + + new_packet = eop; + + *xsk_ring_prod__fill_addr(&xsk->umem->fq, idx_fq++) = desc->addr;Indentation is off here...
Will fix.
Quoted 3 lines
-Toke
Re: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
Quoted 85 lines · Magnus Karlsson
Quoted 75 lines · Toke Høiland-Jørgensen
Quoted 72 lines · Maciej Fijalkowski
From: Magnus Karlsson <[email protected]>
Add
AF_XDPmulti-buffer support documentation including two pseudo-code samples.Signed-off-by Magnus Karlsson <[email protected]>--- Documentation/networking/af_xdp.rst | 177 ++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+)Documentation/networking/af_xdp.rst +54
-0@@ -453,6 +453,93 @@ XDP_OPTIONS getsockopt Gets options from an XDP socket. The only one supported so far is XDP_OPTIONS_ZEROCOPY which tells you if zero-copy is on or not. +Multi-Buffer Support +-------------------- + +With multi-buffer support, programs using AF_XDP sockets can receive +and transmit packets consisting of multiple buffers both in copy and +zero-copy mode. For example, a packet can consist of two +frames/buffers, one with the header and the other one with the data, +or a 9K Ethernet jumbo frame can be constructed by chaining together +three 4K frames. + +Some definitions: + +* A packet consists of one or more frames + +* A descriptor in one of the AF_XDP rings always refers to a single + frame. In the case the packet consists of a single frame, the + descriptor refers to the whole packet. + +To enable multi-buffer support for an AF_XDP socket, use the new bind +flag XDP_USE_SG. If this is not provided, all multi-buffer packets +will be dropped just as before. Note that the XDP program loaded also +needs to be in multi-buffer mode. This can be accomplished by using +"xdp.frags" as the section name of the XDP program used. + +To represent a packet consisting of multiple frames, a new flag called +XDP_PKT_CONTD is introduced in the options field of the Rx and Tx +descriptors. If it is true (1) the packet continues with the next +descriptor and if it is false (0) it means this is the last descriptor +of the packet. Why the reverse logic of end-of-packet (eop) flag found +in many NICs? Just to preserve compatibility with non-multi-buffer +applications that have this bit set to false for all packets on Rx, +and the apps set the options field to zero for Tx, as anything else +will be treated as an invalid descriptor. + +These are the semantics for producing packets onto AF_XDP Tx ring +consisting of multiple frames: + +* When an invalid descriptor is found, all the other + descriptors/frames of this packet are marked as invalid and not + completed. The next descriptor is treated as the start of a new + packet, even if this was not the intent (because we cannot guess + the intent). As before, if your program is producing invalid + descriptors you have a bug that must be fixed. + +* Zero length descriptors are treated as invalid descriptors. + +* For copy mode, the maximum supported number of frames in a packet is + equal to CONFIG_MAX_SKB_FRAGS + 1. If it is exceeded, all + descriptors accumulated so far are dropped and treated as + invalid. To produce an application that will work on any system + regardless of this config setting, limit the number of frags to 18, + as the minimum value of the config is 17. + +* For zero-copy mode, the limit is up to what the NIC HWQuoted 8 lines
Documentation/networking/af_xdp.rst XDP_OPTIONS getsockopt · line 514
Quoted 5 lines
Documentation/networking/af_xdp.rst +5
-0+ supports. Usually at least five on the NICs we have checked. We + consciously chose to not enforce a rigid limit (such as + CONFIG_MAX_SKB_FRAGS + 1) for zero-copy mode, as it would have + resulted in copy actions under the hood to fit into what limit + the NIC supports. Kind of defeats the purpose of zero-copy mode.How is an application supposed to discover the actual limit for a given NIC/driver?
Quoted 5 lines
Thanks for your comments Toke. I will add an example here of how to discover this. Basically you can send a packet with N frags (N = 2 to start with), check the error stats through the getsockopt. If no
invalid_tx_descerror, increase N with one and send this new packet. If you get an error, then the max number of frags is N-1.
Hmm, okay, that sounds pretty tedious :P
Also, it has side effects (you'll be putting frames on the wire while testing, right?), so I guess this is not something you'll do on every startup of your application? What are you expecting app developers to do here in practice? Run the test while developing and expect the value to stay constant for a given driver (does it?), or? Or will most people in practice only need a few frags to get up to 9k MTU?
Quoted 29 lines
Quoted 20 lines
Documentation/networking/af_xdp.rst XDP_OPTIONS getsockopt · line 520
Quoted 5 lines
Documentation/networking/af_xdp.rst +5
-0+* The ZC batch API guarantees that it will provide a batch of Tx + descriptors that ends with full packet at the end. If not, ZC + drivers would have to gather the full packet on their side. The + approach we picked makes ZC drivers' life much easier (at least on + Tx side).This seems like it implies some constraint on how an application can use the APIs, but it's not quite clear to me what those constraints are, nor what happens if an application does something different. This should probably be spelled out...
Quoted 9 lines
Documentation/networking/af_xdp.rst +9
-0+On the Rx path in copy-mode, the xsk core copies the XDP data into +multiple descriptors, if needed, and sets the XDP_PKT_CONTD flag as +detailed before. Zero-copy mode works the same, though the data is not +copied. When the application gets a descriptor with the XDP_PKT_CONTD +flag set to one, it means that the packet consists of multiple buffers +and it continues with the next buffer in the following +descriptor. When a descriptor with XDP_PKT_CONTD == 0 is received, it +means that this is the last buffer of the packet. AF_XDP guarantees +that only a complete packet (all frames in the packet) is sent to theQuoted 8 lines
Documentation/networking/af_xdp.rst XDP_OPTIONS getsockopt · line 531
Quoted 1 line
Documentation/networking/af_xdp.rst +1
-0+application.In light of the comment on batch size below, I think it would be useful to spell out what this means exactly. IIUC correctly, it means that the kernel will check the ringbuffer before starting to copy the data, and if there are not enough descriptors available, it will drop the packet instead of doing a partial copy, right? And this is the case for both ZC and copy mode?
Quoted 2 lines
I will make this paragraph and the previous one clearer. And yes, copy mode and zc mode have the same behaviour.
Alright, great!
-Toke
Re: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
Quoted 88 lines · Toke Høiland-Jørgensen
Quoted 85 lines · Magnus Karlsson
Quoted 83 lines · Toke Høiland-Jørgensen
Quoted 67 lines · Maciej Fijalkowski
From: Magnus Karlsson <[email protected]>
Add
AF_XDPmulti-buffer support documentation including two pseudo-code samples.Signed-off-by Magnus Karlsson <[email protected]>--- Documentation/networking/af_xdp.rst | 177 ++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+)Documentation/networking/af_xdp.rst +49
-0@@ -453,6 +453,93 @@ XDP_OPTIONS getsockopt Gets options from an XDP socket. The only one supported so far is XDP_OPTIONS_ZEROCOPY which tells you if zero-copy is on or not. +Multi-Buffer Support +-------------------- + +With multi-buffer support, programs using AF_XDP sockets can receive +and transmit packets consisting of multiple buffers both in copy and +zero-copy mode. For example, a packet can consist of two +frames/buffers, one with the header and the other one with the data, +or a 9K Ethernet jumbo frame can be constructed by chaining together +three 4K frames. + +Some definitions: + +* A packet consists of one or more frames + +* A descriptor in one of the AF_XDP rings always refers to a single + frame. In the case the packet consists of a single frame, the + descriptor refers to the whole packet. + +To enable multi-buffer support for an AF_XDP socket, use the new bind +flag XDP_USE_SG. If this is not provided, all multi-buffer packets +will be dropped just as before. Note that the XDP program loaded also +needs to be in multi-buffer mode. This can be accomplished by using +"xdp.frags" as the section name of the XDP program used. + +To represent a packet consisting of multiple frames, a new flag called +XDP_PKT_CONTD is introduced in the options field of the Rx and Tx +descriptors. If it is true (1) the packet continues with the next +descriptor and if it is false (0) it means this is the last descriptor +of the packet. Why the reverse logic of end-of-packet (eop) flag found +in many NICs? Just to preserve compatibility with non-multi-buffer +applications that have this bit set to false for all packets on Rx, +and the apps set the options field to zero for Tx, as anything else +will be treated as an invalid descriptor. + +These are the semantics for producing packets onto AF_XDP Tx ring +consisting of multiple frames: + +* When an invalid descriptor is found, all the other + descriptors/frames of this packet are marked as invalid and not + completed. The next descriptor is treated as the start of a new + packet, even if this was not the intent (because we cannot guess + the intent). As before, if your program is producing invalid + descriptors you have a bug that must be fixed. + +* Zero length descriptors are treated as invalid descriptors. + +* For copy mode, the maximum supported number of frames in a packet is + equal to CONFIG_MAX_SKB_FRAGS + 1. If it is exceeded, all + descriptors accumulated so far are dropped and treated asDocumentation/networking/af_xdp.rst XDP_OPTIONS getsockopt · line 514
Quoted 10 lines
Documentation/networking/af_xdp.rst +10
-0+ invalid. To produce an application that will work on any system + regardless of this config setting, limit the number of frags to 18, + as the minimum value of the config is 17. + +* For zero-copy mode, the limit is up to what the NIC HW + supports. Usually at least five on the NICs we have checked. We + consciously chose to not enforce a rigid limit (such as + CONFIG_MAX_SKB_FRAGS + 1) for zero-copy mode, as it would have + resulted in copy actions under the hood to fit into what limit + the NIC supports. Kind of defeats the purpose of zero-copy mode.How is an application supposed to discover the actual limit for a given NIC/driver?
Quoted 7 lines
Quoted 5 lines
Thanks for your comments Toke. I will add an example here of how to discover this. Basically you can send a packet with N frags (N = 2 to start with), check the error stats through the getsockopt. If no
invalid_tx_descerror, increase N with one and send this new packet. If you get an error, then the max number of frags is N-1.Hmm, okay, that sounds pretty tedious :P
Indeed if you had to do it manually ;-). Do not think this max is important though, see next answer.
Quoted 6 lines
Also, it has side effects (you'll be putting frames on the wire while testing, right?), so I guess this is not something you'll do on every startup of your application? What are you expecting app developers to do here in practice? Run the test while developing and expect the value to stay constant for a given driver (does it?), or? Or will most people in practice only need a few frags to get up to 9k MTU?
I believe that the question that a developer wants to answer is not "max number of frags" supported, but "is 3 or 5 frags" supported. This corresponds to 4K and 2K chunks used to send a 9K MTU. My guess is that any driver that reports that it supports XDP multibuffer will support at least 5 frags too. (Just note that I have not checked around if there are NICs that only support up to 3 frags which would mean that 4K chunks would have to be used.) This value will not change for a NIC and the question is if there are XDP MB enabled NIC drivers that do not support 5 frags? If not, then 5 is the lower bound for the max number of frags in zc mode, at least for the current set of XDP MB enabled drivers.
If an application would like to try if 3 or 5 frags (or any other value) is supported by a NIC when the app is launched, then we would need to try to send something as you say. I wonder if there is a way to transmit a frame that does not reach the wire? What happens if I send a frame with all zeroes, MAC addresses and the like? Will it reach the wire? Another option would be to just send something you really would like to send and if it does not complete and/or you get an error in the getsockopt() stats call, you know that this amount of frags is not supported and you need to try it again with less frags or fallback to copy mode.
I do think there will be applications that require more than 5 frags. I just do not know what they are due to a lack of imagination on my part. They could use the algorithm from above, or just try the number of frags they need depending on the flexibility of the code. A fallback to copy-mode is always possible when the supported number of frags is not there in the NIC HW.
Quoted 36 lines
Quoted 29 lines
Quoted 20 lines
Documentation/networking/af_xdp.rst XDP_OPTIONS getsockopt · line 520
Quoted 5 lines
Documentation/networking/af_xdp.rst +5
-0+* The ZC batch API guarantees that it will provide a batch of Tx + descriptors that ends with full packet at the end. If not, ZC + drivers would have to gather the full packet on their side. The + approach we picked makes ZC drivers' life much easier (at least on + Tx side).This seems like it implies some constraint on how an application can use the APIs, but it's not quite clear to me what those constraints are, nor what happens if an application does something different. This should probably be spelled out...
Quoted 9 lines
Documentation/networking/af_xdp.rst +9
-0+On the Rx path in copy-mode, the xsk core copies the XDP data into +multiple descriptors, if needed, and sets the XDP_PKT_CONTD flag as +detailed before. Zero-copy mode works the same, though the data is not +copied. When the application gets a descriptor with the XDP_PKT_CONTD +flag set to one, it means that the packet consists of multiple buffers +and it continues with the next buffer in the following +descriptor. When a descriptor with XDP_PKT_CONTD == 0 is received, it +means that this is the last buffer of the packet. AF_XDP guarantees +that only a complete packet (all frames in the packet) is sent to theQuoted 8 lines
Documentation/networking/af_xdp.rst XDP_OPTIONS getsockopt · line 531
Quoted 1 line
Documentation/networking/af_xdp.rst +1
-0+application.In light of the comment on batch size below, I think it would be useful to spell out what this means exactly. IIUC correctly, it means that the kernel will check the ringbuffer before starting to copy the data, and if there are not enough descriptors available, it will drop the packet instead of doing a partial copy, right? And this is the case for both ZC and copy mode?
Quoted 2 lines
I will make this paragraph and the previous one clearer. And yes, copy mode and zc mode have the same behaviour.
Alright, great!
-Toke
Jakub Kicinski
maintainerRe: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
Quoted 4 lines · On Wed, 21 Jun 2023 16:15:32 +0200 Magnus Karlsson wrote:
Quoted 1 line
Hmm, okay, that sounds pretty tedious :P
Indeed if you had to do it manually ;-). Do not think this max is important though, see next answer.
Can't we add max segs to Lorenzo's XDP info?include/uapi/linux/netdev.h
Re: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
Quoted 9 lines · Jakub Kicinski
Quoted 4 lines · On Wed, 21 Jun 2023 16:15:32 +0200 Magnus Karlsson wrote:
Quoted 1 line
Hmm, okay, that sounds pretty tedious :P
Indeed if you had to do it manually ;-). Do not think this max is important though, see next answer.
Can't we add max segs to Lorenzo's XDP info?
include/uapi/linux/netdev.h
That should be straight forward. I am just reluctant to add a user interface that might not be necessary.
Maciej, how about changing your patch #13 so that we do not add a flag for zc_mb supported or not, but instead we add a flag that gives the user the max number of frags supported in zc mode? A 1 returned would mean that max 1 frag is supported, i.e. mb is not supported. Any number >1 would mean that mb is supported in zc mode for this device and the returned number is the max number of frags supported. This way we would not have to add one more user interface solely for getting the max number of frags supported. What do you think?
Re: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
Quoted 5 lines · Magnus Karlsson
Quoted 4 lines · Jakub Kicinski
Quoted 2 lines · On Wed, 21 Jun 2023 16:15:32 +0200 Magnus Karlsson wrote:
Quoted 1 line
Hmm, okay, that sounds pretty tedious :P
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Indeed if you had to do it manually ;-). Do not think this max is important though, see next answer.
Can't we add max segs to Lorenzo's XDP info?
include/uapi/linux/netdev.hThat should be straight forward. I am just reluctant to add a user interface that might not be necessary.
Yeah, that was why I was asking what the expectations were before suggesting adding this to the feature bits :)
However, given that the answer seems to be "it varies"...
Quoted 8 lines
Maciej, how about changing your patch #13 so that we do not add a flag for
zc_mbsupported or not, but instead we add a flag that gives the user the max number of frags supported in zc mode? A 1 returned would mean that max 1 frag is supported, i.e. mb is not supported. Any number >1 would mean that mb is supported in zc mode for this device and the returned number is the max number of frags supported. This way we would not have to add one more user interface solely for getting the max number of frags supported. What do you think?
...I think it's a good idea to add the field, and this sounds like a reasonable way of dealing with it (although it may need a bit more plumbing on the netlink side?)
-Toke
A message that is not in the archive (sent off-list or not yet received): ZJx9WkB/dfB5EFjE@boxer
Jakub Kicinski
maintainerRe: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
Quoted 4 lines · On Wed, 28 Jun 2023 20:35:06 +0200 Maciej Fijalkowski wrote:
Okay, here's what I came up with, PTAL, it's on top of the current set but that should not matter a lot, you'll get the idea of it. I think it's better to post a diff here and if you guys find it alright then I'll include this in v5.
LGTM!
Re: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
In reply to a message not in the archivenet/core/netdev-genl.c netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp, · line 23
Quoted 10 lines
net/core/netdev-genl.c +2
-0@@ -19,6 +19,8 @@ netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp,return -EMSGSIZE ; if (nla_put_u32(rsp, NETDEV_A_DEV_IFINDEX, netdev->ifindex) || + nla_put_u32(rsp, NETDEV_A_DEV_XDP_ZC_MAX_SEGS, + netdev->xdp_zc_max_segs) ||
Should this be omitted if the driver doesn't support zero-copy at all?
-Toke
Maciej Fijalkowski
maintainerRe: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
Quoted 7 lines · Toke Høiland-Jørgensen
Quoted 7 lines
net/core/netdev-genl.c +0
-0@@ -19,6 +19,8 @@ netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp,return -EMSGSIZE ;
Quoted 5 lines
net/core/netdev-genl.c netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp, · line 23
Quoted 3 lines
net/core/netdev-genl.c +2
-0if (nla_put_u32(rsp, NETDEV_A_DEV_IFINDEX, netdev->ifindex) || + nla_put_u32(rsp, NETDEV_A_DEV_XDP_ZC_MAX_SEGS, + netdev->xdp_zc_max_segs) ||Should this be omitted if the driver doesn't support zero-copy at all?
This is now set independently when allocing net_device struct, so this can be read without issues. Furthermore this value should not be used to find out if underlying driver supports ZC or not - let us keep using xdp_features for that.
Does it make sense?
Quoted 4 lines
-Toke
Re: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
Quoted 14 lines · Maciej Fijalkowski
Quoted 7 lines · Toke Høiland-Jørgensen
Quoted 7 lines
net/core/netdev-genl.c +0
-0@@ -19,6 +19,8 @@ netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp,return -EMSGSIZE ;Quoted 5 lines
net/core/netdev-genl.c netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp, · line 23
Quoted 3 lines
net/core/netdev-genl.c +2
-0if (nla_put_u32(rsp, NETDEV_A_DEV_IFINDEX, netdev->ifindex) || + nla_put_u32(rsp, NETDEV_A_DEV_XDP_ZC_MAX_SEGS, + netdev->xdp_zc_max_segs) ||Should this be omitted if the driver doesn't support zero-copy at all?
Quoted 6 lines
This is now set independently when allocing
net_devicestruct, so this can be read without issues. Furthermore this value should not be used to find out if underlying driver supports ZC or not - let us keep usingxdp_featuresfor that.Does it make sense?
Yes, I agree we shouldn't use this field for that. However, I am not sure I trust all userspace applications to get that right, so I fear some will end up looking at the field even when the flag is not set, which will lead to confused users. So why not just omit the property entirely when the flag is not set? :)
-Toke
Maciej Fijalkowski
maintainerRe: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
Quoted 21 lines · Toke Høiland-Jørgensen
Quoted 19 lines · Maciej Fijalkowski
Quoted 7 lines · Toke Høiland-Jørgensen
Quoted 7 lines
net/core/netdev-genl.c +0
-0@@ -19,6 +19,8 @@ netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp,return -EMSGSIZE ;Quoted 5 lines
net/core/netdev-genl.c netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp, · line 23
Quoted 3 lines
net/core/netdev-genl.c +2
-0if (nla_put_u32(rsp, NETDEV_A_DEV_IFINDEX, netdev->ifindex) || + nla_put_u32(rsp, NETDEV_A_DEV_XDP_ZC_MAX_SEGS, + netdev->xdp_zc_max_segs) ||Should this be omitted if the driver doesn't support zero-copy at all?
This is now set independently when allocing
net_devicestruct, so this can be read without issues. Furthermore this value should not be used to find out if underlying driver supports ZC or not - let us keep usingxdp_featuresfor that.
Quoted 7 lines
Quoted 1 line
Does it make sense?
Yes, I agree we shouldn't use this field for that. However, I am not sure I trust all userspace applications to get that right, so I fear some will end up looking at the field even when the flag is not set, which will lead to confused users. So why not just omit the property entirely when the flag is not set? :)
I think that if you would read anything different than default 1 from this field and your driver does not zupport even ZC then your driver is wrong. It's like reporting something via xdp_features and not supporting it. You only overwrite this within your driver *if* you support ZC multi-buffer.
OTOH were you referring to omitting putting the u32 to netlink response at all?
Quoted 3 lines
-Toke
Re: [PATCH v4 bpf-next 15/22] xsk: add multi-buffer documentation
Quoted 30 lines · Maciej Fijalkowski
Quoted 21 lines · Toke Høiland-Jørgensen
Quoted 19 lines · Maciej Fijalkowski
Quoted 7 lines · Toke Høiland-Jørgensen
Quoted 7 lines
net/core/netdev-genl.c +0
-0@@ -19,6 +19,8 @@ netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp,return -EMSGSIZE ;Quoted 5 lines
net/core/netdev-genl.c netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp, · line 23
Quoted 3 lines
net/core/netdev-genl.c +2
-0if (nla_put_u32(rsp, NETDEV_A_DEV_IFINDEX, netdev->ifindex) || + nla_put_u32(rsp, NETDEV_A_DEV_XDP_ZC_MAX_SEGS, + netdev->xdp_zc_max_segs) ||Should this be omitted if the driver doesn't support zero-copy at all?
This is now set independently when allocing
net_devicestruct, so this can be read without issues. Furthermore this value should not be used to find out if underlying driver supports ZC or not - let us keep usingxdp_featuresfor that.Quoted 7 lines
Quoted 1 line
Does it make sense?
Yes, I agree we shouldn't use this field for that. However, I am not sure I trust all userspace applications to get that right, so I fear some will end up looking at the field even when the flag is not set, which will lead to confused users. So why not just omit the property entirely when the flag is not set? :)
Quoted 7 lines
I think that if you would read anything different than default 1 from this field and your driver does not zupport even ZC then your driver is wrong. It's like reporting something via
xdp_featuresand not supporting it. You only overwrite this within your driver *if* you support ZC multi-buffer.OTOH were you referring to omitting putting the u32 to netlink response at all?
Yes, the latter. I have no objection to the internal field being set to 1 by default or anything, I just think we should omit the netlink attribute when it doesn't have a meaningful value, to avoid confusion - being able to do that is one of the nice properties of netlink, after all :)
-Toke
Maciej Fijalkowski
maintainerPATCH v4 16/22 selftests/xsk: transmit and receive multi-buffer packets
In reply to Maciej FijalkowskiFrom: Magnus Karlsson <[email protected]>
Add the ability to send and receive packets that are larger than the size of a umem frame, using the AF_XDP /XDP multi-buffer support. There are three pieces of code that need to be changed to achieve this: the Rx path, the Tx path, and the validation logic.
Both the Rx path and Tx could only deal with a single fragment per packet. The Tx path is extended with a new function called pkt_nb_frags() that can be used to retrieve the number of fragments a packet will consume. We then create these many fragments in a loop and fill the N-1 first ones to the max size limit to use the buffer space efficiently, and the Nth one with whatever data that is left. This goes on until we have filled in at the most BATCH_SIZE worth of descriptors and fragments. If we detect that the next packet would lead to BATCH_SIZE number of fragments sent being exceeded, we do not send this packet and finish the batch. This packet is instead sent in the next iteration of BATCH_SIZE fragments.
For Rx, we loop over all fragments we receive as usual, but for every descriptor that we receive we call a new validation function called is_frag_valid() to validate the consistency of this fragment. The code then checks if the packet continues in the next frame. If so, it loops over the next packet and performs the same validation. once we have received the last fragment of the packet we also call the function is_pkt_valid() to validate the packet as a whole. If we get to the end of the batch and we are not at the end of the current packet, we back out the partial packet and end the loop. Once we get into the receive loop next time, we start over from the beginning of that packet. This so the code becomes simpler at the cost of some performance.
The validation function is_frag_valid() checks that the sequence and packet numbers are correct at the start and end of each fragment.
--- tools/include/uapi/linux/if_xdp.h | 3 + tools/testing/selftests/bpf/xskxceiver.c | 167 ++++++++++++++++++----- tools/testing/selftests/bpf/xskxceiver.h | 3 +- 3 files changed, 139 insertions(+), 34 deletions(-)
tools/include/uapi/linux/if_xdp.h +3 -0
@@ -106,6 +106,9 @@ struct xdp_desc { __u32 options; }; +/* Flag indicating packet constitutes of multiple buffers*/ +#define XDP_PKT_CONTD (1 << 0) +/* UMEM descriptor is __u64 */ #endif /* _LINUX_IF_XDP_H */
tools/testing/selftests/bpf/xskxceiver.c +134 -33
274 lines not on this page · raw message
tools/testing/selftests/bpf/xskxceiver.h +2 -1
@@ -38,6 +38,7 @@#define MAX_TEARDOWN_ITER 10#define PKT_HDR_SIZE (sizeof(struct ethhdr) + 2)/* Just to align the data in the packet */ #define MIN_PKT_SIZE 64 +#define MAX_ETH_JUMBO_SIZE 9000#define USLEEP_MAX 10000#define SOCK_RECONF_CTR 10#define BATCH_SIZE 64
@@ -47,7 +48,7 @@#define DEFAULT_UMEM_BUFFERS (DEFAULT_PKT_CNT / 4)#define RX_FULL_RXQSIZE 32#define UMEM_HEADROOM_TEST_SIZE 128 -#define XSK_UMEM__INVALID_FRAME_SIZE (XSK_UMEM__DEFAULT_FRAME_SIZE + 1) +#define XSK_UMEM__INVALID_FRAME_SIZE (MAX_ETH_JUMBO_SIZE + 1)#define HUGEPAGE_SIZE (2 * 1024 * 1024)#define PKT_DUMP_NB_TO_PRINT 16
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 17/22 selftests/xsk: add basic multi-buffer test
In reply to Maciej FijalkowskiFrom: Magnus Karlsson <[email protected]>
Add the first basic multi-buffer test that sends a stream of 9K packets and validates that they are received at the other end. In order to enable sending and receiving multi-buffer packets, code that sets the MTU is introduced as well as modifications to the XDP programs so that they signal that they are multi-buffer enabled.
--- tools/include/uapi/linux/if_xdp.h | 6 + .../selftests/bpf/progs/xsk_xdp_progs.c | 4 +- tools/testing/selftests/bpf/xsk.c | 136 +++++++++++++++++- tools/testing/selftests/bpf/xsk.h | 2 + tools/testing/selftests/bpf/xskxceiver.c | 67 +++++++++ tools/testing/selftests/bpf/xskxceiver.h | 6 + 6 files changed, 218 insertions(+), 3 deletions(-)
tools/include/uapi/linux/if_xdp.h +6 -0
@@ -25,6 +25,12 @@* application. */ #define XDP_USE_NEED_WAKEUP (1 << 3) +/* By setting this option, userspace application indicates that it can +* handle multiple descriptors per packet thus enabling xsk core to split +* multi-buffer XDP frames into multiple Rx descriptors. Without this set +* such frames will be dropped by xsk. +*/ +#define XDP_USE_SG (1 << 4)/* Flags for xsk_umem_config flags */ #define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
tools/testing/selftests/bpf/progs/xsk_xdp_progs.c +2 -2
@@ -15,12 +15,12 @@ struct {static unsigned int idx;int count =0 ; -SEC("xdp") int xsk_def_prog(struct xdp_md *xdp) +SEC("xdp.frags") int xsk_def_prog(struct xdp_md *xdp) {return bpf_redirect_map (&xsk,0 ,XDP_DROP ); } -SEC("xdp") int xsk_xdp_drop(struct xdp_md *xdp) +SEC("xdp.frags") int xsk_xdp_drop(struct xdp_md *xdp) {/* Drop every other packet */ if (idx++ %2 )
tools/testing/selftests/bpf/xsk.c +135 -1
164 lines not on this page · raw message
tools/testing/selftests/bpf/xsk.h +2 -0
@@ -239,6 +239,8 @@ int xsk_socket__create_shared(struct xsk_socket **xsk_ptr,int xsk_umem__delete (struct xsk_umem *umem);void xsk_socket__delete (struct xsk_socket *xsk); +int xsk_set_mtu (int ifindex,int mtu); + #ifdef __cplusplus }/* extern "C" */ #endif
tools/testing/selftests/bpf/xskxceiver.c +67 -0
127 lines not on this page · raw message
tools/testing/selftests/bpf/xskxceiver.h +6 -0
@@ -38,6 +38,7 @@#define MAX_TEARDOWN_ITER 10#define PKT_HDR_SIZE (sizeof(struct ethhdr) + 2)/* Just to align the data in the packet */ #define MIN_PKT_SIZE 64 +#define MAX_ETH_PKT_SIZE 1518#define MAX_ETH_JUMBO_SIZE 9000#define USLEEP_MAX 10000#define SOCK_RECONF_CTR 10
@@ -84,6 +85,7 @@ enum test_type {TEST_TYPE_BPF_RES ,TEST_TYPE_XDP_DROP_HALF ,TEST_TYPE_XDP_METADATA_COUNT , +TEST_TYPE_RUN_TO_COMPLETION_MB , TEST_TYPE_MAX };
@@ -142,6 +144,7 @@ struct ifobject {struct bpf_program *xdp_prog;enum test_mode mode;int ifindex; +int mtu;u32 bind_flags;bool tx_on;bool rx_on;
@@ -152,6 +155,8 @@ struct ifobject {bool shared_umem;bool use_metadata;bool unaligned_supp; +bool multi_buff_supp; +bool multi_buff_zc_supp;u8 dst_mac[ETH_ALEN ];u8 src_mac[ETH_ALEN ]; };
@@ -165,6 +170,7 @@ struct test_spec {struct bpf_program *xdp_prog_tx;struct bpf_map *xskmap_rx;struct bpf_map *xskmap_tx; +int mtu;u16 total_steps;u16 current_step;u16 nb_sockets;
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 18/22 selftests/xsk: add unaligned mode test for multi-buffer
In reply to Maciej FijalkowskiFrom: Magnus Karlsson <[email protected]>
Add a test for multi-buffer AF_XDP when using unaligned mode. The test sends 4096 9K-buffers.
--- tools/testing/selftests/bpf/xskxceiver.c | 15 +++++++++++++++ tools/testing/selftests/bpf/xskxceiver.h | 1 + 2 files changed, 16 insertions(+)
tools/testing/selftests/bpf/xskxceiver.c +15 -0
@@ -50,6 +50,8 @@* are discarded and let through, respectively. * i. 2K frame size tests * j. If multi-buffer is supported, send 9k packets divided into 3 frames +* k. If multi-buffer and huge pages are supported, send 9k packets in a single frame +* using unaligned mode * * Total tests: 12 *
@@ -1761,6 +1763,16 @@ static int testapp_unaligned(struct test_spec *test)return testapp_validate_traffic (test); } +static int testapp_unaligned_mb (struct test_spec *test) +{ +test_spec_set_name (test,"UNALIGNED_MODE_9K" ); + test->mtu =MAX_ETH_JUMBO_SIZE ; + test->ifobj_tx->umem->unaligned_mode = true; + test->ifobj_rx->umem->unaligned_mode = true; +pkt_stream_replace (test,DEFAULT_PKT_CNT ,MAX_ETH_JUMBO_SIZE ); +return testapp_validate_traffic (test); +} +static int testapp_single_pkt (struct test_spec *test) {struct pkt pkts[] = {{0 ,MIN_PKT_SIZE ,0 , true}};
@@ -2037,6 +2049,9 @@ static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_case TEST_TYPE_UNALIGNED : ret =testapp_unaligned (test);break ; +case TEST_TYPE_UNALIGNED_MB : + ret =testapp_unaligned_mb (test); +break ;case TEST_TYPE_HEADROOM : ret =testapp_headroom (test);break ;
tools/testing/selftests/bpf/xskxceiver.h +1 -0
@@ -86,6 +86,7 @@ enum test_type {TEST_TYPE_XDP_DROP_HALF ,TEST_TYPE_XDP_METADATA_COUNT ,TEST_TYPE_RUN_TO_COMPLETION_MB , +TEST_TYPE_UNALIGNED_MB , TEST_TYPE_MAX };
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 19/22 selftests/xsk: add invalid descriptor test for multi-buffer
In reply to Maciej FijalkowskiFrom: Magnus Karlsson <[email protected]>
Add a test that produces lots of nasty descriptors testing the corner cases of the descriptor validation. Some of these descriptors are valid and some are not as indicated by the valid flag. For a description of all the test combinations, please see the code.
To stress the API, we need to be able to generate combinations of descriptors that make little sense. A new verbatim mode is introduced for the packet_stream to accomplish this. In this mode, all packets in the packet_stream are sent as is. We do not try to chop them up into frames that are of the right size that we know are going to work as we would normally do. The packets are just written into the Tx ring even if we know they make no sense.
--- tools/testing/selftests/bpf/xskxceiver.c | 185 ++++++++++++++++++----- tools/testing/selftests/bpf/xskxceiver.h | 7 + 2 files changed, 151 insertions(+), 41 deletions(-)
tools/testing/selftests/bpf/xskxceiver.c +144 -41
@@ -52,8 +52,8 @@* j. If multi-buffer is supported, send 9k packets divided into 3 frames * k. If multi-buffer and huge pages are supported, send 9k packets in a single frame * using unaligned mode -* -* Total tests: 12 +* l. If multi-buffer is supported, try various nasty combinations of descriptors to +* check if they pass the validation or not * * Flow: * -----
@@ -76,7 +76,6 @@#include <fcntl.h> #include <errno.h> #include <getopt.h> -#include <asm/barrier.h> #include <linux/if_link.h> #include <linux/if_ether.h> #include <linux/mman.h>
@@ -95,7 +94,6 @@#include <sys/socket.h> #include <sys/time.h> #include <sys/types.h> -#include <time.h> #include <unistd.h> #include "xsk_xdp_progs.skel.h"
@@ -560,9 +558,9 @@ static struct pkt_stream *__pkt_stream_alloc(u32 nb_pkts)return pkt_stream; } -static bool pkt_continues (const struct xdp_desc *desc) +static bool pkt_continues (u32 options) { -return desc->options &XDP_PKT_CONTD ; +return options &XDP_PKT_CONTD ; }static u32 ceil_u32 (u32 a,u32 b)
@@ -570,11 +568,32 @@ static u32 ceil_u32(u32 a, u32 b)return (a + b -1 ) / b; } -static u32 pkt_nb_frags (u32 frame_size,struct pkt *pkt) +static u32 pkt_nb_frags (u32 frame_size,struct pkt_stream *pkt_stream,struct pkt *pkt) { -if (!pkt || !pkt->valid) +u32 nb_frags =1 , next_frag; + +if (!pkt)return 1 ; -return ceil_u32 (pkt->len, frame_size); + +if (!pkt_stream->verbatim) { +if (!pkt->valid || !pkt->len) +return 1 ; +return ceil_u32 (pkt->len, frame_size); + } + +/* Search for the end of the packet in verbatim mode */ +if (!pkt_continues (pkt->options)) +return nb_frags; + + next_frag = pkt_stream->current_pkt_nb; + pkt++; +while (next_frag++ < pkt_stream->nb_pkts) { + nb_frags++; +if (!pkt_continues (pkt->options) || !pkt->valid) +break ; + pkt++; + } +return nb_frags; }static void pkt_set (struct xsk_umem_info *umem,struct pkt *pkt,int offset,u32 len)
@@ -694,34 +713,59 @@ static void pkt_generate(struct ifobject *ifobject, u64 addr, u32 len, u32 pkt_nwrite_payload (data, pkt_nb, bytes_written, len); } -static void __pkt_stream_generate_custom (struct ifobject *ifobj, -struct pkt *pkts,u32 nb_pkts) +static struct pkt_stream *__pkt_stream_generate_custom (struct ifobject *ifobj,struct pkt *frames, +u32 nb_frames,bool verbatim) { +u32 i, len =0 , pkt_nb =0 , payload =0 ;struct pkt_stream *pkt_stream; -u32 i; - pkt_stream =__pkt_stream_alloc (nb_pkts); + pkt_stream =__pkt_stream_alloc (nb_frames);if (!pkt_stream)exit_with_error (ENOMEM ); -for (i =0 ; i < nb_pkts; i++) { -struct pkt *pkt = &pkt_stream->pkts[i]; +for (i =0 ; i < nb_frames; i++) { +struct pkt *pkt = &pkt_stream->pkts[pkt_nb]; +struct pkt *frame = &frames[i]; - pkt->offset = pkts[i].offset; - pkt->len = pkts[i].len; - pkt->pkt_nb = i; - pkt->valid = pkts[i].valid; -if (pkt->len > pkt_stream->max_pkt_len) + pkt->offset = frame->offset; +if (verbatim) { + *pkt = *frame; + pkt->pkt_nb = payload; +if (!frame->valid || !pkt_continues (frame->options)) + payload++; + }else { +if (frame->valid) + len += frame->len; +if (frame->valid &&pkt_continues (frame->options)) +continue ; + + pkt->pkt_nb = pkt_nb; + pkt->len = len; + pkt->valid = frame->valid; + pkt->options =0 ; + + len =0 ; + } + +if (pkt->valid && pkt->len > pkt_stream->max_pkt_len) pkt_stream->max_pkt_len = pkt->len; + pkt_nb++; } - ifobj->pkt_stream = pkt_stream; + pkt_stream->nb_pkts = pkt_nb; + pkt_stream->verbatim = verbatim; +return pkt_stream; }static void pkt_stream_generate_custom (struct test_spec *test,struct pkt *pkts,u32 nb_pkts) { -__pkt_stream_generate_custom (test->ifobj_tx, pkts, nb_pkts); -__pkt_stream_generate_custom (test->ifobj_rx, pkts, nb_pkts); +struct pkt_stream *pkt_stream; + + pkt_stream =__pkt_stream_generate_custom (test->ifobj_tx, pkts, nb_pkts, true); + test->ifobj_tx->pkt_stream = pkt_stream; + + pkt_stream =__pkt_stream_generate_custom (test->ifobj_rx, pkts, nb_pkts, false); + test->ifobj_rx->pkt_stream = pkt_stream; }static void pkt_print_data (u32 *data,u32 cnt)
@@ -862,11 +906,6 @@ static bool is_frag_valid(struct xsk_umem_info *umem, u64 addr, u32 len, u32 expstatic bool is_pkt_valid (struct pkt *pkt,void *buffer,u64 addr,u32 len) { -if (!pkt) { -ksft_print_msg ("[%s] too many packets received\n" , __func__); -return false; - } -if (pkt->len != len) {ksft_print_msg ("[%s] expected packet length [%d], got length [%d]\n" , __func__, pkt->len, len);
@@ -966,7 +1005,6 @@ static int receive_pkts(struct test_spec *test, struct pollfd *fds)ksft_print_msg ("ERROR: [%s] Poll timed out\n" , __func__);return TEST_FAILURE ; - }if (!(fds->revents &POLLIN ))
@@ -998,6 +1036,12 @@ static int receive_pkts(struct test_spec *test, struct pollfd *fds) orig =xsk_umem__extract_addr (addr); addr =xsk_umem__add_offset_to_addr (addr); +if (!pkt) { +ksft_print_msg ("[%s] received too many packets addr: %lx len %u\n" , + __func__, addr, desc->len); +return TEST_FAILURE ; + } +if (!is_frag_valid (umem, addr, desc->len, pkt->pkt_nb, pkt_len) || !is_offset_correct (umem, pkt, addr) || (ifobj->use_metadata && !is_metadata_correct (pkt, umem->buffer, addr)))
@@ -1010,7 +1054,7 @@ static int receive_pkts(struct test_spec *test, struct pollfd *fds)if (ifobj->use_fill_ring) *xsk_ring_prod__fill_addr (&umem->fq, idx_fq++) = orig; -if (pkt_continues (desc)) +if (pkt_continues (desc->options))continue ;/* The complete packet has been received */
@@ -1089,31 +1133,29 @@ static int __send_pkts(struct ifobject *ifobject, struct pollfd *fds, bool timeofor (i =0 ; i <BATCH_SIZE ; i++) {struct pkt *pkt =pkt_stream_get_next_tx_pkt (pkt_stream); -u32 nb_frags, bytes_written =0 ; +u32 nb_frags_left, nb_frags, bytes_written =0 ;if (!pkt)break ; - nb_frags =pkt_nb_frags (umem->frame_size, pkt); + nb_frags =pkt_nb_frags (umem->frame_size, pkt_stream, pkt);if (nb_frags >BATCH_SIZE - i) {pkt_stream_cancel (pkt_stream);xsk_ring_prod__cancel (&xsk->tx,BATCH_SIZE - i);break ; } + nb_frags_left = nb_frags; -if (pkt->valid) { - valid_pkts++; - valid_frags += nb_frags; - } - -while (nb_frags--) { +while (nb_frags_left--) {struct xdp_desc *tx_desc =xsk_ring_prod__tx_desc (&xsk->tx, idx + i); tx_desc->addr =pkt_get_addr (pkt, ifobject->umem); -if (nb_frags) { +if (pkt_stream->verbatim) { + tx_desc->len = pkt->len; + tx_desc->options = pkt->options; + }else if (nb_frags_left) { tx_desc->len = umem->frame_size; tx_desc->options =XDP_PKT_CONTD ; - i++; }else { tx_desc->len = pkt->len - bytes_written; tx_desc->options =0 ;
@@ -1122,6 +1164,17 @@ static int __send_pkts(struct ifobject *ifobject, struct pollfd *fds, bool timeopkt_generate (ifobject, tx_desc->addr, tx_desc->len, pkt->pkt_nb, bytes_written); bytes_written += tx_desc->len; + +if (nb_frags_left) { + i++; +if (pkt_stream->verbatim) + pkt =pkt_stream_get_next_tx_pkt (pkt_stream); + } + } + +if (pkt && pkt->valid) { + valid_pkts++; + valid_frags += nb_frags; } }
@@ -1350,7 +1403,7 @@ static void xsk_populate_fill_ring(struct xsk_umem_info *umem, struct pkt_streamu64 addr;u32 i; -for (i =0 ; i <pkt_nb_frags (rx_frame_size, pkt); i++) { +for (i =0 ; i <pkt_nb_frags (rx_frame_size, pkt_stream, pkt); i++) {if (!pkt) {if (!fill_up)break ;
@@ -1790,6 +1843,46 @@ static int testapp_multi_buffer(struct test_spec *test)return testapp_validate_traffic (test); } +static int testapp_invalid_desc_mb (struct test_spec *test) +{ +struct xsk_umem_info *umem = test->ifobj_tx->umem; +u64 umem_size = umem->num_frames * umem->frame_size; +struct pkt pkts[] = { +/* Valid packet for synch to start with */ + {0 ,MIN_PKT_SIZE ,0 , true,0 }, +/* Zero frame len is not legal */ + {0 ,XSK_UMEM__LARGE_FRAME_SIZE ,0 , false,XDP_PKT_CONTD }, + {0 ,XSK_UMEM__LARGE_FRAME_SIZE ,0 , false,XDP_PKT_CONTD }, + {0 ,0 ,0 , false,0 }, +/* Invalid address in the second frame */ + {0 ,XSK_UMEM__LARGE_FRAME_SIZE ,0 , false,XDP_PKT_CONTD }, + {umem_size,XSK_UMEM__LARGE_FRAME_SIZE ,0 , false,XDP_PKT_CONTD }, +/* Invalid len in the middle */ + {0 ,XSK_UMEM__LARGE_FRAME_SIZE ,0 , false,XDP_PKT_CONTD }, + {0 ,XSK_UMEM__INVALID_FRAME_SIZE ,0 , false,XDP_PKT_CONTD }, +/* Invalid options in the middle */ + {0 ,XSK_UMEM__LARGE_FRAME_SIZE ,0 , false,XDP_PKT_CONTD }, + {0 ,XSK_UMEM__LARGE_FRAME_SIZE ,0 , false,XSK_DESC__INVALID_OPTION }, +/* Transmit 2 frags, receive 3 */ + {0 ,XSK_UMEM__MAX_FRAME_SIZE ,0 , true,XDP_PKT_CONTD }, + {0 ,XSK_UMEM__MAX_FRAME_SIZE ,0 , true,0 }, +/* Middle frame crosses chunk boundary with small length */ + {0 ,XSK_UMEM__LARGE_FRAME_SIZE ,0 , false,XDP_PKT_CONTD }, + {-MIN_PKT_SIZE /2 ,MIN_PKT_SIZE ,0 , false,0 }, +/* Valid packet for synch so that something is received */ + {0 ,MIN_PKT_SIZE ,0 , true,0 }}; + +if (umem->unaligned_mode) { +/* Crossing a chunk boundary allowed */ + pkts[12 ].valid = true; + pkts[13 ].valid = true; + } + + test->mtu =MAX_ETH_JUMBO_SIZE ; +pkt_stream_generate_custom (test, pkts,ARRAY_SIZE (pkts)); +return testapp_validate_traffic (test); +} +static int testapp_invalid_desc (struct test_spec *test) {struct xsk_umem_info *umem = test->ifobj_tx->umem;
@@ -2046,6 +2139,16 @@ static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_ ret =testapp_invalid_desc (test);break ; } +case TEST_TYPE_ALIGNED_INV_DESC_MB : +test_spec_set_name (test,"ALIGNED_INV_DESC_MULTI_BUFF" ); + ret =testapp_invalid_desc_mb (test); +break ; +case TEST_TYPE_UNALIGNED_INV_DESC_MB : +test_spec_set_name (test,"UNALIGNED_INV_DESC_MULTI_BUFF" ); + test->ifobj_tx->umem->unaligned_mode = true; + test->ifobj_rx->umem->unaligned_mode = true; + ret =testapp_invalid_desc_mb (test); +break ;case TEST_TYPE_UNALIGNED : ret =testapp_unaligned (test);break ;
tools/testing/selftests/bpf/xskxceiver.h +7 -0
@@ -50,6 +50,9 @@#define RX_FULL_RXQSIZE 32#define UMEM_HEADROOM_TEST_SIZE 128#define XSK_UMEM__INVALID_FRAME_SIZE (MAX_ETH_JUMBO_SIZE + 1) +#define XSK_UMEM__LARGE_FRAME_SIZE (3 * 1024) +#define XSK_UMEM__MAX_FRAME_SIZE (4 * 1024) +#define XSK_DESC__INVALID_OPTION (0xffff)#define HUGEPAGE_SIZE (2 * 1024 * 1024)#define PKT_DUMP_NB_TO_PRINT 16
@@ -87,6 +90,8 @@ enum test_type {TEST_TYPE_XDP_METADATA_COUNT ,TEST_TYPE_RUN_TO_COMPLETION_MB ,TEST_TYPE_UNALIGNED_MB , +TEST_TYPE_ALIGNED_INV_DESC_MB , +TEST_TYPE_UNALIGNED_INV_DESC_MB , TEST_TYPE_MAX };
@@ -119,6 +124,7 @@ struct pkt {u32 len;u32 pkt_nb;bool valid; +u16 options; };struct pkt_stream {
@@ -126,6 +132,7 @@ struct pkt_stream {u32 current_pkt_nb;struct pkt *pkts;u32 max_pkt_len; +bool verbatim; };struct ifobject ;
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 20/22 selftests/xsk: add metadata copy test for multi-buff
In reply to Maciej FijalkowskiFrom: Magnus Karlsson <[email protected]>
Enable the already existing metadata copy test to also run in multi-buffer mode with 9K packets.
--- tools/testing/selftests/bpf/progs/xsk_xdp_progs.c | 2 +- tools/testing/selftests/bpf/xskxceiver.c | 7 ++++++- tools/testing/selftests/bpf/xskxceiver.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/xsk_xdp_progs.c +1 -1
@@ -29,7 +29,7 @@ SEC("xdp.frags") int xsk_xdp_drop(struct xdp_md *xdp)return bpf_redirect_map (&xsk,0 ,XDP_DROP ); } -SEC("xdp") int xsk_xdp_populate_metadata(struct xdp_md *xdp) +SEC("xdp.frags") int xsk_xdp_populate_metadata(struct xdp_md *xdp) {void *data, *data_meta;struct xdp_info *meta;
tools/testing/selftests/bpf/xskxceiver.c +6 -1
@@ -1949,7 +1949,6 @@ static int testapp_xdp_metadata_count(struct test_spec *test)int count =0 ;int key =0 ; -test_spec_set_name (test,"XDP_METADATA_COUNT" );test_spec_set_xdp_prog (test, skel_rx->progs.xsk_xdp_populate_metadata, skel_tx->progs.xsk_xdp_populate_metadata, skel_rx->maps.xsk, skel_tx->maps.xsk);
@@ -2162,6 +2161,12 @@ static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_ ret =testapp_xdp_drop (test);break ;case TEST_TYPE_XDP_METADATA_COUNT : +test_spec_set_name (test,"XDP_METADATA_COUNT" ); + ret =testapp_xdp_metadata_count (test); +break ; +case TEST_TYPE_XDP_METADATA_COUNT_MB : +test_spec_set_name (test,"XDP_METADATA_COUNT_MULTI_BUFF" ); + test->mtu =MAX_ETH_JUMBO_SIZE ; ret =testapp_xdp_metadata_count (test);break ;default :
tools/testing/selftests/bpf/xskxceiver.h +1 -0
@@ -88,6 +88,7 @@ enum test_type {TEST_TYPE_BPF_RES ,TEST_TYPE_XDP_DROP_HALF ,TEST_TYPE_XDP_METADATA_COUNT , +TEST_TYPE_XDP_METADATA_COUNT_MB ,TEST_TYPE_RUN_TO_COMPLETION_MB ,TEST_TYPE_UNALIGNED_MB , TEST_TYPE_ALIGNED_INV_DESC_MB,
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 21/22 selftests/xsk: add test for too many frags
In reply to Maciej FijalkowskiFrom: Magnus Karlsson <[email protected]>
Add a test for testing that a packet consisting of more than 18 frags is discarded. This is only valid for SKB and DRV mode since in zero-copy mode, this limit is up to the HW and what it supports.
--- tools/testing/selftests/bpf/xskxceiver.c | 40 ++++++++++++++++++++++++ tools/testing/selftests/bpf/xskxceiver.h | 2 ++ 2 files changed, 42 insertions(+)
tools/testing/selftests/bpf/xskxceiver.c +40 -0
@@ -1982,6 +1982,43 @@ static int testapp_poll_rxq_tmout(struct test_spec *test)return testapp_validate_traffic_single_thread (test, test->ifobj_rx); } +static int testapp_too_many_frags (struct test_spec *test) +{ +struct pkt pkts[2 *XSK_DESC__MAX_FRAGS +2 ] = {}; +u32 i; + +test_spec_set_name (test,"TOO_MANY_FRAGS" ); +if (test->mode ==TEST_MODE_ZC ) { +/* Limit is up to driver for zero-copy mode so not testable. */ +ksft_test_result_skip ("Cannot be run for zero-copy mode.\n" ); +return TEST_SKIP ; + } + + test->mtu =MAX_ETH_JUMBO_SIZE ; + +/* Valid packet for synch */ + pkts[0 ].len =MIN_PKT_SIZE ; + pkts[0 ].valid = true; + +/* Produce two longs packets below out of this */ +for (i =1 ; i <2 *XSK_DESC__MAX_FRAGS +1 ; i++) { + pkts[i].len =MIN_PKT_SIZE ; + pkts[i].options =XDP_PKT_CONTD ; + pkts[i].valid = true; + } +/* 1st packet: Produce the highest amount of frags possible */ + pkts[XSK_DESC__MAX_FRAGS ].options =0 ; +/* 2nd packet: Do not signal end-of-packet in the 17th frag. This is not legal. */ + pkts[2 *XSK_DESC__MAX_FRAGS ].valid = false; + +/* Valid packet for synch */ + pkts[2 *XSK_DESC__MAX_FRAGS +1 ].len =MIN_PKT_SIZE ; + pkts[2 *XSK_DESC__MAX_FRAGS +1 ].valid = true; + +pkt_stream_generate_custom (test, pkts,ARRAY_SIZE (pkts)); +return testapp_validate_traffic (test); +} +static int xsk_load_xdp_programs (struct ifobject *ifobj) { ifobj->xdp_progs =xsk_xdp_progs__open_and_load ();
@@ -2169,6 +2206,9 @@ static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_ test->mtu =MAX_ETH_JUMBO_SIZE ; ret =testapp_xdp_metadata_count (test);break ; +case TEST_TYPE_TOO_MANY_FRAGS : + ret =testapp_too_many_frags (test); +break ;default :break ; }
tools/testing/selftests/bpf/xskxceiver.h +2 -0
@@ -53,6 +53,7 @@#define XSK_UMEM__LARGE_FRAME_SIZE (3 * 1024)#define XSK_UMEM__MAX_FRAME_SIZE (4 * 1024)#define XSK_DESC__INVALID_OPTION (0xffff) +#define XSK_DESC__MAX_FRAGS 18#define HUGEPAGE_SIZE (2 * 1024 * 1024)#define PKT_DUMP_NB_TO_PRINT 16
@@ -93,6 +94,7 @@ enum test_type {TEST_TYPE_UNALIGNED_MB ,TEST_TYPE_ALIGNED_INV_DESC_MB ,TEST_TYPE_UNALIGNED_INV_DESC_MB , +TEST_TYPE_TOO_MANY_FRAGS , TEST_TYPE_MAX };
Signature · 1 line
2.34.1
Maciej Fijalkowski
maintainerPATCH v4 22/22 selftests/xsk: reset NIC settings to default after running test suite
In reply to Maciej FijalkowskiCurrently, when running ZC test suite, after finishing first run of test suite and then switching to busy-poll tests within xskxceiver, such errors are observed:
libbpf: Kernel error message: ice: MTU is too large for linear frames and XDP prog does not support frags 1..26
libbpf: Kernel error message: Native and generic XDP can't be active at the same time Error attaching XDP program
not ok 1 [xskxceiver.c:xsk_reattach_xdp:1568]: ERROR: 17/"File exists"
this is because test suite ends with 9k MTU and native xdp program being loaded. Busy-poll tests start non-multi-buffer tests for generic mode. To fix this, let us introduce bash function that will reset NIC settings to default (e.g. 1500 MTU and no xdp progs loaded) so that test suite can continue without interrupts. It also means that after busy-poll tests NIC will have those default settings, whereas right now it is left with 9k MTU and xdp prog loaded in native mode.
--- tools/testing/selftests/bpf/test_xsk.sh | 5 +++++ tools/testing/selftests/bpf/xsk_prereqs.sh | 7 +++++++ 2 files changed, 12 insertions(+)
tools/testing/selftests/bpf/test_xsk.sh +5 -0
@@ -171,7 +171,10 @@ exec_xskxceiver if [ -z $ETH ]; then cleanup_exit ${VETH0} ${VETH1} +else + cleanup_iface ${ETH} ${MTU} fi + TEST_NAME="XSK_SELFTESTS_${VETH0}_BUSY_POLL" busy_poll=1
@@ -184,6 +187,8 @@ exec_xskxceiver if [ -z $ETH ]; then cleanup_exit ${VETH0} ${VETH1} +else + cleanup_iface ${ETH} ${MTU} fi failures=0
tools/testing/selftests/bpf/xsk_prereqs.sh +7 -0
@@ -53,6 +53,13 @@ test_exit() exit 1 } +cleanup_iface() +{ + ip link set $1 mtu $2 + ip link set $1 xdp off + ip link set $1 xdpgeneric off +} + clear_configs() { [ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] &&
Signature · 1 line
2.34.1