From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 AC7514A33F9 for ; Wed, 1 Jul 2026 15:59:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782921597; cv=none; b=OunGiLEY27+bxql4MuiQrOQSUkuL2MNxlSzDZcDntdXYuttCW5t9D7uf5A0kQJABFJ24aYg1OWbaQe+a5nPzqrbsFvj4v/M1fLfsI1LH/957jJ7OW1Zxk2iIHTOORcVOo1bUiNDcoNYs7k5ylemZz2mCSxuVh3vg9+EXvb832nw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782921597; c=relaxed/simple; bh=/Rbzez6OSn0Ne6QpmaCrOlRbTea9JTBQjVIlOTIm5aA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kw4FbbZxuOGWoPdUHdKuplO6+Z6hPtbtYYYk/mcvKO+vzoRzVgeVSqd0GaXCPopHQ4JSuJomAAJjhlrxHPhb8icXSzvVyjlrJC3Cane3+ZCcejHWgWa+8pCOs/RBXwAzjaXpQFaQDtuplJjWhe4pexQmHSrx3Gb3Aw4wRtfdnLk= 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=XaB4qcyr; arc=none smtp.client-ip=209.85.221.41 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="XaB4qcyr" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-475cb71a4ebso808113f8f.0 for ; Wed, 01 Jul 2026 08:59:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782921594; x=1783526394; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=R0Zv4szbiOCmaSd10e4M4H4VKLp4KVo+EvzxqVVVejA=; b=XaB4qcyrhycHJLnfJYpBRlBZzXFSF0LmYIEmdWq1BZ/amKA2lKr0k5ziUyt+G04ZAh ODI2N1XHPAix78V8Lh8YBjHXJc53C1MDh+gV7q3k9qKJQI91uWqhmTx7/5/Hn5uqLH9X xi+AyxgULx/dW/uAj6gj5vI55aayWeRUTCPAtU38b6gOP18NOlqYbX3ryGP5yxLmPSei MqjcwzXLUIh6XFbhoe50yFw6SoE3kqoXYAAJ70hpMD6/39DCBVtEbxG0RIOaaTDZNaWC hr7aDhkfOFz7JlZRapSxHuwnlXu7JIjGFVMZgntFRk9cT1bKzh2wpe/wJy8akn0uz5h+ 7BJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782921594; x=1783526394; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=R0Zv4szbiOCmaSd10e4M4H4VKLp4KVo+EvzxqVVVejA=; b=HUB+G3fBbdHec5eMb/tTGGPUdyUKub6cdsip57M8zbjasOTGsuKtO+Ufmo8U+jqXZ3 +CoPGMXaBMpZRvh2Rz8cL69PgCZI+0T4a5pU1avNkNl4zN7QNLQgIN8qSLXBVVX09gCp a20fLY2wXX9JMlwwz/SuSXyp9Bw4p05pDcKTt2LGKdtM7v+xA5J23FR/Twove42UztsN GFW1lEcNajGDlJwFoNS5W8GfUhhmChCIflGlW9T0z0YYDaq1lTDapEigqbVNO7kToOvu 8lh2FyMIOVyo/XMk3OHRf+REzVwKcVcQB98ZuXvZ4oKtbUG1mog7Ui5TF8UaCFeVl/mq Cupg== X-Forwarded-Encrypted: i=1; AFNElJ9Jcsz1HXJR6E5EoaFrqZmkUR6xYW30gUR6UwMcsGC1vhfpScJR9WiRoGocvqPYRWlqKRR3JZHIS9H6g1Q=@vger.kernel.org X-Gm-Message-State: AOJu0YwJXtQwBsrM8a8DE7R1VmfKfbz4CHmcmUn4Uy1B6mmxI8lT/QNA xFVZbjSVPgT1m4nJqmyyd62CDVqrq22bGOPFUODOOm0wCKe116xkKNGM X-Gm-Gg: AfdE7cmRIg+jdJW0AahxopxwLbbPDel3o+to1vK0CpMareCioWPjJyC5UCZBwyDvuqz 9gqEAKVCL2gsFGSC0y1TRH/ep/vr+ycrCEA+UcgHU4y/UgDLq3CIJiq3elo0u3uRZVLKTNP1dqP ds8IOd7wLgU6yab1bX7p7mp8ZrWetVBrSagPkab1O+jm4ZYQTbgFIRNgdtYHQUAJkekS5fl/d6q zV2AluK0u7DtOSkA57YMbZdA5oEUmj1JlRz5HD1Y5mEJ6RSioPkGNWQXAmScTf1eAwJySNC7ww1 rAOQ7UVCicCjP7i07czh6v7lGIMtyDzy1BcMOkNDfzA8UAoOJRlrWYtYgZFjzP2pZeBY4sDIGFv 8WAFE6lrnpGmcs470sQQy+zNgfLbl2Lnj44nJV5WrHxEhuPYqprFVo6p5CILwWmZ6ExJjZBCBCd HakWy7MJ1pD5xx0oTN49GT6Y+MuqIOkL5304MRVuni1l6L7lKqyKlyqEx+hCYUdwPpqXGQ4D0= X-Received: by 2002:a05:600c:8b61:b0:493:c47f:3c55 with SMTP id 5b1f17b1804b1-493c47f3c63mr5632275e9.5.1782921593630; Wed, 01 Jul 2026 08:59:53 -0700 (PDT) Received: from mskvarla-mac.brq.redhat.com ([213.175.46.86]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493be810bafsm79724475e9.10.2026.07.01.08.59.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 01 Jul 2026 08:59:53 -0700 (PDT) From: skvarlamatus@gmail.com To: ericvh@kernel.org, lucho@ionkov.net, asmadeus@codewreck.org, linux_oss@crudebyte.com, skvarlamatus@gmail.com Cc: v9fs@lists.linux.dev, linux-kernel@vger.kernel.org, stefanha@redhat.com, sgarzare@redhat.com Subject: [PATCH v2] net/9p: add vsock transport Date: Wed, 1 Jul 2026 17:59:22 +0200 Message-ID: <20260701155922.95502-1-skvarlamatus@gmail.com> X-Mailer: git-send-email 2.47.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Matus Skvarla 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=] /mnt/point Signed-off-by: Matus Skvarla --- Changes in v2: - Add depends on NET_9P_FD to Kconfig - Use #include - 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/20260527073447.86538-1-skvarlamatus@gmail.com/ --- 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(-) diff --git a/Documentation/filesystems/9p.rst b/Documentation/filesystems/9p.rst index 3f65db648db0..d1bac30b3c9d 100644 --- a/Documentation/filesystems/9p.rst +++ b/Documentation/filesystems/9p.rst @@ -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/mount_tag files. +For server accessible over vsock (VM sockets):: + + mount -t 9p -o trans=vsock /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 diff --git a/include/net/9p/client.h b/include/net/9p/client.h index 55c6cb54bd25..c0eca56c1f5f 100644 --- a/include/net/9p/client.h +++ b/include/net/9p/client.h @@ -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; }; diff --git a/net/9p/Kconfig b/net/9p/Kconfig index 22f8c167845d..b0a6342e3475 100644 --- a/net/9p/Kconfig +++ b/net/9p/Kconfig @@ -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 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index eb685b52aeb2..3e094ece863e 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -28,6 +28,9 @@ #include #include #include +#if IS_ENABLED(CONFIG_NET_9P_VSOCK) +#include +#endif #include /* 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; } @@ -875,7 +887,7 @@ p9_fd_create_tcp(struct p9_client *client, struct fs_context *fc) const char *addr = fc->source; struct v9fs_context *ctx = fc->fs_private; int err; - char port_str[6]; + char port_str[11]; struct socket *csocket; struct sockaddr_storage stor = { 0 }; struct p9_fd_opts opts; @@ -966,6 +978,66 @@ 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 (opts.privport) { + pr_err("%s (%d): privport not supported for vsock\n", + __func__, task_pid_nr(current)); + return -EOPNOTSUPP; + } + + 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; + } + + csocket = NULL; + + client->trans_opts.vsock.port = opts.port; + err = __sock_create(fc->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; + } + + 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) { @@ -1036,6 +1108,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 @@ -1073,6 +1162,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; } @@ -1083,6 +1175,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); -- 2.47.1