From nobody Mon Dec 1 22:36:53 2025 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 D39E631D393 for ; Thu, 27 Nov 2025 07:47:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764229674; cv=none; b=Yjrl6KTtPTTmQUa3GpoGc51tsLhTKoeST8ziVY0m0P1AhY1xOs8tAI39lftYiku/HPuNR09R61+54Nxn6qM6ZIdCIBJ+FXuxoucD8wRuBG4U7l9HBPxebB0u5jkhGyG3p0D3Z+P4bOenXvCQbSvwgTLxUeAFwrQEj1nA69HmeBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764229674; c=relaxed/simple; bh=FIt2oxmgoQb57azIqfEcz6F2qrbhumVCF150+ACSdDE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ry6VeMxUGD4DnlPWj+bUInt6aXX/7MDWmB8lMFKjrHDlFUNSXkXhCjV5vm2j7W2R6RxBFqA5OaZDS9T/+3178BusNzlifJgK6pfYLMv/rLZQAuRZCBwXEb1GHTUs/KcVlfvMiMm+px51ij3Bs/+89R4SFjBaKQBYUTa+Hle8uVw= 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=S8dmhVe9; arc=none smtp.client-ip=209.85.214.174 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="S8dmhVe9" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-297d4a56f97so8824245ad.1 for ; Wed, 26 Nov 2025 23:47:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764229667; x=1764834467; 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=tjmfflkrIQyOb2uIHthf9fdUT5FnOR2WdSUpkaHf4Lw=; b=S8dmhVe96YK9XVNIMydo3RnR8Gt4u4efKEsLV51fGmwQEAdIM//boFV1H8/LsVrACm 4Ejc+aTDiJsZxtJffDMZePlP/AeBdrjLhldUUQF3er8RkAsFInEFp6vEjANkHf/lSYCC IKPjciCzw+yRqYWPceysDaYK3rbEnp/96oMhfEjlwbhwxDzfdgX+DAzpo+lvXu4MVWQB 8lgcxQBnJds2WtaDaqI0NWACEGr0PvpG5Z4K8tIWpgFwzX2PN4nkl58DFYYsfazjtp1L +UQ0JT+aBZ5pVmd3uXcEdtpL98BoCp36pTx+rqrX4hfsODcEVbfbBlZcYY1Fkv6vLxcn D5Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764229667; x=1764834467; 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=tjmfflkrIQyOb2uIHthf9fdUT5FnOR2WdSUpkaHf4Lw=; b=J9fYWOR13ylsGdVhK+BwT2TRpK7UYiiWSKuLTWJCfcO/z0ClRBAmMgBlMI9jyn/u35 5bwvIObkoSgjWXj9uIMFE8YNzLIMcZ6LtBt2Q+q3ck5fUdb/vG/YN5uvGafGOPhjSwrC S28fxcQyfOY/gRMKYXpyR3FN0WhXr+TowguwQkYUX0L3p/sqMvJK0IgRrwwK7QKsTSJQ KGf7Cx909Mr7UbPiVA8C+Z7KRvtgAubB0TOchMpDPnyZTyzOshgqyt3ELmX66XKBak/N ODkjxoAhyJvoWkiDzf3Fy3XmOj8qGc9kfUDot7YeVXEfczV+arDu7i3jz4h9OjQLEOEg oSfA== X-Gm-Message-State: AOJu0YxwvN+3JrC8KN6Z5sNJp1+s8LZxA7YNnZZ19D3zynLMD9amG4uI s7eTgDOc36cuhS1TIR4GyyeAw0FiNhGXsLFfVWhNx4SeTNk6aBs3ZThJ X-Gm-Gg: ASbGncuhK3d1hddGodmFVUUEBKXYW3eMRzoJA11VlPmqJVfyuk6N0cEl0H9PPa17K9H uD0nBpPucO2T0FLJBZ1xS8aC7fgjFDNdOWAyQiIV0NtCCgHK3b5dmq8vyMuxWGG4ulg4SBAXxcO qRUHjpVMHiZ7hIcvBauSdM9w4L2/Ku69hH1+sY8vwKhD5UnFjgJQ1lmj+e37EH/nEXPCthNizXo EBI6UWD6mFKzW7jr6oSKc3ME9v/JLnoDWvDTpHt2GpN0g5Iq01BTtJJgaHDqdWapa5WMbo3beQH mq8MrA15zDEDURUhYNgIpjzhGWgmpWg7P3ZgtMouhfeiIPlPBQCdvnI1ETkcCdDFi9bUx3mVskj nA3Vx+k7mQt9T7SRJZreqCJ4wpFkUz3ECAbjKjHkE1LCx59IK1MdluXUDf/I2G2MAJtlSD39Oqz DQmh6NbqD335Wh1bM7DcU= X-Google-Smtp-Source: AGHT+IGzIj0RBcOTfa1PNXG+NMokMcuP8zx8upgTsaJ9DjkuXxVomM1coxobYxop1zZyF5DYgmD1nw== X-Received: by 2002:a17:903:1b30:b0:295:4936:d1e9 with SMTP id d9443c01a7336-29b6c574f5fmr244227805ad.36.1764229666887; Wed, 26 Nov 2025 23:47:46 -0800 (PST) Received: from localhost ([2a03:2880:2ff:1::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bceb5442csm8175885ad.85.2025.11.26.23.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 23:47:46 -0800 (PST) From: Bobby Eshleman Date: Wed, 26 Nov 2025 23:47:33 -0800 Subject: [PATCH net-next v12 04/12] vsock: add netns support to virtio transports 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: <20251126-vsock-vmtest-v12-4-257ee21cd5de@meta.com> References: <20251126-vsock-vmtest-v12-0-257ee21cd5de@meta.com> In-Reply-To: <20251126-vsock-vmtest-v12-0-257ee21cd5de@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 netns support to loopback and vhost. Keep netns disabled for virtio-vsock, but add necessary changes to comply with common API updates. This is the patch in the series when vhost-vsock namespaces actually come online. Hence, vhost_transport_supports_local_mode() is switched to return true. Signed-off-by: Bobby Eshleman Reviewed-by: Stefano Garzarella --- Changes in v12: - change seqpacket_allow() and stream_allow() to return true for loopback and vhost (Stefano) Changes in v11: - reorder with the skb ownership patch for loopback (Stefano) - toggle vhost_transport_supports_local_mode() to true Changes in v10: - Splitting patches complicates the series with meaningless placeholder values that eventually get replaced anyway, so to avoid that this patch combines into one. Links to previous patches here: - Link: https://lore.kernel.org/all/20251111-vsock-vmtest-v9-3-852787a37b= ed@meta.com/ - Link: https://lore.kernel.org/all/20251111-vsock-vmtest-v9-6-852787a37b= ed@meta.com/ - Link: https://lore.kernel.org/all/20251111-vsock-vmtest-v9-7-852787a37b= ed@meta.com/ - remove placeholder values (Stefano) - update comment describe net/net_mode for virtio_transport_reset_no_sock() --- drivers/vhost/vsock.c | 56 +++++++++++++++++++++-------- include/linux/virtio_vsock.h | 8 +++-- net/vmw_vsock/virtio_transport.c | 10 ++++-- net/vmw_vsock/virtio_transport_common.c | 63 ++++++++++++++++++++++++-----= ---- net/vmw_vsock/vsock_loopback.c | 19 +++++++--- 5 files changed, 118 insertions(+), 38 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 83937e1d63fa..82cb9ec09e78 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -46,6 +46,11 @@ static DEFINE_READ_MOSTLY_HASHTABLE(vhost_vsock_hash, 8); struct vhost_vsock { struct vhost_dev dev; struct vhost_virtqueue vqs[2]; + struct net *net; + netns_tracker ns_tracker; + + /* The ns mode at the time vhost_vsock was created */ + enum vsock_net_mode net_mode; =20 /* Link to global vhost_vsock_hash, writes use vhost_vsock_mutex */ struct hlist_node hash; @@ -67,7 +72,8 @@ static u32 vhost_transport_get_local_cid(void) /* Callers that dereference the return value must hold vhost_vsock_mutex o= r the * RCU read lock. */ -static struct vhost_vsock *vhost_vsock_get(u32 guest_cid) +static struct vhost_vsock *vhost_vsock_get(u32 guest_cid, struct net *net, + enum vsock_net_mode mode) { struct vhost_vsock *vsock; =20 @@ -78,9 +84,10 @@ static struct vhost_vsock *vhost_vsock_get(u32 guest_cid) if (other_cid =3D=3D 0) continue; =20 - if (other_cid =3D=3D guest_cid) + if (other_cid =3D=3D guest_cid && + vsock_net_check_mode(net, mode, vsock->net, + vsock->net_mode)) return vsock; - } =20 return NULL; @@ -269,7 +276,8 @@ static void vhost_transport_send_pkt_work(struct vhost_= work *work) } =20 static int -vhost_transport_send_pkt(struct sk_buff *skb) +vhost_transport_send_pkt(struct sk_buff *skb, struct net *net, + enum vsock_net_mode net_mode) { struct virtio_vsock_hdr *hdr =3D virtio_vsock_hdr(skb); struct vhost_vsock *vsock; @@ -278,7 +286,7 @@ vhost_transport_send_pkt(struct sk_buff *skb) rcu_read_lock(); =20 /* Find the vhost_vsock according to guest context id */ - vsock =3D vhost_vsock_get(le64_to_cpu(hdr->dst_cid)); + vsock =3D vhost_vsock_get(le64_to_cpu(hdr->dst_cid), net, net_mode); if (!vsock) { rcu_read_unlock(); kfree_skb(skb); @@ -305,7 +313,8 @@ vhost_transport_cancel_pkt(struct vsock_sock *vsk) rcu_read_lock(); =20 /* Find the vhost_vsock according to guest context id */ - vsock =3D vhost_vsock_get(vsk->remote_addr.svm_cid); + vsock =3D vhost_vsock_get(vsk->remote_addr.svm_cid, + sock_net(sk_vsock(vsk)), vsk->net_mode); if (!vsock) goto out; =20 @@ -407,6 +416,12 @@ static bool vhost_transport_msgzerocopy_allow(void) static bool vhost_transport_seqpacket_allow(struct vsock_sock *vsk, u32 remote_cid); =20 +static bool +vhost_transport_stream_allow(struct vsock_sock *vsk, u32 cid, u32 port) +{ + return true; +} + static struct virtio_transport vhost_transport =3D { .transport =3D { .module =3D THIS_MODULE, @@ -431,7 +446,7 @@ static struct virtio_transport vhost_transport =3D { .stream_has_space =3D virtio_transport_stream_has_space, .stream_rcvhiwat =3D virtio_transport_stream_rcvhiwat, .stream_is_active =3D virtio_transport_stream_is_active, - .stream_allow =3D virtio_transport_stream_allow, + .stream_allow =3D vhost_transport_stream_allow, =20 .seqpacket_dequeue =3D virtio_transport_seqpacket_dequeue, .seqpacket_enqueue =3D virtio_transport_seqpacket_enqueue, @@ -464,14 +479,12 @@ static struct virtio_transport vhost_transport =3D { static bool vhost_transport_seqpacket_allow(struct vsock_sock *vsk, u32 remote_cid) { + struct net *net =3D sock_net(sk_vsock(vsk)); struct vhost_vsock *vsock; bool seqpacket_allow =3D false; =20 - if (vsk->net_mode !=3D VSOCK_NET_MODE_GLOBAL) - return false; - rcu_read_lock(); - vsock =3D vhost_vsock_get(remote_cid); + vsock =3D vhost_vsock_get(remote_cid, net, vsk->net_mode); =20 if (vsock) seqpacket_allow =3D vsock->seqpacket_allow; @@ -542,7 +555,8 @@ static void vhost_vsock_handle_tx_kick(struct vhost_wor= k *work) if (le64_to_cpu(hdr->src_cid) =3D=3D vsock->guest_cid && le64_to_cpu(hdr->dst_cid) =3D=3D vhost_transport_get_local_cid()) - virtio_transport_recv_pkt(&vhost_transport, skb); + virtio_transport_recv_pkt(&vhost_transport, skb, + vsock->net, vsock->net_mode); else kfree_skb(skb); =20 @@ -659,6 +673,7 @@ static int vhost_vsock_dev_open(struct inode *inode, st= ruct file *file) { struct vhost_virtqueue **vqs; struct vhost_vsock *vsock; + struct net *net; int ret; =20 /* This struct is large and allocation could fail, fall back to vmalloc @@ -674,6 +689,17 @@ static int vhost_vsock_dev_open(struct inode *inode, s= truct file *file) goto out; } =20 + net =3D current->nsproxy->net_ns; + vsock->net =3D get_net_track(net, &vsock->ns_tracker, GFP_KERNEL); + + /* Store the mode of the namespace at the time of creation. If this + * namespace later changes from "global" to "local", we want this vsock + * to continue operating normally and not suddenly break. For that + * reason, we save the mode here and later use it when performing + * socket lookups with vsock_net_check_mode() (see vhost_vsock_get()). + */ + vsock->net_mode =3D vsock_net_mode(net); + vsock->guest_cid =3D 0; /* no CID assigned yet */ vsock->seqpacket_allow =3D false; =20 @@ -713,7 +739,8 @@ static void vhost_vsock_reset_orphans(struct sock *sk) */ =20 /* If the peer is still valid, no need to reset connection */ - if (vhost_vsock_get(vsk->remote_addr.svm_cid)) + if (vhost_vsock_get(vsk->remote_addr.svm_cid, sock_net(sk), + vsk->net_mode)) return; =20 /* If the close timeout is pending, let it expire. This avoids races @@ -758,6 +785,7 @@ static int vhost_vsock_dev_release(struct inode *inode,= struct file *file) virtio_vsock_skb_queue_purge(&vsock->send_pkt_queue); =20 vhost_dev_cleanup(&vsock->dev); + put_net_track(vsock->net, &vsock->ns_tracker); kfree(vsock->dev.vqs); vhost_vsock_free(vsock); return 0; @@ -784,7 +812,7 @@ static int vhost_vsock_set_cid(struct vhost_vsock *vsoc= k, u64 guest_cid) =20 /* Refuse if CID is already in use */ mutex_lock(&vhost_vsock_mutex); - other =3D vhost_vsock_get(guest_cid); + other =3D vhost_vsock_get(guest_cid, vsock->net, vsock->net_mode); if (other && other !=3D vsock) { mutex_unlock(&vhost_vsock_mutex); return -EADDRINUSE; diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h index 1845e8d4f78d..7ea264dcfff7 100644 --- a/include/linux/virtio_vsock.h +++ b/include/linux/virtio_vsock.h @@ -173,6 +173,8 @@ struct virtio_vsock_pkt_info { u32 remote_cid, remote_port; struct vsock_sock *vsk; struct msghdr *msg; + struct net *net; + enum vsock_net_mode net_mode; u32 pkt_len; u16 type; u16 op; @@ -185,7 +187,8 @@ struct virtio_transport { struct vsock_transport transport; =20 /* Takes ownership of the packet */ - int (*send_pkt)(struct sk_buff *skb); + int (*send_pkt)(struct sk_buff *skb, struct net *net, + enum vsock_net_mode net_mode); =20 /* Used in MSG_ZEROCOPY mode. Checks, that provided data * (number of buffers) could be transmitted with zerocopy @@ -280,7 +283,8 @@ virtio_transport_dgram_enqueue(struct vsock_sock *vsk, void virtio_transport_destruct(struct vsock_sock *vsk); =20 void virtio_transport_recv_pkt(struct virtio_transport *t, - struct sk_buff *skb); + struct sk_buff *skb, struct net *net, + enum vsock_net_mode net_mode); void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct sk_= buff *skb); u32 virtio_transport_get_credit(struct virtio_vsock_sock *vvs, u32 wanted); void virtio_transport_put_credit(struct virtio_vsock_sock *vvs, u32 credit= ); diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transp= ort.c index f5123810192d..3ff695740108 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -231,7 +231,8 @@ static int virtio_transport_send_skb_fast_path(struct v= irtio_vsock *vsock, struc } =20 static int -virtio_transport_send_pkt(struct sk_buff *skb) +virtio_transport_send_pkt(struct sk_buff *skb, struct net *net, + enum vsock_net_mode net_mode) { struct virtio_vsock_hdr *hdr; struct virtio_vsock *vsock; @@ -665,7 +666,12 @@ static void virtio_transport_rx_work(struct work_struc= t *work) virtio_vsock_skb_put(skb, payload_len); =20 virtio_transport_deliver_tap_pkt(skb); - virtio_transport_recv_pkt(&virtio_transport, skb); + + /* Force virtio-transport into global mode since it + * does not yet support local-mode namespacing. + */ + virtio_transport_recv_pkt(&virtio_transport, skb, + NULL, VSOCK_NET_MODE_GLOBAL); } } while (!virtqueue_enable_cb(vq)); =20 diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio= _transport_common.c index de71e2b3f77e..a818152d8b79 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -413,7 +413,7 @@ static int virtio_transport_send_pkt_info(struct vsock_= sock *vsk, =20 virtio_transport_inc_tx_pkt(vvs, skb); =20 - ret =3D t_ops->send_pkt(skb); + ret =3D t_ops->send_pkt(skb, info->net, info->net_mode); if (ret < 0) break; =20 @@ -527,6 +527,8 @@ static int virtio_transport_send_credit_update(struct v= sock_sock *vsk) struct virtio_vsock_pkt_info info =3D { .op =3D VIRTIO_VSOCK_OP_CREDIT_UPDATE, .vsk =3D vsk, + .net =3D sock_net(sk_vsock(vsk)), + .net_mode =3D vsk->net_mode, }; =20 return virtio_transport_send_pkt_info(vsk, &info); @@ -1067,6 +1069,8 @@ int virtio_transport_connect(struct vsock_sock *vsk) struct virtio_vsock_pkt_info info =3D { .op =3D VIRTIO_VSOCK_OP_REQUEST, .vsk =3D vsk, + .net =3D sock_net(sk_vsock(vsk)), + .net_mode =3D vsk->net_mode, }; =20 return virtio_transport_send_pkt_info(vsk, &info); @@ -1082,6 +1086,8 @@ int virtio_transport_shutdown(struct vsock_sock *vsk,= int mode) (mode & SEND_SHUTDOWN ? VIRTIO_VSOCK_SHUTDOWN_SEND : 0), .vsk =3D vsk, + .net =3D sock_net(sk_vsock(vsk)), + .net_mode =3D vsk->net_mode, }; =20 return virtio_transport_send_pkt_info(vsk, &info); @@ -1108,6 +1114,8 @@ virtio_transport_stream_enqueue(struct vsock_sock *vs= k, .msg =3D msg, .pkt_len =3D len, .vsk =3D vsk, + .net =3D sock_net(sk_vsock(vsk)), + .net_mode =3D vsk->net_mode, }; =20 return virtio_transport_send_pkt_info(vsk, &info); @@ -1145,6 +1153,8 @@ static int virtio_transport_reset(struct vsock_sock *= vsk, .op =3D VIRTIO_VSOCK_OP_RST, .reply =3D !!skb, .vsk =3D vsk, + .net =3D sock_net(sk_vsock(vsk)), + .net_mode =3D vsk->net_mode, }; =20 /* Send RST only if the original pkt is not a RST pkt */ @@ -1156,9 +1166,14 @@ static int virtio_transport_reset(struct vsock_sock = *vsk, =20 /* Normally packets are associated with a socket. There may be no socket = if an * attempt was made to connect to a socket that does not exist. + * + * net and net_mode refer to the namespace of whoever sent the invalid mes= sage. + * For loopback, this is the namespace of the socket. For vhost, this is t= he + * namespace of the VM (i.e., vhost_vsock). */ static int virtio_transport_reset_no_sock(const struct virtio_transport *t, - struct sk_buff *skb) + struct sk_buff *skb, struct net *net, + enum vsock_net_mode net_mode) { struct virtio_vsock_hdr *hdr =3D virtio_vsock_hdr(skb); struct virtio_vsock_pkt_info info =3D { @@ -1171,6 +1186,13 @@ static int virtio_transport_reset_no_sock(const stru= ct virtio_transport *t, * sock_net(sk) until the reply skb is freed. */ .vsk =3D vsock_sk(skb->sk), + + /* net or net_mode are not defined here because we pass + * net and net_mode directly to t->send_pkt(), instead of + * relying on virtio_transport_send_pkt_info() to pass them to + * t->send_pkt(). They are not needed by + * virtio_transport_alloc_skb(). + */ }; struct sk_buff *reply; =20 @@ -1189,7 +1211,7 @@ static int virtio_transport_reset_no_sock(const struc= t virtio_transport *t, if (!reply) return -ENOMEM; =20 - return t->send_pkt(reply); + return t->send_pkt(reply, net, net_mode); } =20 /* This function should be called with sk_lock held and SOCK_DONE set */ @@ -1471,6 +1493,8 @@ virtio_transport_send_response(struct vsock_sock *vsk, .remote_port =3D le32_to_cpu(hdr->src_port), .reply =3D true, .vsk =3D vsk, + .net =3D sock_net(sk_vsock(vsk)), + .net_mode =3D vsk->net_mode, }; =20 return virtio_transport_send_pkt_info(vsk, &info); @@ -1513,12 +1537,14 @@ virtio_transport_recv_listen(struct sock *sk, struc= t sk_buff *skb, int ret; =20 if (le16_to_cpu(hdr->op) !=3D VIRTIO_VSOCK_OP_REQUEST) { - virtio_transport_reset_no_sock(t, skb); + virtio_transport_reset_no_sock(t, skb, sock_net(sk), + vsk->net_mode); return -EINVAL; } =20 if (sk_acceptq_is_full(sk)) { - virtio_transport_reset_no_sock(t, skb); + virtio_transport_reset_no_sock(t, skb, sock_net(sk), + vsk->net_mode); return -ENOMEM; } =20 @@ -1526,13 +1552,15 @@ virtio_transport_recv_listen(struct sock *sk, struc= t sk_buff *skb, * Subsequent enqueues would lead to a memory leak. */ if (sk->sk_shutdown =3D=3D SHUTDOWN_MASK) { - virtio_transport_reset_no_sock(t, skb); + virtio_transport_reset_no_sock(t, skb, sock_net(sk), + vsk->net_mode); return -ESHUTDOWN; } =20 child =3D vsock_create_connected(sk); if (!child) { - virtio_transport_reset_no_sock(t, skb); + virtio_transport_reset_no_sock(t, skb, sock_net(sk), + vsk->net_mode); return -ENOMEM; } =20 @@ -1554,7 +1582,8 @@ virtio_transport_recv_listen(struct sock *sk, struct = sk_buff *skb, */ if (ret || vchild->transport !=3D &t->transport) { release_sock(child); - virtio_transport_reset_no_sock(t, skb); + virtio_transport_reset_no_sock(t, skb, sock_net(sk), + vsk->net_mode); sock_put(child); return ret; } @@ -1582,7 +1611,8 @@ static bool virtio_transport_valid_type(u16 type) * lock. */ void virtio_transport_recv_pkt(struct virtio_transport *t, - struct sk_buff *skb) + struct sk_buff *skb, struct net *net, + enum vsock_net_mode net_mode) { struct virtio_vsock_hdr *hdr =3D virtio_vsock_hdr(skb); struct sockaddr_vm src, dst; @@ -1605,24 +1635,25 @@ void virtio_transport_recv_pkt(struct virtio_transp= ort *t, le32_to_cpu(hdr->fwd_cnt)); =20 if (!virtio_transport_valid_type(le16_to_cpu(hdr->type))) { - (void)virtio_transport_reset_no_sock(t, skb); + (void)virtio_transport_reset_no_sock(t, skb, net, net_mode); goto free_pkt; } =20 /* The socket must be in connected or bound table * otherwise send reset back */ - sk =3D vsock_find_connected_socket(&src, &dst); + sk =3D vsock_find_connected_socket_net(&src, &dst, net, net_mode); if (!sk) { - sk =3D vsock_find_bound_socket(&dst); + sk =3D vsock_find_bound_socket_net(&dst, net, net_mode); if (!sk) { - (void)virtio_transport_reset_no_sock(t, skb); + (void)virtio_transport_reset_no_sock(t, skb, net, + net_mode); goto free_pkt; } } =20 if (virtio_transport_get_type(sk) !=3D le16_to_cpu(hdr->type)) { - (void)virtio_transport_reset_no_sock(t, skb); + (void)virtio_transport_reset_no_sock(t, skb, net, net_mode); sock_put(sk); goto free_pkt; } @@ -1641,7 +1672,7 @@ void virtio_transport_recv_pkt(struct virtio_transpor= t *t, */ if (sock_flag(sk, SOCK_DONE) || (sk->sk_state !=3D TCP_LISTEN && vsk->transport !=3D &t->transport)) { - (void)virtio_transport_reset_no_sock(t, skb); + (void)virtio_transport_reset_no_sock(t, skb, net, net_mode); release_sock(sk); sock_put(sk); goto free_pkt; @@ -1673,7 +1704,7 @@ void virtio_transport_recv_pkt(struct virtio_transpor= t *t, kfree_skb(skb); break; default: - (void)virtio_transport_reset_no_sock(t, skb); + (void)virtio_transport_reset_no_sock(t, skb, net, net_mode); kfree_skb(skb); break; } diff --git a/net/vmw_vsock/vsock_loopback.c b/net/vmw_vsock/vsock_loopback.c index afad27cf533a..aef44d1631c3 100644 --- a/net/vmw_vsock/vsock_loopback.c +++ b/net/vmw_vsock/vsock_loopback.c @@ -26,7 +26,8 @@ static u32 vsock_loopback_get_local_cid(void) return VMADDR_CID_LOCAL; } =20 -static int vsock_loopback_send_pkt(struct sk_buff *skb) +static int vsock_loopback_send_pkt(struct sk_buff *skb, struct net *net, + enum vsock_net_mode net_mode) { struct vsock_loopback *vsock =3D &the_vsock_loopback; int len =3D skb->len; @@ -48,6 +49,13 @@ static int vsock_loopback_cancel_pkt(struct vsock_sock *= vsk) =20 static bool vsock_loopback_seqpacket_allow(struct vsock_sock *vsk, u32 remote_cid); + +static bool vsock_loopback_stream_allow(struct vsock_sock *vsk, u32 cid, + u32 port) +{ + return true; +} + static bool vsock_loopback_msgzerocopy_allow(void) { return true; @@ -77,7 +85,7 @@ static struct virtio_transport loopback_transport =3D { .stream_has_space =3D virtio_transport_stream_has_space, .stream_rcvhiwat =3D virtio_transport_stream_rcvhiwat, .stream_is_active =3D virtio_transport_stream_is_active, - .stream_allow =3D virtio_transport_stream_allow, + .stream_allow =3D vsock_loopback_stream_allow, =20 .seqpacket_dequeue =3D virtio_transport_seqpacket_dequeue, .seqpacket_enqueue =3D virtio_transport_seqpacket_enqueue, @@ -110,7 +118,7 @@ static struct virtio_transport loopback_transport =3D { static bool vsock_loopback_seqpacket_allow(struct vsock_sock *vsk, u32 remote_cid) { - return vsk->net_mode =3D=3D VSOCK_NET_MODE_GLOBAL; + return true; } =20 static void vsock_loopback_work(struct work_struct *work) @@ -132,7 +140,10 @@ static void vsock_loopback_work(struct work_struct *wo= rk) */ virtio_transport_consume_skb_sent(skb, false); virtio_transport_deliver_tap_pkt(skb); - virtio_transport_recv_pkt(&loopback_transport, skb); + + virtio_transport_recv_pkt(&loopback_transport, skb, + sock_net(skb->sk), + vsock_sk(skb->sk)->net_mode); } } =20 --=20 2.47.3