From: Bobby Eshleman <bobbyeshleman@meta.com>
To: "Stefano Garzarella" <sgarzare@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowangio@gmail.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Shuah Khan" <shuah@kernel.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Donald Hunter" <donald.hunter@gmail.com>,
"Eric Dumazet" <edumazet@kernel.org>,
"Eric Dumazet" <edumazet@kernel.org>
Cc: <virtualization@lists.linux.dev>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-doc@vger.kernel.org>,
<kvm@vger.kernel.org>, <linux-kselftest@vger.kernel.org>,
<sargun@sargun.me>, <jlinbox@meta.com>,
Bobby Eshleman <bobbyeshleman@gmail.com>,
Bobby Eshleman <bobbyeshleman@meta.com>
Subject: [PATCH net-next v4 0/7] vsock: assign the guest vsock device to a network namespace
Date: Tue, 20 Oct 2026 18:15:03 -0700 [thread overview]
Message-ID: <20261020-vsock-guest-ns-v4-0-047527cfccfc@meta.com> (raw)
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 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 nothing has moved and no mode has changed. 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. The assignment holds a reference on
the namespace, so deleting that namespace does not move the device; only
another assignment does.
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 <sgarzare@redhat.com>
Link: https://lore.kernel.org/all/20200427142518.uwssa6dtasrp3bfc@steredhat/
Signed-off-by: Bobby Eshleman <bobbyeshleman@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 | 42 +++
Documentation/netlink/specs/vsock.yaml | 75 +++++
MAINTAINERS | 2 +
drivers/vhost/vsock.c | 23 +-
include/net/af_vsock.h | 17 +-
include/uapi/linux/vsock.h | 28 ++
net/vmw_vsock/Makefile | 2 +-
net/vmw_vsock/af_vsock.c | 501 ++++++++++++++++++++++++++--
net/vmw_vsock/virtio_transport.c | 34 +-
net/vmw_vsock/virtio_transport_common.c | 18 +-
net/vmw_vsock/vsock_nl_gen.c | 36 ++
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 | 550 ++++++++++++++++++++++++++++++-
16 files changed, 1299 insertions(+), 56 deletions(-)
---
base-commit: 599d0e97610f09162d84c4ede4164628c066921e
change-id: 20260831-vsock-guest-ns-d06af451da67
Best regards,
--
Bobby Eshleman <bobbyeshleman@meta.com>
next reply other threads:[~2026-10-21 1:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 1:15 Bobby Eshleman [this message]
2026-10-21 1:15 ` [PATCH net-next v4 1/7] vsock: constify the transport in vsock_for_each_connected_socket() Bobby Eshleman
2026-10-21 1:15 ` [PATCH net-next v4 2/7] vsock: rename the vsock pernet operations Bobby Eshleman
2026-10-21 10:11 ` Stefano Garzarella
2026-10-21 1:15 ` [PATCH net-next v4 3/7] vsock: pass the netns to ->has_remote_cid() Bobby Eshleman
2026-10-21 10:14 ` Stefano Garzarella
2026-10-21 1:15 ` [PATCH net-next v4 4/7] vsock: add a netlink command to assign the g2h device to a netns Bobby Eshleman
2026-10-21 1:15 ` [PATCH net-next v4 5/7] vsock/virtio: support guest device network namespace Bobby Eshleman
2026-10-21 1:15 ` [PATCH net-next v4 6/7] selftests/vsock: test the guest vsock " Bobby Eshleman
2026-10-21 1:15 ` [PATCH net-next v4 7/7] selftests/vsock: test the netns assign privilege checks Bobby Eshleman
2026-10-21 1:35 ` [PATCH net-next v4 0/7] vsock: assign the guest vsock device to a network namespace Jakub Kicinski
2026-10-21 9:48 ` Stefano Garzarella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261020-vsock-guest-ns-v4-0-047527cfccfc@meta.com \
--to=bobbyeshleman@meta.com \
--cc=bobbyeshleman@gmail.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@kernel.org \
--cc=eperezma@redhat.com \
--cc=horms@kernel.org \
--cc=jasowangio@gmail.com \
--cc=jlinbox@meta.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=sargun@sargun.me \
--cc=sgarzare@redhat.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®