From nobody Fri Sep 25 02:43:45 2026 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6BDF372662 for ; Thu, 17 Sep 2026 11:15:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789643740; cv=none; b=pPiFMnXpctSpGx1H7LTVU9vws2xdSVO7168vCnUB6IX61FGHr0s3zY6ECmjmLwjUE8Bx/8fJe4sbSTtIatAs0IrFN3o0pfsqpvkjd5eKp3c8pcFSfIWMUS+8oP4aiGy8+qE4xFH6TFHaOUFqCXiiiUW1zcyog67rxdhDQSxANUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789643740; c=relaxed/simple; bh=AJ5mMe8CMyMMvu5opXwqf0CvLKRMqW+UoSHD9baNOoM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=lrWJzrULpqAQ/w/61rFMEffBemqxGsVnl4xBkNCAlzM97ZfpivVdRcoUvuHHZXwpPdBYciThdjkugH2LXnV13uaCuv+C+uMUsUJ8DVEKPboLGcy4uj3LKhlobAiqXK3CoSyVAmQXRYjwfTO9cNuIg9qRuzMXyLjkc+aK0LpOfMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (4096-bit key) header.d=canonical.com header.i=@canonical.com header.b=mP4TE9si; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=canonical.com header.i=@canonical.com header.b="mP4TE9si" Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 87ED93F52D for ; Thu, 17 Sep 2026 11:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20251003; t=1789643722; bh=bd10M+bix5UlEXeH9BMOYOfhizghQyBfU2z5WWgogyc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=mP4TE9si7YEmNK+Kl+nZ4R54ZZD2gK6BBN/03rTJrQFEgbFBBL9lrGRZhIxNZENxC O1InBbRC1hsjymkQXhfvQOGAu8sbF6Bubm1by/lniFWc92fvYssnDMtESSw/N9/HnS J0fakDtN3te9x4sMOaohdAcUBaKScv2FeicK+PIT/O8p3VU47oMBMdHtqJ0UWw+D01 9dpFWoK+3mmyImUwOIyMXrFtZB0+LuuXxAjfmcxCMWJa1XjZrqdYYN9Lc2932bnJKa rYGJccglK3lnh6szL08RVppb81eYbIivGZJBmawBkKX43hx1x/Kb8BVTLzi9ynVw4V hNM7hQ5zl3pO66CKuKqAJVlchINSnsViifYKEeos8+9jdsF8exY0CHxDuFs44MXGpZ xVkf5NzQIbgvln/CBkX/FrIlA+KIjSBABcQcQHyLUwMdrQjkSb5aDOOPtakLLVHEdB LfgQhDRpVHMxQI0EeUn2fimAeGTC1dxa0/Z57ash+llyMAEcxu3ToOKmz4CtDalJzK qD6jQwogeYhOeKxI0aWonygLCpRwwLvg9JslnroapqBpav/09ZYANwOrp2YG+EuNXf prNERExivtQdrd8T6mYaHeFwcGJ9daPUZWIUhmLmDyKzhC/M3wBgUWLZ0JkVWjahEV eYCA221HehuWQabmbmznPDOs= Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4957a231facso124295e9.2 for ; Thu, 17 Sep 2026 04:15:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789643722; x=1790248522; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bd10M+bix5UlEXeH9BMOYOfhizghQyBfU2z5WWgogyc=; b=YIt1mi1Lsx03dG9VMLHe1noh0ONqWA755qrhtxSl244XQmAZfQQs9P63abQIQ3Obm4 ZcA1snAPC9Ow0w7rckt1JjChIKeBiKr82VHE2hToGNuEJ2IidORagC7m/sKUG78hnL0S iJSzifpdd+LdcIphAItxPK5F/X1EqPetEh4odrSByP7aqUhXlqq8u57P3jZHjgNBzb0x BtEk7LuuHjvrS+f1wOB5I58EZt6ohVv+Vktyvcjgl6Q7Nt/YeklVylnh+XupCjrzA9W5 2f2lsz4xXIFbW5jLVVHK8ABkW0A5yw2/4fN8iy6AjRMDswNuFLQSsfGVE21qxD13tAyu 3h5g== X-Forwarded-Encrypted: i=1; AKwUvBwstt/vbM1MSyV6Rs+ceKUb3xcCFj6zkLltYmwAUPiiWTYyIUOGdh1+j8uT/XAATewGRRXLa08nrCnchOI=@vger.kernel.org X-Gm-Message-State: AFuF++mag8UMfQvmkiV8VYDgN4VBjYGj9ZztnDzlvjCVJqQKRyo2T+cl jB+M1wHIbiL6927W2uRCfd/b+rZDZ+R6Y4G2glra+qa9mlLaaN0X6H+Ebzbi/upHA39VoZa+ict 81UwATSC2DUXmTKbnIsg34e3LoJecXlJZl78JEn6KTKToyg1qPf+273B2mkxhvEgQ1XCT4HOouP UUGULSlQ== X-Gm-Gg: AYBFou375dI7+JjeTMtcrVMzuoHcD7yo75BXgzPm1lEEox+en0eid8F07TD4QvEcJNs mY8e9/+E7g9Nu+q4IXU2CEXhF35/coTU4JqST7Q8ADU2G1hamrfB1d6jIgBvUfX7tPo25cHUx5G Cmgucw9Ua7BJcFJM64ioqEZekjApN7cTEGv9OXWU2phNa5W90jo+ULxJjVbiX4xka87yYiFOdqb 6zjRs8ze/IXn5JjnC2EQG8sJnrX77Ca9E/amlsEZZLDxeWfFQb8GRvL8vHp2MTnSU0km9ZVsENt Yk6JxiDZ2Hr5tVHxXNtkpKa8XgYdxTTrSj3NukP6pb9T8SdJb+XCkiFfV51v8xwYisjqJVyaEsU 0MO57VyfgqnHjX1YJeiWes3a7YdVWMxQGdLgJIJAxdaEtaesiNt1Q X-Received: by 2002:a05:600c:4e48:b0:49e:7186:f36e with SMTP id 5b1f17b1804b1-49eb731c39emr77445295e9.1.1789643722164; Thu, 17 Sep 2026 04:15:22 -0700 (PDT) X-Received: by 2002:a05:600c:4e48:b0:49e:7186:f36e with SMTP id 5b1f17b1804b1-49eb731c39emr77444985e9.1.1789643721803; Thu, 17 Sep 2026 04:15:21 -0700 (PDT) Received: from localhost (host-79-46-33-118.retail.telecomitalia.it. [79.46.33.118]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fbf415058sm42111315e9.0.2026.09.17.04.15.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 04:15:20 -0700 (PDT) From: Edoardo Canepa To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Xu Du , Po-Hsu Lin , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net v3] selftests/net: run tun tests in a dedicated network namespace Date: Thu, 17 Sep 2026 13:15:20 +0200 Message-ID: <20260917111520.2614448-1-edoardo.canepa@canonical.com> X-Mailer: git-send-email 2.53.0 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" The tun_vnet_udptnl fixture creates a fresh tap device, assigns it a fixed MAC address and installs the outer neighbor entry as NUD_PERMANENT. On systems where systemd-udevd is running and a systemd .link file sets MACAddressPolicy=3Dpersistent (the default shipped by systemd in 99-default.link, so this is what most systemd-based hosts inherit), systemd-udevd's net_setup_link builtin asynchronously sends an RTM_SETLINK to reassign the freshly created tap device's MAC to a machine-persistent value. When that lands after the fixture has configured the device, both directions break: - recv_gso_packet transmits through the tap, and the address change flushes the neighbor entry the fixture installed: do_setlink -> netif_set_mac_address -> call_netdevice_notifiers(NETDEV_CHANGEADDR) -> ndisc_netdev_event (arp_netdev_event for an IPv4 outer) -> neigh_changeaddr -> neigh_flush_dev(tbl, dev, /* skip_perm =3D */ false) so the packet hits __neigh_create() and waits on neighbor resolution that never completes. - send_gso_packet writes frames addressed to the MAC the fixture assigned. Once the tap has a different address, eth_type_trans() marks them PACKET_OTHERHOST and the IP receive path drops them. Either way nothing arrives before the receive timeout, and the test fails with, for example: tun.c:947:send_gso_packet:Expected ret (0) =3D=3D variant->data_size (1) tun.c:948:send_gso_packet:Expected r_num_mss (0) =3D=3D variant->r_num_ms= s (1) tun.c:962:recv_gso_packet:Expected ret (0) =3D=3D variant->data_size (1) The failure is non-deterministic and reproduces on a plain systemd-based VM with no containers. Fix by calling unshare(CLONE_NEWNET) from both fixture setups. The harness runs each test in its own forked process, so every test gets a private network namespace that is torn down with it, and all tap and geneve devices are created in a namespace that systemd-udevd (running in the init netns) does not watch, so its RTM_SETLINK never fires against them. Creating a network namespace needs CAP_SYS_ADMIN in the current user namespace and CONFIG_NET_NS=3Dy, neither of which the tests required before. Where they are unavailable the unshare() is reported with SKIP() rather than aborting, so the binary still emits a full TAP stream and a runner can tell "network namespaces unavailable" apart from a real tun/tap regression. Verified on a plain systemd-based VM running the affected kernel. Without the fix, 1000 sequential invocations of tun -r tun_vnet_udptnl.4in6_nogsosz_1byte.recv_gso_packet fail 10 times, and 2 out of 20 full runs of the test binary fail. With the fix there are no failures in either case. Reported-by: Po-Hsu Lin Closes: https://bugs.launchpad.net/bugs/2158217 Fixes: 24e59f26eef2 ("selftest: tun: Add helpers for GSO over UDP tunnel") Assisted-by: LLM Signed-off-by: Edoardo Canepa Reviewed-by: Simon Horman --- v3: - Drop the claim that a failure leaves the tap and geneve devices behind. The failing checks are EXPECT_EQ()s in the test body, so FIXTURE_TEARDOWN still runs (Sashiko). - Explain the send_gso_packet failure correctly: its frames are dropped as PACKET_OTHERHOST once the tap's MAC changes. The neighbor flush only affects recv_gso_packet. - Redo the measurements on a freshly booted host. The v2 numbers were taken in an unclean environment. The v1 numbers were fine, and the v2 entry saying otherwise was wrong. - Go back to "Assisted-by: LLM", the current format in Documentation/process/coding-assistants.rst. v2 followed an older copy of that document (Sashiko). v2: https://lore.kernel.org/netdev/20260914211921.3786609-1-edoardo.canepa@= canonical.com/ - Add the unshare(CLONE_NEWNET) to FIXTURE_SETUP(tun) and FIXTURE_SETUP(tun_vnet_udptnl) instead of replacing TEST_HARNESS_MAIN with a hand-written main() (Jakub). - Report an unshare() failure with SKIP() instead of aborting the binary before the harness starts (Sashiko). - Mention the new CAP_SYS_ADMIN / CONFIG_NET_NS prerequisite in the commit message (Sashiko). - Change the Assisted-by: format (reverted in v3). - Redo the measurements (redone again in v3). v1: https://lore.kernel.org/netdev/20260905085318.3416670-1-edoardo.canepa@= canonical.com/ tools/testing/selftests/net/tun.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/ne= t/tun.c index abe488bac50b..6db21dad0efe 100644 --- a/tools/testing/selftests/net/tun.c +++ b/tools/testing/selftests/net/tun.c @@ -4,6 +4,7 @@ =20 #include #include +#include #include #include #include @@ -488,6 +489,10 @@ FIXTURE(tun) =20 FIXTURE_SETUP(tun) { + if (unshare(CLONE_NEWNET)) + SKIP(return, "Cannot create network namespace: %s", + strerror(errno)); + memset(self->ifname, 0, sizeof(self->ifname)); =20 self->fd =3D tun_alloc(self->ifname); @@ -732,6 +737,10 @@ FIXTURE_SETUP(tun_vnet_udptnl) struct sockaddr_storage ssa, dsa; void *sip, *dip, *smac, *dmac; =20 + if (unshare(CLONE_NEWNET)) + SKIP(return, "Cannot create network namespace: %s", + strerror(errno)); + flags =3D (variant->is_tap ? IFF_TAP : IFF_TUN) | IFF_VNET_HDR | IFF_MULTI_QUEUE | IFF_NO_PI; features =3D TUN_F_CSUM | TUN_F_UDP_TUNNEL_GSO | --=20 2.53.0