net/9p: add vsock transport
Subsystems (3)
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
@@ -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
@@ -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
@@ -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
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.cwith vsock support, reusing the existing socket infrastructure. A newp9_fd_create_vsock()function handles vsock connection setup by parsing the CID from the mount source, creating anAF_VSOCKsocket, 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
-EOPNOTSUPPif specified.Add
CONFIG_NET_9P_VSOCKoption that conditionally compiles vsock support into 9pnet_fd.ko. This follows the pattern where socket-based transports (TCP, Unix, vsock) sharetrans_fd.c, while specialized hardware transports (virtio, xen, rdma) have dedicated files.Usage:
mount -t 9p -o trans=vsock[,port=<port>] <CID>/mnt/pointSigned-off-by Matus Skvarla <[email protected]>---
Changes in v2:
- Add depends onNET_9P_FDtoKconfig
- Use #include <uapi/linux/vm_sockets.h>
- Reject privport option with-EOPNOTSUPP
- Usefc->net_nsinstead ofcurrent->nsproxy->net_ns
- Widen vsock port to u32 to match sockaddr_vm.svm_port
- Widen p9_fd_opts.port to u32 andport_strbuffer accordingly (inp9_fd_create_tcp())
- Add vsock toDocumentation/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
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:
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
Dominique Martinet
maintainerMatúš Š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/9My 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
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
Quoted 1 line · On Fri, Jul 03, 2026 at 05:41 +0000, [email protected] wrote:
Reviewed-by Stefan Hajnoczi <[email protected]>
Thanks for the review!
--
Matus
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.cwith vsock support, reusing the existing socket infrastructure. A newp9_fd_create_vsock()function handles vsock connection setup by parsing the CID from the mount source, creating anAF_VSOCKsocket, 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
-EOPNOTSUPPif specified.
Why not?
I'm no expert on 9p; it's just out of curiosity.
Quoted 47 lines
Add
CONFIG_NET_9P_VSOCKoption that conditionally compiles vsock support into 9pnet_fd.ko. This follows the pattern where socket-based transports (TCP, Unix, vsock) sharetrans_fd.c, while specialized hardware transports (virtio, xen, rdma) have dedicated files.Usage:
mount -t 9p -o trans=vsock[,port=<port>] <CID>/mnt/pointSigned-off-by Matus Skvarla <[email protected]>---
Changes in v2:
- Add depends onNET_9P_FDtoKconfig
- Use #include <uapi/linux/vm_sockets.h>
- Reject privport option with-EOPNOTSUPP
- Usefc->net_nsinstead ofcurrent->nsproxy->net_ns
- Widen vsock port to u32 to match sockaddr_vm.svm_port
- Widen p9_fd_opts.port to u32 andport_strbuffer accordingly (inp9_fd_create_tcp())
- Add vsock toDocumentation/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@@ -50,6 +50,14 @@ mount points. Each 9P export is seen by the client as a virtio device with anassociated "
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:
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
-EOPNOTSUPPif 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 connectionnit: 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
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
-EOPNOTSUPPif specified.Why not?
The existing
p9_bind_privport()implementation is TCP-specific (usesinet_ptonand structsockaddr_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