From nobody Sun Feb 8 23:35:06 2026 Received: from mail-yx1-f47.google.com (mail-yx1-f47.google.com [74.125.224.47]) (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 14D8E3148C7 for ; Fri, 16 Jan 2026 21:29:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768598955; cv=none; b=AQ7uqJL1Qd+vqvYnfVUwZw2zAG0cHYYE+LPcG5yc3UPlCLfPKIoDXeJfeEKfgm4TxyeJbWIgcS04I485uHBlyl+cqtKwTEF15NfzbZfM6gVkwS4koAkkNoRmRgBpeakCMEIiCno+ucGxPzyiQmzLJQ1j3P2BLUce3BlWLXzp4Iw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768598955; c=relaxed/simple; bh=FIcglHOWrEg8hIuKGpVPQi7ir3gvt3puG14NMEVOHaI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IA2N8Dv69Llw8/cZJq3N9fHan9a6w6sv4VHCXuKE+u4j/7SoajY9dcGazb4zfdx78hA04Cl93/eX0EH4xE6Zh200M2RCFPbTlY93ieWbEpHiYbkwDbSRyGjLSOI3+JszLZ00DKwOQxlq5emtK0ErO8II1hPP/KVbSMAjuuYacJU= 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=AvhfVHsD; arc=none smtp.client-ip=74.125.224.47 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="AvhfVHsD" Received: by mail-yx1-f47.google.com with SMTP id 956f58d0204a3-646d9eb45afso2209330d50.2 for ; Fri, 16 Jan 2026 13:29:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768598951; x=1769203751; 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=CfX5aCEAXTMRHVqkeJXb/fPPli7OvyVPTLJ4OZc+4kA=; b=AvhfVHsD2WmNwe/00gmgljdjyzjNPr5KDDTDBq09LZa7epDUyjTeh9AdtV9euGud4f nWdqmVLKIPWHMC8mttxZLtmaogifay7tRVBd1ZE2vPw/DTrM/a5BBlZ9jIdh8JXS35eg 2nIXQlpdK26TsHbSC7IYoB2YZeaPFMgj85zXP7Z+v4Ii7z0QBkj7g0bwlRaJIXOqGeKu vN6IADqdJHeYEJOVwMSUdFymZsxoCR/LkA2FncXIs6hFe6Xl+DVqvjqMjSrLm/rxeqIj Gv8bpQ3uv74XvAMB/lpX5KzIWd8iYbWuKpejphh5TSBSP3DIEAK/DdjshKo4g1ITDj2h WO9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768598951; x=1769203751; 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=CfX5aCEAXTMRHVqkeJXb/fPPli7OvyVPTLJ4OZc+4kA=; b=R7969fTTlxb1aHYNuUGLjnlDjmJe4rdpAMFsGK6GGQR3IJP9zkgw4YvZCCnssw/PNS yh5bVbn6ZehlVARjYzX2F+mcNkk5WnjHsEAEpLVI3LEF0t4GaNNmDF21WOfAGGJafyQG g1FN6/5DMvl2YpOYhXj6YIviIADyZbEL+sXSvZU9aOBbcUdHkXTiIidCLiMPx3U/tQCn 9TY/QFql0T8TwyrYwHyHLdyY88DKVo7U4dmVHoun41pIBCl/vEv2OGkQJNSzrrdfY5KS DOctAJpYPfuuRto2Q4otXkXBzMe3Gqi7Si7GS1z6VuDVoM9QbEK/yytlFpJ8g4FxAHg/ CH7Q== X-Gm-Message-State: AOJu0YxWZerQBNv4lEtX3gx/XNKlOHA9qfMqfaBAm0X45aB6Lm40Gd13 fY1RtOxuklBajFUEkapoyXSuQ9iE7B32k14h3n1poU/C0wCisd1QrQMn X-Gm-Gg: AY/fxX7mPAUjhbpgQAtUXnZP1tPwm9I4TX2Lgf35o4yNps70iqTdKI5ImFmg4sSEGlM oqreAnd3XxDE1TRCt/9Z7GShg706kXxiZtjD+APz/46pry2nvbLZPCbEiEemKdAQpAjifTfIFZK bzNbJDt4xfyUlRhrKi5O019SDRHkMz4Sj+6pzgANrUL3kO57+E6M6walpSj4tDFNVmZrRbh0Uq1 n7n1GVeyy1SN4SZRBgH2OVE+xVTygIfK8w8tGnyoi0hAodiEIl2/14PbFTTZGZXeT7t6dt02s/u l4XLnP6f1t8lbXwywwR1gcs4na2G3ABa6uoEQYuXteQjkGaZr8kZewNGJgqgthgKVDtcuUlHATC RVdtvVws75NBL5TstVzDRGOq2GLAoh2h9VCk1tq58+GyheUh1zlHWEd3k1LNzEqB2DcniJMojm1 R9LIm/+RcU X-Received: by 2002:a05:690e:1344:b0:646:7ae4:11e9 with SMTP id 956f58d0204a3-6491648afe7mr3823738d50.15.1768598950861; Fri, 16 Jan 2026 13:29:10 -0800 (PST) Received: from localhost ([2a03:2880:25ff:1::]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-649170be316sm1663704d50.20.2026.01.16.13.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jan 2026 13:29:10 -0800 (PST) From: Bobby Eshleman Date: Fri, 16 Jan 2026 13:28:49 -0800 Subject: [PATCH net-next v15 09/12] selftests/vsock: add tests for proc sys vsock ns_mode 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: <20260116-vsock-vmtest-v15-9-bbfd1a668548@meta.com> References: <20260116-vsock-vmtest-v15-0-bbfd1a668548@meta.com> In-Reply-To: <20260116-vsock-vmtest-v15-0-bbfd1a668548@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 , Jonathan Corbet 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 , linux-doc@vger.kernel.org, Bobby Eshleman , Bobby Eshleman X-Mailer: b4 0.14.3 From: Bobby Eshleman Add tests for the /proc/sys/net/vsock/{ns_mode,child_ns_mode} interfaces. Namely, that they accept/report "global" and "local" strings and enforce their access policies. Start a convention of commenting the test name over the test description. Add test name comments over test descriptions that existed before this convention. Add a check_netns() function that checks if the test requires namespaces and if the current kernel supports namespaces. Skip tests that require namespaces if the system does not have namespace support. This patch is the first to add tests that do *not* re-use the same shared VM. For that reason, it adds a run_ns_tests() function to run these tests and filter out the shared VM tests. Reviewed-by: Stefano Garzarella Signed-off-by: Bobby Eshleman --- Changes in v13: - remove write-once test ns_host_vsock_ns_mode_write_once_ok to reflect removing the write-once policy - add child_ns_mode test test_ns_host_vsock_child_ns_mode_ok - modify test_ns_host_vsock_ns_mode_ok() to check that the correct mode was inherited from child_ns_mode Changes in v12: - remove ns_vm_local_mode_rejected test, due to dropping that constraint Changes in v11: - Document ns_ prefix above TEST_NAMES (Stefano) Changes in v10: - Remove extraneous add_namespaces/del_namespaces calls. - Rename run_tests() to run_ns_tests() since it is designed to only run ns tests. Changes in v9: - add test ns_vm_local_mode_rejected to check that guests cannot use local mode --- tools/testing/selftests/vsock/vmtest.sh | 140 ++++++++++++++++++++++++++++= +++- 1 file changed, 138 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selfte= sts/vsock/vmtest.sh index 0e681d4c3a15..38785a102236 100755 --- a/tools/testing/selftests/vsock/vmtest.sh +++ b/tools/testing/selftests/vsock/vmtest.sh @@ -41,14 +41,38 @@ readonly KERNEL_CMDLINE=3D"\ virtme.ssh virtme_ssh_channel=3Dtcp virtme_ssh_user=3D$USER \ " readonly LOG=3D$(mktemp /tmp/vsock_vmtest_XXXX.log) -readonly TEST_NAMES=3D(vm_server_host_client vm_client_host_server vm_loop= back) + +# Namespace tests must use the ns_ prefix. This is checked in check_netns(= ) and +# is used to determine if a test needs namespace setup before test executi= on. +readonly TEST_NAMES=3D( + vm_server_host_client + vm_client_host_server + vm_loopback + ns_host_vsock_ns_mode_ok + ns_host_vsock_child_ns_mode_ok +) readonly TEST_DESCS=3D( + # vm_server_host_client "Run vsock_test in server mode on the VM and in client mode on the host." + + # vm_client_host_server "Run vsock_test in client mode on the VM and in server mode on the host." + + # vm_loopback "Run vsock_test using the loopback transport in the VM." + + # ns_host_vsock_ns_mode_ok + "Check /proc/sys/net/vsock/ns_mode strings on the host." + + # ns_host_vsock_child_ns_mode_ok + "Check /proc/sys/net/vsock/ns_mode is read-only and child_ns_mode is writ= able." ) =20 -readonly USE_SHARED_VM=3D(vm_server_host_client vm_client_host_server vm_l= oopback) +readonly USE_SHARED_VM=3D( + vm_server_host_client + vm_client_host_server + vm_loopback +) readonly NS_MODES=3D("local" "global") =20 VERBOSE=3D0 @@ -196,6 +220,20 @@ check_deps() { fi } =20 +check_netns() { + local tname=3D$1 + + # If the test requires NS support, check if NS support exists + # using /proc/self/ns + if [[ "${tname}" =3D~ ^ns_ ]] && + [[ ! -e /proc/self/ns ]]; then + log_host "No NS support detected for test ${tname}" + return 1 + fi + + return 0 +} + check_vng() { local tested_versions local version @@ -519,6 +557,54 @@ log_guest() { LOG_PREFIX=3Dguest log "$@" } =20 +ns_get_mode() { + local ns=3D$1 + + ip netns exec "${ns}" cat /proc/sys/net/vsock/ns_mode 2>/dev/null +} + +test_ns_host_vsock_ns_mode_ok() { + for mode in "${NS_MODES[@]}"; do + local actual + + actual=3D$(ns_get_mode "${mode}0") + if [[ "${actual}" !=3D "${mode}" ]]; then + log_host "expected mode ${mode}, got ${actual}" + return "${KSFT_FAIL}" + fi + done + + return "${KSFT_PASS}" +} + +test_ns_host_vsock_child_ns_mode_ok() { + local orig_mode + local rc + + orig_mode=3D$(cat /proc/sys/net/vsock/child_ns_mode) + + rc=3D"${KSFT_PASS}" + for mode in "${NS_MODES[@]}"; do + local ns=3D"${mode}0" + + if echo "${mode}" 2>/dev/null > /proc/sys/net/vsock/ns_mode; then + log_host "ns_mode should be read-only but write succeeded" + rc=3D"${KSFT_FAIL}" + continue + fi + + if ! echo "${mode}" > /proc/sys/net/vsock/child_ns_mode; then + log_host "child_ns_mode should be writable to ${mode}" + rc=3D"${KSFT_FAIL}" + continue + fi + done + + echo "${orig_mode}" > /proc/sys/net/vsock/child_ns_mode + + return "${rc}" +} + test_vm_server_host_client() { if ! vm_vsock_test "init_ns" "server" 2 "${TEST_GUEST_PORT}"; then return "${KSFT_FAIL}" @@ -592,6 +678,11 @@ run_shared_vm_tests() { continue fi =20 + if ! check_netns "${arg}"; then + check_result "${KSFT_SKIP}" "${arg}" + continue + fi + run_shared_vm_test "${arg}" check_result "$?" "${arg}" done @@ -645,6 +736,49 @@ run_shared_vm_test() { return "${rc}" } =20 +run_ns_tests() { + for arg in "${ARGS[@]}"; do + if shared_vm_test "${arg}"; then + continue + fi + + if ! check_netns "${arg}"; then + check_result "${KSFT_SKIP}" "${arg}" + continue + fi + + add_namespaces + + name=3D$(echo "${arg}" | awk '{ print $1 }') + log_host "Executing test_${name}" + + host_oops_before=3D$(dmesg 2>/dev/null | grep -c -i 'Oops') + host_warn_before=3D$(dmesg --level=3Dwarn 2>/dev/null | grep -c -i 'vsoc= k') + eval test_"${name}" + rc=3D$? + + host_oops_after=3D$(dmesg 2>/dev/null | grep -c -i 'Oops') + if [[ "${host_oops_after}" -gt "${host_oops_before}" ]]; then + echo "FAIL: kernel oops detected on host" | log_host + check_result "${KSFT_FAIL}" "${name}" + del_namespaces + continue + fi + + host_warn_after=3D$(dmesg --level=3Dwarn 2>/dev/null | grep -c -i 'vsock= ') + if [[ "${host_warn_after}" -gt "${host_warn_before}" ]]; then + echo "FAIL: kernel warning detected on host" | log_host + check_result "${KSFT_FAIL}" "${name}" + del_namespaces + continue + fi + + check_result "${rc}" "${name}" + + del_namespaces + done +} + BUILD=3D0 QEMU=3D"qemu-system-$(uname -m)" =20 @@ -690,6 +824,8 @@ if shared_vm_tests_requested "${ARGS[@]}"; then terminate_pidfiles "${pidfile}" fi =20 +run_ns_tests "${ARGS[@]}" + echo "SUMMARY: PASS=3D${cnt_pass} SKIP=3D${cnt_skip} FAIL=3D${cnt_fail}" echo "Log: ${LOG}" =20 --=20 2.47.3