From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 224D934DB41 for ; Thu, 23 Oct 2025 18:28:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761244102; cv=none; b=bDIals+KssECPpuWmH5SNkLX6jR31klQg1aoLZtdKC6H2DwShsB6AjoZImFcHhGbu/EaIv7n36z0TG8tuAC7cabNH1XNoYpdaHE+k2p3ji74Ra5DjlirYdZsViM89UukXvPD7PIoGd7ticc08k9gx0vmYIbcV+f6f+k4y5lXNYg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761244102; c=relaxed/simple; bh=kQBee9DoWSc6883yGLsxi//tyX5HHzjIliVS8SZbc0w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UQ0zmxiy7kXGG+Vw/MFP8yR/WlrNT2TTUkXvq1ZesRPJESOrh4L+yoIAvfs52hH34XSFvUmrLp6ub5Gmk3p061gXLirDrt9sOdv9SGbSa+3tkXH2qvwREX3wPdatk3XRT/20Pb67exvqxPzg4ETfGH9C8Op1I4pqkBXDMgbCLg0= 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=Tge3NCLR; arc=none smtp.client-ip=209.85.214.182 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="Tge3NCLR" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-290ac2ef203so11112485ad.1 for ; Thu, 23 Oct 2025 11:28:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761244094; x=1761848894; 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=ukvtIuA2GTbBdDn1KeFlCInIvIk5c30LHz1pGa2sbYQ=; b=Tge3NCLRtkzCQ+jCqUZQOyaNp+loo8/G+rXlppiyrkJsyLa3KmOjBPaeOVTE777T3w Ian3aCFII+IIdvkwSFHutd5pRjp1idCDfDfM6a669EwCOjisrLkfjMJnih0JtyyhYSAN lR8i/fsQ+b0FPhI+GvEjS8GI919qut77AfSO8u/i/XAzmJ6EPIbc9nALDhziOD02CV6E Fv7Sda1NjdbCmCxeRMqY2QHOfteR8llI6n9lOrPdABjyto52cQskLHLEkt0QcBG732DR GujtI/ZrAn2yfqc2wJ7XIxspzgXDfJmu8nsUw4AYd6eTqZbSfNwEDYWKPASxs0ttuWPu S8Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761244094; x=1761848894; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ukvtIuA2GTbBdDn1KeFlCInIvIk5c30LHz1pGa2sbYQ=; b=ArMDvgm1VAXIhgJvIOhTB1TEcckArSEvV4K8ldjGHf4rI+u0jbYto1gHPJFuIDo+Mo l5FM40ZlZBJkp0LO/mZZOjOZevVNbOBU+SGUPJfYaGonoShRFJHAJBcdiZZViC06+9kf LS32yH7w8B1xJxpzNR70GXlSFUmzPFYMhaOjwtR3Ky+vC37S7LlPV1p0ZKsMNXCz+m29 t8xbfR68y27NXRNX0ZARJPQ20pQBB4ufjROGkpQPmejhzZuF5ZF6BGgWczEZrEZdL6A4 4/3+bW6nuYfdTNwE3BFhxEQRu9vY3650etqMS23eFyZ9j21deSz6yT/+FAsIGtU3BRcD mrwA== X-Forwarded-Encrypted: i=1; AJvYcCWpkeybFM6rHMBs/AlFx/yoZ1kR0DeBTa5oasKqYmoiWzt0RL6wL8iPFi8DlrkiON01Fps/D3MCXWH+KT1sitY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxl92kW41gEmGXsae9TuPJPhUOJQJV8/eScZldmOeZrbJp3Ym3N EdsN6AVBlo0+JKB17FNRagtJXP4t/hnrhNjQJVwXc9mPWN4EZR2g+fj8 X-Gm-Gg: ASbGncu4K5FlJ1eHWd6YHJZS/jo26UZOFdA0Vf5f2HH+C7xvNjEpoIqwjAlxm90WBh/ b3ISONFHFPC8ya+/w5khjq94v9/QV6c9wL+i/qAQyFF53ScXG5FGSoldGe2ctTa67UpeBOuufJ+ 3uYy2/Tv2w8hKbKJ5u1BwJmEYIYrfGJ2IbdQHIcsVmrNilKanh3Sr8zateyQAIzAWwBV+Peftng xnfcvoZSh16F3zpasj7vxVRF+KPMDalY1QUBCULdDuXjymZyDpHLX0iKbMqnPv2OwzmMBGGXdHJ QszER68AisYiBBaP1jYrYgRZiQeLMT6yBe3vvfisuIzZas3vUWgf8xkSZLmt/pAZjq2EKVAkONX fKIvI77zokI+iRMpiMwxaqlzxZouIqgps8jn02IZAlNSTJo6LtNgMTBSFrQ6MtyAyaktOMi5Ulz 1y0BxEODLzEO0iDzMPsjg= X-Google-Smtp-Source: AGHT+IGZ1uFbSH3kISIMtcXAT6m/nUhLcNZeEGyE8hNSy9KW4xwjRKfbKytlo0lhRW4rLAUXnaGm1g== X-Received: by 2002:a17:902:f605:b0:26e:62c9:1cc4 with SMTP id d9443c01a7336-290c9c89da2mr279808105ad.4.1761244093791; Thu, 23 Oct 2025 11:28:13 -0700 (PDT) Received: from localhost ([2a03:2880:2ff:40::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2946de03081sm30876635ad.43.2025.10.23.11.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Oct 2025 11:28:13 -0700 (PDT) From: Bobby Eshleman Date: Thu, 23 Oct 2025 11:27:49 -0700 Subject: [PATCH net-next v8 10/14] selftests/vsock: add tests for proc sys vsock ns_mode Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20251023-vsock-vmtest-v8-10-dea984d02bb0@meta.com> References: <20251023-vsock-vmtest-v8-0-dea984d02bb0@meta.com> In-Reply-To: <20251023-vsock-vmtest-v8-0-dea984d02bb0@meta.com> To: Stefano Garzarella , Shuah Khan , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Bryan Tan , Vishnu Dasa , Broadcom internal kernel review list , Bobby Eshleman Cc: virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, berrange@redhat.com, Bobby Eshleman X-Mailer: b4 0.14.3 From: Bobby Eshleman Add tests for the /proc/sys/net/vsock/ns_mode interface. Namely, that it accepts "global" and "local" strings and enforces a write-once policy. 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_tests() function to run these tests and filter out the shared VM tests. Signed-off-by: Bobby Eshleman --- tools/testing/selftests/vsock/vmtest.sh | 99 ++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selftests/vsock/vmtest.sh index d047f6d27df4..b775fb0cd4ed 100755 --- a/tools/testing/selftests/vsock/vmtest.sh +++ b/tools/testing/selftests/vsock/vmtest.sh @@ -38,11 +38,28 @@ readonly KERNEL_CMDLINE="\ virtme.ssh virtme_ssh_channel=tcp virtme_ssh_user=$USER \ " readonly LOG=$(mktemp /tmp/vsock_vmtest_XXXX.log) -readonly TEST_NAMES=(vm_server_host_client vm_client_host_server vm_loopback) +readonly TEST_NAMES=( + vm_server_host_client + vm_client_host_server + vm_loopback + ns_host_vsock_ns_mode_ok + ns_host_vsock_ns_mode_write_once_ok +) readonly TEST_DESCS=( + # 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_ns_mode_write_once_ok + "Check /proc/sys/net/vsock/ns_mode is write-once on the host." ) readonly USE_SHARED_VM=(vm_server_host_client vm_client_host_server vm_loopback) @@ -203,6 +220,20 @@ check_deps() { fi } +check_netns() { + local tname=$1 + + # If the test requires NS support, check if NS support exists + # using /proc/self/ns + if [[ "${tname}" =~ ^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 @@ -502,6 +533,43 @@ log_guest() { LOG_PREFIX=guest log $@ } +test_ns_host_vsock_ns_mode_ok() { + add_namespaces + + for mode in "${NS_MODES[@]}"; do + if ! ns_set_mode "${mode}0" "${mode}"; then + del_namespaces + return "${KSFT_FAIL}" + fi + done + + del_namespaces + + return "${KSFT_PASS}" +} + +test_ns_host_vsock_ns_mode_write_once_ok() { + add_namespaces + + for mode in "${NS_MODES[@]}"; do + local ns="${mode}0" + if ! ns_set_mode "${ns}" "${mode}"; then + del_namespaces + return "${KSFT_FAIL}" + fi + + # try writing again and expect failure + if ns_set_mode "${ns}" "${mode}"; then + del_namespaces + return "${KSFT_FAIL}" + fi + done + + del_namespaces + + return "${KSFT_PASS}" +} + test_vm_server_host_client() { if ! vm_vsock_test "init_ns" "server" 2 "${TEST_GUEST_PORT}"; then return "${KSFT_FAIL}" @@ -575,6 +643,11 @@ run_shared_vm_tests() { continue fi + if ! check_netns "${arg}"; then + check_result "${KSFT_SKIP}" + continue + fi + run_shared_vm_test "${arg}" check_result $? done @@ -628,6 +701,28 @@ run_shared_vm_test() { return "${rc}" } +run_tests() { + for arg in "${ARGS[@]}"; do + if shared_vm_test "${arg}"; then + continue + fi + + if ! check_netns "${arg}"; then + check_result "${KSFT_SKIP}" + continue + fi + + add_namespaces + + name=$(echo "${arg}" | awk '{ print $1 }') + log_host "Executing test_${name}" + eval test_"${name}" + check_result $? + + del_namespaces + done +} + BUILD=0 QEMU="qemu-system-$(uname -m)" @@ -671,6 +766,8 @@ if shared_vm_tests_requested "${ARGS[@]}"; then terminate_pidfiles "${pidfile}" fi +run_tests "${ARGS[@]}" + echo "SUMMARY: PASS=${cnt_pass} SKIP=${cnt_skip} FAIL=${cnt_fail}" echo "Log: ${LOG}" -- 2.47.3