From nobody Mon Feb 9 13:37:07 2026 Received: from mail-yx1-f45.google.com (mail-yx1-f45.google.com [74.125.224.45]) (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 A861C315D47 for ; Tue, 13 Jan 2026 03:13:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768273987; cv=none; b=kspHAo2LddN9LhZEuTMpSBGJSTj1rBFttcXX2s/rCa19PYsWtlTZTKzeuD0axwTkLetKP3XC7skUecvXdo5JerCz4dYD4QVFqGypm8EYhRBh5xCC3OuXeNdWBZG9vMEkab7QCG7BpgcXOeLQTKj99Lcb3CYGyvd/30oVIUrajpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768273987; c=relaxed/simple; bh=1Q26HXpW7TYNGutKg90p+BWQKQP/kUEHf57kmmFmrxY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=naflxiZJA8gk6WdYOZY3Z2LphpWafy0wmQd+Lh7lCwZ/VhbZ1umZBxuAVMJVqY9A3d0tfEzzI+osTbaaE1C2ecnXq0RX9ewSmFQ8OeAnRmCphcVPgcpK2d5ydcTb52DwLfEvzAJ0jytxdDGHg+CitxlCEsutkIwBLElSYJee+fY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ntE8jSAq; arc=none smtp.client-ip=74.125.224.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ntE8jSAq" Received: by mail-yx1-f45.google.com with SMTP id 956f58d0204a3-6446c2bbfe3so6144472d50.1 for ; Mon, 12 Jan 2026 19:13:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768273983; x=1768878783; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lG0BScxKvY/q9QPoykPF18FCgS+okYK88nxhg8/Kgqs=; b=ntE8jSAqXpWoEJ/5lAVEyPeWvMw1kNR3mOoxm9WlaResZIQv7h8SLwvvhGSOgAv4AV j3mRKmweyevdUNQqtSAWiH3lYGyxm0SCbhghqWcLWa2UPdD00BhqSptUV63VQO8BwM9u WsgLTMZamHh1bKEEw1Keq0u9n1xPVfotSofeYOa5sKDjt/ZQ/7EkrzuKk/8oFpX0t4gX ki0arvULNrhbVWaJWhAdeHqoolB7G70IV2FBbhiJvGuIXY2IsqDhiTz7rblGydHkNjdy GdVkhDWaa9O37ZBsEv0L2QL8eCSMpx58//LZPVpG4X2pLp1kv+zwFW+jBHNAgonZKFgn sA8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768273983; x=1768878783; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=lG0BScxKvY/q9QPoykPF18FCgS+okYK88nxhg8/Kgqs=; b=f7oI92klCrU1Wp3pGce5Vk5y8ufAKnMgk5IaXpaATd0Cxd9IfmfEyCsEhLrU8L5BZP 8IEq0Ma9GgJ4L9GwIG6CDori7BxNOG0WoPumWymMXlyK10dIJBjqBu4k5WeflyiR17F5 CS7GdZognGTj3K9DMbRfevhKXj8fI9bEKY7HT8kvXo4SOHtDf7yFG/biEc2H2zn7hbRx cQ447fB7wuU3AULmbKIYOHhnn1adZvIW0j21oCTGk1umo6RmKV1ueNUHwf0bGIDNpjKO AMpu+j8WvDsSfYZRQRVZZLv/ITKqGof8v5AOijb/jScal4RgQ3cbr0cy+Hh2JKunvvC1 JPiQ== X-Gm-Message-State: AOJu0Yx7sTTcCHL80sBhuRwiqy0S51UgDgnTCN65BrlOjGLHvlME8qNo YkX6MAcFTjBQvdee/EzgdBUuB2EpErS43PgHmeQrrga5y5oO5L8tfApT X-Gm-Gg: AY/fxX7TqkHiSdo8+xDGgojwmXq4E9LGGOzOFH4PImfsdftrlNl7xiZveEheP72WgW1 QPchPe+NlVmoKep3Mg8Wv65dnsvf2XdV4McVv6UhyPetZEEDpFEGbNvIsZW0cwV4oWN6e5564wm 8kd5gbQa4zthLoKHuhQOWdrKuWcfa/CtikyIitN3miKjEXnedS+ejHlghQ2ba+JmEy9uBYXEkMM LrawTK9VAMxWDGp83a2X/LPhThyPDqtI5wFnlW/pzDHnFcwieDGOMSDgd2QA/LDW7Aky9+Xv1go MJdkpzAv0+mtEmTmr1slKf4Ig3dKr73c+SEuG4/JZwOOH0oBzeIv5kwPSAf2kfvWnJQ8U7XxBn3 y4UjpK8x0U/tWhYoJSI2HNGv5LhHHdx2dgL5AiK+T3G1opYnAd/owIjr156kUEVEItfpdN4d0mI AEVWYlrBUSGm0PQtvAO3g= X-Google-Smtp-Source: AGHT+IH87jmxPaRSAq2EVgGLmPyh2NiseD4EQw9Mxc2LqJKsZ80wHV+7ZKSjM+OAS1QsEBzlpSNPpw== X-Received: by 2002:a05:690e:14c8:b0:645:541a:4f11 with SMTP id 956f58d0204a3-64716c66416mr15549542d50.49.1768273982699; Mon, 12 Jan 2026 19:13:02 -0800 (PST) Received: from localhost ([2a03:2880:25ff:b::]) by smtp.gmail.com with ESMTPSA id 00721157ae682-790aa57a73csm75319457b3.19.2026.01.12.19.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jan 2026 19:13:02 -0800 (PST) From: Bobby Eshleman Date: Mon, 12 Jan 2026 19:11:15 -0800 Subject: [PATCH net-next v14 06/12] selftests/vsock: prepare vm management helpers for namespaces Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260112-vsock-vmtest-v14-6-a5c332db3e2b@meta.com> References: <20260112-vsock-vmtest-v14-0-a5c332db3e2b@meta.com> In-Reply-To: <20260112-vsock-vmtest-v14-0-a5c332db3e2b@meta.com> To: Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , =?utf-8?q?Eugenio_P=C3=A9rez?= , Xuan Zhuo , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Bryan Tan , Vishnu Dasa , Broadcom internal kernel review list , Shuah Khan , Long Li Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kselftest@vger.kernel.org, berrange@redhat.com, Sargun Dhillon , Bobby Eshleman , Bobby Eshleman X-Mailer: b4 0.14.3 From: Bobby Eshleman Add namespace support to vm management, ssh helpers, and vsock_test wrapper functions. This enables running VMs and test helpers in specific namespaces, which is required for upcoming namespace isolation tests. The functions still work correctly within the init ns, though the caller must now pass "init_ns" explicitly. No functional changes for existing tests. All have been updated to pass "init_ns" explicitly. Affected functions (such as vm_start() and vm_ssh()) now wrap their commands with 'ip netns exec' when executing commands in non-init namespaces. Reviewed-by: Stefano Garzarella Signed-off-by: Bobby Eshleman --- tools/testing/selftests/vsock/vmtest.sh | 93 +++++++++++++++++++++++------= ---- 1 file changed, 65 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selfte= sts/vsock/vmtest.sh index c2bdc293b94c..1d03acb62347 100755 --- a/tools/testing/selftests/vsock/vmtest.sh +++ b/tools/testing/selftests/vsock/vmtest.sh @@ -135,7 +135,18 @@ del_namespaces() { } =20 vm_ssh() { - ssh -q -o UserKnownHostsFile=3D/dev/null -p ${SSH_HOST_PORT} localhost "$= @" + local ns_exec + + if [[ "${1}" =3D=3D init_ns ]]; then + ns_exec=3D"" + else + ns_exec=3D"ip netns exec ${1}" + fi + + shift + + ${ns_exec} ssh -q -o UserKnownHostsFile=3D/dev/null -p "${SSH_HOST_PORT}"= localhost "$@" + return $? } =20 @@ -258,10 +269,12 @@ terminate_pidfiles() { =20 vm_start() { local pidfile=3D$1 + local ns=3D$2 local logfile=3D/dev/null local verbose_opt=3D"" local kernel_opt=3D"" local qemu_opts=3D"" + local ns_exec=3D"" local qemu =20 qemu=3D$(command -v "${QEMU}") @@ -282,7 +295,11 @@ vm_start() { kernel_opt=3D"${KERNEL_CHECKOUT}" fi =20 - vng \ + if [[ "${ns}" !=3D "init_ns" ]]; then + ns_exec=3D"ip netns exec ${ns}" + fi + + ${ns_exec} vng \ --run \ ${kernel_opt} \ ${verbose_opt} \ @@ -297,6 +314,7 @@ vm_start() { } =20 vm_wait_for_ssh() { + local ns=3D$1 local i =20 i=3D0 @@ -304,7 +322,8 @@ vm_wait_for_ssh() { if [[ ${i} -gt ${WAIT_PERIOD_MAX} ]]; then die "Timed out waiting for guest ssh" fi - if vm_ssh -- true; then + + if vm_ssh "${ns}" -- true; then break fi i=3D$(( i + 1 )) @@ -338,30 +357,41 @@ wait_for_listener() } =20 vm_wait_for_listener() { - local port=3D$1 + local ns=3D$1 + local port=3D$2 =20 - vm_ssh <&1 | log_guest rc=3D$? else - vm_ssh -- "${VSOCK_TEST}" \ + vm_ssh "${ns}" -- "${VSOCK_TEST}" \ --mode=3Dserver \ --peer-cid=3D"${cid}" \ --control-port=3D"${port}" \ @@ -381,7 +411,7 @@ vm_vsock_test() { return $rc fi =20 - vm_wait_for_listener "${port}" + vm_wait_for_listener "${ns}" "${port}" rc=3D$? fi set +o pipefail @@ -390,22 +420,28 @@ vm_vsock_test() { } =20 host_vsock_test() { - local host=3D$1 - local cid=3D$2 - local port=3D$3 + local ns=3D$1 + local host=3D$2 + local cid=3D$3 + local port=3D$4 local rc =20 + local cmd=3D"${VSOCK_TEST}" + if [[ "${ns}" !=3D "init_ns" ]]; then + cmd=3D"ip netns exec ${ns} ${cmd}" + fi + # log output and use pipefail to respect vsock_test errors set -o pipefail if [[ "${host}" !=3D server ]]; then - ${VSOCK_TEST} \ + ${cmd} \ --mode=3Dclient \ --peer-cid=3D"${cid}" \ --control-host=3D"${host}" \ --control-port=3D"${port}" 2>&1 | log_host rc=3D$? else - ${VSOCK_TEST} \ + ${cmd} \ --mode=3Dserver \ --peer-cid=3D"${cid}" \ --control-port=3D"${port}" 2>&1 | log_host & @@ -416,7 +452,7 @@ host_vsock_test() { return $rc fi =20 - host_wait_for_listener "${port}" + host_wait_for_listener "${ns}" "${port}" rc=3D$? fi set +o pipefail @@ -460,11 +496,11 @@ log_guest() { } =20 test_vm_server_host_client() { - if ! vm_vsock_test "server" 2 "${TEST_GUEST_PORT}"; then + if ! vm_vsock_test "init_ns" "server" 2 "${TEST_GUEST_PORT}"; then return "${KSFT_FAIL}" fi =20 - if ! host_vsock_test "127.0.0.1" "${VSOCK_CID}" "${TEST_HOST_PORT}"; then + if ! host_vsock_test "init_ns" "127.0.0.1" "${VSOCK_CID}" "${TEST_HOST_PO= RT}"; then return "${KSFT_FAIL}" fi =20 @@ -472,11 +508,11 @@ test_vm_server_host_client() { } =20 test_vm_client_host_server() { - if ! host_vsock_test "server" "${VSOCK_CID}" "${TEST_HOST_PORT_LISTENER}"= ; then + if ! host_vsock_test "init_ns" "server" "${VSOCK_CID}" "${TEST_HOST_PORT_= LISTENER}"; then return "${KSFT_FAIL}" fi =20 - if ! vm_vsock_test "10.0.2.2" 2 "${TEST_HOST_PORT_LISTENER}"; then + if ! vm_vsock_test "init_ns" "10.0.2.2" 2 "${TEST_HOST_PORT_LISTENER}"; t= hen return "${KSFT_FAIL}" fi =20 @@ -486,13 +522,14 @@ test_vm_client_host_server() { test_vm_loopback() { local port=3D60000 # non-forwarded local port =20 - vm_ssh -- modprobe vsock_loopback &> /dev/null || : + vm_ssh "init_ns" -- modprobe vsock_loopback &> /dev/null || : =20 - if ! vm_vsock_test "server" 1 "${port}"; then + if ! vm_vsock_test "init_ns" "server" 1 "${port}"; then return "${KSFT_FAIL}" fi =20 - if ! vm_vsock_test "127.0.0.1" 1 "${port}"; then + + if ! vm_vsock_test "init_ns" "127.0.0.1" 1 "${port}"; then return "${KSFT_FAIL}" fi =20 @@ -621,8 +658,8 @@ cnt_total=3D0 if shared_vm_tests_requested "${ARGS[@]}"; then log_host "Booting up VM" pidfile=3D"$(create_pidfile)" - vm_start "${pidfile}" - vm_wait_for_ssh + vm_start "${pidfile}" "init_ns" + vm_wait_for_ssh "init_ns" log_host "VM booted up" =20 run_shared_vm_tests "${ARGS[@]}" --=20 2.47.3