net/9p: add vsock transport
Subsystems (2)
PATCH 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.
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
--- include/net/9p/client.h | 6 ++- net/9p/Kconfig | 9 +++++ net/9p/trans_fd.c | 89 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-)
include/net/9p/client.h +5 -1
@@ -122,8 +122,12 @@ struct p9_client {struct {u16 port;bool privport; - } tcp; +#if IS_ENABLED (CONFIG_NET_9P_VSOCK ) +struct { +u16 port; + } vsock; +#endif } trans_opts;struct idr fids;
net/9p/Kconfig +9 -0
@@ -32,6 +32,15 @@ config NET_9P_VIRTIO This builds support for a transports between guest partitions and a host partition. +config NET_9P_VSOCK + 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 +89 -0
131 lines not on this page · raw message
Signature · 1 line
2.47.1
Quoted 51 lines · On Wed, May 27, 2026 at 09:34:47AM +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.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]>--- include/net/9p/client.h | 6 ++- net/9p/Kconfig | 9 +++++ net/9p/trans_fd.c | 89 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-)include/net/9p/client.h +5
-1@@ -122,8 +122,12 @@ struct p9_client {struct {u16 port;bool privport; - } tcp; +#if IS_ENABLED (CONFIG_NET_9P_VSOCK ) +struct { +u16 port; + } vsock; +#endif } trans_opts;struct idr fids;net/9p/Kconfig +0
-0
net/9p/Kconfig config NET_9P_VIRTIO · line 36
Quoted 5 lines
net/9p/Kconfig +2
-0@@ -32,6 +32,15 @@ config NET_9P_VIRTIO This builds support for a transports between guest partitions and a host partition. +config NET_9P_VSOCK + depends on VSOCKETS
This must depend on NET_9P_FD too.
net/9p/Kconfig config NET_9P_VIRTIO · line 42
Quoted 6 lines
net/9p/Kconfig +6
-0+ 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.
The way that trans_fd.c is structured right now still requires CONFIG_INET and CONFIG_UNIX even if you only want the VSOCK transport. If someone wanted to build a really minimal kernel in the future, then it would be necessary to separate some of the code. This is not a serious issue since TCP/IP and UNIX domain sockets are very standard kernel features that most systems cannot do without, but I wanted to mention it.
Quoted 9 lines
net/9p/Kconfig +1
-0+ config NET_9P_XEN depends on XEN select XEN_XENBUS_FRONTENDnet/9p/trans_fd.c +0
-0
net/9p/trans_fd.c line 33
Quoted 6 lines
net/9p/trans_fd.c +3
-0@@ -28,6 +28,9 @@#include <net/9p/9p.h> #include <net/9p/client.h> #include <net/9p/transport.h> +#if IS_ENABLED (CONFIG_NET_9P_VSOCK ) +#include <linux/vm_sockets.h> +#endif
Kernel code uses #include <uapi/linux/vm_sockets.h> rather than the userspace <linux/vm_sockets.h> include path:
$ git grep vm_sockets.h ... include/net/af_vsock.h:#include <uapi/linux/vm_sockets.h> include/net/vsock_addr.h:#include <uapi/linux/vm_sockets.h> net/vmw_vsock/af_vsock.c:#include <uapi/linux/vm_sockets.h> ...
Quoted 55 lines
net/9p/trans_fd.c +34
-0#include <linux/syscalls.h> /* killme */ @@ -36,6 +39,9 @@static struct p9_trans_module p9_tcp_trans;static struct p9_trans_module p9_fd_trans; +#if IS_ENABLED (CONFIG_NET_9P_VSOCK ) +static struct p9_trans_module p9_vsock_trans; +#endif enum { Rworksched =1 ,/* read work scheduled or running */ @@ -714,6 +720,12 @@ static int p9_fd_show_options(struct seq_file *m, struct p9_client *clnt)if (clnt->trans_opts.fd.wfd != ~0 )seq_printf (m,",wfd=%u" , clnt->trans_opts.fd.wfd); } +#if IS_ENABLED (CONFIG_NET_9P_VSOCK ) + else if (clnt->trans_mod == &p9_vsock_trans) { +if (clnt->trans_opts.vsock.port !=P9_FD_PORT ) +seq_printf (m,",port=%u" , clnt->trans_opts.vsock.port); + } +#endif return 0 ; }@@ -968,6 +980,60 @@ p9_fd_create_unix(struct p9_client *client, struct fs_context *fc)return p9_socket_open (client, csocket); } +#if IS_ENABLED (CONFIG_NET_9P_VSOCK ) +static int +p9_fd_create_vsock (struct p9_client *client,struct fs_context *fc) +{ +const char *addr = fc->source; +struct v9fs_context *ctx = fc->fs_private; +int err; +struct socket *csocket; +struct sockaddr_vm addr_vm = {0 }; +struct p9_fd_opts opts; +unsigned int cid; + +/* opts are already parsed in context */ + opts = ctx->fd_opts; + +if (!addr) +return -EINVAL ; + + err =kstrtouint (addr,10 , &cid); +if (err <0 ) { +pr_err ("%s (%d): invalid CID: %s\n" , + __func__,task_pid_nr (current), addr); +return err; + } +
net/9p/trans_fd.c p9_fd_create_unix(struct p9_client *client, struct fs_context *fc) · line 1017
Quoted 10 lines
net/9p/trans_fd.c +10
-0+ csocket =NULL ; + + client->trans_opts.vsock.port = opts.port; + err =__sock_create (current->nsproxy->net_ns,AF_VSOCK , +SOCK_STREAM ,0 , &csocket,1 ); +if (err) { +pr_err ("%s (%d): problem creating socket\n" , + __func__,task_pid_nr (current)); +return err; + }
AF_VSOCK reserves ports below 1024 for privileged processes. It probably makes sense to implement the same privport option that TCP and RDMA also support. If you don't want to implement that, then enabling the privport option should cause an error here.
Quoted 69 lines
net/9p/trans_fd.c +42
-0+ + addr_vm.svm_family =AF_VSOCK ; + addr_vm.svm_port = opts.port; + addr_vm.svm_cid = cid; + + err =READ_ONCE (csocket->ops)->connect (csocket, + (struct sockaddr_unsized *)&addr_vm, +sizeof (addr_vm),0 ); +if (err <0 ) { +pr_err ("%s (%d): problem connecting socket to %s:%u\n" , + __func__,task_pid_nr (current), addr, opts.port); +sock_release (csocket); +return err; + } + + return p9_socket_open(client, csocket); +} +#endif /* CONFIG_NET_9P_VSOCK */ +static int p9_fd_create (struct p9_client *client,struct fs_context *fc) {@@ -1038,6 +1104,23 @@ static struct p9_trans_module p9_fd_trans = { };MODULE_ALIAS_9P ("fd" ); +#if IS_ENABLED (CONFIG_NET_9P_VSOCK ) +static struct p9_trans_module p9_vsock_trans = { + .name ="vsock" , + .maxsize =MAX_SOCK_BUF , + .def = false, + .supports_vmalloc = true, + .create = p9_fd_create_vsock, + .close = p9_fd_close, + .request = p9_fd_request, + .cancel = p9_fd_cancel, + .cancelled = p9_fd_cancelled, + .show_options = p9_fd_show_options, + .owner =THIS_MODULE , +}; +MODULE_ALIAS_9P ("vsock" ); +#endif +/** * p9_poll_workfn - poll worker thread * @work: work queue @@ -1075,6 +1158,9 @@ static int __init p9_trans_fd_init(void)v9fs_register_trans (&p9_tcp_trans);v9fs_register_trans (&p9_unix_trans);v9fs_register_trans (&p9_fd_trans); +#if IS_ENABLED (CONFIG_NET_9P_VSOCK ) +v9fs_register_trans (&p9_vsock_trans); +#endif return 0 ; }@@ -1085,6 +1171,9 @@ static void __exit p9_trans_fd_exit(void)v9fs_unregister_trans (&p9_tcp_trans);v9fs_unregister_trans (&p9_unix_trans);v9fs_unregister_trans (&p9_fd_trans); +#if IS_ENABLED (CONFIG_NET_9P_VSOCK ) +v9fs_unregister_trans (&p9_vsock_trans); +#endif }module_init (p9_trans_fd_init);Signature · 1 line
2.47.1
Dominique Martinet
maintainer[email protected] wrote on Wed, May 27, 2026 at 09:34:47AM +0200:
Quoted 18 lines
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.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.
Quoted 4 lines
Usage:
mount -t 9p -o trans=vsock[,port=<port>] <CID>/mnt/pointSigned-off-by Matus Skvarla <[email protected]>
In addition to Stefan's comments there are a few valid remarks from sashiko.dev (e.g. port number being truncated); please have a look
https://sashiko.dev/#/patchset/20260527073447.86538-1-skvarlamatus%40gmail.com
Signature · 1 line
Dominique
Thank you all for reviewing this patch and sorry for the late reply. I am already working on a v2.
I wanted to ask you about your opinions on the issue with port number truncation. The port number is parsed from mount options as u16, which is sufficient for TCP, but vsock uses u32.
I see two ways to resolve this. One is adding a new command line option for vsock only that would be stored in a u32. The other is changing the type of the port variable to u32, and adding a range check for TCP.
Personally, I would lean towards the second option.
--
Matus
Dominique Martinet
maintainer[email protected] wrote on Thu, Jun 25, 2026 at 05:16:36PM +0200:
Quoted 10 lines
I wanted to ask you about your opinions on the issue with port number truncation. The port number is parsed from mount options as u16, which is sufficient for TCP, but vsock uses u32.
I see two ways to resolve this. One is adding a new command line option for vsock only that would be stored in a u32. The other is changing the type of the port variable to u32, and adding a range check for TCP.
Personally, I would lean towards the second option.
Actually the port is already parsed as u32 and silently truncated, so you don't need to worry too much about it (I just tried mounting with port=0x120235 and it mounted on port 0x234=564 successfully)
We can add a check for tcp/rdma truncation later if someone complains about it, just make the vsock port type u32
Signature · 1 line
Dominique Martinet | Asmadeus