Skip to contentSkip to conversation

fs: Add 9P filesystem support over virtio

PATCH In review Kuan-Wei Chiu 3 participants 15 messages Sep 23 – Oct 7

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 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. This is useful for loading kernel and initramfs images directly from the host into the VM during development and testing without having to rebuild disk images or set up a TFTP server.

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 v3:
- Return received byte length from virtio_9p_request() and check it against the reply header size in p9_request().
- Call virtio_del_vqs() before virtio_reset() in virtio_9p_remove().
- Use double backticks for literal text in 9p.rst.
- Assert expected error strings in test_9p.py negative test cases.
- Add doc/develop/pytest/test_9p.rst.

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                    |  12 +
 configs/qemu_arm64_defconfig   |   3 +
 disk/part.c                    |  16 ++
 doc/develop/pytest/test_9p.rst |  10 +
 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     | 120 ++++++++++
 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                | 415 +++++++++++++++++++++++++++++++++
 net/Kconfig                    |   2 +
 net/Makefile                   |   1 +
 test/py/tests/test_9p.py       |  82 +++++++
 27 files changed, 1238 insertions(+), 1 deletion(-)
 create mode 100644 doc/develop/pytest/test_9p.rst
 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.56.0.rc1.310.g51773c2048-goog
#1 lore raw

PATCH v3 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 v3:
- Check received byte count against reply header size in p9_request().

---
 include/9p.h           | 203 ++++++++++++++++++++
 include/dm/uclass-id.h |   1 +
 net/9p/Kconfig         |   5 +
 net/9p/Makefile        |   5 +
 net/9p/client.c        | 415 +++++++++++++++++++++++++++++++++++++++++
 net/Kconfig            |   2 +
 net/Makefile           |   1 +
 7 files changed, 632 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
new file mode 100644
index 00000000000..e755c78be0f
@@ -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
index fe0aae2720c..10680dc860c 100644
@@ -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
new file mode 100644
index 00000000000..5fda98cb23d
@@ -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
new file mode 100644
index 00000000000..e9220b0826e
@@ -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 +415 -0

415 lines not on this page · raw message

net/Kconfig +2 -0
index 386376ce884..00448ab4cc6 100644
@@ -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
index ceac6de6377..7745607248b 100644
@@ -49,3 +49,4 @@ obj-y += net-common.o
 endif
 
 obj-$(CONFIG_NET_LWIP) += lwip/
+obj-$(CONFIG_NET_9P) += 9p/
Signature · 1 line
2.56.0.rc1.310.g51773c2048-goog
#2 lore raw

PATCH v3 2/6 fs: 9p: Add 9P filesystem support

In reply to Kuan-Wei Chiu

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.

---
 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
index 4923dc44593..8fa1dfd4c19 100644
@@ -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
new file mode 100644
index 00000000000..bc6d4962288
@@ -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
new file mode 100644
index 00000000000..c7f7553e8f4
@@ -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
index e0b0b901e1d..e4aa726ea35 100644
@@ -26,4 +26,6 @@ source "fs/squashfs/Kconfig"
 
 source "fs/erofs/Kconfig"
 
+source "fs/9p/Kconfig"
+
 endmenu
fs/Makefile +1 -0
index ce5e74257a0..5aa34b39172 100644
@@ -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
index 2824c7defa2..b18ccec8cb4 100644
@@ -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
index bec02117737..8afc81c0017 100644
@@ -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      10
 
 struct blk_desc;
 
Signature · 1 line
2.56.0.rc1.310.g51773c2048-goog
#3 lore raw

PATCH v3 3/6 virtio: 9p: Add 9P transport driver

In reply to Kuan-Wei Chiu

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_9P device. It implements the transmit and receive routines.

---
Changes in v3:
- Return received length from virtio_9p_request().
- Call virtio_del_vqs() before virtio_reset() in virtio_9p_remove().

---
 drivers/virtio/Kconfig         |   7 ++
 drivers/virtio/Makefile        |   1 +
 drivers/virtio/virtio-uclass.c |   1 +
 drivers/virtio/virtio_9p.c     | 120 +++++++++++++++++++++++++++++++++
 include/virtio.h               |  12 +++-
 5 files changed, 140 insertions(+), 1 deletion(-)
 create mode 100644 drivers/virtio/virtio_9p.c
drivers/virtio/Kconfig +7 -0
index 512ac376f18..55b44428026 100644
@@ -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
index 4c63a6c6904..6e7bcfc8eaa 100644
@@ -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
index a871a1439d4..c163b2fd7d5 100644
@@ -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 +120 -0

120 lines not on this page · raw message

include/virtio.h +11 -1
index 3edf023463d..b981eead5d7 100644
@@ -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.56.0.rc1.310.g51773c2048-goog
Reviewed-by on v3 3/6
#4 lore raw

Re: [PATCH v3 3/6] virtio: 9p: Add 9P transport driver

Quoted 8 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_9P device. It implements the transmit and receive routines.

Quoted 8 lines

drivers/virtio/Kconfig | 7 +++

 drivers/virtio/Makefile        |   1 +
 drivers/virtio/virtio-uclass.c |   1 +
 drivers/virtio/virtio_9p.c     | 120 +++++++++++++++++++++++++++++++++++++++++
 include/virtio.h               |  12 ++++-
 5 files changed, 140 insertions(+), 1 deletion(-)
#5 lore raw

PATCH v3 4/6 doc: 9p: Add 9P filesystem documentation

In reply to Kuan-Wei Chiu

Add documentation for 9P filesystem support, including configuration options, QEMU configuration, and basic usage examples.

---
Changes in v3:
- Use double backticks for literal text in 9p.rst.

---
 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
new file mode 100644
index 00000000000..fb4e8bcb9c0
@@ -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
index 6f477b842ca..6d7ca6b9aec 100644
@@ -46,3 +46,4 @@ File Systems
    :maxdepth: 1
 
    filesystems/ext4
+   filesystems/9p
Signature · 1 line
2.56.0.rc1.310.g51773c2048-goog
Reviewed-by on v3 4/6
#6 lore raw

Re: [PATCH v3 4/6] doc: 9p: Add 9P filesystem documentation

Quoted 10 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.

doc/usage/filesystems/9p.rst | 55 ++++++++++++++++++++++++++++++++++++++++++++

 doc/usage/index.rst          |  1 +
 2 files changed, 56 insertions(+)
#7 lore raw

PATCH v3 5/6 test: 9p: Add test for 9P filesystem

In reply to 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.

---
Changes in v3:
- Assert expected error strings in negative test cases.
- Add doc/develop/pytest/test_9p.rst.

---
 configs/qemu_arm64_defconfig   |  3 ++
 doc/develop/pytest/test_9p.rst | 10 +++++
 test/py/tests/test_9p.py       | 82 ++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+)
 create mode 100644 doc/develop/pytest/test_9p.rst
 create mode 100644 test/py/tests/test_9p.py
configs/qemu_arm64_defconfig +3 -0
index ae6dd770f3e..75b50eeb5ea 100644
@@ -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
doc/develop/pytest/test_9p.rst new file +10 -0
new file mode 100644
index 00000000000..9c4d18e66fd
@@ -0,0 +1,10 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+test_9p
+=======
+
+.. automodule:: test_9p
+   :synopsis:
+   :member-order: bysource
+   :members:
+   :undoc-members:
test/py/tests/test_9p.py new file +82 -0

82 lines not on this page · raw message

Signature · 1 line
2.56.0.rc1.310.g51773c2048-goog
Reviewed-by on v3 5/6
#8 lore raw

Re: [PATCH v3 5/6] test: 9p: Add test for 9P filesystem

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 6 lines

configs/qemu_arm64_defconfig | 3 ++

 doc/develop/pytest/test_9p.rst | 10 ++++++
 test/py/tests/test_9p.py       | 82 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+)

Regards,
Simon

#9 lore raw

PATCH v3 6/6 MAINTAINERS: Add entry for 9PFS

In reply to Kuan-Wei Chiu

Add maintainer entry for the newly introduced 9P filesystem subsystem, including the protocol core, vfs integration, and virtio transport driver.

---
 MAINTAINERS | 12 ++++++++++++
 1 file changed, 12 insertions(+)
MAINTAINERS +12 -0
index acaba95ed03..5bef76bc43a 100644
@@ -50,6 +50,18 @@ 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/develop/pytest/test_9p.rst
+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.56.0.rc1.310.g51773c2048-goog
#10 lore raw
In reply to Kuan-Wei Chiu
Quoted 9 lines · Kuan-Wei Chiu

Add 9P network filesystem support to U-Boot.

It allows U-Boot to directly mount host directories in virtualization environments via virtio. This is useful for loading kernel and initramfs images directly from the host into the VM during development and testing without having to rebuild disk images or set up a TFTP server.

[...]

Applied to u-boot/main, thanks!

[1/6] net: 9p: Add 9P2000.L protocol support

      commit: 48bb83195682d189273bdba813fa67f7f2760d59
[2/6] fs: 9p: Add 9P filesystem support
      commit: 9e14f904f8f12cd9df07e99a679453c8782e523b
[3/6] virtio: 9p: Add 9P transport driver
      commit: 09e668e32b4c14ce5c929d6cebfac75d2aefb90d
[4/6] doc: 9p: Add 9P filesystem documentation
      commit: 7d963df1bc38f5ae070ea8b96e03afc1ef7e23ed
[5/6] test: 9p: Add test for 9P filesystem
      commit: d446ef40b87d53ef7ac59ac9b1d79a16f0a065b0
[6/6] MAINTAINERS: Add entry for 9PFS
      commit: f6002d5e8018714ca80dcf1835c230c99c5090b3
Signature · 1 line
Tom
#11 lore raw
Quoted 15 lines · Tom Rini
Quoted 9 lines · Kuan-Wei Chiu

Add 9P network filesystem support to U-Boot.

It allows U-Boot to directly mount host directories in virtualization environments via virtio. This is useful for loading kernel and initramfs images directly from the host into the VM during development and testing without having to rebuild disk images or set up a TFTP server.

[...]

Applied to u-boot/main, thanks!

[1/6] net: 9p: Add 9P2000.L protocol support

Quoted 11 lines
      commit: 48bb83195682d189273bdba813fa67f7f2760d59
[2/6] fs: 9p: Add 9P filesystem support
      commit: 9e14f904f8f12cd9df07e99a679453c8782e523b
[3/6] virtio: 9p: Add 9P transport driver
      commit: 09e668e32b4c14ce5c929d6cebfac75d2aefb90d
[4/6] doc: 9p: Add 9P filesystem documentation
      commit: 7d963df1bc38f5ae070ea8b96e03afc1ef7e23ed
[5/6] test: 9p: Add test for 9P filesystem
      commit: d446ef40b87d53ef7ac59ac9b1d79a16f0a065b0
[6/6] MAINTAINERS: Add entry for 9PFS
      commit: f6002d5e8018714ca80dcf1835c230c99c5090b3

Are there special permissions required for 9p to run? This works in Gitlab, but in Azure:
test/py/tests/test_9p.py:46: in test_fs_9p
assert test_file_name in output
E assert '9p_test_small.txt' in "9P Error: No matching 9P transport device found for '-'"

Signature · 1 line
Tom
#12 lore raw

Hi Tom,

Quoted 28 lines · Tom Rini
Quoted 15 lines · Tom Rini
Quoted 9 lines · Kuan-Wei Chiu

Add 9P network filesystem support to U-Boot.

It allows U-Boot to directly mount host directories in virtualization environments via virtio. This is useful for loading kernel and initramfs images directly from the host into the VM during development and testing without having to rebuild disk images or set up a TFTP server.

[...]

Applied to u-boot/main, thanks!

[1/6] net: 9p: Add 9P2000.L protocol support

Quoted 11 lines
      commit: 48bb83195682d189273bdba813fa67f7f2760d59
[2/6] fs: 9p: Add 9P filesystem support
      commit: 9e14f904f8f12cd9df07e99a679453c8782e523b
[3/6] virtio: 9p: Add 9P transport driver
      commit: 09e668e32b4c14ce5c929d6cebfac75d2aefb90d
[4/6] doc: 9p: Add 9P filesystem documentation
      commit: 7d963df1bc38f5ae070ea8b96e03afc1ef7e23ed
[5/6] test: 9p: Add test for 9P filesystem
      commit: d446ef40b87d53ef7ac59ac9b1d79a16f0a065b0
[6/6] MAINTAINERS: Add entry for 9PFS
      commit: f6002d5e8018714ca80dcf1835c230c99c5090b3
Quoted 6 lines

Are there special permissions required for 9p to run? This works in Gitlab, but in Azure:
test/py/tests/test_9p.py:46: in test_fs_9p
assert test_file_name in output
E assert '9p_test_small.txt' in "9P Error: No matching 9P transport device found for '-'"

That's weird. In theory, no special permissions should be required. That error messag indicates that u-boot didn't detect any 9p transport device. I'll take a look at it.

Regards,
Kuan-Wei

#13 lore raw

Hi Tom,

Quoted 37 lines · Kuan-Wei Chiu

Hi Tom,

Quoted 28 lines · Tom Rini
Quoted 15 lines · Tom Rini
Quoted 9 lines · Kuan-Wei Chiu

Add 9P network filesystem support to U-Boot.

It allows U-Boot to directly mount host directories in virtualization environments via virtio. This is useful for loading kernel and initramfs images directly from the host into the VM during development and testing without having to rebuild disk images or set up a TFTP server.

[...]

Applied to u-boot/main, thanks!

[1/6] net: 9p: Add 9P2000.L protocol support

Quoted 11 lines
      commit: 48bb83195682d189273bdba813fa67f7f2760d59
[2/6] fs: 9p: Add 9P filesystem support
      commit: 9e14f904f8f12cd9df07e99a679453c8782e523b
[3/6] virtio: 9p: Add 9P transport driver
      commit: 09e668e32b4c14ce5c929d6cebfac75d2aefb90d
[4/6] doc: 9p: Add 9P filesystem documentation
      commit: 7d963df1bc38f5ae070ea8b96e03afc1ef7e23ed
[5/6] test: 9p: Add test for 9P filesystem
      commit: d446ef40b87d53ef7ac59ac9b1d79a16f0a065b0
[6/6] MAINTAINERS: Add entry for 9PFS
      commit: f6002d5e8018714ca80dcf1835c230c99c5090b3
Quoted 6 lines

Are there special permissions required for 9p to run? This works in Gitlab, but in Azure:
test/py/tests/test_9p.py:46: in test_fs_9p
assert test_file_name in output
E assert '9p_test_small.txt' in "9P Error: No matching 9P transport device found for '-'"

Quoted 4 lines

That's weird. In theory, no special permissions should be required. That error messag indicates that u-boot didn't detect any 9p transport device. I'll take a look at it.

Azure currently points to the github mirror of u-boot-test-hooks, which does not include my previous u-boot-test-hooks patch that adds the 9p device to arm64 qemu.

The following change should fix it, although I haven't tested it yet. I can submit it separately as a formal patch.

Regards,
Kuan-Wei

.azure-pipelines.yml +1 -1
index 015fc15d5c2..93bdbf4a4cf 100644
@@ -251,7 +251,7 @@ stages:
           # the below corresponds to .gitlab-ci.yml "before_script"
           cd \${WORK_DIR}
           git config --global --add safe.directory \${WORK_DIR}
-          git clone --depth=1 https://github.com/u-boot/u-boot-test-hooks /tmp/uboot-test-hooks
+          git clone --depth=1 https://git.u-boot-project.org/u-boot/u-boot-test-hooks /tmp/uboot-test-hooks
           # qemu_arm64_lwip_defconfig is the same as qemu_arm64 but with NET_LWIP enabled.
           # The test config and the boardenv file from qemu_arm64 can be re-used so create symlinks
           ln -s conf.qemu_arm64 /tmp/uboot-test-hooks/bin/travis-ci/conf.qemu_arm64_lwip_na
#14 lore raw
Quoted 59 lines · Kuan-Wei Chiu

Hi Tom,

Quoted 37 lines · Kuan-Wei Chiu

Hi Tom,

Quoted 28 lines · Tom Rini
Quoted 15 lines · Tom Rini
Quoted 9 lines · Kuan-Wei Chiu

Add 9P network filesystem support to U-Boot.

It allows U-Boot to directly mount host directories in virtualization environments via virtio. This is useful for loading kernel and initramfs images directly from the host into the VM during development and testing without having to rebuild disk images or set up a TFTP server.

[...]

Applied to u-boot/main, thanks!

[1/6] net: 9p: Add 9P2000.L protocol support

Quoted 11 lines
      commit: 48bb83195682d189273bdba813fa67f7f2760d59
[2/6] fs: 9p: Add 9P filesystem support
      commit: 9e14f904f8f12cd9df07e99a679453c8782e523b
[3/6] virtio: 9p: Add 9P transport driver
      commit: 09e668e32b4c14ce5c929d6cebfac75d2aefb90d
[4/6] doc: 9p: Add 9P filesystem documentation
      commit: 7d963df1bc38f5ae070ea8b96e03afc1ef7e23ed
[5/6] test: 9p: Add test for 9P filesystem
      commit: d446ef40b87d53ef7ac59ac9b1d79a16f0a065b0
[6/6] MAINTAINERS: Add entry for 9PFS
      commit: f6002d5e8018714ca80dcf1835c230c99c5090b3
Quoted 6 lines

Are there special permissions required for 9p to run? This works in Gitlab, but in Azure:
test/py/tests/test_9p.py:46: in test_fs_9p
assert test_file_name in output
E assert '9p_test_small.txt' in "9P Error: No matching 9P transport device found for '-'"

Quoted 4 lines

That's weird. In theory, no special permissions should be required. That error messag indicates that u-boot didn't detect any 9p transport device. I'll take a look at it.

Azure currently points to the github mirror of u-boot-test-hooks, which does not include my previous u-boot-test-hooks patch that adds the 9p device to arm64 qemu.

The following change should fix it, although I haven't tested it yet. I can submit it separately as a formal patch.

Regards,
Kuan-Wei

.azure-pipelines.yml +0 -0
index 015fc15d5c2..93bdbf4a4cf 100644

.azure-pipelines.yml stages: · line 257

Quoted 8 lines
.azure-pipelines.yml +1 -1
@@ -251,7 +251,7 @@ stages:
           # the below corresponds to .gitlab-ci.yml "before_script"
           cd \${WORK_DIR}
           git config --global --add safe.directory \${WORK_DIR}
-          git clone --depth=1 https://github.com/u-boot/u-boot-test-hooks /tmp/uboot-test-hooks
+          git clone --depth=1 https://git.u-boot-project.org/u-boot/u-boot-test-hooks /tmp/uboot-test-hooks
           # qemu_arm64_lwip_defconfig is the same as qemu_arm64 but with NET_LWIP enabled.
           # The test config and the boardenv file from qemu_arm64 can be re-used so create symlinks
           ln -s conf.qemu_arm64 /tmp/uboot-test-hooks/bin/travis-ci/conf.qemu_arm64_lwip_na

Ah! Thanks! Yes, please post a proper patch and I'll grab and push it out.

Signature · 1 line
Tom