fs: Add 9P filesystem support over virtio
Subsystems (4)
v2 cover fs: Add 9P filesystem support over virtio
Add 9P network filesystem support to U-Boot.
It allows U-Boot to directly mount host directories in virtualization environments via virtio.
The functionality has been verified on qemu arm64 by successfully loading a Linux kernel image and an initramfs image via 9P, and booting to the Linux shell.
To test with QEMU:
-fsdev local,id=fsdev0,path=/path/to/host/dir,security_model=none \
-device virtio-9p-device,fsdev=fsdev0,mount_tag=rootfs
U-Boot usage:
=> virtio scan
=> ls 9p rootfs /
=> ls 9p 0 /
=> ls 9p - /
=> load 9p rootfs $kernel_addr_r /Image
=> load 9p rootfs $ramdisk_addr_r /initramfs.cpio
=> booti $kernel_addr_r $ramdisk_addr_r:$filesize $fdtcontroladdr
Changes in v2:
- Introduce DM UCLASS_9P and dm_p9_ops for transport devices.
- Support selecting devices by mount tag, sequence index, or default.
- Integrate 9p into disk/part.c and generic VFS null_dev_desc handling.
- Consistently use 9P2000.L naming across subjects, code, and Kconfig.
- Add kerneldoc comments and separate filesystem header.
- Add timeout handling, feature negotiation, and remove callback.
- Add 9P documentation.
- Add automated pytest and enable in qemu_arm64_defconfig.
- Fix error checking, bounds checks, and memory leaks.
Kuan-Wei Chiu (6):
net: 9p: Add 9P2000.L protocol support
fs: 9p: Add 9P filesystem support
virtio: 9p: Add 9P transport driver
doc: 9p: Add 9P filesystem documentation
test: 9p: Add test for 9P filesystem
MAINTAINERS: Add entry for 9PFS
MAINTAINERS | 11 + configs/qemu_arm64_defconfig | 3 + disk/part.c | 16 ++ doc/usage/filesystems/9p.rst | 55 +++++ doc/usage/index.rst | 1 + drivers/virtio/Kconfig | 7 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio-uclass.c | 1 + drivers/virtio/virtio_9p.c | 119 ++++++++++ fs/9p/9p.c | 185 +++++++++++++++ fs/9p/Kconfig | 8 + fs/9p/Makefile | 5 + fs/Kconfig | 2 + fs/Makefile | 1 + fs/fs.c | 25 ++ include/9p.h | 203 ++++++++++++++++ include/9pfs.h | 60 +++++ include/dm/uclass-id.h | 1 + include/fs.h | 1 + include/virtio.h | 12 +- net/9p/Kconfig | 5 + net/9p/Makefile | 5 + net/9p/client.c | 408 +++++++++++++++++++++++++++++++++ net/Kconfig | 2 + net/Makefile | 1 + test/py/tests/test_9p.py | 82 +++++++ 26 files changed, 1219 insertions(+), 1 deletion(-) create mode 100644 doc/usage/filesystems/9p.rst create mode 100644 drivers/virtio/virtio_9p.c create mode 100644 fs/9p/9p.c create mode 100644 fs/9p/Kconfig create mode 100644 fs/9p/Makefile create mode 100644 include/9p.h create mode 100644 include/9pfs.h create mode 100644 net/9p/Kconfig create mode 100644 net/9p/Makefile create mode 100644 net/9p/client.c create mode 100644 test/py/tests/test_9p.py
Signature · 1 line
2.55.0.897.gb25b4bd76c-goog
PATCH v2 1/6 net: 9p: Add 9P2000.L protocol support
Introduce the core 9P network protocol client implementation.
9P is a network filesystem protocol originally developed for the Plan 9 operating system. Add the baseline 9P2000.L protocol handling, including message serialization, DM UCLASS_9P transport management, and basic transport operations.
---
Changes in v2:
- Consistently use 9P2000.L instead of 9P2000 in subject and Kconfig.
- Add kerneldoc comments in include/9p.h.
- Move filesystem declarations to include/9pfs.h.
- Add LOG_CATEGORY and drop #include <config.h>.
- Return -ecode from P9_RLERROR in p9_check_error().
- Check memalign() return for NULL and return -ENOMEM.
- Parse server msize and version string in Rversion.
- Check return value of strlcpy() in p9_client_walk().
- Check nwqid == nwname in Rwalk reply.
- Validate count <= read_len before memcpy in read/readdir.
- Implement DM UCLASS_9P.
--- include/9p.h | 203 ++++++++++++++++++++ include/dm/uclass-id.h | 1 + net/9p/Kconfig | 5 + net/9p/Makefile | 5 + net/9p/client.c | 408 +++++++++++++++++++++++++++++++++++++++++ net/Kconfig | 2 + net/Makefile | 1 + 7 files changed, 625 insertions(+) create mode 100644 include/9p.h create mode 100644 net/9p/Kconfig create mode 100644 net/9p/Makefile create mode 100644 net/9p/client.c
include/9p.h new file +203 -0
@@ -0,0 +1,203 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (C) 2026, Kuan-Wei Chiu <[email protected]> +*/ + +#ifndef __9P_H__ +#define __9P_H__ + +#include <linux/types.h> + +#define P9_MSIZE 65536 +#define P9_NOFID (~0U) +#define P9_NOTAG 0xFFFF +#define P9_REQ_TAG 1 + +#define P9_RLERROR 7 +#define P9_TLOPEN 12 +#define P9_RLOPEN 13 +#define P9_TGETATTR 24 +#define P9_RGETATTR 25 +#define P9_TREADDIR 40 +#define P9_RREADDIR 41 +#define P9_TVERSION 100 +#define P9_RVERSION 101 +#define P9_TATTACH 104 +#define P9_RATTACH 105 +#define P9_TWALK 110 +#define P9_RWALK 111 +#define P9_TREAD 116 +#define P9_RREAD 117 +#define P9_TCLUNK 120 +#define P9_RCLUNK 121 + +#define P9_O_RDONLY 00000000 +#define P9_GETATTR_SIZE 0x00000010ULL +#define P9_GETATTR_SIZE_OFFSET 41 +#define P9_DT_DIR 4 + +/** +* struct p9_dirent_hdr - 9P2000.L directory entry wire header +* @qid: File QID (13 bytes) +* @offset: Offset cookie for next readdir (8 bytes) +* @type: Directory entry type (1 byte) +* @name_len: Length of filename (2 bytes) +*/ +struct p9_dirent_hdr { +u8 qid[13 ]; +u64 offset; +u8 type; +u16 name_len; +} __packed; + +/** +* struct p9_header - 9P message header +* @size: Total message size in bytes, including this header +* @id: Message type / opcode (e.g. P9_TVERSION) +* @tag: Message tag to match request and reply +*/ +struct p9_header { +u32 size; +u8 id; +u16 tag; +} __packed; + +struct udevice ; + +/** +* struct dm_p9_ops - Driver model operations for 9P transports +* @request: Execute a transmit/receive transaction +* @get_mount_tag: (optional) Retrieve the mount tag string +*/ +struct dm_p9_ops { +int (*request)(struct udevice *dev,void *tx,int tx_len,void *rx,int rx_len); +const char *(*get_mount_tag)(struct udevice *dev); +}; + +/** +* struct p9_client - 9P client state +* @dev: Underlying transport udevice +* @tx: Transmit buffer +* @rx: Receive buffer +* @next_fid: Next FID to allocate +* @msize: Negotiated maximum message size +*/ +struct p9_client { +struct udevice *dev; +u8 *tx; +u8 *rx; +u32 next_fid; +u32 msize; +}; + +/** +* p9_get_device() - Find a 9P transport device by mount tag or default +* @tag: Mount tag to match, or NULL/"-" for default/first device +* @devp: Output pointer to the found udevice +* +* Return: 0 on success, negative error code on failure +*/ +int p9_get_device (const char *tag,struct udevice **devp); + +/** +* p9_get_client() - Get 9P client state from a transport udevice +* @dev: 9P transport udevice +* +* Return: Pointer to struct p9_client +*/ +struct p9_client *p9_get_client (struct udevice *dev); + +/** +* p9_client_alloc_fid() - Allocate a unique FID +* @c: Pointer to 9P client +* +* Return: Newly allocated FID +*/ +u32 p9_client_alloc_fid (struct p9_client *c); + +/** +* p9_client_version() - Negotiate 9P2000.L protocol version and msize +* @c: Pointer to 9P client +* +* Return: 0 on success, negative error code on failure +*/ +int p9_client_version (struct p9_client *c); + +/** +* p9_client_attach() - Attach to the root directory +* @c: Pointer to 9P client +* @fid: FID to assign to root +* @uname: User name +* @aname: File tree / mount point name +* +* Return: 0 on success, negative error code on failure +*/ +int p9_client_attach (struct p9_client *c,u32 fid,const char *uname,const char *aname); + +/** +* p9_client_walk() - Walk a path and associate with a new FID +* @c: Pointer to 9P client +* @base_fid: Starting directory FID +* @new_fid: New FID to associate with target path +* @path: Relative path to walk +* +* Return: 0 on success, negative error code on failure +*/ +int p9_client_walk (struct p9_client *c,u32 base_fid,u32 new_fid,const char *path); + +/** +* p9_client_lopen() - Open a file (9P2000.L) +* @c: Pointer to 9P client +* @fid: FID of file to open +* @flags: Open flags (e.g. P9_O_RDONLY) +* +* Return: 0 on success, negative error code on failure +*/ +int p9_client_lopen (struct p9_client *c,u32 fid,u32 flags); + +/** +* p9_client_clunk() - Forget / close a FID +* @c: Pointer to 9P client +* @fid: FID to clunk +* +* Return: 0 on success, negative error code on failure +*/ +int p9_client_clunk (struct p9_client *c,u32 fid); + +/** +* p9_client_stat() - Get file size attribute via Tgetattr +* @c: Pointer to 9P client +* @fid: FID of file +* @size: Output pointer for file size +* +* Return: 0 on success, negative error code on failure +*/ +int p9_client_stat (struct p9_client *c,u32 fid,loff_t *size); + +/** +* p9_client_read() - Read data from a file +* @c: Pointer to 9P client +* @fid: FID of file +* @offset: Byte offset in file to read from +* @count: Maximum number of bytes to read +* @buf: Destination buffer +* @actread: Output pointer for actual bytes read +* +* Return: 0 on success, negative error code on failure +*/ +int p9_client_read (struct p9_client *c,u32 fid,u64 offset,u32 count,void *buf,u32 *actread); + +/** +* p9_client_readdir() - Read directory entries +* @c: Pointer to 9P client +* @fid: FID of directory +* @offset: Directory offset / cookie +* @count: Maximum bytes of dirents to read +* @buf: Destination buffer +* @actread: Output pointer for actual bytes returned +* +* Return: 0 on success, negative error code on failure +*/ +int p9_client_readdir (struct p9_client *c,u32 fid,u64 offset,u32 count,void *buf,u32 *actread); + +#endif /* __9P_H__ */
include/dm/uclass-id.h +1 -0
@@ -108,6 +108,7 @@ enum uclass_id {UCLASS_PANEL ,/* Display panel, such as an LCD */ UCLASS_PANEL_BACKLIGHT ,/* Backlight controller for panel */ UCLASS_PARTITION ,/* Logical disk partition device */ +UCLASS_9P ,/* 9P protocol transport */ UCLASS_PCH ,/* x86 platform controller hub */ UCLASS_PCI ,/* PCI bus */ UCLASS_PCI_EP, /* PCI endpoint device */
net/9p/Kconfig new file +5 -0
@@ -0,0 +1,5 @@ +config NET_9P + bool "9P2000.L protocol support" + help + This enables support for the 9P network protocol (9P2000.L). + It implements the core 9P2000.L client and protocol handling.
net/9p/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (C) 2026, Kuan-Wei Chiu <[email protected]> + +obj-y += client.o
net/9p/client.c new file +408 -0
408 lines not on this page · raw message
net/Kconfig +2 -0
@@ -236,6 +236,8 @@ endif # if NET_LEGACY source "net/lwip/Kconfig" +source "net/9p/Kconfig" + config BOOTDEV_ETH bool "Enable bootdev for ethernet" depends on BOOTSTD
net/Makefile +1 -0
@@ -49,3 +49,4 @@ obj-y += net-common.o endif obj-$(CONFIG_NET_LWIP) += lwip/ +obj-$(CONFIG_NET_9P) += 9p/
Signature · 1 line
2.55.0.897.gb25b4bd76c-goog
Re: [PATCH v2 1/6] net: 9p: Add 9P2000.L protocol support
Quoted 11 lines · Kuan-Wei Chiu
net: 9p: Add 9P2000.L protocol support
Introduce the core 9P network protocol client implementation.
9P is a network filesystem protocol originally developed for the Plan 9 operating system. Add the baseline 9P2000.L protocol handling, including message serialization, DM
UCLASS_9Ptransport management, and basic transport operations.Signed-off-by Kuan-Wei Chiu <[email protected]>
Quoted 8 lines
include/9p.h| 203 ++++++++++++++++++++++++include/dm/uclass-id.h | 1 + net/9p/Kconfig | 5 + net/9p/Makefile | 5 + net/9p/client.c | 408 +++++++++++++++++++++++++++++++++++++++++++++++++ net/Kconfig | 2 + net/Makefile | 1 + 7 files changed, 625 insertions(+)
PATCH v2 2/6 fs: 9p: Add 9P filesystem support
In reply to Kuan-Wei ChiuImplement the VFS interface for the 9P filesystem.
Map VFS operations to the underlying 9P protocol client and register the 9P filesystem type, allowing access without traditional block device partition tables.
---
Changes in v2:
- Add pseudo block device "9p" handling in disk/part.c.
- Look up 9P transport device via DM UCLASS_9P by mount tag or index.
- Add p9_client_clunk() calls on open failure.
- Dynamically allocate readdir buffer and implement pagination loop.
- Propagate return error code in p9_fs_read().
--- disk/part.c | 16 +++++ fs/9p/9p.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/9p/Kconfig | 8 +++ fs/9p/Makefile | 5 ++ fs/Kconfig | 2 + fs/Makefile | 1 + fs/fs.c | 25 +++++++ include/9pfs.h | 60 ++++++++++++++++ include/fs.h | 1 + 9 files changed, 303 insertions(+) create mode 100644 fs/9p/9p.c create mode 100644 fs/9p/Kconfig create mode 100644 fs/9p/Makefile create mode 100644 include/9pfs.h
disk/part.c +16 -0
@@ -482,6 +482,22 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, }#endif +#if IS_ENABLED (CONFIG_FS_9P ) +/* +* Special-case a pseudo block device "9p", to allow access to the +* 9P filesystem. +*/ +if (!strcmp (ifname,"9p" )) { +strcpy ((char *)info->type,BOOT_PART_TYPE ); +if (dev_part_str) +strlcpy ((char *)info->name, dev_part_str,sizeof (info->name)); +else +strcpy ((char *)info->name,"9P filesystem" ); + +return 0 ; + } +#endif +#if IS_ENABLED (CONFIG_CMD_UBIFS ) && !IS_ENABLED (CONFIG_XPL_BUILD )/* * Special-case ubi, ubi goes through a mtd, rather than through
fs/9p/9p.c new file +185 -0
185 lines not on this page · raw message
fs/9p/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +config FS_9P + bool "9P filesystem support" + depends on NET_9P + help + This provides support for the 9P2000.L filesystem. + + To use this filesystem, you also need to enable a 9P + transport driver.
fs/9p/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (C) 2026, Kuan-Wei Chiu <[email protected]> + +obj-y += 9p.o
fs/Kconfig +2 -0
@@ -26,4 +26,6 @@ source "fs/squashfs/Kconfig" source "fs/erofs/Kconfig" +source "fs/9p/Kconfig" + endmenu
fs/Makefile +1 -0
@@ -26,5 +26,6 @@ obj-$(CONFIG_CMD_UBIFS) += ubifs/ obj-$(CONFIG_CMD_ZFS) += zfs/ obj-$(CONFIG_FS_SQUASHFS) += squashfs/ obj-$(CONFIG_FS_EROFS) += erofs/ +obj-$(CONFIG_FS_9P) += 9p/ endif obj-y += fs_internal.o
fs/fs.c +25 -0
@@ -32,6 +32,7 @@#include <squashfs.h> #include <erofs.h> #include <exfat.h> +#include <9pfs.h> static struct blk_desc *fs_dev_desc;static int fs_dev_part;
@@ -400,6 +401,26 @@ static struct fstype_info fstypes[] = { .mkdir = exfat_fs_mkdir, .rename = exfat_fs_rename, }, +#endif +#if CONFIG_IS_ENABLED (FS_9P ) + { + .fstype = FS_TYPE_9P, + .name = "9p", + .null_dev_desc_ok = true, + .probe = p9_fs_set_blk_dev, + .close = fs_close_unsupported, + .ls = p9_fs_ls, + .exists = p9_fs_exists, + .size = p9_fs_size, + .read = p9_fs_read, + .write = fs_write_unsupported, + .uuid = fs_uuid_unsupported, + .opendir = fs_opendir_unsupported, + .unlink = fs_unlink_unsupported, + .mkdir = fs_mkdir_unsupported, + .ln = fs_ln_unsupported, + .rename = fs_rename_unsupported, + }, #endif { .fstype = FS_TYPE_ANY,
@@ -501,11 +522,15 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)if (info) { fs_dev_desc =NULL ;memset (&fs_partition,0 ,sizeof (fs_partition)); +if (dev_part_str) +strlcpy ((char *)fs_partition.name, dev_part_str, +sizeof (fs_partition.name));if (!info->probe (NULL , &fs_partition)) { fs_type = info->fstype; fs_dev_part =0 ;return 0 ; } +return -1 ; } part = part_get_info_by_dev_and_name_or_num(ifname, dev_part_str, &fs_dev_desc,
include/9pfs.h new file +60 -0
60 lines not on this page · raw message
include/fs.h +1 -0
@@ -19,6 +19,7 @@ struct cmd_tbl;#define FS_TYPE_EROFS 7#define FS_TYPE_SEMIHOSTING 8#define FS_TYPE_EXFAT 9 +#define FS_TYPE_9P 10struct blk_desc ;
Signature · 1 line
2.55.0.897.gb25b4bd76c-goog
Re: [PATCH v2 2/6] fs: 9p: Add 9P filesystem support
Quoted 11 lines · Kuan-Wei Chiu
fs: 9p: Add 9P filesystem support
Implement the VFS interface for the 9P filesystem.
Map VFS operations to the underlying 9P protocol client and register the 9P filesystem type, allowing access without traditional block device partition tables.
Signed-off-by Kuan-Wei Chiu <[email protected]>
disk/part.c| 16 +++++
Quoted 9 lines
fs/9p/9p.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/9p/Kconfig | 8 +++ fs/9p/Makefile | 5 ++ fs/Kconfig | 2 + fs/Makefile | 1 + fs/fs.c | 25 ++++++++ include/9pfs.h | 60 +++++++++++++++++++ include/fs.h | 1 + 9 files changed, 303 insertions(+)
PATCH v2 3/6 virtio: 9p: Add 9P transport driver
In reply to Kuan-Wei ChiuAdd virtio transport driver for the 9P filesystem.
This driver binds to the virtio-9p device exposed by the hypervisor and registers as a DM UCLASS_9P device. It implements the transmit and receive routines.
---
Changes in v2:
- Drop D-cache flush and invalidate operations.
- Propagate error code returned by virtqueue_add().
- Add get_timer() timeout handling for virtqueue_get_buf().
- Verify received length is at least sizeof(struct p9_header).
- Bind driver to UCLASS_9P with dm_p9_ops.
- Negotiate VIRTIO_9P_MOUNT_TAG feature in .bind.
- Read mount tag from virtio config space during probe.
- Add .remove callback with virtio_reset().
- Add DM_FLAG_ACTIVE_DMA to driver flags.
--- drivers/virtio/Kconfig | 7 ++ drivers/virtio/Makefile | 1 + drivers/virtio/virtio-uclass.c | 1 + drivers/virtio/virtio_9p.c | 119 +++++++++++++++++++++++++++++++++ include/virtio.h | 12 +++- 5 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 drivers/virtio/virtio_9p.c
drivers/virtio/Kconfig +7 -0
@@ -77,4 +77,11 @@ config VIRTIO_RNG help This is the virtual random number generator driver. It can be used with QEMU based targets. + +config VIRTIO_9P + bool "virtio 9P transport driver" + depends on VIRTIO && NET_9P + help + This enables the 9P transport driver over virtio. + It can be used with QEMU based targets. endmenu
drivers/virtio/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-$(CONFIG_VIRTIO_SANDBOX) += virtio_sandbox.o obj-$(CONFIG_VIRTIO_NET) += virtio_net.o obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o obj-$(CONFIG_VIRTIO_RNG) += virtio_rng.o +obj-$(CONFIG_VIRTIO_9P) += virtio_9p.o
drivers/virtio/virtio-uclass.c +1 -0
@@ -30,6 +30,7 @@ static const char *const virtio_drv_name[VIRTIO_ID_MAX_NUM] = { [VIRTIO_ID_NET] = VIRTIO_NET_DRV_NAME, [VIRTIO_ID_BLOCK] = VIRTIO_BLK_DRV_NAME, [VIRTIO_ID_RNG] = VIRTIO_RNG_DRV_NAME, + [VIRTIO_ID_9P] = VIRTIO_9P_DRV_NAME, }; int virtio_get_config(struct udevice *vdev, unsigned int offset,
drivers/virtio/virtio_9p.c new file +119 -0
119 lines not on this page · raw message
include/virtio.h +11 -1
@@ -31,11 +31,21 @@#define VIRTIO_ID_NET 1/* virtio net */ #define VIRTIO_ID_BLOCK 2/* virtio block */ #define VIRTIO_ID_RNG 4/* virtio rng */ -#define VIRTIO_ID_MAX_NUM 5 +#define VIRTIO_ID_9P 9/* virtio 9p */ +#define VIRTIO_ID_MAX_NUM 10#define VIRTIO_NET_DRV_NAME "virtio-net"#define VIRTIO_BLK_DRV_NAME "virtio-blk"#define VIRTIO_RNG_DRV_NAME "virtio-rng" +#define VIRTIO_9P_DRV_NAME "virtio-9p" + +/* Feature bits for virtio 9P */ +#define VIRTIO_9P_MOUNT_TAG 0 + +struct virtio_9p_config { +__virtio16 tag_len; +u8 tag[]; +} __packed;/* Status byte for guest to report progress, and synchronize features */
Signature · 1 line
2.55.0.897.gb25b4bd76c-goog
Re: [PATCH v2 3/6] virtio: 9p: Add 9P transport driver
Hi Kuan-Wei,
Quoted 21 lines · Kuan-Wei Chiu
virtio: 9p: Add 9P transport driver
Add virtio transport driver for the 9P filesystem.
This driver binds to the virtio-9p device exposed by the hypervisor and registers as a DM
UCLASS_9Pdevice. It implements the transmit and receive routines.Signed-off-by Kuan-Wei Chiu <[email protected]>
drivers/virtio/Kconfig| 7 +++drivers/virtio/Makefile | 1 + drivers/virtio/virtio-uclass.c | 1 + drivers/virtio/virtio_9p.c | 119 +++++++++++++++++++++++++++++++++++++++++ include/virtio.h | 12 ++++- 5 files changed, 139 insertions(+), 1 deletion(-)drivers/virtio/virtio_9p.c +2
-0@@ -0,0 +1,119 @@ +static int virtio_9p_remove (struct udevice *dev) +{
drivers/virtio/virtio_9p.c line 12
Quoted 10 lines
drivers/virtio/virtio_9p.c +10
-0+return virtio_reset (dev); +} + +U_BOOT_DRIVER (virtio_9p) = { + .name =VIRTIO_9P_DRV_NAME , + .id =UCLASS_9P , + .ops = &virtio_9p_ops, + .bind = virtio_9p_bind, + .probe = virtio_9p_probe, + .remove = virtio_9p_remove,
Sorry, I gave you the wrong function name last time. Other virtio drivers set .remove = virtio_remove, which calls virtio_del_vqs() before virtio_reset(). Going straight to virtio_reset() here leaks the vq allocated in probe(). Please drop the wrapper and use virtio_remove directly.
drivers/virtio/virtio_9p.c line 11
Quoted 13 lines
drivers/virtio/virtio_9p.c +11
-0@@ -0,0 +1,119 @@ + start =get_timer (0 ); +while (!virtqueue_get_buf (priv->vq, &len)) { +if (get_timer (start) >VIRTIO_9P_TIMEOUT_MS ) +return -ETIMEDOUT ; + } + +if (len < (int )sizeof (struct p9_header )) +return -EIO ; + +return 0 ; +}
Looks good, It might be worth returning len to the caller so the client can cross-check it against the size field in the reply header, but up to you.
Regards,
Simon
Re: [PATCH v2 3/6] virtio: 9p: Add 9P transport driver
Hi Simon,
Quoted 32 lines · Simon Glass
Hi Kuan-Wei,
Quoted 29 lines · Kuan-Wei Chiu
virtio: 9p: Add 9P transport driver
Add virtio transport driver for the 9P filesystem.
This driver binds to the virtio-9p device exposed by the hypervisor and registers as a DM
UCLASS_9Pdevice. It implements the transmit and receive routines.Signed-off-by Kuan-Wei Chiu <[email protected]>
drivers/virtio/Kconfig| 7 +++drivers/virtio/Makefile | 1 + drivers/virtio/virtio-uclass.c | 1 + drivers/virtio/virtio_9p.c | 119 +++++++++++++++++++++++++++++++++++++++++ include/virtio.h | 12 ++++- 5 files changed, 139 insertions(+), 1 deletion(-)drivers/virtio/virtio_9p.c +10
-0@@ -0,0 +1,119 @@ +static int virtio_9p_remove (struct udevice *dev) +{ +return virtio_reset (dev); +} + +U_BOOT_DRIVER (virtio_9p) = { + .name =VIRTIO_9P_DRV_NAME , + .id =UCLASS_9P , + .ops = &virtio_9p_ops, + .bind = virtio_9p_bind,
Quoted 8 lines
drivers/virtio/virtio_9p.c line 116
Quoted 2 lines
drivers/virtio/virtio_9p.c +2
-0+ .probe = virtio_9p_probe, + .remove = virtio_9p_remove,Sorry, I gave you the wrong function name last time. Other virtio drivers set .remove =
virtio_remove, which callsvirtio_del_vqs()beforevirtio_reset(). Going straight tovirtio_reset()here leaks the vq allocated inprobe(). Please drop the wrapper and usevirtio_removedirectly.
I checked the tree and it seems virtio_remove() does not exist in U-Boot. Existing drivers like virtio_blk, virtio_net, and virtio_rng all set .remove = virtio_reset directly. To avoid leaking the vq on removal, I will keep virtio_9p_remove() and call virtio_del_vqs(dev) before virtio_reset(dev) in v3.
Quoted 10 lines
Quoted 10 lines
drivers/virtio/virtio_9p.c +7
-0@@ -0,0 +1,119 @@ + start =get_timer (0 ); +while (!virtqueue_get_buf (priv->vq, &len)) { +if (get_timer (start) >VIRTIO_9P_TIMEOUT_MS ) +return -ETIMEDOUT ; + } + +if (len < (int )sizeof (struct p9_header ))
Quoted 9 lines
drivers/virtio/virtio_9p.c line 59
Quoted 4 lines
drivers/virtio/virtio_9p.c +4
-0+return -EIO ; + +return 0 ; +}Looks good, It might be worth returning len to the caller so the client can cross-check it against the size field in the reply header, but up to you.
Ack. Will do in v3.
Regards,
Kuan-Wei
PATCH v2 4/6 doc: 9p: Add 9P filesystem documentation
In reply to Kuan-Wei ChiuAdd documentation for 9P filesystem support, including configuration options, QEMU configuration, and basic usage examples.
--- doc/usage/filesystems/9p.rst | 55 ++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 56 insertions(+) create mode 100644 doc/usage/filesystems/9p.rst
doc/usage/filesystems/9p.rst new file +55 -0
@@ -0,0 +1,55 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright (C) 2026, Kuan-Wei Chiu <[email protected]> + +9P Filesystem +============= + +The 9P filesystem is a network-based file sharing protocol. It is primarily +used to share files between a host and a guest over virtio, providing a way +to load kernels, device trees, and initial ramdisks without needing a disk +image or networking setup like TFTP. + +Configuration +------------- + +To enable the 9P filesystem support, you must enable the following configuration +options: + +* ``CONFIG_FS_9P``: Enables the 9P filesystem layer. +* ``CONFIG_NET_9P``: Enables the core 9P2000.L client protocol. +* ``CONFIG_VIRTIO_9P``: Enables the virtio transport driver for 9P. + +QEMU Setup +---------- + +To use 9P with QEMU, you need to expose a host directory to the guest using +the ``-fsdev`` and ``-device`` parameters. + +For example, to share the host's `/tmp/shared` directory with the guest under +the mount tag `rootfs`: + +.. code-block:: bash + + qemu-system-aarch64 \ + -machine virt \ + -nographic \ + -fsdev local,id=fsdev0,path=/tmp/shared,security_model=none \ + -device virtio-9p-device,fsdev=fsdev0,mount_tag=rootfs + +U-Boot Usage +------------ + +Once booted into U-Boot, you must first probe the virtio subsystem. You can then +access the 9P filesystem using the ``9p`` interface name. You can specify a mount tag +(such as ``rootfs``), a device index (such as ``0``), or use ``-`` to select the +default (first) device. + +.. code-block:: bash + + => virtio scan + => ls 9p rootfs / + => ls 9p 0 / + => ls 9p - / + => load 9p rootfs $kernel_addr_r /Image + => load 9p rootfs $ramdisk_addr_r /initramfs.cpio + => booti $kernel_addr_r $ramdisk_addr_r:$filesize $fdtcontroladdr
doc/usage/index.rst +1 -0
@@ -46,3 +46,4 @@ File Systems :maxdepth: 1 filesystems/ext4 + filesystems/9p
Signature · 1 line
2.55.0.897.gb25b4bd76c-goog
Re: [PATCH v2 4/6] doc: 9p: Add 9P filesystem documentation
Hi Kuan-Wei,
Quoted 13 lines · Kuan-Wei Chiu
doc: 9p: Add 9P filesystem documentation
Add documentation for 9P filesystem support, including configuration options, QEMU configuration, and basic usage examples.
Signed-off-by Kuan-Wei Chiu <[email protected]>
doc/usage/filesystems/9p.rst| 55 ++++++++++++++++++++++++++++++++++++++++++++doc/usage/index.rst | 1 + 2 files changed, 56 insertions(+)
doc/usage/filesystems/9p.rst line 2
Quoted 2 lines
doc/usage/filesystems/9p.rst +2
-0@@ -0,0 +1,55 @@ +For example, to share the host's `/tmp/shared` directory with the guest under +the mount tag `rootfs`:
Single backticks render as the default rST role (italic title reference) rather than literal text. Please use double backticks here to match the rest of the file.
Regards,
Simon
PATCH v2 5/6 test: 9p: Add test for 9P filesystem
In reply to Kuan-Wei ChiuAdd automated pytest for the 9P filesystem testing directory listing (ls) and file loading (load) over virtio-9p in QEMU ARM64. Also enable the relevant configurations in qemu_arm64_defconfig.
--- configs/qemu_arm64_defconfig | 3 ++ test/py/tests/test_9p.py | 82 ++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 test/py/tests/test_9p.py
configs/qemu_arm64_defconfig +3 -0
@@ -40,6 +40,7 @@ CONFIG_CMD_TPM=y CONFIG_CMD_MTDPARTS=y CONFIG_CMD_SPAWN=y CONFIG_ENV_IS_IN_FLASH=y +CONFIG_NET_9P=y CONFIG_AHCI=y CONFIG_SCSI_AHCI=y CONFIG_AHCI_PCI=y
@@ -73,6 +74,8 @@ CONFIG_SYSRESET_PSCI=y CONFIG_TPM2_MMIO=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_PCI=y +CONFIG_VIRTIO_9P=y +CONFIG_FS_9P=y CONFIG_MBEDTLS_LIB=y CONFIG_TPM=y CONFIG_TPM_PCR_ALLOCATE=y
test/py/tests/test_9p.py new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.55.0.897.gb25b4bd76c-goog
Re: [PATCH v2 5/6] test: 9p: Add test for 9P filesystem
Hi Kuan-Wei,
Quoted 11 lines · Kuan-Wei Chiu
test: 9p: Add test for 9P filesystem
Add automated pytest for the 9P filesystem testing directory listing (ls) and file loading (load) over virtio-9p in QEMU ARM64. Also enable the relevant configurations in
qemu_arm64_defconfig.Signed-off-by Kuan-Wei Chiu <[email protected]>configs/qemu_arm64_defconfig | 3 ++
test/py/tests/test_9p.py | 82 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
I think I saw a change to the hooks for this, so I assume it passes OK.
test/py/tests/test_9p.py line 5
Quoted 7 lines
test/py/tests/test_9p.py +5
-0@@ -0,0 +1,82 @@ + output = ubman.run_command(f"load 9p rootfs {addr:x} /non_existent_file_9p.txt") + assert "bytes read" not in output + + output = ubman.run_command("ls 9p invalid_tag /") + assert test_file_name not in output
Both negative cases pass for the wrong reason if the command silently produces no output. Please assert on the expected error string (e.g. 'Failed to load' / 'No such device') rather than the absence of a success token, so a future regression that swallows errors still fails the test.
Regards,
Simon
Re: [PATCH v2 5/6] test: 9p: Add test for 9P filesystem
Quoted 9 lines · Simon Glass
Hi Kuan-Wei,
Quoted 6 lines · Kuan-Wei Chiu
test: 9p: Add test for 9P filesystem
Add automated pytest for the 9P filesystem testing directory listing (ls) and file loading (load) over virtio-9p in QEMU ARM64. Also enable the relevant configurations in
qemu_arm64_defconfig.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Kuan-Wei Chiu <[email protected]>configs/qemu_arm64_defconfig | 3 ++
test/py/tests/test_9p.py | 82 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)I think I saw a change to the hooks for this, so I assume it passes OK.
Yes. I tested with:
gitlab-ci-local --variable TEST_PY_TEST_SPEC=test_fs_9p "qemu_arm64 test.py"
Quoted 15 lines
test/py/tests/test_9p.py line 5
Quoted 8 lines
test/py/tests/test_9p.py +5
-0@@ -0,0 +1,82 @@ + output = ubman.run_command(f"load 9p rootfs {addr:x} /non_existent_file_9p.txt") + assert "bytes read" not in output + + output = ubman.run_command("ls 9p invalid_tag /") + assert test_file_name not in outputBoth negative cases pass for the wrong reason if the command silently produces no output. Please assert on the expected error string (e.g. 'Failed to load' / 'No such device') rather than the absence of a success token, so a future regression that swallows errors still fails the test.
Ack. Will do in v3.
Regards,
Kuan-Wei
Re: [PATCH v2 5/6] test: 9p: Add test for 9P filesystem
In reply to Kuan-Wei ChiuQuoted 10 lines · Kuan-Wei Chiu
Add automated pytest for the 9P filesystem testing directory listing (ls) and file loading (load) over virtio-9p in QEMU ARM64. Also enable the relevant configurations in
qemu_arm64_defconfig.Signed-off-by Kuan-Wei Chiu <[email protected]>--- configs/qemu_arm64_defconfig | 3 ++ test/py/tests/test_9p.py | 82 ++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 test/py/tests/test_9p.py
We should also update the docs by adding doc/develop/pytest/test_9p.rst based on the other rst files there. Thanks.
Signature · 1 line
Tom
PATCH v2 6/6 MAINTAINERS: Add entry for 9PFS
In reply to Kuan-Wei ChiuAdd maintainer entry for the newly introduced 9P filesystem subsystem, including the protocol core, vfs integration, and virtio transport driver.
--- MAINTAINERS | 11 +++++++++++ 1 file changed, 11 insertions(+)
MAINTAINERS +11 -0
@@ -50,6 +50,17 @@ so much easier [Ed] Maintainers List (try to look for most precise areas first) ----------------------------------- +9PFS +M: Kuan-Wei Chiu <[email protected]> +S: Maintained +F: doc/usage/filesystems/9p.rst +F: drivers/virtio/virtio_9p.c +F: fs/9p/ +F: include/9p.h +F: include/9pfs.h +F: net/9p/ +F: test/py/tests/test_9p.py + ACPI M: Simon Glass <[email protected]> S: Maintained
Signature · 1 line
2.55.0.897.gb25b4bd76c-goog
Hi Kuan-Wei,
Quoted 4 lines
Add 9P network filesystem support to U-Boot.
It allows U-Boot to directly mount host directories in virtualization environments via virtio.
It would be useful to give an overview in the cover letter how/where you expect to be used. While new features are always welcome they also come with a maintenance burden so some background is always useful to provide more information.
From a network stack PoV does this work, been tested, with both the legacy stack and LWIP stack? I would tend to push this towards working with the LWIP stack as we're moving towards that being the default for standard U-Boot (not in SPL) and I wouldn't expect 9P to be supported in SPL.
Peter
Quoted 78 lines
The functionality has been verified on qemu arm64 by successfully loading a Linux kernel image and an initramfs image via 9P, and booting to the Linux shell.
To test with QEMU:
-fsdev local,id=fsdev0,path=/path/to/host/dir,security_model=none \
-device virtio-9p-device,fsdev=fsdev0,mount_tag=rootfsU-Boot usage:
=> virtio scan
=> ls 9p rootfs /
=> ls 9p 0 /
=> ls 9p - /
=> load 9p rootfs $kernel_addr_r /Image
=> load 9p rootfs $ramdisk_addr_r /initramfs.cpio
=> booti $kernel_addr_r $ramdisk_addr_r:$filesize $fdtcontroladdrChanges in v2:
- Introduce DMUCLASS_9Panddm_p9_opsfor transport devices.
- Support selecting devices by mount tag, sequence index, or default.
- Integrate 9p intodisk/part.cand generic VFSnull_dev_deschandling.
- Consistently use 9P2000.L naming across subjects, code, andKconfig.
- Add kerneldoc comments and separate filesystem header.
- Add timeout handling, feature negotiation, and remove callback.
- Add 9P documentation.
- Add automated pytest and enable inqemu_arm64_defconfig.
- Fix error checking, bounds checks, and memory leaks.Kuan-Wei Chiu (6):
net: 9p: Add 9P2000.L protocol support
fs: 9p: Add 9P filesystem support
virtio: 9p: Add 9P transport driver
doc: 9p: Add 9P filesystem documentation
test: 9p: Add test for 9P filesystem
MAINTAINERS: Add entry for 9PFSMAINTAINERS | 11 + configs/qemu_arm64_defconfig | 3 + disk/part.c | 16 ++ doc/usage/filesystems/9p.rst | 55 +++++ doc/usage/index.rst | 1 + drivers/virtio/Kconfig | 7 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio-uclass.c | 1 + drivers/virtio/virtio_9p.c | 119 ++++++++++ fs/9p/9p.c | 185 +++++++++++++++ fs/9p/Kconfig | 8 + fs/9p/Makefile | 5 + fs/Kconfig | 2 + fs/Makefile | 1 + fs/fs.c | 25 ++ include/9p.h | 203 ++++++++++++++++ include/9pfs.h | 60 +++++ include/dm/uclass-id.h | 1 + include/fs.h | 1 + include/virtio.h | 12 +- net/9p/Kconfig | 5 + net/9p/Makefile | 5 + net/9p/client.c | 408 +++++++++++++++++++++++++++++++++ net/Kconfig | 2 + net/Makefile | 1 + test/py/tests/test_9p.py | 82 +++++++ 26 files changed, 1219 insertions(+), 1 deletion(-) create mode 100644 doc/usage/filesystems/9p.rst create mode 100644 drivers/virtio/virtio_9p.c create mode 100644 fs/9p/9p.c create mode 100644 fs/9p/Kconfig create mode 100644 fs/9p/Makefile create mode 100644 include/9p.h create mode 100644 include/9pfs.h create mode 100644 net/9p/Kconfig create mode 100644 net/9p/Makefile create mode 100644 net/9p/client.c create mode 100644 test/py/tests/test_9p.py--
2.55.0.897.gb25b4bd76c-goog
Hi Peter,
Quoted 11 lines · Peter Robinson
Hi Kuan-Wei,
Quoted 4 lines
Add 9P network filesystem support to U-Boot.
It allows U-Boot to directly mount host directories in virtualization environments via virtio.
It would be useful to give an overview in the cover letter how/where you expect to be used. While new features are always welcome they also come with a maintenance burden so some background is always useful to provide more information.
The use case is loading images directly from the host into the VM. That way I don't need to rebuild and repack disk images like ext4 every time I modify the kernel, and I also don't have to bother setting up a TFTP server.
I got the idea a while ago while browsing the upstream LK code and noticed it had 9P support. I thought it would be cool to have something similar in U-Boot for kernel loading and testing in qemu.
I will add this background to the cover letter if a v3 is needed.
Quoted 7 lines
From a network stack PoV does this work, been tested, with both the legacy stack and LWIP stack? I would tend to push this towards working with the LWIP stack as we're moving towards that being the default for standard U-Boot (not in SPL) and I wouldn't expect 9P to be supported in SPL.
I have only implemented and tested 9P over virtio, so it uses virtqueues and doesn't go through the network stack at all. It's independent of both legacy and LWIP stacks. I am not sure if anyone would actually want 9P over TCP in U-Boot, but if there is demand for it, I can look into adding a transport driver over the network stack.
Regards,
Kuan-Wei