From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=67.231.145.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796087249; b=AxWFJ0hOQRjc+Q7HjhHLbDi+81n6A2sid46G6P60Rxhlbf+H98I5Pbf/gg3cbCq5/niY DWx9+T0yQYPMI/c7nI86RuXbc6Sb38oh7n1E2SMJfDZs9MOrbk8aFB9W/+/v2RGuVrJit TJE7+08V4H/8Ibs0651pDi9O0TprH/pPa/2JLdPFRWbOrzTCgzCDelA5HhG1+L58AL/V5 ipNumO4UAP7Qr64+VXu9dThaTX1X3ZLQC3Ngnr0EIM3GBEAsLR7F10uDF47I0sY+1UgCU /sVcwneWVdM7bd6PLkA/jLeo2qLh8HsxzRkUxSqo2+inGAslIKy9qEjMTJF8yZAqCtQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796087249; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:From:Subject: Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding: X-B4-Tracking:X-Change-ID:To:CC:X-Mailer:X-Originating-IP: X-Proofpoint-GUID:X-Proofpoint-ORIG-GUID:X-Authority-Analysis: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Spam-Info: X-Proofpoint-Virus-Version; bh=D7f1S0dMtx18/dt6wjL5n8ux7RUCfLJdYAW0W8eOYJ0=; b=cpCCnkuL/egpxL2fhV62GyIwI8AxJhKknbyjoeFlmYpQpdAm2P45U39TB2NVUx2r8s6l Ibqns64NUvHJaMn/OhYE0VXeMCTwxYB7XLlYj+L7p7LIb3dg5Hg+a32K0S0LEdTiDZUnJ WrEw9LLBwusC62gYCPf67+W/qC+gxA0l8COslJPvxRyJSCfMq7HU+PmDBM6z5yDTa9mVw eG8KKStfFG90OEEYnplQMf2z5463jF6pd1n6JzrPLST2q3sMvUT0nONTdSIglpyiR8nbK WGtukPGVcVlnXSTLNs+hsK7u4DQ7JUlfMDpfb6znRoKBJJzR9UNnJ9OEnuNPPHibOlw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass header.d=meta.com header.i=@meta.com header.a=rsa-sha256 header.s=pps82601-s2048-2026-q3 header.b=aJddP3bH; arc=none smtp.remote-ip=67.231.145.42 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 653EC606A329; Tue, 1 Dec 2026 01:07:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 653EC606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.a=rsa-sha256 header.s=pps82601-s2048-2026-q3 header.b=aJddP3bH Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AUNgEw5597922; Mon, 30 Nov 2026 17:07:07 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=pps82601-s2048-2026-q3; bh=D7f1S0dMt x18/dt6wjL5n8ux7RUCfLJdYAW0W8eOYJ0=; b=aJddP3bHjH2gKhZ6Hdxb9v35W 8xAgNwAncoCspMmTtvxOcZ+slVm8cda9Mr19NDbF8HWyT6hVcL4HsOO09/AksZ2t Fr9CU0K8CnlEXEORSfTM54VeqzfEbUCzeWWJa/G5l+g/cBbdILAkBopT9SZ7fUGp 60eGE4BODbS3Ex2DoOpB2OB7oj2ly3rHof7RMYHMIvrzeSTaMUalaA1FlrKwoKRc Zl6ifRLNCwOwTBszxKz51EPPBwu4A2jNIVjcbMp0EXAor4DQA9jnV03wguRn+SZa t5vV+eHlA3bGNWQ2FB+WkGu7By6ocoRYh+/4QNyWLTnAvKe86CWcUWDXlBR9A== Received: from mail.thefacebook.com ([163.114.134.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 4j7u52nygm-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Mon, 30 Nov 2026 17:07:06 -0800 (PST) Received: from localhost (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c08b:78::c78f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.56; Tue, 1 Dec 2026 01:06:57 +0000 From: Bobby Eshleman Subject: [PATCH net-next v8 0/7] vsock: assign the guest vsock device to a network namespace Date: Mon, 30 Nov 2026 17:06:48 -0800 Message-ID: <20261130-vsock-guest-ns-v8-0-5fff852d325b@meta.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAKkdDmsC/2XRy2rDQAwF0F8xs46K5u3xqv9RspiHJhmK7dbjm JSQfy+4pTX2Wpx7hfRglaZClXXNg020lFrGgXVNe2pYvPrhQlAS6xomUBhsJYeljvEdLjeqMww VEhqflebJG8tODfuYKJf7GvjGBpphoPvMzqeGXUudx+lrbVr4Ol9DHYp96MIBwTmnZSvJ+Ta89 jT7lzj2a9IiNlocVloEIBgnQ7JtTuRop+Wf5siP3RIQghRK2WhMEHKn1UYLPGgFCKisFjbmGHP caf2vOcqD1oCgWm5dcMGY0O602Wh+1AYQpJU2kjJWRtxpu9X2oC0gWNJCkHcpue3Nnz+PnejzV mqZf78bfCWIY9+XuWt8VAat0DornY0yWgVvU/AxCpNzTJQF19Zkdn4+vwH9aoiQdQIAAA== X-Change-ID: 20260831-vsock-guest-ns-d06af451da67 To: Stefano Garzarella , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , Shuah Khan , Randy Dunlap , Donald Hunter , Eric Dumazet , George Zhang , Andy King , Dmitry Torokhov , Willem de Bruijn , Eric Dumazet CC: , , , , , , , , Bobby Eshleman , Bobby Eshleman X-Mailer: b4 0.14.3 X-Proofpoint-GUID: zphK6ojwUkxBGJLtTsHHepggvFTp0zLo X-Proofpoint-ORIG-GUID: zphK6ojwUkxBGJLtTsHHepggvFTp0zLo X-Authority-Analysis: v=2.4 cv=eMmGH3p1 c=1 sm=1 tr=0 ts=6b0e1dba cx=c_pps a=CB4LiSf2rd0gKozIdrpkBw==:117 a=CB4LiSf2rd0gKozIdrpkBw==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7x6HtfJdh03M6CCDgxCd:22 a=8elwO82fXORLTBIkMd32:22 a=VwQbUJbxAAAA:8 a=VabnemYjAAAA:8 a=20KFwNOVAAAA:8 a=CwaEL1FD_NP_m3sJzAQA:9 a=QEXdDO2ut3YA:10 a=gKebqoRLp9LExxC7YDUY:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDAwNCBTYWx0ZWRfX/0i3QFO1X9Z+ UOyapdIUfo3Q9DZ4bDPw+Hl2NQcDG2XuU0h9Viu3zxXG+kXq2eRsACaTQye0dKxBlG3WfTx+gh9 TwXwMVEW0tL+BgvlrJZzQnnPhlXhUZOCuZmIBaSm90isN9ZNOV2XU5V57sZfGBzdl8qBrIR1RbA hMdTWuogl9LWnK/gIiBgx0O08e9rPltjKDDReYEVz1YQGn3qhJ3pEbcDjx3/OfmhI/XQy/FIZIW maA/rkQJ7bfiUVuDG91N2pDcAvn1925FSaZOSK/V6+VT0ea4D7oPB+UtiBMbW2ZkzlhDmGP0KDz O04uocG/82Usc2f1ROS5f8Nfi+F68XDuTCypoFn1BpWQgFx1olq2mqbuB3M9cTrGTkAyMOTrmSq knOAUTyNMhwLyN/ulhglA6JUQGAdEoORm1jnKectNlrNAtLJ07tsI318Y2wUcu6Lo8fKdV4gxY0 0FyEiu8HYMy0HHkyiyQ== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDAwNCBTYWx0ZWRfX0HJ2ogCf4FNy t3yewjXOlS9UlTUjCezKdmRQh22XrsLxc1wDnR0vVmEgyTvE0p3AvJ+6QmqTDb10OFlfkwFRCLl ogi8iNustRK0kJV4Qh6YNoI9q/qcRNU= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-30_05,2026-11-30_01,2025-10-01_01 vsock network namespaces let a host put each VM in a namespace of its own. A guest has no equivalent yet. It has a single G2H device that cannot be assigned to a network namespace. This series lets a guest move that device into a network namespace. A new generic netlink family, "vsock", supports the command VSOCK_CMD_DEV_NETNS_SET which assigns the device to the namespace given by fd or PID, or else to the namespace the request was sent from. The namespace's existing ns_mode then decides who may use it: a "global" namespace shares the device with every other global namespace, and a "local" namespace keeps the host connection to itself. The device starts out in the initial namespace, so until the command is issued global namespaces see no change, and local namespaces still cannot use it. There is no explicit unassign as assigning the device back to the initial namespace is equivalent. The command requires CAP_NET_ADMIN in the initial user namespace, so that an unprivileged user namespace cannot claim the device. Connections that can no longer reach the device after a move are reset, so that a namespace which has lost access cannot keep using a socket it opened while it still had access. They are reset the same way as when the device is removed, so to the old namespace a move looks like an unplug. The assignment holds a reference on the namespace, so deleting that namespace does not move the device; only another assignment does. Because a move looks like an unplug, swept sockets share two known issues with unplug and replug: connect() can fail with ECONNRESET and leave the socket SS_CONNECTED, and shutdown() and credit updates can still be sent once the device is reachable again. These will be addressed in a separate series. A socket swept while connect() sleeps hits the same connect() vs reset race as on unplug, which is fixed separately in net. This series builds and applies without it: https://lore.kernel.org/all/20261117-vsock-connect-close-v2-1-db5388323770@meta.com/ Transports opt in through a new netns_assign_allow flag. Only virtio-vsock sets it here, because it is the only guest transport that I am able to test against. Based off of Stefano's original series: https://lore.kernel.org/all/20200116172428.311437-1-sgarzare@redhat.com/ Suggested-by: Stefano Garzarella Link: https://lore.kernel.org/all/20200427142518.uwssa6dtasrp3bfc@steredhat/ Signed-off-by: Bobby Eshleman --- Changes in v8: - When the device moves to a netns that can no longer reach it, model the behavior after a device unplug instead of a peer RST. This simplifies the code by reusing vsock_for_each_connected_socket() and dropping the lock_sock() sweep, vsock_g2h_assign_mutex and the SOCK_DONE/peer_shutdown/TCP_CLOSING juggling - Drop cancel_pkt() of swept sockets, so purged skbs no longer leave vvs->bytes_unsent elevated (Sashiko) - Swept sockets now behave as after an unplug: recv() returns -ENOTCONN rather than EOF, and SIOCINQ may report bytes that recv() can no longer read (fixing that requires recvmsg() to drain regardless of socket state) - Fix stale comments - Rebased to latest net-next, the tap netns fix is now merged - Link to v7: https://lore.kernel.org/r/20261117-vsock-guest-ns-v7-0-7e522ea9dd9b@meta.com Changes in v7: - Post the tap netns fix separately to net: https://lore.kernel.org/all/20261116-vsock-tap-net-v1-1-7e24f45adad3@meta.com/ - Post the connect() fix separately to net: https://lore.kernel.org/all/20261117-vsock-connect-close-v2-1-db5388323770@meta.com/ - Keep swept sockets in the connected table (Sashiko). Reproduced with an ad-hoc Python test, not included as it isn't realy mergeable - Reply to VSOCK_CMD_DEV_NETNS_SET now that the return is meaningful (Sashiko) - Fail CID 2 with ENETUNREACH when the g2h device is in another netns, instead of falling back to loopback - Cancel queued packets of reset swept sockets to avoid driving a bunch of pkts into the tap device that never actually get sent - Keep swept sockets readable until drained, so that the behavior is the same as for sockets that are actually reset by a peer (and so that SIOCINQ doesn't report bytes that are never readable) - Fix stale docs and comments - Link to v6: https://lore.kernel.org/r/20261113-vsock-guest-ns-v6-0-3737ce4673c0@meta.com Changes in v6: - New patch 1: move vsock_connect_close() out of the netlink patch, since it also fixes connect() vs transport reset races (Michal) - Set swept sockets to TCP_CLOSING instead of TCP_CLOSE, as a peer RST does: they were established, and vsock_connect() handles TCP_CLOSING as such rather than as a failed connect (Sashiko) - Accept netns-fd and netns-pid attributes in VSOCK_CMD_DEV_NETNS_SET to name the target namespace, and test the netns-pid one (Stephen) - Check reachability in virtio_transport_send_pkt_info() instead of virtio_transport_send_pkt(), so RSTs from virtio_transport_reset_no_sock() reach the host after an assign (Paolo, Sashiko) - Revert the v5 change that sent the recv_listen()/recv_connecting() RSTs to the netns the packet arrived on; sock_net(sk) works again now that those RSTs skip the check - Export vsock_g2h_reachable_sk() for virtio_transport_send_pkt_info() - Rewrite the commit message of the virtio patch (Paolo) - Require setpriv only for the two privilege tests, not every ns_guest_ test (Sashiko) - Link to v5: https://lore.kernel.org/r/20261103-vsock-guest-ns-v5-0-48179b9b66b8@meta.com Changes in v5: - Rename the uapi header to linux/vsock_netlink.h (Stefano) - Drop the VSOCK_CMD_DEV_NETNS_SET reply and rely on the netlink ack (Stefano) - Keep vsock_register_mutex static, export vsock_cid_lock() and vsock_cid_unlock() for vhost_vsock_set_cid() instead (Stefano) - Replace vsock_g2h_next_unreachable() with a generic vsock_next_connected_socket() next to vsock_for_each_connected_socket(), which cannot be reused because the sweep takes lock_sock() (Stefano) - Use rcu_dereference_protected() in vsock_nl_dev_netns_fill(), drop the RCU read lock and allocate the nsid with GFP_KERNEL (Stefano) - Point to the vsock_g2h_assign_mutex comment for the lock ordering in vsock_g2h_net_assign() (Stefano) - Reverse xmas tree in vsock_dev_do_ioctl() (Stefano) - Set SOCK_DONE and peer_shutdown on swept sockets, so recv() returns EOF and send() fails with -EPIPE/-ECONNRESET instead of -ENOTCONN (Sashiko) - Only move sock->state back to SS_UNCONNECTED in vsock_connect() if it is still SS_CONNECTING, via the new vsock_connect_close(), so a socket swept while connect() sleeps cannot be connect()ed again and have vsk->trans freed under in-flight skbs (Michal) - Send the RSTs in virtio_transport_recv_listen() and virtio_transport_recv_connecting() to the netns the packet arrived on, not the socket's: after an assign the socket's netns may no longer reach the device, so the RST would be dropped by the reachability check this patch adds to virtio_transport_send_pkt() (Stefano, Sashiko) - Pick up Stefano's RoBs on patches 2 and 3 - Link to v4: https://lore.kernel.org/r/20261020-vsock-guest-ns-v4-0-047527cfccfc@meta.com Changes in v4: - All Sashiko fixes (see individual patch change lists) - Link to v3: https://lore.kernel.org/r/20261012-vsock-guest-ns-v3-0-b32447c66b23@meta.com Changes in v3: - Lots of fixes for race conditions found by local and upstream Sashiko. Sorry for the delayed reposting, it took significant time to track down and confirm that these were real issues, and come up with a decent solution for each... - Pin the assigned netns instead of returning the device to init_net when it is deleted, and refuse an assign that would make the device's CID collide with a nested H2G vhost-vsock with the same CID - Drop the idea of sending RST to the peer from the reset sweep. Sending a RST required a lock_sock, which can't be acquired underneath the vsock_table_lock. Splitting into two phases of locking opened up new races, I couldn't find a solution I was really happy with. Probably not worth the complexity - New prep patch passing the netns to ->has_remote_cid(), which is used in a later patch in the series for avoid CID collisions between nested H2G guests and the G2H device - Various fixes (see individual patch change lists for more details) - Link to v2: https://lore.kernel.org/r/20260921-vsock-guest-ns-v2-0-693bd78fde9e@meta.com Changes in v2: - Replace the IOCTL_VM_SOCKETS_ASSIGN_G2H_NETNS ioctl with the "vsock" genl family and VSOCK_CMD_DEV_NETNS_SET - RST the peer from the reset sweep, v1 only set TCP_CLOSE locally, so the peer waited on a connection the guest had abandoned (Stefano) - Drop the vsock_assign_g2h_netns helper patch, the tests use ynl cli.py - Note why only virtio-vsock opts in (Stefano) - Add a getter to the uAPI - Various fixes (see individual patch change list for more details) - Link to v1: https://lore.kernel.org/r/20260902-vsock-guest-ns-v1-0-9995383e9a8b@meta.com --- Bobby Eshleman (7): vsock: constify the transport in vsock_for_each_connected_socket() vsock: rename the vsock pernet operations vsock: pass the netns to ->has_remote_cid() vsock: add a netlink command to assign the g2h device to a netns vsock/virtio: support guest device network namespace selftests/vsock: test the guest vsock device network namespace selftests/vsock: test the netns assign privilege checks Documentation/admin-guide/sysctl/net.rst | 40 ++ Documentation/netlink/specs/vsock.yaml | 95 +++++ MAINTAINERS | 2 + drivers/vhost/vsock.c | 23 +- include/net/af_vsock.h | 20 +- include/uapi/linux/vsock_netlink.h | 30 ++ net/vmw_vsock/Makefile | 2 +- net/vmw_vsock/af_vsock.c | 489 +++++++++++++++++++++++-- net/vmw_vsock/virtio_transport.c | 32 +- net/vmw_vsock/virtio_transport_common.c | 37 +- net/vmw_vsock/vsock_nl_gen.c | 44 +++ net/vmw_vsock/vsock_nl_gen.h | 20 + tools/net/ynl/Makefile.deps | 1 + tools/testing/selftests/vsock/Makefile | 5 + tools/testing/selftests/vsock/config | 1 + tools/testing/selftests/vsock/vmtest.sh | 611 ++++++++++++++++++++++++++++++- 16 files changed, 1384 insertions(+), 68 deletions(-) --- base-commit: ac4607255f45f64654ba7dbacc26ffcdef21576f change-id: 20260831-vsock-guest-ns-d06af451da67 Best regards, -- Bobby Eshleman