From nobody Tue Dec 2 01:50:08 2025 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 8DBE62F9DB8 for ; Fri, 21 Nov 2025 05:44:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763703901; cv=none; b=Gbtq+XDh8o/dSa/4bFCwtJ6/2je1VEmUYi2HUpfWLNj5Cv0NMVaeZB6zBunWVYpG8kLd5RFLYTomJWIvVE0lVh8s8AQ4jn0yj9RV09ZkmaOGYrm3QSBxNBlWVTc+5g2BapvsJVz9iWkVVld6RWtvw99Kr/hXAa/MYJFQYaSvZOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763703901; c=relaxed/simple; bh=uK+7wonqeqIE2+4J4eSHlB1BJW2sPOHiw05XtJHZdQM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hWltsLpcJH8/2xte0o3GXa4Ola579gW9NLe5u+IntnD3nC9aJ7s2gQBepc831YVGOn5tTUeZbHC/ms3LEaDTW0jWDbGSLZ//NEPvH9Z7lP2yN+u/PyBjqZyOpy9qJnTEPHv0XYdXGIPRVSWm9jwYqYEUVjrb/7K9NcIXXZggTFg= 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=QAUOO0WH; arc=none smtp.client-ip=209.85.214.170 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="QAUOO0WH" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-299d40b0845so26505225ad.3 for ; Thu, 20 Nov 2025 21:44:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763703897; x=1764308697; 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=fSkbmakY8QtibtOCdba8TmlxElnFph3vUeoyjgD6/iw=; b=QAUOO0WH3+qgxCZ6gMwgQYIf1kk8I60OZx+Wxe2+vqswILHB94RidaRv6PgCam5Q/2 0QeqACwTPcokwZ1EwCE9dam0p5utVtxibxiUmQQP4AH9iFGNKaLyhRpYOEnHT9bSW9w3 nhpWiRmeFGT2pphlhz6ckYZJZlrPTLQUtOx6da7bJ2js+q7FehULpnpD7Lku6lz3sXbN KC2TRvN/VeTSxcaaEOdNbgXjk0EKihxBvkR8mfc8eU2hGDUwvoJ3m3eWqgcg3guyA7O9 MWl5ys8XEXnSXyMtIMLQuXdf5YL/w78Un6fNQG9qKtkWEIG1PTstwa2KYP0Ip0sZFAzt 99RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763703897; x=1764308697; 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=fSkbmakY8QtibtOCdba8TmlxElnFph3vUeoyjgD6/iw=; b=oFtzP8zNPwxHs5pbcKq6xCwfaRts8NzAch6Aq/UOeArmMbMwwb5w5NDiTCSBBZuNU+ lGeeRUHOxQJu25/VsvSlMqs8JD0XeDS9jM3EEtGG752TwNj6/K1koZHlh7B+8kmL4q1g af/r2WW3YyTscuX9CmBz7JX81HxzgkDEhl91lOLvTPOImafaTmD1HEOzpMbvZB2zwe5O kRQDznsZgrhThWpduyNpMG0bRuwPWe+CpT76x6+vTxcSkIbHkSR4jIy1tubR2ooWpC1O efCavHKQim9/dpObAHl60GJqeZulDK0Ss4dsSlaPvQ6iSusvtki49LpiYtQa4FMr1DdS AAcA== X-Gm-Message-State: AOJu0Yy2wGJAstlMkUsmDhAE/qFjIf2xcj4RYA/oWn3U1WTiNSzLrISX A03gnWgohwd3lqh5n/WrG4TKyzqAliJTVMef3VaphuC5u1Or7LH9wWjK5fJKxdK6 X-Gm-Gg: ASbGncuufmVOS3SQqSOl8m68mT6dmTc35ua8E+3n+uju7w+d+Gy3eFlfXecMmhrJsqA AO9j6hNR8GGMsoX3VjTj1wikSS3p73dkhpnrRASr9bv6LjCmeYcU3BcGOtbaF+UHI6KVEPMgzfP ePEm34tepp8e9X8HBAY+oHV8CH9hHO2gWhjmSk6umoYnjZqA98Uz6avpKH6x65rCyElL9eNmwOg psJZHPAiOdsrxCo307q+r212gmZe+3iN0oYUUAyFFduHJD+PDXNgQ/gRO3SlGGodvChzhyMBnOb Zlzgs71LzBGofFe0ssufgK/WLWP8SXrYya15FfXqy8MxDQ+piBvl30j/sCWbmTGY32ASTgp1tfv s5bLvvZiBIZe0RA9ZuwLnDNez5OI3ofTmd2uVkkPTid3y/C4+2gEpoKSi2oWfxVsnXrCp5lywSm 4nEb2LU8QL+coExdF/6b8= X-Google-Smtp-Source: AGHT+IGGsDu1q3vm1jDYt6q/UI5NUFr2N2GTMwEvCBun/hcx13LSj7midmn1ev74SGvBLriqPu/3+g== X-Received: by 2002:a17:903:2ac5:b0:297:e59c:63cc with SMTP id d9443c01a7336-29b6bf19ef0mr14465525ad.35.1763703896832; Thu, 20 Nov 2025 21:44:56 -0800 (PST) Received: from localhost ([2a03:2880:2ff:4::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29b5b25c104sm44306755ad.54.2025.11.20.21.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Nov 2025 21:44:56 -0800 (PST) From: Bobby Eshleman Date: Thu, 20 Nov 2025 21:44:38 -0800 Subject: [PATCH net-next v11 06/13] selftests/vsock: add namespace helpers to vmtest.sh 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: <20251120-vsock-vmtest-v11-6-55cbc80249a7@meta.com> References: <20251120-vsock-vmtest-v11-0-55cbc80249a7@meta.com> In-Reply-To: <20251120-vsock-vmtest-v11-0-55cbc80249a7@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 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 functions for initializing namespaces with the different vsock NS modes. Callers can use add_namespaces() and del_namespaces() to create namespaces global0, global1, local0, and local1. The init_namespaces() function initializes global0, local0, etc... with their respective vsock NS mode. This function is separate so that tests that depend on this initialization can use it, while other tests that want to test the initialization interface itself can start with a clean slate by omitting this call. Remove namespaces upon exiting the program in cleanup(). This is unlikely to be needed for a healthy run, but it is useful for tests that are manually killed mid-test. In that case, this patch prevents the subsequent test run from finding stale namespaces with already-write-once-locked vsock ns modes. This patch is in preparation for later namespace tests. Reviewed-by: Stefano Garzarella Signed-off-by: Bobby Eshleman --- tools/testing/selftests/vsock/vmtest.sh | 41 +++++++++++++++++++++++++++++= ++++ 1 file changed, 41 insertions(+) diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selfte= sts/vsock/vmtest.sh index c7b270dd77a9..f78cc574c274 100755 --- a/tools/testing/selftests/vsock/vmtest.sh +++ b/tools/testing/selftests/vsock/vmtest.sh @@ -49,6 +49,7 @@ readonly TEST_DESCS=3D( ) =20 readonly USE_SHARED_VM=3D(vm_server_host_client vm_client_host_server vm_l= oopback) +readonly NS_MODES=3D("local" "global") =20 VERBOSE=3D0 =20 @@ -103,6 +104,45 @@ check_result() { fi } =20 +add_namespaces() { + # add namespaces local0, local1, global0, and global1 + for mode in "${NS_MODES[@]}"; do + ip netns add "${mode}0" 2>/dev/null + ip netns add "${mode}1" 2>/dev/null + done +} + +init_namespaces() { + for mode in "${NS_MODES[@]}"; do + ns_set_mode "${mode}0" "${mode}" + ns_set_mode "${mode}1" "${mode}" + + log_host "set ns ${mode}0 to mode ${mode}" + log_host "set ns ${mode}1 to mode ${mode}" + + # we need lo for qemu port forwarding + ip netns exec "${mode}0" ip link set dev lo up + ip netns exec "${mode}1" ip link set dev lo up + done +} + +del_namespaces() { + for mode in "${NS_MODES[@]}"; do + ip netns del "${mode}0" &>/dev/null + ip netns del "${mode}1" &>/dev/null + log_host "removed ns ${mode}0" + log_host "removed ns ${mode}1" + done +} + +ns_set_mode() { + local ns=3D$1 + local mode=3D$2 + + echo "${mode}" | ip netns exec "${ns}" \ + tee /proc/sys/net/vsock/ns_mode &>/dev/null +} + vm_ssh() { ssh -q -o UserKnownHostsFile=3D/dev/null -p ${SSH_HOST_PORT} localhost "$= @" return $? @@ -110,6 +150,7 @@ vm_ssh() { =20 cleanup() { terminate_pidfiles "${!PIDFILES[@]}" + del_namespaces } =20 check_args() { --=20 2.47.3