From nobody Thu Apr 2 20:22:00 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 B3A5538F634 for ; Thu, 26 Mar 2026 23:53:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774569197; cv=none; b=l9JuZdE6J7a6IkVKmwRln45jqNsfZIH4Gpd/HmY+ZwWj1zO4rrOBvd9rIqV+ZbqKjo/8XoRFXB/MPqax8Ig/WpM/0aWVFVrt+WMWDsliob3yAYSJZAUY4XhDcuitHl/nbbEY7zXsMvQdbwn/+Ghjy2j4roYpY1myBR/nBd6vCac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774569197; c=relaxed/simple; bh=S62nqp/L7oaBVz+l0EkYVc7w8PWzqc5mHLXWWDxhwe8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CAcBQC0MffJh3E78VpUFTQjx5OWDorKS9GAUsaimIIfapgL7yk62o4aTy+MLol9ZuvuXw03RXqb0/rp4JbFalgQVOsha7Ou4shAjmJ3LG/HOa4WLs49H5O+uKh5TNfLVDAC9UGV7soiROJDvwJdQJqGUjjhfLYRu0+WW6peaGMo= 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.20230601.gappssmtp.com header.i=@dama-to.20230601.gappssmtp.com header.b=UsJJEm5P; arc=none smtp.client-ip=209.85.214.179 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.20230601.gappssmtp.com header.i=@dama-to.20230601.gappssmtp.com header.b="UsJJEm5P" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2b0ba3bfe16so14034145ad.1 for ; Thu, 26 Mar 2026 16:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dama-to.20230601.gappssmtp.com; s=20230601; t=1774569192; x=1775173992; 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=r9OKWh4GFeDrs3iW8vGT1OneAtu45dtpNVuW7lfnaEs=; b=UsJJEm5Pz1rIeqzf4B5RAagtfXe24nDNyZBZGb/qo7zY7flCo/Hbs+JNlULaCmC6eh N9XIV4Mj7aMcVSK/xaAlQqzMLe3jYWIZu5Ja3nm4W32TIwtadjIiT9omtkwImZJg6r/O B1pR7+5mww8vbRebznyH/OMe/hbpHpxg7jLir+Mu0r/0yLOJis2iiEHIg+iJBwZ+1Jxx XP3QMiMEWChljqFc/aQqNnlgcByeqySzroFS8rVLrerHvdBt4pUkDZLsdItlhBHGCFxy 2nfErfxeFm75SCDubQOu/s8YlEtzixSVt1LqqXL3vWKR1v2sPDrPfAjW1s+YUNZJa4tg A5tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774569192; x=1775173992; 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=r9OKWh4GFeDrs3iW8vGT1OneAtu45dtpNVuW7lfnaEs=; b=k/ZV3Jh1IPbtiXSkU+sxj4TL1w3DO4vdB6eEPeU7e5hunsHlFKacXA84PDmr2oemds 6y7ZI9P8Oew0hYUAds2IBDGgaOAt8PuxTO9b9FPuRNp52QF8x8y8hlSJceI6WDgXwNRN MsV8OWKeayeYIc22+47FVM2G71KFjeMDQddUiFkFny9fafj11aHvo465RVxfniV2UgYu t8b5gKGEbieXiQs7KtQoygu9ZA6mjR4S5VJEWZE93SOy4bM4sCFhLpx4JNuSZzyeLZh8 l4XM6F+UP+bi7ACKi0cZ+VPtgIBlVkgdp/LEM/f/meZSzGB8xfD2EqlsCnIDPkkjlRdx 0szQ== X-Forwarded-Encrypted: i=1; AJvYcCV563euTKyd9AkD9hGbtueG4w32RY4znnuenikIrUepgPACsVvmZuO7gfJ5InG0HgXnXhyAfR99J8Ctfmc=@vger.kernel.org X-Gm-Message-State: AOJu0YzSxWDHoU/yphyyjlg6tsKhWwnI5BcRuq7FBq06Ae8dgDe7wLHx 0AB+nNJJz6QR7hlLBULUOp6NCIZGJ/UyaSvthFBimSiczRXOWwTCSb8cj0jRjzG0F6I= X-Gm-Gg: ATEYQzzv2LyTkY1IIaSYy0tjFWwQJ4ryHh+7tortbZQPPK74i9wpmwgnKIb16FZhjRp i2cldHPTTgZcluiKpIP4tQslDz12DrHbtPVGFPorfVEbIfovmifiu2jtg5ODjUUjBcfsL2eGrw3 J32Jw3cggb8HX5k1W+K/sIZnhwAqOfR0eMBfC5Dk36xhcXTOxjPUXbMGLn2u7/zhBe5haKhSsqF YZnJ1s/niopfopdndFlUUz7YDjM3EiA+LTyLRHP8f36H0QGy/4TJUL6FDEG014GtuISKDyGvw8e w2prTh5r0M8JNbVqhaZDiFXGUKn87U0BZnV6co44225+TbnDyvAZ9VTmPzXmHZ8AJV1XdcqMS+A 5KhwD1bwdEinbdXSJC5yWxRRhre8ISICGJeZDsp6J5737Oua/j1n9rUt/QxH9bskM0XjNKNAVBT Doq/h7KtzWwFoNtA== X-Received: by 2002:a17:902:ef4c:b0:2b0:501e:d751 with SMTP id d9443c01a7336-2b0ce5b10f3mr2054445ad.20.1774569192019; Thu, 26 Mar 2026 16:53:12 -0700 (PDT) Received: from localhost ([2a03:2880:2ff:7::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b0bc786b7fsm52644875ad.20.2026.03.26.16.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 16:53:11 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org, Shuah Khan Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, 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 v6 12/12] selftests: drv-net: Add USO test Date: Thu, 26 Mar 2026 16:52:31 -0700 Message-ID: <20260326235238.2940471-13-joe@dama.to> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260326235238.2940471-1-joe@dama.to> References: <20260326235238.2940471-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. Can be used with netdevsim or real hardware. Tests both ipv4 and ipv6 with several full segments and a partial segment. Suggested-by: Jakub Kicinski Reviewed-by: Pavan Chebbi Signed-off-by: Joe Damato --- 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 | 96 ++++++++++++++++++++ 2 files changed, 97 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..2ddeae99b4d6 --- /dev/null +++ b/tools/testing/selftests/drivers/net/uso.py @@ -0,0 +1,96 @@ +#!/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 correct number of individual segments with correct sizes. +""" +import socket +import time + +from lib.py import ksft_run, ksft_exit, KsftSkipEx +from lib.py import ksft_ge +from lib.py import NetDrvEpEnv +from lib.py import defer, ethtool, ip, rand_port + +# 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 bytes(range(256)) * ((total_payload // 256) + 1) + payload =3D payload[:total_payload] + sock.sendto(payload, dst) + sock.close() + return payload + + +def _get_rx_packets(cfg): + stats =3D ip(f"-s link show dev {cfg.remote_ifname}", + json=3DTrue, host=3Dcfg.remote)[0] + return stats['stats64']['rx']['packets'] + + +def _test_uso(cfg, ipver, mss, total_payload): + cfg.require_ipver(ipver) + + 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 + defer(ethtool, f"-K {cfg.ifname} tx-udp-segmentation off") + + expected_segs =3D (total_payload + mss - 1) // mss + + rx_before =3D _get_rx_packets(cfg) + + port =3D rand_port(stype=3Dsocket.SOCK_DGRAM) + _send_uso(cfg, ipver, mss, total_payload, port) + + time.sleep(0.5) + + rx_after =3D _get_rx_packets(cfg) + rx_delta =3D rx_after - rx_before + + ksft_ge(rx_delta, expected_segs, + comment=3Df"Expected >=3D {expected_segs} rx packets, got {rx_= delta}") + + +def test_uso_v4(cfg): + """USO IPv4: 11 segments (10 full + 1 partial).""" + _test_uso(cfg, "4", 1400, 1400 * 10 + 500) + + +def test_uso_v6(cfg): + """USO IPv6: 11 segments (10 full + 1 partial).""" + _test_uso(cfg, "6", 1400, 1400 * 10 + 500) + + +def test_uso_v4_exact(cfg): + """USO IPv4: exact multiple of MSS (5 full segments).""" + _test_uso(cfg, "4", 1400, 1400 * 5) + + +def main() -> None: + """Run USO tests.""" + with NetDrvEpEnv(__file__) as cfg: + ksft_run([test_uso_v4, + test_uso_v6, + test_uso_v4_exact], + args=3D(cfg, )) + ksft_exit() + + +if __name__ =3D=3D "__main__": + main() --=20 2.52.0