Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: Magnus Karlsson <magnus.karlsson@intel.com>
Cc: <netdev@vger.kernel.org>, <magnus.karlsson@gmail.com>,
	<sdf@fomichev.me>,  <davem@davemloft.net>, <edumazet@kernel.org>,
	<kuba@kernel.org>, <pabeni@redhat.com>, <horms@kernel.org>,
	<bjorn@kernel.org>, <kerneljasonxing@gmail.com>,
	<intel-wired-lan@lists.osuosl.org>, <anthony.l.nguyen@intel.com>,
	<przemyslaw.kitszel@intel.com>, <jacob.e.keller@intel.com>
Subject: Re: [PATCH net-next 5/5] selftests: net: add AF_XDP USO test
Date: Thu, 19 Nov 2026 20:05:15 +0100	[thread overview]
Message-ID: <av9Ia2gpMyF9jTuE@boxer> (raw)
In-Reply-To: <20261119165340.1071525-6-magnus.karlsson@intel.com>

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?

Also since you're adding support to copy mode i assume veth runs would be
welcome...

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 ?

> 
> 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 <magnus.karlsson@intel.com>
> ---
>  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...

  reply	other threads:[~2026-11-19 19:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 16:53 [PATCH net-next 0/5] xsk: ice: USO support for AF_XDP Magnus Karlsson
2026-11-19 16:53 ` [PATCH net-next 1/5] xsk: add USO support for skb path Magnus Karlsson
2026-11-19 18:47   ` Maciej Fijalkowski
2026-11-19 16:53 ` [PATCH net-next 2/5] ice: add Tx descriptor builders and header length check Magnus Karlsson
2026-11-19 16:53 ` [PATCH net-next 3/5] xsk: ice: add USO zero-copy support Magnus Karlsson
2026-11-19 16:53 ` [PATCH net-next 4/5] xsk: add KUnit tests for AF_XDP USO header helpers Magnus Karlsson
2026-11-19 16:53 ` [PATCH net-next 5/5] selftests: net: add AF_XDP USO test Magnus Karlsson
2026-11-19 19:05   ` Maciej Fijalkowski [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-11-19 14:10 [PATCH net-next 0/5] xsk: ice: USO support for AF_XDP Magnus Karlsson
2026-11-19 14:10 ` [PATCH net-next 5/5] selftests: net: add AF_XDP USO test Magnus Karlsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=av9Ia2gpMyF9jTuE@boxer \
    --to=maciej.fijalkowski@intel.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=bjorn@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jacob.e.keller@intel.com \
    --cc=kerneljasonxing@gmail.com \
    --cc=kuba@kernel.org \
    --cc=magnus.karlsson@gmail.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=sdf@fomichev.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox