Skip to contentSkip to conversation

net/9p: add vsock transport

PATCH Superseded [email protected] 4 participants 9 messages Jul 1 – Jul 3 1 message not in the archive

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net/9p: add vsock transport

From: Matus Skvarla <[email protected]>

Add vsock as a transport option for 9P client connections. This allows mounting 9P filesystems over VM sockets without requiring TCP/IP networking or additional userspace tools.

The implementation extends trans_fd.c with vsock support, reusing the existing socket infrastructure. A new p9_fd_create_vsock() function handles vsock connection setup by parsing the CID from the mount source, creating an AF_VSOCK socket, and connecting to the specified endpoint. All other transport operations (close, request, cancel) use the shared fd transport implementation.

The privport mount option is not currently supported for vsock and returns -EOPNOTSUPP if specified.

Add CONFIG_NET_9P_VSOCK option that conditionally compiles vsock support into 9pnet_fd.ko. This follows the pattern where socket-based transports (TCP, Unix, vsock) share trans_fd.c, while specialized hardware transports (virtio, xen, rdma) have dedicated files.

Usage:
mount -t 9p -o trans=vsock[,port=<port>] <CID> /mnt/point

---
Changes in v2:
- Add depends on NET_9P_FD to Kconfig
- Use #include <uapi/linux/vm_sockets.h>
- Reject privport option with -EOPNOTSUPP
- Use fc->net_ns instead of current->nsproxy->net_ns
- Widen vsock port to u32 to match sockaddr_vm.svm_port
- Widen p9_fd_opts.port to u32 and port_str buffer accordingly (in p9_fd_create_tcp())
- Add vsock to Documentation/filesystems/9p.rst
Link to v1: https://lore.kernel.org/v9fs/[email protected]/

---
 Documentation/filesystems/9p.rst | 12 +++-
 include/net/9p/client.h          | 10 +++-
 net/9p/Kconfig                   | 10 ++++
 net/9p/trans_fd.c                | 97 +++++++++++++++++++++++++++++++-
 4 files changed, 124 insertions(+), 5 deletions(-)
Documentation/filesystems/9p.rst +11 -1
index 3f65db648db0..d1bac30b3c9d 100644
@@ -50,6 +50,14 @@ mount points. Each 9P export is seen by the client as a virtio device with an
 associated "mount_tag" property. Available mount tags can be
 seen by reading /sys/bus/virtio/drivers/9pnet_virtio/virtio<n>/mount_tag files.
 
+For server accessible over vsock (VM sockets)::
+
+	mount -t 9p -o trans=vsock <CID> /mnt/9
+
+where CID is the vsock Context ID of the remote endpoint (2 for host from
+a guest VM, 3+ for guest VMs from the host). The port to connect to can be
+specified with the port option (default: 564).
+
 USBG Usage
 ==========
 
@@ -115,8 +123,10 @@ Options
 			========  ============================================
 			unix 	  specifying a named pipe mount point
 			tcp	  specifying a normal TCP/IP connection
-			fd   	  used passed file descriptors for connection
+			fd   	  uses passed file descriptors for connection
                                   (see rfdno and wfdno)
+			vsock	  connect over VM sockets (vsock) using
+				  CID as the mount source
 			virtio	  connect to the next virtio channel available
 				  (from QEMU with trans_virtio module)
 			rdma	  connect to a specified RDMA channel
include/net/9p/client.h +7 -3
index 55c6cb54bd25..c0eca56c1f5f 100644
@@ -122,8 +122,12 @@ struct p9_client {
 		struct {
 			u16 port;
 			bool privport;
-
 		} tcp;
+#if IS_ENABLED(CONFIG_NET_9P_VSOCK)
+		struct {
+			u32 port;
+		} vsock;
+#endif
 	} trans_opts;
 
 	struct idr fids;
@@ -151,13 +155,13 @@ struct p9_client_opts {
  * struct p9_fd_opts - per-transport options for fd transport
  * @rfd: file descriptor for reading (trans=fd)
  * @wfd: file descriptor for writing (trans=fd)
- * @port: port to connect to (trans=tcp)
+ * @port: port to connect to (trans=tcp, trans=vsock)
  * @privport: port is privileged
  */
 struct p9_fd_opts {
 	int rfd;
 	int wfd;
-	u16 port;
+	u32 port;
 	bool privport;
 };
 
net/9p/Kconfig +10 -0
index 22f8c167845d..b0a6342e3475 100644
@@ -32,6 +32,16 @@ config NET_9P_VIRTIO
 	  This builds support for a transports between
 	  guest partitions and a host partition.
 
+config NET_9P_VSOCK
+	depends on NET_9P_FD
+	depends on VSOCKETS
+	bool "9P VSOCK Transport"
+	help
+	  This builds support for a transport for 9pfs over
+	  virtual sockets (vsock). This is useful for communication
+	  between virtual machines and their host without requiring
+	  TCP/IP networking configuration or additional userspace software.
+
 config NET_9P_XEN
 	depends on XEN
 	select XEN_XENBUS_FRONTEND
net/9p/trans_fd.c +96 -1

145 lines not on this page · raw message

Signature · 1 line
2.47.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 47 lines · On Wed, Jul 01, 2026 at 05:59:22PM +0200, [email protected] wrote:

From: Matus Skvarla <[email protected]>

Add vsock as a transport option for 9P client connections. This allows mounting 9P filesystems over VM sockets without requiring TCP/IP networking or additional userspace tools.

The implementation extends trans_fd.c with vsock support, reusing the existing socket infrastructure. A new p9_fd_create_vsock() function handles vsock connection setup by parsing the CID from the mount source, creating an AF_VSOCK socket, and connecting to the specified endpoint. All other transport operations (close, request, cancel) use the shared fd transport implementation.

The privport mount option is not currently supported for vsock and returns -EOPNOTSUPP if specified.

Add CONFIG_NET_9P_VSOCK option that conditionally compiles vsock support into 9pnet_fd.ko. This follows the pattern where socket-based transports (TCP, Unix, vsock) share trans_fd.c, while specialized hardware transports (virtio, xen, rdma) have dedicated files.

Usage:
mount -t 9p -o trans=vsock[,port=<port>] <CID> /mnt/point

---
Changes in v2:
- Add depends on NET_9P_FD to Kconfig
- Use #include <uapi/linux/vm_sockets.h>
- Reject privport option with -EOPNOTSUPP
- Use fc->net_ns instead of current->nsproxy->net_ns
- Widen vsock port to u32 to match sockaddr_vm.svm_port
- Widen p9_fd_opts.port to u32 and port_str buffer accordingly (in p9_fd_create_tcp())
- Add vsock to Documentation/filesystems/9p.rst
Link to v1: https://lore.kernel.org/v9fs/[email protected]/

---
 Documentation/filesystems/9p.rst | 12 +++-
 include/net/9p/client.h          | 10 +++-
 net/9p/Kconfig                   | 10 ++++
 net/9p/trans_fd.c                | 97 +++++++++++++++++++++++++++++++-
 4 files changed, 124 insertions(+), 5 deletions(-)
Documentation/filesystems/9p.rst +0 -0
index 3f65db648db0..d1bac30b3c9d 100644

Documentation/filesystems/9p.rst mount points. Each 9P export is seen by the client as a virtio device with an · line 55

Quoted 6 lines
Documentation/filesystems/9p.rst +3 -0
@@ -50,6 +50,14 @@ mount points. Each 9P export is seen by the client as a virtio device with an
 associated "mount_tag" property. Available mount tags can be
 seen by reading /sys/bus/virtio/drivers/9pnet_virtio/virtio<n>/mount_tag files.
 
+For server accessible over vsock (VM sockets)::
+
+	mount -t 9p -o trans=vsock <CID> /mnt/9

If you respin this patch, please add the port= option because it is absent from this example and it could be missed if one doesn't read the paragraph below carefully:

mount -t 9p -o trans=vsock[,port=<port>] <CID> /mnt/9

Other than that:

#2 lore raw
Quoted 5 lines · On Fri, Jul 03, 2026 at 05:41 +0000, [email protected] wrote:

If you respin this patch, please add the port= option because it is absent from this example and it could be missed if one doesn't read the paragraph below carefully:

	mount -t 9p -o trans=vsock[,port=<port>] <CID> /mnt/9

My first idea was to have it there, but I removed it before submitting as I thought it would be redundant. No problem with having the port option specified in the example. I'll submit a v3 with this change.

--
Matus

A message that is not in the archive (sent off-list or not yet received): CANG_AsJtiN+31UCEZDSRX5ckq10vW-Qw7gjcBcB+feDZA7rgww@mail.gmail.com

#4 lore raw

Matúš Škvarla wrote on Fri, Jul 03, 2026 at 02:31:41PM +0200:

Quoted 6 lines

pi 3. 7. 2026 o 7:41 Stefan Hajnoczi <[email protected]> napísal(a):

Quoted 4 lines

If you respin this patch, please add the port= option because it is absent from this example and it could be missed if one doesn't read the paragraph below carefully:

Quoted 6 lines
Quoted 2 lines

mount -t 9p -o trans=vsock[,port=<port>] <CID> /mnt/9

My first idea was to have it there, but I removed it before submitting as I thought it would be redundant. No problem with having the port option specified in the example. I'll submit a v3 with this change.

If that's the only change required I can do it when applying, don't bother with a v3 just yet

(didn't check the patch itself yet, will probably take a couple of weeks...)

Signature · 1 line
Dominique Martinet | Asmadeus
#5 lore raw
Quoted 2 lines · On Fri, Jul 03, 2026 at 14:16 +0000, [email protected] wrote:

If that's the only change required I can do it when applying, don't bother with a v3 just yet

No problem Dominique, there are a couple more small changes, not only this one. I'll submit the v3 next week (probably). But there shouldn't be any more significant changes to the code.

--
Matus

Acked-by on v2 1/1
#7 lore raw
In reply to [email protected]
Quoted 13 lines · On Wed, Jul 01, 2026 at 05:59:22PM +0200, [email protected] wrote:

From: Matus Skvarla <[email protected]>

Add vsock as a transport option for 9P client connections. This allows mounting 9P filesystems over VM sockets without requiring TCP/IP networking or additional userspace tools.

The implementation extends trans_fd.c with vsock support, reusing the existing socket infrastructure. A new p9_fd_create_vsock() function handles vsock connection setup by parsing the CID from the mount source, creating an AF_VSOCK socket, and connecting to the specified endpoint. All other transport operations (close, request, cancel) use the shared fd transport implementation.

Quoted 2 lines

The privport mount option is not currently supported for vsock and returns -EOPNOTSUPP if specified.

Why not?

I'm no expert on 9p; it's just out of curiosity.

Quoted 47 lines

Add CONFIG_NET_9P_VSOCK option that conditionally compiles vsock support into 9pnet_fd.ko. This follows the pattern where socket-based transports (TCP, Unix, vsock) share trans_fd.c, while specialized hardware transports (virtio, xen, rdma) have dedicated files.

Usage:
mount -t 9p -o trans=vsock[,port=<port>] <CID> /mnt/point

---
Changes in v2:
- Add depends on NET_9P_FD to Kconfig
- Use #include <uapi/linux/vm_sockets.h>
- Reject privport option with -EOPNOTSUPP
- Use fc->net_ns instead of current->nsproxy->net_ns
- Widen vsock port to u32 to match sockaddr_vm.svm_port
- Widen p9_fd_opts.port to u32 and port_str buffer accordingly (in p9_fd_create_tcp())
- Add vsock to Documentation/filesystems/9p.rst
Link to v1: https://lore.kernel.org/v9fs/[email protected]/
---

Documentation/filesystems/9p.rst | 12 +++-
include/net/9p/client.h          | 10 +++-
net/9p/Kconfig                   | 10 ++++
net/9p/trans_fd.c                | 97 +++++++++++++++++++++++++++++++-
4 files changed, 124 insertions(+), 5 deletions(-)
Documentation/filesystems/9p.rst +0 -0
index 3f65db648db0..d1bac30b3c9d 100644
@@ -50,6 +50,14 @@ mount points. Each 9P export is seen by the client as a virtio device with an

associated "mount_tag" property. Available mount tags can be
seen by reading /sys/bus/virtio/drivers/9pnet_virtio/virtio<n>/mount_tag files.

Documentation/filesystems/9p.rst +8 -0
+For server accessible over vsock (VM sockets)::
+
+	mount -t 9p -o trans=vsock <CID> /mnt/9
+
+where CID is the vsock Context ID of the remote endpoint (2 for host from
+a guest VM, 3+ for guest VMs from the host). The port to connect to can be
+specified with the port option (default: 564).
+

USBG Usage
==========

Documentation/filesystems/9p.rst Options · line 126

Quoted 5 lines
Documentation/filesystems/9p.rst +1 -1
@@ -115,8 +123,10 @@ Options
 			========  ============================================
 			unix 	  specifying a named pipe mount point
 			tcp	  specifying a normal TCP/IP connection
-			fd   	  used passed file descriptors for connection
+			fd   	  uses passed file descriptors for connection

nit: unrelated change?

The rest LGTM, so for vsock point of view:

#8 lore raw
Quoted 4 lines · On Fri, Jul 03, 2026 at 09:12 +0000, [email protected] wrote:
Quoted 2 lines

The privport mount option is not currently supported for vsock and returns -EOPNOTSUPP if specified.

Why not?

The existing p9_bind_privport() implementation is TCP-specific (uses inet_pton and struct sockaddr_in), so it cannot be reused for vsock directly. Per Stefan Hajnoczi's suggestion, I opted to reject the option cleanly for now rather than leave it silently ignored. Support can be added in a follow-up if needed.

Quoted 4 lines

Documentation/filesystems/9p.rst Options · line 126

Quoted 2 lines
Documentation/filesystems/9p.rst +1 -1
-			fd   	  used passed file descriptors for connection
+			fd   	  uses passed file descriptors for connection

nit: unrelated change?

I noticed it as I was adding the vsock line below, but you're right, it's not related, so I'll drop it in v3.

Quoted 3 lines

The rest LGTM, so for vsock point of view:

Thank you!

--
Matus

#9 lore raw
Quoted 10 lines · On Fri, Jul 03, 2026 at 04:31:25PM +0200, [email protected] wrote:
Quoted 4 lines · On Fri, Jul 03, 2026 at 09:12 +0000, [email protected] wrote:
Quoted 2 lines

The privport mount option is not currently supported for vsock and returns -EOPNOTSUPP if specified.

Why not?

The existing p9_bind_privport() implementation is TCP-specific (uses inet_pton and struct sockaddr_in), so it cannot be reused for vsock directly. Per Stefan Hajnoczi's suggestion, I opted to reject the option cleanly for now rather than leave it silently

Ah, I see now. Sorry, I didn't look at the v1.

Quoted 1 line

ignored. Support can be added in a follow-up if needed.

I'd add a comment in the code to explain that, maybe with a TODO label. Because initially I thought it was not applicable to AF_VSOCK sockets for some reason related to he socket family.

Thanks,
Stefano