From nobody Tue Dec 16 06:54:15 2025 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 DD2B034DB58 for ; Thu, 23 Oct 2025 18:28:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761244103; cv=none; b=fZLHCPq4t8Iyf9AwKk/jI7z0gvMqAI9WANpc9FyjRBV2CDLp/mzZ7ztFFYiTf/0DIEQWyFOjdnrko86WiiNB4oLxhPZAinwSUrqj6ht4FMhxMtd0IU9QXL5vvgIKqCs+A6ciD8VVhkkDGi55OCChCV0NYiqiNl5QfRD1JsjXY5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761244103; c=relaxed/simple; bh=5F5v73spaO6g7IkcyDH3GDS87tLNHAMWY+Aqa2TXZbk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZJu+gpk0Id1pfz8i+gIYVJbcAfoDkzNvB5efaRFUIhMPdqLoNXC7x06hNN5BlrmaMCfYyX5k0aS8tlK8aAKeqqR0pUfypzGZIjII/XPJtibEuityfTEMkIpCaoYHewvj7M4BRUBdXVHz5nkf9QGLmvfgh6yinWHIcBhWK619HKA= 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=K3mXFKU1; arc=none smtp.client-ip=209.85.216.48 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="K3mXFKU1" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-3307de086d8so1252251a91.2 for ; Thu, 23 Oct 2025 11:28:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761244095; x=1761848895; 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=edpWGMd9VbWpBkt/1Y+NJ91tcxlgSe0i7beuNiNUjc4=; b=K3mXFKU1z8DIYxbpDKyktLYsC/hgT6Bvk5OrT5VySiqYV7V/79Ov1oDZSzNH1b62mG Hxp6rJy1jAY/7hVXibbWe1UFc/MvRkM1k5mHCYGDpC74WNKWwV8eYaYz3lr0kzE6p1tG DFepQjfMGH/K54xapxNktsHKS7Tm2lEsRW9Aha+yMUawDSqmMb7betN2QVpmoADlRqSI JEflOzK/A2WqCv1v+JKeS0596yhIqZ4kwVsK3s4qs0V3VXWyk3aNIqxl5oWHZjV44Q7f iiqBn56AagoeQHjtFsunyKzWTDc7qL4d2EZJzu/ytv9Zlvr9lKBhjDUG2CuwkTa58obc F89g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761244095; x=1761848895; 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=edpWGMd9VbWpBkt/1Y+NJ91tcxlgSe0i7beuNiNUjc4=; b=XSoNmydkGwCMMcNe6GuZpI1RvLfJb2i5LhnmemwagE2H+jYpK0fPsxPrw8RV0Y7jmQ 6KDAl/eN15NKNNDHAamPfhLLvbQRLzmKGFbcc4XAwE9Cfu/uBEc15dUJO66RIjRU30zU mvOpx7RTaOSf5YDfIRVfb73wZn7KykPV65DP1+wxZV8rPeOm1vZwb0D9mc4C4oLZDuFJ OzoVjxCGWhi9qFnft0INb0H1szjy4mx9HzC6pJIPnHk+ZFaLDZiu5EqmItSWGnTcdjwI UbdUG+u8hTIjoxti7ZsvsAdRJIZ/bbC0Z/arIAPIcyxM5ulQAnJj0+CMOFIwQOZtHKkJ yUwg== X-Forwarded-Encrypted: i=1; AJvYcCWkozUuhtGTLycJExHD/wRpNvYgkeWzvf5xW6Bf068NczhGcxeHkerGbTp4B0nXhN5dQ+p9NLDyvvkQzH4=@vger.kernel.org X-Gm-Message-State: AOJu0YxX4O4fKSIOvoUrz9EaPxGVYLPDQQTlIclQIN1VA7zxv9z8GoWb RIx4c8NYR45F14pntvM9DB9CFxKeL92RWiKUkN7U/SDdIbyTHP4cMJNN X-Gm-Gg: ASbGncvnHkiWwel6Qy/KbN6OPz9YoGp+HaUZUYuAUU//sPqXX3rHgCKMgf1g6VGSZAr bhcpEp/GBF6GDpn7WeP1AVj1MJyDHbcLRkdwiW+yjpJy/aCS3gs5n0TPrdqvrt4hPUduIX9zN10 OeDomXpPpz2mNglj82O4xqFxGFxDV2M1NjTobmuXsUGWPoCegr50SHHejFubYRaZuUsskP7aTeu N7dvWhLpU0EmM5d1biy6L5exCk9aGOibXYh9v5ThQ+ZtA/5lEZLesrBKqptoJZ+olIH3GnG0uH6 ZbAyRdIPFBD6YuGTckHXb/zTGjE6pvAl4bjob1vVAkPGHREc2I4P17xS5VQeJuAc+kHLvFhbrrg Qe8x6gRYFCH40uKlR2fgIvzMcWlD3DeFSeQRvd7STbqsOhuFtNstDq342cnIF8mXbjONKn3ggbZ w9tOxCsKI= X-Google-Smtp-Source: AGHT+IHqGJGfE7/AR7EEKGb5aGT4lYi4Q0CdcUhFDN32WBMZZ/a+b4mtH/4xEGFnf/S5gHM7f9sTTQ== X-Received: by 2002:a17:90b:2789:b0:329:e703:d00b with SMTP id 98e67ed59e1d1-33bcf8f769fmr34761255a91.19.1761244094881; Thu, 23 Oct 2025 11:28:14 -0700 (PDT) Received: from localhost ([2a03:2880:2ff:2::]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-33dff46d539sm3689641a91.13.2025.10.23.11.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Oct 2025 11:28:14 -0700 (PDT) From: Bobby Eshleman Date: Thu, 23 Oct 2025 11:27:50 -0700 Subject: [PATCH net-next v8 11/14] selftests/vsock: add namespace tests for CID collisions 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: <20251023-vsock-vmtest-v8-11-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 to verify CID collision rules across different vsock namespace modes. 1. Two VMs with the same CID cannot start in different global namespaces (ns_global_same_cid_fails) 2. Two VMs with the same CID can start in different local namespaces (ns_local_same_cid_ok) 3. VMs with the same CID can coexist when one is in a global namespace and another is in a local namespace (ns_global_local_same_cid_ok and ns_local_global_same_cid_ok) The tests ns_global_local_same_cid_ok and ns_local_global_same_cid_ok make sure that ordering does not matter. The tests use a shared helper function namespaces_can_boot_same_cid() that attempts to start two VMs with identical CIDs in the specified namespaces and verifies whether VM initialization failed or succeeded. Signed-off-by: Bobby Eshleman --- tools/testing/selftests/vsock/vmtest.sh | 74 +++++++++++++++++++++++++++++= ++++ 1 file changed, 74 insertions(+) diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selfte= sts/vsock/vmtest.sh index b775fb0cd4ed..f2a99cde9fb4 100755 --- a/tools/testing/selftests/vsock/vmtest.sh +++ b/tools/testing/selftests/vsock/vmtest.sh @@ -44,6 +44,10 @@ readonly TEST_NAMES=3D( vm_loopback ns_host_vsock_ns_mode_ok ns_host_vsock_ns_mode_write_once_ok + ns_global_same_cid_fails + ns_local_same_cid_ok + ns_global_local_same_cid_ok + ns_local_global_same_cid_ok ) readonly TEST_DESCS=3D( # vm_server_host_client @@ -60,6 +64,18 @@ readonly TEST_DESCS=3D( =20 # ns_host_vsock_ns_mode_write_once_ok "Check /proc/sys/net/vsock/ns_mode is write-once on the host." + + # ns_global_same_cid_fails + "Check QEMU fails to start two VMs with same CID in two different global = namespaces." + + # ns_local_same_cid_ok + "Check QEMU successfully starts two VMs with same CID in two different lo= cal namespaces." + + # ns_global_local_same_cid_ok + "Check QEMU successfully starts one VM in a global ns and then another VM= in a local ns with the same CID." + + # ns_local_global_same_cid_ok + "Check QEMU successfully starts one VM in a local ns and then another VM = in a global ns with the same CID." ) =20 readonly USE_SHARED_VM=3D(vm_server_host_client vm_client_host_server vm_l= oopback) @@ -548,6 +564,64 @@ test_ns_host_vsock_ns_mode_ok() { return "${KSFT_PASS}" } =20 +namespaces_can_boot_same_cid() { + local ns0=3D$1 + local ns1=3D$2 + local pidfile1 pidfile2 + local rc + + pidfile1=3D$(mktemp $PIDFILE_TEMPLATE) + vm_start "${pidfile1}" "${ns0}" + + pidfile2=3D$(mktemp $PIDFILE_TEMPLATE) + vm_start "${pidfile2}" "${ns1}" + + rc=3D$? + terminate_pidfiles "${pidfile1}" "${pidfile2}" + + return $rc +} + +test_ns_global_same_cid_fails() { + init_namespaces + + if namespaces_can_boot_same_cid "global0" "global1"; then + return "${KSFT_FAIL}" + fi + + return "${KSFT_PASS}" +} + +test_ns_local_global_same_cid_ok() { + init_namespaces + + if namespaces_can_boot_same_cid "local0" "global0"; then + return "${KSFT_PASS}" + fi + + return "${KSFT_FAIL}" +} + +test_ns_global_local_same_cid_ok() { + init_namespaces + + if namespaces_can_boot_same_cid "global0" "local0"; then + return "${KSFT_PASS}" + fi + + return "${KSFT_FAIL}" +} + +test_ns_local_same_cid_ok() { + init_namespaces + + if namespaces_can_boot_same_cid "local0" "local0"; then + return "${KSFT_FAIL}" + fi + + return "${KSFT_PASS}" +} + test_ns_host_vsock_ns_mode_write_once_ok() { add_namespaces =20 --=20 2.47.3