On Thu, 19 Nov 2026 at 20:05, Maciej Fijalkowski <[email protected]> wrote: > > On Thu, Nov 19, 2026 at 05:53:40PM +0100, Magnus Karlsson wrote: > > Add xsk_uso, a functional test for AF_XDP UDP segmentation offload in > > copy and zero-copy mode. It sends USO requests from an AF_XDP socket > > and checks the datagrams received on a packet socket: the number of > > datagrams, the IP and UDP lengths, the checksums and the payload, for > > IPv4 and IPv6, and single and multi-buffer requests. It also checks > > that invalid requests are dropped and counted in tx_invalid_descs. > > > > The test needs root and physical NICs with an MTU of at least 1448, > > either two connected ports (-i TX_IFACE -r RX_IFACE) or one in NIC > > loopback (-l -i IFACE). Virtual devices such as veth pass the packet on > > without segmenting it. Zero copy (-z) also needs a native XDP program on > > the interface. Standalone checksum offload cases run only with -C, as > > they test the existing checksum offload rather than USO. As it needs > > real hardware, it is built but not run by default, like xdp_hw_metadata. > > It uses the AF_XDP library in net/lib/xsk. > > I assume the end goal for xdp_hw_metadata is to pull in its contents onto > xsk python runner. What is the case for this one?
It should be merged into the python runner that you are working on. But I need that to land first before I can move this. You could say that this patch is just temporary until your stuff has landed. > Also since you're adding support to copy mode i assume veth runs would be > welcome... While veth accepts USO, it will never segment the packet. The skb will just be delivered to the other side as is, so we need real HW for these tests. > Did you try to point AI to my set and ask whether it would be able to > produce python runner for that? Or do we don't want to have this CI'ed ? I am sure that is possible, but I will spend those tokens once your move has landed. We definitely want this to be in the CI and integrated with your stuff. > > > > Missing prerequisites are reported as skips. In zero-copy mode, the > > device must report xsk-zerocopy and tx-uso-zc, and checksum-only cases > > need tx-checksum. In both modes, cases that produce more than one > > datagram need tx-udp-segmentation, including the invalid ones, which > > would otherwise be dropped for lack of the offload whatever their > > headers. Cases that need more descriptors than xdp-zc-max-segs are > > skipped, and so are binds that the device refuses with EOPNOTSUPP. > > Receive-side UDP GRO (rx-udp-gro-forwarding, rx-gro-list) must be off, > > as it would merge the segments again before the packet socket sees them. > > USO with launch time must succeed in copy mode and be dropped in > > zero-copy mode. > > > > Signed-off-by: Magnus Karlsson <[email protected]> > > --- > > tools/testing/selftests/net/.gitignore | 1 + > > tools/testing/selftests/net/Makefile | 10 +- > > tools/testing/selftests/net/xsk_uso.c | 954 +++++++++++++++++++++++++ > > 3 files changed, 964 insertions(+), 1 deletion(-) > > create mode 100644 tools/testing/selftests/net/xsk_uso.c > > > > ... > > > + > > +static void get_mac(const char *name, unsigned char *mac) > > +{ > > + struct ifreq ifr = {}; > > + int fd = socket(AF_INET, SOCK_DGRAM, 0); > > + > > + if (fd < 0) > > + ksft_exit_fail_msg("socket: %s\n", strerror(errno)); > > + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", name); > > + if (ioctl(fd, SIOCGIFHWADDR, &ifr)) > > + ksft_exit_fail_msg("MAC address for %s: %s\n", name, > > strerror(errno)); > > + memcpy(mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN); > > + close(fd); > > +} > > + > > +static unsigned int get_mtu(const char *name) > > +{ > > + struct ifreq ifr = {}; > > + int fd = socket(AF_INET, SOCK_DGRAM, 0); > > + > > + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", name); > > + if (fd < 0 || ioctl(fd, SIOCGIFMTU, &ifr)) > > + ksft_exit_fail_msg("MTU of %s: %s\n", name, strerror(errno)); > > + close(fd); > > + return ifr.ifr_mtu; > > +} > > this is a lib content which i'm also adding, so we're gonna clash. > > > + > > +/* Virtual devices have no backing device, and pass GSO packets on whole. > > */ > > +static bool is_physical(const char *name) > > +{ > > + char path[64]; > > + > > + snprintf(path, sizeof(path), "/sys/class/net/%s/device", name); > > + return !access(path, F_OK); > > +} > > + > > +static int ethtool_ioctl(const char *name, void *cmd) > > +{ > > + struct ifreq ifr = { .ifr_data = cmd }; > > + int fd = socket(AF_INET, SOCK_DGRAM, 0), err; > > + > > + if (fd < 0) > > + return -1; > > + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", name); > > + err = ioctl(fd, SIOCETHTOOL, &ifr); > > + close(fd); > > + return err; > > +} > > + > > +/* Returns whether the netdev feature called @feature is active on @name. > > */ > > +static bool feature_active(const char *name, const char *feature) > > +{ > > + struct ethtool_gfeatures *features = NULL; > > + struct ethtool_gstrings *strings = NULL; > > + struct ethtool_sset_info *sset; > > + unsigned int count, blocks, i; > > + bool active = false; > > + > > + sset = calloc(1, sizeof(*sset) + sizeof(sset->data[0])); > > + if (!sset) > > + ksft_exit_fail_msg("calloc: %s\n", strerror(errno)); > > + sset->cmd = ETHTOOL_GSSET_INFO; > > + sset->sset_mask = 1ULL << ETH_SS_FEATURES; > > + if (ethtool_ioctl(name, sset)) > > + ksft_exit_fail_msg("ETHTOOL_GSSET_INFO: %s\n", > > strerror(errno)); > > + if (!sset->sset_mask) > > + ksft_exit_fail_msg("%s reports no feature strings\n", name); > > + count = sset->data[0]; > > + blocks = (count + 31) / 32; > > + strings = calloc(1, sizeof(*strings) + count * ETH_GSTRING_LEN); > > + features = calloc(1, sizeof(*features) + > > + blocks * sizeof(features->features[0])); > > + if (!strings || !features) > > + ksft_exit_fail_msg("calloc: %s\n", strerror(errno)); > > + strings->cmd = ETHTOOL_GSTRINGS; > > + strings->string_set = ETH_SS_FEATURES; > > + strings->len = count; > > + features->cmd = ETHTOOL_GFEATURES; > > + features->size = blocks; > > + if (ethtool_ioctl(name, strings) || ethtool_ioctl(name, features)) > > + ksft_exit_fail_msg("ethtool features: %s\n", strerror(errno)); > > + for (i = 0; i < count; i++) > > + if (!strncmp((char *)strings->data + i * ETH_GSTRING_LEN, > > feature, > > + ETH_GSTRING_LEN)) { > > + active = features->features[i / 32].active & (1U << > > (i % 32)); > > + break; > > + } > > + free(features); > > + free(strings); > > + free(sset); > > + return active; > > +} > > + > > +static void get_xdp_features(unsigned int ifindex, uint64_t *xdp, uint64_t > > *xsk, > > + unsigned int *zc_max_segs) > > +{ > > + struct netdev_dev_get_req *req; > > + struct netdev_dev_get_rsp *rsp; > > + struct ynl_error yerr; > > + struct ynl_sock *ys; > > + > > + ys = ynl_sock_create(&ynl_netdev_family, &yerr); > > + if (!ys) > > + ksft_exit_fail_msg("YNL: %s\n", yerr.msg); > > + req = netdev_dev_get_req_alloc(); > > + if (!req) > > + ksft_exit_fail_msg("netdev_dev_get_req_alloc failed\n"); > > + netdev_dev_get_req_set_ifindex(req, ifindex); > > + rsp = netdev_dev_get(ys, req); > > + netdev_dev_get_req_free(req); > > + if (!rsp) > > + ksft_exit_fail_msg("netdev dev-get: %s\n", ys->err.msg); > > + *xdp = rsp->_present.xdp_features ? rsp->xdp_features : 0; > > + *xsk = rsp->_present.xsk_features ? rsp->xsk_features : 0; > > + *zc_max_segs = rsp->_present.xdp_zc_max_segs ? rsp->xdp_zc_max_segs : > > 1; > > + netdev_dev_get_rsp_free(rsp); > > + ynl_sock_destroy(ys); > > you really should look at python drv-net infra...
