From nobody Thu Apr 9 06:51:26 2026 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C753037A493 for ; Wed, 8 Apr 2026 23:06:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775689612; cv=none; b=DYhSrx+yZYONjc0m/Oi5eqjYSiVueWIzoIIc5HIMDT7QDZHJISOXuYyyXce0Evu6CUJpZelp8Lrmw2N629vf5jEYrH8F7jYldxkXlb1g+vZZ6H1FhF5HC/Au25VbCiqGSKOte3Helobx4j/s1oCnfJUbFO+VK+/Tk0ayOmNExic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775689612; c=relaxed/simple; bh=eavrLBchN8fm9XIu1vqukYxkvy5howdAitN/UagQmIk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SilflrM6UAZsQLAKA1WEkJqmPdR4Y5GC1DsAX8AdJYL8+CWJqkwqmNpvQd2SvPin7/YLfn9ku6uP7/kBoJ4kU0qWQKA3Nw7g991FzcC44NqaK9ZF67U4EhsOoGTN4r1fQe3xs1+Day2yyz/YcL+T2LgqSBHtbzPS6TRlzENTTUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dama.to; spf=none smtp.mailfrom=dama.to; dkim=pass (2048-bit key) header.d=dama-to.20251104.gappssmtp.com header.i=@dama-to.20251104.gappssmtp.com header.b=lxP6H9ib; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dama.to Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=dama.to Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dama-to.20251104.gappssmtp.com header.i=@dama-to.20251104.gappssmtp.com header.b="lxP6H9ib" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-c648bc907ebso183034a12.3 for ; Wed, 08 Apr 2026 16:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dama-to.20251104.gappssmtp.com; s=20251104; t=1775689592; x=1776294392; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RaI/8wTi1iXn0q/44Vh7ATr+prNCrN7zaPdtxJM69Ko=; b=lxP6H9ib/yxziiVSV5eUcStMTXg6xPl7bTt/AwD1Ib5uGElTb3dfZ7gFwz68PtJjhR K1BPBNN7ixBemH6aFegfukdaDLMPgb77P8qQM75sA7ZAKWhBUbq78/5BkiuyYZ0HXgRp Nk92WEpuZ+bVZK9CnBS8NbOKKMMH9KU8b/882XhvJ8jW1IBy9PPArBKGqxG9/ZducAzh M81eVMdEE7k1NqR8hTSiTk+sc4IKfm3RWUy4aR2MxJ4Lf9IbyqerEDJ560PZp9ZpvPdN osL0VrnPWkkh4sWnknvP+zC1457GX+qbqqo7YY2RSEG5hgCTfOreo3pl+PlPSQM7VtMT O9Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775689592; x=1776294392; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RaI/8wTi1iXn0q/44Vh7ATr+prNCrN7zaPdtxJM69Ko=; b=NYRUPdPocsSH1foVxh8YxRd1Fd67GBiOxkel961xRf6ZHyXSa+T5dW5+HNnLDtiu1M 04NaLSKcNw+je93NpaH1TdDj/HZpdW0AdADnkwcmlSP72zw0ZgRhUc3Pbczg2cIY+mrX n9JATldVMpj5XZIjoFi4P2RyDgc0XtqA4xD+/XLoCAE9QjhnrpETmRdUIXGf/7kJoPMj +I9CKZhe4JpDpaNl/sN2ejcse+s+2g7Jin3x9zW2FFDLy5UEahx092+1Quo9ei71uYFf zAp42eo3icpGSHRrMJpvdAlcGFJBn6P6rzisfGD7c0/hq2txo9/tEPc2ZOYvGfH+FxfD 6pqw== X-Forwarded-Encrypted: i=1; AJvYcCXUDVaWlnskhOdEgcQ4wIA4YXrCM6O1ZbguoEoJYZRP32uU5kEcMZbZzYlpsYL0Vn1EvbQpci36LOI9qIw=@vger.kernel.org X-Gm-Message-State: AOJu0YzBtlsydC7TEAcJEU+s3oNeBRGznoGgmwRpJlyGlboEm+eYXWbN BhPsKm2fGXQGFfDJMVjD3CXnriNIvT6lQTUPXoGK26XRNWrQXBYBMQIoILU6VcR1SaU= X-Gm-Gg: AeBDieuH3x8+xBk4n0OYbXhhKQrRHg6zt3ibRPhjAQ8evWevPuspUTmGeMXFfZWHkmk t1NR0YRcaUj2cj1KV0YeJait3Ar/CUidieHPjbhEuCiZXXkK1LBz9EJKYJrtV4BxIfBpjSxlpBf SR3i4wSecW1dxleNMMeuAJnIXuDmsNrwi6Wj7LeoSRsjB+joqwMGA7ngEAJbfgDO8S2RhOzLZI9 M2kJvbjwxzvUFrJIZuM78asECbXCLbf5QCqeoyM1dout+Ea+ipurxo2gJiV7T+/Ru3dql6ZMAzr itbae+Q8hG3ZlZwYFzO73v8e1+/f9/uG2tIhTTP4aBxOnRZzURLAjtVsKWwWhaY1QIP2RbDbweu KagWBVhX5aBglKDDGK8M0K/MksXP+SIlJaZhj3G4GfaKweceS3ngl/YS8OqM3v/z3wuK/EYB1JO fKdjU= X-Received: by 2002:a05:6a20:94c8:b0:398:7998:8300 with SMTP id adf61e73a8af0-39f2f179df6mr22822579637.58.1775689592275; Wed, 08 Apr 2026 16:06:32 -0700 (PDT) Received: from localhost ([2a03:2880:2ff:4::]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82cf9c6ad8asm22239635b3a.40.2026.04.08.16.06.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 16:06:31 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org, Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: horms@kernel.org, michael.chan@broadcom.com, pavan.chebbi@broadcom.com, linux-kernel@vger.kernel.org, leon@kernel.org, Joe Damato , linux-kselftest@vger.kernel.org Subject: [net-next v10 10/10] selftests: drv-net: Add USO test Date: Wed, 8 Apr 2026 16:05:59 -0700 Message-ID: <20260408230607.2019402-11-joe@dama.to> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260408230607.2019402-1-joe@dama.to> References: <20260408230607.2019402-1-joe@dama.to> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a simple test for USO. Tests both ipv4 and ipv6 with several full segments and a partial segment. Suggested-by: Jakub Kicinski Signed-off-by: Joe Damato --- v10: - Moved test from drivers/net/ to drivers/net/hw/ since it requires real hardware. No functional changes. v9: - Use UDP-LISTEN instead of UDP-RECV in socat receiver (suggested by AI). - Fixed stale docstring. - Removed unused return value. v7: - Dropped Pavan's Reviewed-by as there were changes. - Update to use ksft_variants with a generator and a parameterized test_= uso function. - Save original USO state and restore it at the end of the test. - Replace sleep with cfg.wait_hw_stats_settle - Use a socat receiver and check tx stats locally instead of rx on the remote. v5: - Added Pavan's Reviewed-by. No functional changes. v4: - Fix python linter issues (unused imports, docstring, etc). rfcv2: - new in rfcv2 .../testing/selftests/drivers/net/hw/Makefile | 1 + tools/testing/selftests/drivers/net/hw/uso.py | 103 ++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/hw/uso.py diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testin= g/selftests/drivers/net/hw/Makefile index deeca3f8d080..5c348c8d72ae 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -43,6 +43,7 @@ TEST_PROGS =3D \ rss_input_xfrm.py \ toeplitz.py \ tso.py \ + uso.py \ xdp_metadata.py \ xsk_reconfig.py \ # diff --git a/tools/testing/selftests/drivers/net/hw/uso.py b/tools/testing/= selftests/drivers/net/hw/uso.py new file mode 100755 index 000000000000..6d61e56cab3c --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/uso.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +"""Test USO + +Sends large UDP datagrams with UDP_SEGMENT and verifies that the peer +receives the expected total payload and that the NIC transmitted at least +the expected number of segments. +""" +import random +import socket +import string + +from lib.py import ksft_run, ksft_exit, KsftSkipEx +from lib.py import ksft_eq, ksft_ge, ksft_variants, KsftNamedVariant +from lib.py import NetDrvEpEnv +from lib.py import bkg, defer, ethtool, ip, rand_port, wait_port_listen + +# python doesn't expose this constant, so we need to hardcode it to enable= UDP +# segmentation for large payloads +UDP_SEGMENT =3D 103 + + +def _send_uso(cfg, ipver, mss, total_payload, port): + if ipver =3D=3D "4": + sock =3D socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + dst =3D (cfg.remote_addr_v["4"], port) + else: + sock =3D socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) + dst =3D (cfg.remote_addr_v["6"], port) + + sock.setsockopt(socket.IPPROTO_UDP, UDP_SEGMENT, mss) + payload =3D ''.join(random.choice(string.ascii_lowercase) + for _ in range(total_payload)) + sock.sendto(payload.encode(), dst) + sock.close() + + +def _get_tx_packets(cfg): + stats =3D ip(f"-s link show dev {cfg.ifname}", json=3DTrue)[0] + return stats['stats64']['tx']['packets'] + + +def _test_uso(cfg, ipver, mss, total_payload): + cfg.require_ipver(ipver) + cfg.require_cmd("socat", remote=3DTrue) + + features =3D ethtool(f"-k {cfg.ifname}", json=3DTrue) + uso_was_on =3D features[0]["tx-udp-segmentation"]["active"] + + try: + ethtool(f"-K {cfg.ifname} tx-udp-segmentation on") + except Exception as exc: + raise KsftSkipEx( + "Device does not support tx-udp-segmentation") from exc + if not uso_was_on: + defer(ethtool, f"-K {cfg.ifname} tx-udp-segmentation off") + + expected_segs =3D (total_payload + mss - 1) // mss + + port =3D rand_port(stype=3Dsocket.SOCK_DGRAM) + rx_cmd =3D f"socat -{ipver} -T 2 -u UDP-LISTEN:{port},reuseport STDOUT" + + tx_before =3D _get_tx_packets(cfg) + + with bkg(rx_cmd, host=3Dcfg.remote, exit_wait=3DTrue) as rx: + wait_port_listen(port, proto=3D"udp", host=3Dcfg.remote) + _send_uso(cfg, ipver, mss, total_payload, port) + + ksft_eq(len(rx.stdout), total_payload, + comment=3Df"Received {len(rx.stdout)}B, expected {total_payloa= d}B") + + cfg.wait_hw_stats_settle() + + tx_after =3D _get_tx_packets(cfg) + tx_delta =3D tx_after - tx_before + + ksft_ge(tx_delta, expected_segs, + comment=3Df"Expected >=3D {expected_segs} tx packets, got {tx_= delta}") + + +def _uso_variants(): + for ipver in ["4", "6"]: + yield KsftNamedVariant(f"v{ipver}_partial", ipver, 1400, 1400 * 10= + 500) + yield KsftNamedVariant(f"v{ipver}_exact", ipver, 1400, 1400 * 5) + + +@ksft_variants(_uso_variants()) +def test_uso(cfg, ipver, mss, total_payload): + """Send a USO datagram and verify the peer receives the expected segme= nts.""" + _test_uso(cfg, ipver, mss, total_payload) + + +def main() -> None: + """Run USO tests.""" + with NetDrvEpEnv(__file__) as cfg: + ksft_run([test_uso], + args=3D(cfg, )) + ksft_exit() + + +if __name__ =3D=3D "__main__": + main() --=20 2.52.0