mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: eva.kurchatova@virtuozzo.com,ast@kernel.org,daniel@iogearbox.net,davem@davemloft.net,kuba@kernel.org,hawk@kernel.org,john.fastabend@gmail.com,sdf@fomichev.me,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,shuah@kernel.org
Cc: linux-kernel@vger.kernel.org,eva.kurchatova@virtuozzo.com,netdev@vger.kernel.org,bpf@vger.kernel.org,linux-kselftest@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH 1/2] selftests: bpf: run test_xdp_features in its own netns
Date: Thu, 17 Sep 2026 02:45:46 +0000 (UTC)	[thread overview]
Message-ID: <3111203b94441ef41565b0b9523a33db24a52fd66b8d309030cd1cfd4c595a12@mail.kernel.org> (raw)
In-Reply-To: <20260917015605.2464043-1-eva.kurchatova@virtuozzo.com>

[-- Attachment #1: Type: text/plain, Size: 4218 bytes --]

> diff --git a/tools/testing/selftests/bpf/test_xdp_features.sh b/tools/testing/selftests/bpf/test_xdp_features.sh
> index 0aa71c4455c0..1f6be4af6718 100755
> --- a/tools/testing/selftests/bpf/test_xdp_features.sh
> +++ b/tools/testing/selftests/bpf/test_xdp_features.sh
> @@ -1,6 +1,19 @@
>  #!/bin/bash
>  # SPDX-License-Identifier: GPL-2.0
>
> +# The device under test listens on the veth address of the namespace this
> +# script runs in and the tester connects to it, so a firewall on the
> +# machine can refuse the control connection:
> +#   Failed connecting to the Device Under Test control socket
> +# That side of the pair is also always called v1, and cleanup only runs
> +# on a signal, so a failed run leaves the device behind and every later
> +# run stops in setup.  A namespace of our own has no such rules, and
> +# takes the leftovers with it when the test ends.
> +if [ -z "${XDP_FEATURES_NETNS:-}" ]; then
> +	XDP_FEATURES_NETNS=1 export XDP_FEATURES_NETNS
> +	exec unshare -n sh -c 'ip link set lo up; exec "$0" "$@"' "$0" "$@"
> +fi

The comment and commit message both state "everything the test made goes
away with the namespace when it exits", but does the anonymous namespace
actually reclaim the persistent named namespace created by ip netns add?

unshare -n only unshares CLONE_NEWNET. The mount namespace remains the
host's, so when setup() later runs:

    ip netns add ${NS}
    ip link add v1 type veth peer name v0 netns ${NS}

ip netns add deliberately creates a persistent namespace by bind-mounting
/proc/self/ns/net onto /run/netns/${NS}. That bind mount is visible on
the host and pins ${NS} with the v0 veth inside it.

Exiting the anonymous netns from unshare -n doesn't remove the named
netns -- that's why cleanup() must explicitly call ip netns del ${NS}.

cleanup() is still only reachable from the signal trap or the fully
successful path. All failure arms are [ $? -ne 0 ] && exit, and there is
no trap cleanup EXIT. On a failing run after the patch:

  - v1 and the anonymous netns: reclaimed
  - /run/netns/ns1-XXXXXX and the netns holding v0: leaked on the host

The practical breakage described in the changelog (name collision
causing later runs to fail in setup) is fixed because ${NS} is
randomised.

But the claim of complete cleanup is not accurate. Should this either
narrow the claim to the device and firewall rules, or make cleanup
complete with trap cleanup EXIT (in addition to the signal trap), or use
unshare -n -m with a private /run/netns so the named namespace really
does die with the test?

> +if [ -z "${XDP_FEATURES_NETNS:-}" ]; then
> +	XDP_FEATURES_NETNS=1 export XDP_FEATURES_NETNS
> +	exec unshare -n sh -c 'ip link set lo up; exec "$0" "$@"' "$0" "$@"
> +fi

A subsystem pattern flags this as potentially concerning: the new code
hand-rolls network-namespace setup (re-exec under unshare -n plus
ip link set lo up) in a script that already hand-rolls ip netns add,
ip link del, and ip netns del.

tools/testing/selftests/net/lib.sh already provides this: setup_ns
generates a randomised namespace name, creates it, brings lo up and
normalises rp_filter; cleanup_ns and cleanup_all_ns tear the list down
and register teardown to run on normal exit as well as on a signal,
which is the gap the patch's changelog identifies.

Worth a maintainer's call on whether the shared helpers should be used
here instead of a second implementation.

The alternative view is that this may be defensible: bpf selftests do
not currently source tools/testing/selftests/net/lib.sh (no bpf/*.sh
does), pulling it in would add a TEST_FILES dependency, and setup_ns is
not a drop-in substitute for what this hunk does. setup_ns creates a
named peer namespace, whereas the hunk moves the script's own process
into an anonymous namespace so the DUT-side v1 device and the host
firewall rules stop mattering. The parts net/lib.sh would genuinely
replace are the pre-existing ip netns add and cleanup lines, not the new
ones.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/35173519344

      parent reply	other threads:[~2026-09-17  2:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17  1:55 Eva Kurchatova
2026-09-17  1:55 ` [PATCH 2/2] selftests: bpf: size the map in test_lru_sanity3 to whole refills Eva Kurchatova
2026-09-17  2:13 ` [PATCH 1/2] selftests: bpf: run test_xdp_features in its own netns Alexei Starovoitov
2026-09-17  2:45 ` bot+bpf-ci [this message]

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=3111203b94441ef41565b0b9523a33db24a52fd66b8d309030cd1cfd4c595a12@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=eva.kurchatova@virtuozzo.com \
    --cc=hawk@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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

all inboxes | Powered by JetHome®