On Thu, Nov 06, 2025 at 05:18:36PM +0100, Stefano Garzarella wrote:
On Thu, Oct 23, 2025 at 11:27:44AM -0700, Bobby Eshleman wrote:
From: Bobby Eshleman bobbyeshleman@meta.com
Add NS support to vsock loopback. Sockets in a global mode netns communicate with each other, regardless of namespace. Sockets in a local mode netns may only communicate with other sockets within the same namespace.
Use pernet_ops to install a vsock_loopback for every namespace that is created (to be used if local mode is enabled).
Retroactively call init/exit on every namespace when the vsock_loopback module is loaded in order to initialize the per-ns device.
Signed-off-by: Bobby Eshleman bobbyeshleman@meta.com
I'm a bit confused, should we move this after the next patch that add support of netns in the virtio common module?
Or this is a pre-requisite?
Yes let's do that, it does need common.
[...]
#endif /* __NET_NET_NAMESPACE_VSOCK_H */ diff --git a/net/vmw_vsock/vsock_loopback.c b/net/vmw_vsock/vsock_loopback.c index a8f218f0c5a3..474083d4cfcb 100644 --- a/net/vmw_vsock/vsock_loopback.c +++ b/net/vmw_vsock/vsock_loopback.c @@ -28,8 +28,16 @@ static u32 vsock_loopback_get_local_cid(void)
static int vsock_loopback_send_pkt(struct sk_buff *skb) {
- struct vsock_loopback *vsock = &the_vsock_loopback;
- struct vsock_loopback *vsock; int len = skb->len;
- struct net *net;
- net = virtio_vsock_skb_net(skb);
- if (virtio_vsock_skb_net_mode(skb) == VSOCK_NET_MODE_LOCAL)
vsock = (struct vsock_loopback *)net->vsock.priv;Is there some kind of refcount on the net? What I mean is, are we sure this pointer is still valid? Could the net disappear in the meantime?
I only considered the case of net being removed, which I think is okay because user sockets take a net reference in sk_alloc(), and we can't reach this point after the sock is destroyed and the reference is released because the transport will be unassigned prior.
But... I'm now realizing there is the case of virtio_transport_reset_no_sock() where skb net is null. I can't see why that wouldn't be possible for loopback?
Let's handle that case to be sure...
The rest LGTM!
Thanks, Stefano
Best, Bobby