From nobody Wed Apr 8 02:50:56 2026 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 692C5387584 for ; Tue, 7 Apr 2026 22:03:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775599426; cv=none; b=tTrnpbOIIPnAIgKF2Y0ebPGmN/uCLMIphkXvXghbhZeEq7fS3BsEeNBq0mmZ7iTZGPc28ieCfYQsa+vrv9hJaDCrVud6cZv+ejQv6VqGNkCh69udbzZThho2EVtL4bFdRR8Sun9w/+ogr2Oq8LprEnq4OPubfYA5IDomeouBPOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775599426; c=relaxed/simple; bh=o/NtSsecFTNFsiPqiNCLzmEF05SSxO9/5XaAXM7arIk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gdn50UgEXl1LYw9vLkOVzx2GCbScoxBtCLO2JViEXy13Ccg260qp6Hy8ixMjVNI+kY57AZKSvza72pK6LQCt03A5DvjQq6mEudvrabuSHU4KxWo+VaZMtaBmZezj+czP1JdypVqlBP4E1CoM2XSj+07QDcqDNunn+rPOikD1re0= 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=A8F05xPr; arc=none smtp.client-ip=209.85.216.52 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="A8F05xPr" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-35da8d037a5so2201381a91.0 for ; Tue, 07 Apr 2026 15:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dama-to.20251104.gappssmtp.com; s=20251104; t=1775599423; x=1776204223; 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=kmD0I3pcx04Mtpj/oo4F+jl+//3G3jRQHwrxWNrdT1Y=; b=A8F05xPr23ZAyBRW50hOtfIKI5FaNNvrIL2+XslcNalgNgrdz3GFTSF3zo0Hd7d9ZU lHmtk/eYMJIKI52ZVn5Y4282qTNAIuMBr0FDeHgK2Ebg60R9vt4U8qK4f0NIRskcD4bK milGHICq9G8hdnR7N+tZovni7XLJkl3YU6RmbKMbcL5mD4OFr1P3LsChDGnM2P6ua/e0 y6rgI2JPGS1je+uLccTK9OiKljSX6O7cLEJuKjwKHbI67foidwCQWnbS0y5KoVh38IWf sVaPiiyPGJzwtFnq8WQYMMwYOoht+LPpNLE1pQ/goG/lStKHPqVQVnozasuEVZuigLD6 cuxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775599423; x=1776204223; 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=kmD0I3pcx04Mtpj/oo4F+jl+//3G3jRQHwrxWNrdT1Y=; b=SwC2V2fqzkp7shFipxCIlqdCHkpqNT7ULNA3OiGJRqoKSe3qUUDj+pVO+aXSP8v3k1 ALnfiANdSC3yKEikek2fiVC+No526CmaXnSWDlc0mAdbi79nlPseLYzDAJ0y4ZxBYJ3V PcpBPwsf+oiJkr5ejm1+grOBbN+6okNW6fCdfwj/aan6qji1v3ip9nQHeoyG69a2Pzvu SlcKTm1XJkpKh2ORneA5UktSmR5UZ6xzsrtdxquGxZEveUjJt9nUjUUUMOltlITP8fXL tUdWos/1QDdl1rxubwJGL20btg+9i03gFo5/7tZwgEYFGYw6tatwPso1CSQZ2oHPM6qd a15g== X-Forwarded-Encrypted: i=1; AJvYcCXLLwiHLoEdsGEutgQG1DFIYbbqW+AHNDX1JsNhAq/rOvSeux0QtHM/eCv5hiE5yu+CnPX0mAMmo1TDUKA=@vger.kernel.org X-Gm-Message-State: AOJu0YyHaB21qR0LJiZ1iv6XHx2tHiFEo6iPDhJ+J9ukst5IwsVvlmCq qcW6B60j1e2dg9aQZRxPiRVBm55Goz1fJ0NgpkmOXNeJAi+zi/NqTa8F9FhIrWDD6dE= X-Gm-Gg: AeBDiescN/FZ/HpFkdRUkL5GbsSbnyuEi3/PPTVgQXp0/1ilLsElOCQN62lpfUjCdPT W0ohruq5dDsCYGcnNVQrJ/q1LdPOe3Ano9lcXzv7LTjSvSlDXOxUsbftYXvArhSCnwXu5NjFRzS UuAEOty+TC9Y2hxY8l6JuFkCxX2I/bJHnCyYyLCUPSMVk9P0K3T4wXLiscjtfaqie5cz7atkEOP tPohBmmpfLj48cONqltRNss0kmUdC+FY5kVCmUqMeVR50sO7+zaJkX88LA/wxe2urGfpVMB8FiH 7gaF284Eev1Q4kJXJhdMdYzImXZoWJG+EzsH7RDyOaitrNvzw0gezAoZO/pDOxtzOV2TOm8nzPC hFfmiS/g+Q9tspSCktq4LirxS0pDkU1YIIWC+TfwcOvT4K+D8icgLpbdUHSPIMU8vN2D98N6CY9 Dmw6ty X-Received: by 2002:a17:90b:2251:b0:35d:b00a:3c54 with SMTP id 98e67ed59e1d1-35de69acf35mr18090837a91.22.1775599422777; Tue, 07 Apr 2026 15:03:42 -0700 (PDT) Received: from localhost ([2a03:2880:2ff:40::]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35dd35f7229sm19645039a91.7.2026.04.07.15.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 15:03:42 -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 v9 10/10] selftests: drv-net: Add USO test Date: Tue, 7 Apr 2026 15:03:06 -0700 Message-ID: <20260407220313.3990909-11-joe@dama.to> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260407220313.3990909-1-joe@dama.to> References: <20260407220313.3990909-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 --- 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 tools/testing/selftests/drivers/net/Makefile | 1 + tools/testing/selftests/drivers/net/uso.py | 103 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/uso.py diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/s= elftests/drivers/net/Makefile index 7c7fa75b80c2..335c2ce4b9ab 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -21,6 +21,7 @@ TEST_PROGS :=3D \ ring_reconfig.py \ shaper.py \ stats.py \ + uso.py \ xdp.py \ # end of TEST_PROGS =20 diff --git a/tools/testing/selftests/drivers/net/uso.py b/tools/testing/sel= ftests/drivers/net/uso.py new file mode 100755 index 000000000000..6d61e56cab3c --- /dev/null +++ b/tools/testing/selftests/drivers/net/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