usb: gadget: 9pfs transport
Subsystems (3)
v12 cover usb: gadget: 9pfs transport
This series is adding support to mount usb hostside exported 9pfs filesystems via the usb gadget interface. It also includes a simple tool (p9_fwd.py) to translate an tcp 9pfs transport and reuse it via the usb interface.
+--------------------------+ | +--------------------------+
| 9PFS mounting client | | | 9PFS exporting server |
SW | | | | |
| (this:trans_usbg) | | |(e.g. diod or nfs-ganesha)|
+-------------^------------+ | +-------------^------------+
| | |
| | +------v------+
| | | p9_fwd.py |
| | +------^------+
| | |
------------------|------------------------------------|-------------
| | |
+-------------v------------+ | +-------------v------------+
| | | | |
HW | USB Device Controller <---------> USB Host Controller |
| | | | |
+--------------------------+ | +--------------------------+The USB host exports a filesystem, while the gadget on the USB device side makes it mountable.
Diod (9pfs server) and the forwarder are on the development host, where the root filesystem is actually stored. The gadget is initialized during boot (or later) on the embedded board. Then the forwarder will find it on the USB bus and start forwarding requests.
In this case the 9p requests come from the device and are handled by the host. The reason is that USB device ports are normally not available on PCs, so a connection in the other direction would not work.
One use-case is to use it as an alternative to NFS root booting during the development of embedded Linux devices.
---
Changes in v12:
- removed the unused "struct usb_function *f" catched by kbuild test robot
- Link to v11: https://lore.kernel.org/r/[email protected]
Changes in v11:
- fixed the include guard in func_utils.h
- Link to v10: https://lore.kernel.org/r/[email protected]
Changes in v10:
- fixed reset of tx req context in complete handler
- added suggestions from Cristoph JAILLET from v9 review
- Link to v9: https://lore.kernel.org/r/[email protected]
Changes in v9:
- solved the error return path by using wait_for_completion instead of
running in the usb complete callback in a loop
- by using wait_for_completion solves the req_lock
- using req->context instead of using a state variable
- Link to v8: https://lore.kernel.org/r/[email protected]
Changes in v8:
- this time really added the req_lock spinlock
- Link to v7: https://lore.kernel.org/r/[email protected]
Changes in v7:
- added back the req_lock spinlock
- Link to v6: https://lore.kernel.org/r/[email protected]
Changes in v6:
- fixed the python script not to have path set by default
- improved the lock init
- fixed usb9pfs status change to connected
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- fixed lockup in mount -> remount -> monut scenario
- improved p9_fwd transport script with more options
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- reworked the naming scheme to be set by the configfs instance
- added conn_cancel function to properly stop the transfers
- ensured that umount -f will work even when the host side has crahed
- added all the review feedback from Andrzej Pietrasiewicz
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- dropped patch "usb: gadget: legacy: add 9pfs multi gadget" as discussed with gregkh
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- improved the commit messages
- introduced an patch to move the header u_f.h to include/linux/usb to compile usb gadget functions treewide
- moved usbg gadget function to net/9p/
- adderessed several comments in function driver, like the cleanup path and kbuild errors
- improved the documentation in Documentation/filesystems/9p.rst
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Michael Grzeschik (3):
usb: gadget: function: move u_f.h to include/linux/usb/func_utils.h net/9p/usbg: Add new usb gadget function transport
tools: usb: p9_fwd: add usb gadget packet forwarder script
Documentation/filesystems/9p.rst | 58 +- drivers/usb/gadget/configfs.c | 2 +- drivers/usb/gadget/function/f_fs.c | 2 +- drivers/usb/gadget/function/f_hid.c | 2 +- drivers/usb/gadget/function/f_loopback.c | 2 +- drivers/usb/gadget/function/f_midi.c | 2 +- drivers/usb/gadget/function/f_midi2.c | 2 +- drivers/usb/gadget/function/f_sourcesink.c | 2 +- drivers/usb/gadget/u_f.c | 2 +- .../gadget/u_f.h => include/linux/usb/func_utils.h | 8 +- net/9p/Kconfig | 6 + net/9p/Makefile | 4 + net/9p/trans_usbg.c | 956 +++++++++++++++++++++ tools/usb/p9_fwd.py | 243 ++++++ 14 files changed, 1278 insertions(+), 13 deletions(-)
---
base-commit: 47ac09b91befbb6a235ab620c32af719f8208399
change-id: 20240116-ml-topic-u9p-895274530eb1
Best regards,
Signature · 1 line
Michael Grzeschik <[email protected]>
PATCH v12 1/3 usb: gadget: function: move u_f.h to include/linux/usb/func_utils.h
We move the func_utils.h header to include/linux/usb to be able to compile function drivers outside of the drivers/usb/gadget/function directory.
---
v11 -> v12: -
v10 -> v11:
- fixed the naming of the include guard in func_utils.h
v9 -> v10:
- respect alphabetical order
- correctly changed filename in func_utils.h itself
v5 -> v9: -
v4 -> v5:
- renamed to func_utils.h
v3 -> v4: -
v1 -> v2:
- new introduced patch
--- drivers/usb/gadget/configfs.c | 2 +- drivers/usb/gadget/function/f_fs.c | 2 +- drivers/usb/gadget/function/f_hid.c | 2 +- drivers/usb/gadget/function/f_loopback.c | 2 +- drivers/usb/gadget/function/f_midi.c | 2 +- drivers/usb/gadget/function/f_midi2.c | 2 +- drivers/usb/gadget/function/f_sourcesink.c | 2 +- drivers/usb/gadget/u_f.c | 2 +- drivers/usb/gadget/u_f.h => include/linux/usb/func_utils.h | 8 ++++---- 9 files changed, 12 insertions(+), 12 deletions(-)
drivers/usb/gadget/configfs.c +1 -1
@@ -6,10 +6,10 @@#include <linux/kstrtox.h> #include <linux/nls.h> #include <linux/usb/composite.h> +#include <linux/usb/func_utils.h> #include <linux/usb/gadget_configfs.h> #include <linux/usb/webusb.h> #include "configfs.h" -#include "u_f.h" #include "u_os_desc.h" int check_user_usb_string(const char *name,
drivers/usb/gadget/function/f_fs.c +1 -1
@@ -33,6 +33,7 @@#include <linux/usb/ccid.h> #include <linux/usb/composite.h> #include <linux/usb/functionfs.h> +#include <linux/usb/func_utils.h> #include <linux/aio.h> #include <linux/kthread.h>
@@ -40,7 +41,6 @@#include <linux/eventfd.h> #include "u_fs.h" -#include "u_f.h" #include "u_os_desc.h" #include "configfs.h"
drivers/usb/gadget/function/f_hid.c +1 -1
@@ -15,9 +15,9 @@#include <linux/uaccess.h> #include <linux/wait.h> #include <linux/sched.h> +#include <linux/usb/func_utils.h> #include <linux/usb/g_hid.h> -#include "u_f.h" #include "u_hid.h" #define HIDG_MINORS 4
drivers/usb/gadget/function/f_loopback.c +1 -1
@@ -14,9 +14,9 @@#include <linux/module.h> #include <linux/err.h> #include <linux/usb/composite.h> +#include <linux/usb/func_utils.h> #include "g_zero.h" -#include "u_f.h" /* * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals,
drivers/usb/gadget/function/f_midi.c +1 -1
@@ -30,11 +30,11 @@#include <sound/rawmidi.h> #include <linux/usb/ch9.h> +#include <linux/usb/func_utils.h> #include <linux/usb/gadget.h> #include <linux/usb/audio.h> #include <linux/usb/midi.h> -#include "u_f.h" #include "u_midi.h" MODULE_AUTHOR ("Ben Williamson" );
drivers/usb/gadget/function/f_midi2.c +1 -1
@@ -15,11 +15,11 @@#include <sound/ump_convert.h> #include <linux/usb/ch9.h> +#include <linux/usb/func_utils.h> #include <linux/usb/gadget.h> #include <linux/usb/audio.h> #include <linux/usb/midi-v2.h> -#include "u_f.h" #include "u_midi2.h" struct f_midi2 ;
drivers/usb/gadget/function/f_sourcesink.c +1 -1
@@ -13,10 +13,10 @@#include <linux/device.h> #include <linux/module.h> #include <linux/usb/composite.h> +#include <linux/usb/func_utils.h> #include <linux/err.h> #include "g_zero.h" -#include "u_f.h" /* * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral
drivers/usb/gadget/u_f.c +1 -1
@@ -8,8 +8,8 @@* Author: Andrzej Pietrasiewicz <[email protected]> */ -#include "u_f.h" #include <linux/usb/ch9.h> +#include <linux/usb/func_utils.h> struct usb_request *alloc_ep_req (struct usb_ep *ep,size_t len) {
include/linux/usb/func_utils.h renamed from drivers/usb/gadget/u_f.h +4 -4
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 /* -* u_f.h +* func_utils.h * * Utility definitions for USB functions *
@@ -10,8 +10,8 @@* Author: Andrzej Pietrasiewicz <[email protected]> */ -#ifndef __U_F_H__ -#define __U_F_H__ +#ifndef _FUNC_UTILS_H_ +#define _FUNC_UTILS_H_#include <linux/usb/gadget.h> #include <linux/overflow.h>
@@ -83,4 +83,4 @@ static inline void free_ep_req(struct usb_ep *ep, struct usb_request *req) usb_ep_free_request(ep, req); } -#endif /* __U_F_H__ */ +#endif /* _FUNC_UTILS_H_ */
Signature · 1 line
2.39.2
PATCH v12 2/3 net/9p/usbg: Add new usb gadget function transport
In reply to Michael GrzeschikAdd the new gadget function for 9pfs transport. This function is defining an simple 9pfs transport interface that consists of one in and one out endpoint. The endpoints transmit and receive the 9pfs protocol payload when mounting a 9p filesystem over usb.
---
v11 -> v12:
- fix warning: variable 'f' set but not used
v10 -> v11: -
v9 -> v10:
- fixed req->context to be reset in tx_complete
- removed extra header files
- used guard for simple mutex/spinlock scenarios
- simple cleanup extra return on void
- added explicit return 0 where appropriate
- removed extra {} in oneliners
- used list_for_each_entry instead of _safe variant since unnecessary
- use sysfs_emit
v8 -> v9:
- removed set but unused variable cdev from p9_usbg_create found by the kernel test robot
- used complete framework to properly return transfer errors
- removed state variable p9_tx_req and added it to usb_req context
- resetting req->zero on every receive, independend of errors
- added cleanups and issues as suggested by Oliver Neukum on v7
- cleaned up return value names
v7 -> v8:
- actually do the change mentioned in v7
v6 -> v7:
- added back req_lock since multiple files could be queud pending like
in the boot case
v5 -> v6:
- moved spinlock_init to usb9pfs_alloc
- set connected status depending on if gadget init came first or usb9pfs(mount) came first
v4 -> v5:
- remove instance from instance list on free
- bail out if no req was queued in disable
- free requests on disable
- use irqsave/restore in other functions then the completion handlers
- simplify the completion handlers
- reset tx_req pointer to NULL after the status update
- add unbind function
- use the right lock when protecting 9p requets
- refactor giveback of tx_request to extra function clear_tx
- enable endpoints once on set_alt
- only disable endpoints on unbind
- reset request pointers on free
- remove req_lock which is not necessary since only one transfer can
be queued for now
v3 -> v4:
- implemented conn_cancel
- moved from mount_tag to device name like ffs does
- renamed function_list to usb9pfs_instance
- renamed usbg_function_list to usb9pfs_instance_list
- renamed rx/tx_fill to queue_rx/tx
- added use of retvals
- added locking comment over usb9pfs_transmit
- using if_else instead of two pathed switch calls
- fixed return values of completion handler
- using void pointer as parameter in rx_header
- added a missed req_put in rx_header
- removed extra disable function but call disable_ep directly
- repaired several return values
- remove the suspicious disable / enable path in usbg_create
v2 -> v3: -
v1 -> v2:
- move the driver to net/9p/trans_usbg.c
- fixed the commit title
- fix %zu usage in p9_debug for size_t type
- define functions static that are only used localy
- return 0 in alloc_requests
- use id_alloc_max instead of ida_simple_get
- call ida_free in usb9pfs_free_func
- call kfree for usb9pfs->tag and usb9pfs in usb9pfs_free_func
- add MODULE_ALIAS_9P to load this module automatic when mounting
- improved the documentation
- added depends on USB_GADGET in Kconfig
--- Documentation/filesystems/9p.rst | 17 +- net/9p/Kconfig | 6 + net/9p/Makefile | 4 + net/9p/trans_usbg.c | 956 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 982 insertions(+), 1 deletion(-)
Documentation/filesystems/9p.rst +16 -1
@@ -48,11 +48,25 @@ For server running on QEMU host with virtio transport:: mount -t 9p -o trans=virtio <mount_tag> /mnt/9 -where mount_tag is the tag associated by the server to each of the exported +where mount_tag is the tag generated by the server to each of the exported mount points. Each 9P export is seen by the client as a virtio device with an associated "mount_tag" property. Available mount tags can be seen by reading /sys/bus/virtio/drivers/9pnet_virtio/virtio<n>/mount_tag files. +USBG Usage +========== + +To mount a 9p FS on a USB Host accessible via the gadget at runtime:: + + mount -t 9p -o trans=usbg,aname=/path/to/fs <device> /mnt/9 + +To mount a 9p FS on a USB Host accessible via the gadget as root filesystem:: + + root=<device> rootfstype=9p rootflags=trans=usbg,cache=loose,uname=root,access=0,dfltuid=0,dfltgid=0,aname=/path/to/rootfs + +where <device> is the tag associated by the usb gadget transport. +It is defined by the configfs instance name. + Options =======
@@ -68,6 +82,7 @@ Options virtio connect to the next virtio channel available (from QEMU with trans_virtio module) rdma connect to a specified RDMA channel + usbg connect to a specified usb gadget channel ======== ============================================ uname=name user name to attempt mount as on the remote server. The
net/9p/Kconfig +6 -0
@@ -40,6 +40,12 @@ config NET_9P_XEN This builds support for a transport for 9pfs between two Xen domains. +config NET_9P_USBG + bool "9P USB Gadget Transport" + depends on USB_GADGET + help + This builds support for a transport for 9pfs over + usb gadget. config NET_9P_RDMA depends on INET && INFINIBAND && INFINIBAND_ADDR_TRANS
net/9p/Makefile +4 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_NET_9P_FD) += 9pnet_fd.o obj-$(CONFIG_NET_9P_XEN) += 9pnet_xen.o obj-$(CONFIG_NET_9P_VIRTIO) += 9pnet_virtio.o obj-$(CONFIG_NET_9P_RDMA) += 9pnet_rdma.o +obj-$(CONFIG_NET_9P_USBG) += 9pnet_usbg.o 9pnet-objs := \ mod.o \
@@ -23,3 +24,6 @@ obj-$(CONFIG_NET_9P_RDMA) += 9pnet_rdma.o 9pnet_rdma-objs := \ trans_rdma.o \ + +9pnet_usbg-objs := \ + trans_usbg.o \
net/9p/trans_usbg.c new file +956 -0
956 lines not on this page · raw message
Signature · 1 line
2.39.2
Dominique Martinet
maintainerRe: [PATCH v12 2/3] net/9p/usbg: Add new usb gadget function transport
Michael Grzeschik wrote on Sun, Sep 01, 2024 at 09:11:17PM +0200:
net/9p/Kconfig config NET_9P_XEN · line 44
Quoted 10 lines
net/9p/Kconfig +2
-0@@ -40,6 +40,12 @@ config NET_9P_XEN This builds support for a transport for 9pfs between two Xen domains. +config NET_9P_USBG + bool "9P USB Gadget Transport"
It's been a while since this got in, but I figured I'd at least start by getting this built since we got a minor fix recently, and this being a bool is a bit weird -- any reaosn this wasn't made tristate?
(If NET_9P=m then setting NET_9P_USBG=y doesn't seem to do anything? while it should be buildable as module, whether NET_9P is m or y)
From the code there's a module_init and MODULE_ALIAS_9P is set so I don't see why it wouldn't just work, but I still haven't taken the time to figure out how to run this in qemu so I can't test this trivial diff:
----
net/9p/Kconfig +1 -1
@@ -41,7 +41,7 @@ config NET_9P_XEN two Xen domains. config NET_9P_USBG - bool "9P USB Gadget Transport" + tristate "9P USB Gadget Transport" depends on USB_GADGET=y || USB_GADGET=NET_9P select CONFIGFS_FS select USB_LIBCOMPOSITE
----
Thoughts?
In particular the depends might need adjusting, it's already in an if NET_9P block so just depends on USB_GADGET is probably enough, but I don't understand the rationale behind USB_GADGET=NET_9P either (can't have NET_9P=y and USB_GADGET=m ?)
Thanks,
Signature · 1 line
Dominique
PATCH v12 3/3 tools: usb: p9_fwd: add usb gadget packet forwarder script
In reply to Michael GrzeschikThis patch is adding an small python tool to forward 9pfs requests from the USB gadget to an existing 9pfs TCP server. Since currently all 9pfs servers lack support for the usb transport this tool is an useful helper to get started.
Refer the Documentation section "USBG Example" in Documentation/filesystems/9p.rst on how to use it.
---
v11 -> v12: -
v10 -> v11: -
v6 -> v10: -
v5 -> v6:
- set path parameter to None when unused
v4 -> v5:
- updated documentation for new subcommands list/connect
- run ruff format
- make vid and pid parameterized
- add list as subcommand to scan for devices
- move connect to extra subcommand
v2 -> v4: -
v1 -> v2:
- added usbg 9pfs detailed instructions to 9p.rst doc
--- Documentation/filesystems/9p.rst | 41 +++++++ tools/usb/p9_fwd.py | 243 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 284 insertions(+)
Documentation/filesystems/9p.rst +41 -0
@@ -67,6 +67,47 @@ To mount a 9p FS on a USB Host accessible via the gadget as root filesystem:: where <device> is the tag associated by the usb gadget transport. It is defined by the configfs instance name. +USBG Example +============ + +The USB host exports a filesystem, while the gadget on the USB device +side makes it mountable. + +Diod (9pfs server) and the forwarder are on the development host, where +the root filesystem is actually stored. The gadget is initialized during +boot (or later) on the embedded board. Then the forwarder will find it +on the USB bus and start forwarding requests. + +In this case the 9p requests come from the device and are handled by the +host. The reason is that USB device ports are normally not available on +PCs, so a connection in the other direction would not work. + +When using the usbg transport, for now there is no native usb host +service capable to handle the requests from the gadget driver. For +this we have to use the extra python tool p9_fwd.py from tools/usb. + +Just start the 9pfs capable network server like diod/nfs-ganesha e.g.: + + $ diod -f -n -d 0 -S -l 0.0.0.0:9999 -e $PWD + +Optionaly scan your bus if there are more then one usbg gadgets to find their path: + + $ python $kernel_dir/tools/usb/p9_fwd.py list + + Bus | Addr | Manufacturer | Product | ID | Path + --- | ---- | ---------------- | ---------------- | --------- | ---- + 2 | 67 | unknown | unknown | 1d6b:0109 | 2-1.1.2 + 2 | 68 | unknown | unknown | 1d6b:0109 | 2-1.1.3 + +Then start the python transport: + + $ python $kernel_dir/tools/usb/p9_fwd.py --path 2-1.1.2 connect -p 9999 + +After that the gadget driver can be used as described above. + +One use-case is to use it as an alternative to NFS root booting during +the development of embedded Linux devices. + Options =======
tools/usb/p9_fwd.py new file +243 -0
243 lines not on this page · raw message
Signature · 1 line
2.39.2