Skip to contentSkip to conversation

RFC - Implement a usbredir kernel module

RFC PATCH In review Jeremy White 8 participants 34 messages Jun 30, 2015 – Dec 9, 2015 1 message not in the archive USB

lore
Share & tools
lore
#0 lore raw

cover RFC - Implement a usbredir kernel module

The following patch proposes a new kernel module to provide an alternate protocol for transporting USB devices over a TCP/IP connection.

This flows from a few conversations on the Spice devel mailing list.[1][2]

I am relying heavily on the opinion of Hans de Goede, who believes that the usbredir protocol is superior to that used by the existing usbip kernel module[3].

The basic approach in this module is the same as usbip (virtual hcd driver) but it attempts to support a configurable number of devices and hubs, rather than just one hub and the limit of 8 devices.

This version of the code should be sufficient to review my general approach, but it is known to be incomplete. I have successfully mounted and operated a thumb drive across the interface.

Hopefully it is enough to warrant advice and comments; feedback is greatly appreciated.

Anyone wishing to test this will also need a related set of usbredir patches, recently sent to the spice-devel mailing list.[4]

Roughly half of the code (all of the code that fails checkpatch <grin>) was copied, essentially unchanged, from the usbredir project. I felt that diffability was more important than checkpatch; I stand ready to be corrected.

After review, I plan to build a fairly extensive set of unit tests (see the new usbredirtestserver in [3]), and would hope to submit a complete module later in the summer.

Cheers,

Jeremy

[1] http://lists.freedesktop.org/archives/spice-devel/2014-August/017145.html
[2] http://lists.freedesktop.org/archives/spice-devel/2015-April/019451.html
[3] http://lists.freedesktop.org/archives/spice-devel/2014-August/017174.html
[4] http://lists.freedesktop.org/archives/spice-devel/2015-June/020595.html

#1 lore raw

RFC PATCH 1/1 Add a usbredir kernel module to remotely connect USB devices over IP.

This module uses the usbredir protocol and user space tools, which are used by the SPICE project.

---
 MAINTAINERS                                 |    6 +
 drivers/usb/Kconfig                         |    2 +
 drivers/usb/Makefile                        |    1 +
 drivers/usb/usbredir/Kconfig                |   25 +
 drivers/usb/usbredir/Makefile               |    4 +
 drivers/usb/usbredir/README                 |   20 +
 drivers/usb/usbredir/TODO                   |   12 +
 drivers/usb/usbredir/device.c               |  327 +++++
 drivers/usb/usbredir/hub.c                  |  489 ++++++++
 drivers/usb/usbredir/main.c                 |  100 ++
 drivers/usb/usbredir/redir.c                |  535 ++++++++
 drivers/usb/usbredir/rx.c                   |   40 +
 drivers/usb/usbredir/strtok_r.c             |   69 +
 drivers/usb/usbredir/strtok_r.h             |   26 +
 drivers/usb/usbredir/sysfs.c                |  145 +++
 drivers/usb/usbredir/tx.c                   |  151 +++
 drivers/usb/usbredir/urb.c                  |  266 ++++
 drivers/usb/usbredir/usbredir.h             |  225 ++++
 drivers/usb/usbredir/usbredirfilter.c       |  294 +++++
 drivers/usb/usbredir/usbredirfilter.h       |  144 +++
 drivers/usb/usbredir/usbredirparser.c       | 1795 +++++++++++++++++++++++++++
 drivers/usb/usbredir/usbredirparser.h       |  386 ++++++
 drivers/usb/usbredir/usbredirproto-compat.h |   88 ++
 drivers/usb/usbredir/usbredirproto.h        |  309 +++++
 24 files changed, 5459 insertions(+)
 create mode 100644 drivers/usb/usbredir/Kconfig
 create mode 100644 drivers/usb/usbredir/Makefile
 create mode 100644 drivers/usb/usbredir/README
 create mode 100644 drivers/usb/usbredir/TODO
 create mode 100644 drivers/usb/usbredir/device.c
 create mode 100644 drivers/usb/usbredir/hub.c
 create mode 100644 drivers/usb/usbredir/main.c
 create mode 100644 drivers/usb/usbredir/redir.c
 create mode 100644 drivers/usb/usbredir/rx.c
 create mode 100644 drivers/usb/usbredir/strtok_r.c
 create mode 100644 drivers/usb/usbredir/strtok_r.h
 create mode 100644 drivers/usb/usbredir/sysfs.c
 create mode 100644 drivers/usb/usbredir/tx.c
 create mode 100644 drivers/usb/usbredir/urb.c
 create mode 100644 drivers/usb/usbredir/usbredir.h
 create mode 100644 drivers/usb/usbredir/usbredirfilter.c
 create mode 100644 drivers/usb/usbredir/usbredirfilter.h
 create mode 100644 drivers/usb/usbredir/usbredirparser.c
 create mode 100644 drivers/usb/usbredir/usbredirparser.h
 create mode 100644 drivers/usb/usbredir/usbredirproto-compat.h
 create mode 100644 drivers/usb/usbredir/usbredirproto.h
MAINTAINERS +6 -0
index d8afd29..738a80d 100644
@@ -10363,6 +10363,12 @@ S:	Maintained
 F:	drivers/usb/usbip/
 F:	tools/usb/usbip/
 
+USBREDIR IP DRIVER
+M:	Jeremy White <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/usb/usbredir/
+
 USB PEGASUS DRIVER
 M:	Petko Manolov <[email protected]>
 L:	[email protected]
drivers/usb/Kconfig +2 -0
index 8ed451d..18940f5 100644
@@ -94,6 +94,8 @@ source "drivers/usb/image/Kconfig"
 
 source "drivers/usb/usbip/Kconfig"
 
+source "drivers/usb/usbredir/Kconfig"
+
 endif
 
 source "drivers/usb/musb/Kconfig"
drivers/usb/Makefile +1 -0
index d8926c6..384fd9f 100644
@@ -62,3 +62,4 @@ obj-$(CONFIG_USB_GADGET)	+= gadget/
 obj-$(CONFIG_USB_COMMON)	+= common/
 
 obj-$(CONFIG_USBIP_CORE)	+= usbip/
+obj-$(CONFIG_USBREDIR)		+= usbredir/
drivers/usb/usbredir/Kconfig new file +25 -0
new file mode 100644
index 0000000..284fd02
@@ -0,0 +1,25 @@
+config USBREDIR
+	tristate "USBREDIR support"
+	depends on USB && NET
+	---help---
+	  This enables connecting a remote USB device over IP using
+          the USBREDIR protocol.  This module provides a sysfs attach
+          interface which, if given a socket connected to a remote
+          usbredirserver, will enable the remote device to behave as
+          though it were connected to the system running this module.
+
+          For more information and user space tools, refer to the
+          USBREDIR project, which can be found at
+          http://www.spice-space.org/page/UsbRedir.
+
+	  To compile this as a module, choose M here: the module will
+	  be called usbredir.
+
+	  If unsure, say N.
+
+config USBREDIR_DEBUG
+	bool "Debug messages for USBREDIR"
+	depends on USBREDIR
+	---help---
+	  This enables the debug messages from the USBREDIR drivers.
+
drivers/usb/usbredir/Makefile new file +4 -0
new file mode 100644
index 0000000..531ff31
@@ -0,0 +1,4 @@
+ccflags-$(CONFIG_USBREDIR_DEBUG) := -DDEBUG
+
+obj-$(CONFIG_USBREDIR) += usbredir.o
+usbredir-y := main.o sysfs.o hub.o device.o urb.o redir.o tx.o rx.o usbredirparser.o strtok_r.o usbredirfilter.o
drivers/usb/usbredir/README new file +20 -0
new file mode 100644
index 0000000..217a2e4
@@ -0,0 +1,20 @@
+USB Redirection Kernel Module
+
+This module allows a Linux system to instatiate USB devices
+that are located on a remote device.  The USB data is transferred
+over a socket using the USBREDIR protocol, which is generally
+used in conjunction with the SPICE project.
+
+You will need the USBREDIR user space tools.  They can
+be found at http://www.spice-space.org/page/UsbRedir.
+
+To use, start the usbredirserver on a remote system.
+For example,
+ ./usbredirserver --port 4000 125f:db8a
+will export my ADATA thumb drive on the remote system.
+
+Next, on the local system, connect a socket and relay that to
+the kernel module.  The connectkernel utility will do this as follows:
+  ./connectkernel adata4000 my.remote.device.com 4000
+
+The device should attach and be usable on the local system.
drivers/usb/usbredir/TODO new file +12 -0
new file mode 100644
index 0000000..605551a
@@ -0,0 +1,12 @@
+TODO:
+  *  Note - during testing, having a device die unexpectedly
+     could go on to cause fairly serious problems.  Need to
+     explore that.
+  *  Still getting sporadic failures
+     - One clue - got an unexpected rc from the write in redir.c
+  *  Hmm.  KFP_ATOMIC on our mallocs may be better than _KERNEL...
+  *  Read and deal with the many TODOs
+  *  Not just hacking the usbredirparser, but proper patches
+     - The filter needs love.  Use strsep, not strtok?
+  *  Expose a sysfs attribute and have udev use it
+  *  Turn on more capabilities and watch it go
drivers/usb/usbredir/device.c new file +327 -0

327 lines not on this page · raw message

drivers/usb/usbredir/hub.c new file +489 -0

489 lines not on this page · raw message

drivers/usb/usbredir/main.c new file +100 -0

100 lines not on this page · raw message

drivers/usb/usbredir/redir.c new file +535 -0

535 lines not on this page · raw message

drivers/usb/usbredir/rx.c new file +40 -0
new file mode 100644
index 0000000..92ffa97
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2015 Jeremy White
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/kthread.h>
+
+#include "usbredir.h"
+
+int usbredir_rx_loop(void *data)
+{
+	struct usbredir_device *udev = data;
+	int rc;
+
+	while (!kthread_should_stop() && atomic_read(&udev->active)) {
+		rc = usbredirparser_do_read(udev->parser);
+		if (rc != -EAGAIN) {
+			pr_info("usbredir/rx:%d connection closed\n",
+				udev->rhport);
+			break;
+		}
+	}
+
+	pr_debug("%s exit\n", __func__);
+
+	usbredir_device_disconnect(udev);
+	usbredir_device_deallocate(udev, false, true);
+
+	return 0;
+}
drivers/usb/usbredir/strtok_r.c new file +69 -0

69 lines not on this page · raw message

drivers/usb/usbredir/strtok_r.h new file +26 -0
new file mode 100644
index 0000000..50e6e0e
@@ -0,0 +1,26 @@
+/* Reentrant string tokenizer.  Generic version.
+   Copyright (C) 1991,1996-1999,2001,2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _USBREDIRPARSER_STRTOK_H_
+#define _USBREDIRPARSER_STRTOK_H_
+
+char *
+glibc_strtok_r(char *s, const char *delim, char **save_ptr);
+
+#endif
drivers/usb/usbredir/sysfs.c new file +145 -0

145 lines not on this page · raw message

drivers/usb/usbredir/tx.c new file +151 -0

151 lines not on this page · raw message

drivers/usb/usbredir/urb.c new file +266 -0

266 lines not on this page · raw message

drivers/usb/usbredir/usbredir.h new file +225 -0

225 lines not on this page · raw message

drivers/usb/usbredir/usbredirfilter.c new file +294 -0

294 lines not on this page · raw message

drivers/usb/usbredir/usbredirfilter.h new file +144 -0

144 lines not on this page · raw message

drivers/usb/usbredir/usbredirparser.c new file +1795 -0

104 lines not on this page · raw message

drivers/usb/usbredir/usbredirparser.h new file +386 -0

386 lines not on this page · raw message

drivers/usb/usbredir/usbredirproto-compat.h new file +88 -0

88 lines not on this page · raw message

drivers/usb/usbredir/usbredirproto.h new file +309 -0

309 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.1.4

Part of the diff is not shown here. View the raw message.

#2 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 43 lines · Jeremy White

This module uses the usbredir protocol and user space tools, which are used by the SPICE project.

---
 MAINTAINERS                                 |    6 +
 drivers/usb/Kconfig                         |    2 +
 drivers/usb/Makefile                        |    1 +
 drivers/usb/usbredir/Kconfig                |   25 +
 drivers/usb/usbredir/Makefile               |    4 +
 drivers/usb/usbredir/README                 |   20 +
 drivers/usb/usbredir/TODO                   |   12 +
 drivers/usb/usbredir/device.c               |  327 +++++
 drivers/usb/usbredir/hub.c                  |  489 ++++++++
 drivers/usb/usbredir/main.c                 |  100 ++
 drivers/usb/usbredir/redir.c                |  535 ++++++++
 drivers/usb/usbredir/rx.c                   |   40 +
 drivers/usb/usbredir/strtok_r.c             |   69 +
 drivers/usb/usbredir/strtok_r.h             |   26 +
 drivers/usb/usbredir/sysfs.c                |  145 +++
 drivers/usb/usbredir/tx.c                   |  151 +++
 drivers/usb/usbredir/urb.c                  |  266 ++++
 drivers/usb/usbredir/usbredir.h             |  225 ++++
 drivers/usb/usbredir/usbredirfilter.c       |  294 +++++
 drivers/usb/usbredir/usbredirfilter.h       |  144 +++
 drivers/usb/usbredir/usbredirparser.c       | 1795 +++++++++++++++++++++++++++
 drivers/usb/usbredir/usbredirparser.h       |  386 ++++++
 drivers/usb/usbredir/usbredirproto-compat.h |   88 ++
 drivers/usb/usbredir/usbredirproto.h        |  309 +++++
 24 files changed, 5459 insertions(+)
 create mode 100644 drivers/usb/usbredir/Kconfig
 create mode 100644 drivers/usb/usbredir/Makefile
 create mode 100644 drivers/usb/usbredir/README
 create mode 100644 drivers/usb/usbredir/TODO
 create mode 100644 drivers/usb/usbredir/device.c
 create mode 100644 drivers/usb/usbredir/hub.c
 create mode 100644 drivers/usb/usbredir/main.c
 create mode 100644 drivers/usb/usbredir/redir.c
 create mode 100644 drivers/usb/usbredir/rx.c
 create mode 100644 drivers/usb/usbredir/strtok_r.c
 create mode 100644 drivers/usb/usbredir/strtok_r.h
 create mode 100644 drivers/usb/usbredir/sysfs.c
 create mode 100644 drivers/usb/usbredir/tx.c
Quoted 8 lines
 create mode 100644 drivers/usb/usbredir/urb.c
 create mode 100644 drivers/usb/usbredir/usbredir.h
 create mode 100644 drivers/usb/usbredir/usbredirfilter.c
 create mode 100644 drivers/usb/usbredir/usbredirfilter.h
 create mode 100644 drivers/usb/usbredir/usbredirparser.c
 create mode 100644 drivers/usb/usbredir/usbredirparser.h
 create mode 100644 drivers/usb/usbredir/usbredirproto-compat.h
 create mode 100644 drivers/usb/usbredir/usbredirproto.h

It's pointless to post a patch that you know has problems with it (i.e. it's not even in proper kernel coding style), as it will never be reviewed or even looked at.

Please do the most basic of polite things and fix this up before posting things.

And really, all in one patch? That too is pretty hard to review...

thanks,

greg k-h

#3 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 4 lines

It's pointless to post a patch that you know has problems with it (i.e. it's not even in proper kernel coding style), as it will never be reviewed or even looked at.

Thanks for the reply, and I'm sorry for the clumsy ask.

I would still appreciate feedback on two points:

1. Is the basic premise reasonable? Is Hans correct in asserting
that an alternate USB over IP module will be considered?

2. Do I correctly understand that there are no circumstances where
copied code can be left unmodified? Even in the case where the copied code is working, production code, and the changes would be just for style?

Quoted 3 lines

Please do the most basic of polite things and fix this up before posting things.

It is often difficult for a newcomer to know what the polite thing is, even after studying FAQs and documentation.

I appreciate your patience (and clue bats) as I try to learn.

Quoted 2 lines

And really, all in one patch? That too is pretty hard to review...

Yeah. I see the point of pain. I did not see a solution as I formed the patch, but I'll try harder before resending.

Cheers,

Jeremy

#4 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 11 lines · Jeremy White
Quoted 4 lines

It's pointless to post a patch that you know has problems with it (i.e. it's not even in proper kernel coding style), as it will never be reviewed or even looked at.

Thanks for the reply, and I'm sorry for the clumsy ask.

I would still appreciate feedback on two points:

1. Is the basic premise reasonable? Is Hans correct in asserting that an
alternate USB over IP module will be considered?

I have no idea, if it fully replaces the usbip functionality, I don't see why that would be rejected. But why can't you just fix up usbip for the issues you find lacking?

Quoted 3 lines

2. Do I correctly understand that there are no circumstances where copied
code can be left unmodified? Even in the case where the copied code is working, production code, and the changes would be just for style?

I doubt the changes would just be for "style" if you are craming it into the kernel tree, as it's a totally different environment from any other place this code might have been running in before.

Quoted 5 lines
Quoted 2 lines

Please do the most basic of polite things and fix this up before posting things.

It is often difficult for a newcomer to know what the polite thing is, even after studying FAQs and documentation.

Did you read Documentation/SubmittingPatches?

Quoted 7 lines

I appreciate your patience (and clue bats) as I try to learn.

Quoted 2 lines

And really, all in one patch? That too is pretty hard to review...

Yeah. I see the point of pain. I did not see a solution as I formed the patch, but I'll try harder before resending.

Remember you need to make this trivial to review in order to get it accepted. You have to do extra work because of this because our limited resource is reviewers and maintainers, not developers.

thanks,

greg k-h

#5 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 7 lines · Greg KH
Quoted 2 lines · Jeremy White

1. Is the basic premise reasonable? Is Hans correct in asserting that an
alternate USB over IP module will be considered?

I have no idea, if it fully replaces the usbip functionality, I don't see why that would be rejected. But why can't you just fix up usbip for the issues you find lacking?

This is what Hans said 5 years ago: [1]

Quoted 35 lines

3) The protocol itself is far from ideal.

Number 3 is the big deal breaker for me. I've looked at the (undocumented) protocol by sifting through the source. And it is very low level, all it does is shove usb packets back and forth over the network. It has no concept of configuration setting (the docs say make sure the device is in the right configuration before sharing it). No concept of caching things like descriptors, active configuration, per interface alt setting, etc.

Besides missing a lot of useful smarts the whole one packet at a time approach does not really fly when it comes to isoc endpoints. As there paper states, the vm-host / guest os drivers need to make sure enough packets are submitted / queued at all time to gap the network delay / fill the network pipe.

For iso endpoints it makes much more sense to have a start / stop stream model, where the usb-host "pumpes" the urb ringbuffer and sends out data received from the usb device to the vm-host (isoc input endp case), or sends data received from the vm-host (through a buffer to deal with network jitter) to the isoc output endpoint.

This also halves the number of packets which need to be send over the network, as their is no need for the vm-host to send a request for each packet once an input stream has started / for the usb-host to send an ack for each delivered packet for an ouput stream. It would still send an error when an error occurs, but their is no reason to ack all delivered packets. Given the delay caused by buffering, etc. not being able to match up the error to an exact packet is not important, as from the vm-host emulated usb hc (host controller), the packet has long been delivered already.

Quoted 3 lines

Instead we will simply report the error to the guest os for the next packet enqueued by the guest after receiving notification of the error from the usb-host.

The protocol is now documented, so that part is out of date. I don't see any evidence that the bulk of his other concerns have been addressed, however.

Quoted 8 lines
Quoted 4 lines

2. Do I correctly understand that there are no circumstances where copied
code can be left unmodified? Even in the case where the copied code is working, production code, and the changes would be just for style?

I doubt the changes would just be for "style" if you are craming it into the kernel tree, as it's a totally different environment from any other place this code might have been running in before.

Well, the checkpatch.pl reports were all style (and mostly whitespace); roughly 3000 of them against 3000 lines of code :-/. I did review the code, looking for areas where I thought it would badly cram into the kernel, and I adjusted the few I found (and sent changes upstream).

The ideal, of course, is to not want to copy this code at all. Daniel makes an alternate point that might lead to that; I'll reply to that thread.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Please do the most basic of polite things and fix this up before posting things.

It is often difficult for a newcomer to know what the polite thing is, even after studying FAQs and documentation.

Did you read Documentation/SubmittingPatches?

Yes, and SubmittingDrivers, SubmitChecklist, every link listed on #kernelnewbies, and the entire lkml FAQ as well.

In hindsight, I think it's mostly a failure of common sense on my part.

The one constructive suggestion I would offer is that the 'RFC PATCH' is used heavily by the linux kernel community, but I didn't find much discussion of it in the documentation or FAQs. I think I jumped to some erroneous conclusions about it's use. I'm willing to try to add a note on that, if that would be helpful.

Quoted 4 lines

Remember you need to make this trivial to review in order to get it accepted. You have to do extra work because of this because our limited resource is reviewers and maintainers, not developers.

Yes, understood.

Cheers,

Jeremy

[1] https://lists.gnu.org/archive/html/qemu-devel/2010-12/msg00008.html

#6 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 46 lines · Jeremy White
Quoted 7 lines · Greg KH
Quoted 2 lines · Jeremy White

1. Is the basic premise reasonable? Is Hans correct in asserting that an
alternate USB over IP module will be considered?

I have no idea, if it fully replaces the usbip functionality, I don't see why that would be rejected. But why can't you just fix up usbip for the issues you find lacking?

This is what Hans said 5 years ago: [1]

Quoted 35 lines

3) The protocol itself is far from ideal.

Number 3 is the big deal breaker for me. I've looked at the (undocumented) protocol by sifting through the source. And it is very low level, all it does is shove usb packets back and forth over the network. It has no concept of configuration setting (the docs say make sure the device is in the right configuration before sharing it). No concept of caching things like descriptors, active configuration, per interface alt setting, etc.

Besides missing a lot of useful smarts the whole one packet at a time approach does not really fly when it comes to isoc endpoints. As there paper states, the vm-host / guest os drivers need to make sure enough packets are submitted / queued at all time to gap the network delay / fill the network pipe.

For iso endpoints it makes much more sense to have a start / stop stream model, where the usb-host "pumpes" the urb ringbuffer and sends out data received from the usb device to the vm-host (isoc input endp case), or sends data received from the vm-host (through a buffer to deal with network jitter) to the isoc output endpoint.

This also halves the number of packets which need to be send over the network, as their is no need for the vm-host to send a request for each packet once an input stream has started / for the usb-host to send an ack for each delivered packet for an ouput stream. It would still send an error when an error occurs, but their is no reason to ack all delivered packets. Given the delay caused by buffering, etc. not being able to match up the error to an exact packet is not important, as from the vm-host emulated usb hc (host controller), the packet has long been delivered already.

Quoted 7 lines
Quoted 3 lines

Instead we will simply report the error to the guest os for the next packet enqueued by the guest after receiving notification of the error from the usb-host.

The protocol is now documented, so that part is out of date. I don't see any evidence that the bulk of his other concerns have been addressed, however.

Because no one has cared to. Now it seems you care, so I'd prefer to see someone fix this up instead of adding another protocol that does much the same thing.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

2. Do I correctly understand that there are no circumstances where copied
code can be left unmodified? Even in the case where the copied code is working, production code, and the changes would be just for style?

Quoted 8 lines
Quoted 3 lines

I doubt the changes would just be for "style" if you are craming it into the kernel tree, as it's a totally different environment from any other place this code might have been running in before.

Well, the checkpatch.pl reports were all style (and mostly whitespace); roughly 3000 of them against 3000 lines of code :-/. I did review the code, looking for areas where I thought it would badly cram into the kernel, and I adjusted the few I found (and sent changes upstream).

style matters, as it's a thing with your brain. You learn patterns and if the patterns change, you have to do more work and don't see the real issues involved. So by ignoring our style you are saying you don't want anyone else in the kernel community to ever review or work on the code, which isn't ok.

Quoted 11 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Please do the most basic of polite things and fix this up before posting things.

It is often difficult for a newcomer to know what the polite thing is, even after studying FAQs and documentation.

Did you read Documentation/SubmittingPatches?

Yes, and SubmittingDrivers, SubmitChecklist, every link listed on #kernelnewbies, and the entire lkml FAQ as well.

Quoted 7 lines

In hindsight, I think it's mostly a failure of common sense on my part.

The one constructive suggestion I would offer is that the 'RFC PATCH' is used heavily by the linux kernel community, but I didn't find much discussion of it in the documentation or FAQs. I think I jumped to some erroneous conclusions about it's use. I'm willing to try to add a note on that, if that would be helpful.

I personally ignore RFC patches unless they are tiny and in an area that I happened to be worried about / working on at the moment as it feels that the submitter doesn't think they are good enough to be merged as-is, so I'll wait until they feel it is worthy for submission to review it.

thanks,

greg k-h

#7 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Hi,

Quoted 51 lines · Greg KH
Quoted 50 lines · Jeremy White
Quoted 7 lines · Greg KH
Quoted 2 lines · Jeremy White

1. Is the basic premise reasonable? Is Hans correct in asserting that an
alternate USB over IP module will be considered?

I have no idea, if it fully replaces the usbip functionality, I don't see why that would be rejected. But why can't you just fix up usbip for the issues you find lacking?

This is what Hans said 5 years ago: [1]

Quoted 38 lines

3) The protocol itself is far from ideal.

Number 3 is the big deal breaker for me. I've looked at the (undocumented) protocol by sifting through the source. And it is very low level, all it does is shove usb packets back and forth over the network. It has no concept of configuration setting (the docs say make sure the device is in the right configuration before sharing it). No concept of caching things like descriptors, active configuration, per interface alt setting, etc.

Besides missing a lot of useful smarts the whole one packet at a time approach does not really fly when it comes to isoc endpoints. As there paper states, the vm-host / guest os drivers need to make sure enough packets are submitted / queued at all time to gap the network delay / fill the network pipe.

For iso endpoints it makes much more sense to have a start / stop stream model, where the usb-host "pumpes" the urb ringbuffer and sends out data received from the usb device to the vm-host (isoc input endp case), or sends data received from the vm-host (through a buffer to deal with network jitter) to the isoc output endpoint.

This also halves the number of packets which need to be send over the network, as their is no need for the vm-host to send a request for each packet once an input stream has started / for the usb-host to send an ack for each delivered packet for an ouput stream. It would still send an error when an error occurs, but their is no reason to ack all delivered packets. Given the delay caused by buffering, etc. not being able to match up the error to an exact packet is not important, as from the vm-host emulated usb hc (host controller), the packet has long been delivered already.

Instead we will simply report the error to the guest os for the next packet enqueued by the guest after receiving notification of the error from the usb-host.

Quoted 7 lines
Quoted 3 lines

The protocol is now documented, so that part is out of date. I don't see any evidence that the bulk of his other concerns have been addressed, however.

Because no one has cared to. Now it seems you care, so I'd prefer to see someone fix this up instead of adding another protocol that does much the same thing.

I understand where you are coming from, but usbip is unfixable as it has no concept of capability negotiation, protocol versioning or some such.

What we need is an usbip v2, and usbredir was written as that, and has been used in production for years now for redirection of usb devices from virtual-machine-viewers into qemu based virtual-machines.

I understand that having 2 protocols for one thing is undesirable in general, but think of this as usb-mass-storage bulk transport vs uas, or ipv4 vs ipv6 in some cases it just is necessary to do a new better protocol.

When I designed and implemented usbredir usbip was pretty much dead, but it got ressurected later. I've never spoken up on this and never attempted to block usbip's promotion out of staging, as that seemed unfair since no-one was working on a virtual-hcd driver for the usbredir protocol.

Likewise I think it is unfair if my not speaking up back then now blocks an usbredir virtual-hcd driver from entering the kernel.

Regards,

Hans

#8 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

In reply to Greg KH
Quoted 7 lines
Quoted 6 lines

Well, the checkpatch.pl reports were all style (and mostly whitespace); roughly 3000 of them against 3000 lines of code :-/. I did review the code, looking for areas where I thought it would badly cram into the kernel, and I adjusted the few I found (and sent changes upstream).

Quoted 5 lines

style matters, as it's a thing with your brain. You learn patterns and if the patterns change, you have to do more work and don't see the real issues involved. So by ignoring our style you are saying you don't want anyone else in the kernel community to ever review or work on the code, which isn't ok.

Looks like I can't side step this unless Hans is willing to shift the usbredir project entirely to using kernel style :-/.

I will plan to make changes so that checkpatch runs clean; I lay out my concerns and my plan below to make sure I'm taking the best path.

My main concern with changing the ~2,500 lines of code from the upstream usbredir project is that it will increase the odds that I will introduce errors, both initially, and again later as I review and attempt to relay patches from the upstream.

To summarize the checkpatch reports: the biggest issue is whitespace, which shouldn't be a problem; I should be able to automate that without error. There are also a fair number of one offs; FSF address, space after '!', etc. I hope to persuade Hans to take a few style only patches upstream to address those. That leaves a pack of about 60 brace placement and line length issues.

I will plan to manually change those prior to submission. Any upstream changes that affect the same code will be manually corrected as well, prior to submission.

Make sense?

Cheers,

Jeremy

#9 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Hi,

Quoted 7 lines · Jeremy White
Quoted 7 lines
Quoted 6 lines

Well, the checkpatch.pl reports were all style (and mostly whitespace); roughly 3000 of them against 3000 lines of code :-/. I did review the code, looking for areas where I thought it would badly cram into the kernel, and I adjusted the few I found (and sent changes upstream).

Quoted 8 lines
Quoted 5 lines

style matters, as it's a thing with your brain. You learn patterns and if the patterns change, you have to do more work and don't see the real issues involved. So by ignoring our style you are saying you don't want anyone else in the kernel community to ever review or work on the code, which isn't ok.

Looks like I can't side step this unless Hans is willing to shift the usbredir project entirely to using kernel style :-/.

I'm fine with moving the usbredir project to the kernel style, the question is how to do this without causing any hidden breakage.

Can you create a gnu-indent invocation which will do most of the work?

And then a hopefully managable sized patch on top to fix the remaining style errors in usbredirparser ?

Quoted 15 lines

I will plan to make changes so that checkpatch runs clean; I lay out my concerns and my plan below to make sure I'm taking the best path.

My main concern with changing the ~2,500 lines of code from the upstream usbredir project is that it will increase the odds that I will introduce errors, both initially, and again later as I review and attempt to relay patches from the upstream.

To summarize the checkpatch reports: the biggest issue is whitespace, which shouldn't be a problem; I should be able to automate that without error. There are also a fair number of one offs; FSF address, space after '!', etc. I hope to persuade Hans to take a few style only patches upstream to address those. That leaves a pack of about 60 brace placement and line length issues.

Quoted 5 lines

I will plan to manually change those prior to submission. Any upstream changes that affect the same code will be manually corrected as well, prior to submission.

Make sense?

Sounds good, note that as said I'm fine with moving over the usbredir(parser) code to the kernel style, as long as the changes are reviewable.

I think it may be best to only convert the usbredirdparser files, as those are the only ones you need for the kernel. Having a mixed style in usbredir is not ideal, but something I can live with.

Regards,

Hans

#10 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 19 lines · Hans de Goede

Hi,

Quoted 7 lines · Jeremy White
Quoted 7 lines
Quoted 6 lines

Well, the checkpatch.pl reports were all style (and mostly whitespace); roughly 3000 of them against 3000 lines of code :-/. I did review the code, looking for areas where I thought it would badly cram into the kernel, and I adjusted the few I found (and sent changes upstream).

Quoted 8 lines
Quoted 5 lines

style matters, as it's a thing with your brain. You learn patterns and if the patterns change, you have to do more work and don't see the real issues involved. So by ignoring our style you are saying you don't want anyone else in the kernel community to ever review or work on the code, which isn't ok.

Looks like I can't side step this unless Hans is willing to shift the usbredir project entirely to using kernel style :-/.

Quoted 7 lines

I'm fine with moving the usbredir project to the kernel style, the question is how to do this without causing any hidden breakage.

Can you create a gnu-indent invocation which will do most of the work?

And then a hopefully managable sized patch on top to fix the remaining style errors in usbredirparser ?

Got it; that's a helpful surprise. I'll work on patches for all but the whitespace, for only the files needed. I'm hoping whitespace changes can be limited to a gnu-indent invocation at patch transfer time. I'd hate to destroy the history like that :-/.

Cheers,

Jeremy

#11 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

In reply to Jeremy White
Quoted 4 lines · Jeremy White

This module uses the usbredir protocol and user space tools, which are used by the SPICE project.

[snip]

Quoted 19 lines
drivers/usb/usbredir/Kconfig new file +13 -0
new file mode 100644
index 0000000..284fd02
@@ -0,0 +1,25 @@
+config USBREDIR
+	tristate "USBREDIR support"
+	depends on USB && NET
+	---help---
+	  This enables connecting a remote USB device over IP using
+          the USBREDIR protocol.  This module provides a sysfs attach
+          interface which, if given a socket connected to a remote
+          usbredirserver, will enable the remote device to behave as
+          though it were connected to the system running this module.
+
+          For more information and user space tools, refer to the
+          USBREDIR project, which can be found at
+          http://www.spice-space.org/page/UsbRedir.

[snip]

Quoted 15 lines

new file mode 100644
index 0000000..217a2e4

drivers/usb/usbredir/README new file +10 -0
@@ -0,0 +1,20 @@
+USB Redirection Kernel Module
+
+This module allows a Linux system to instatiate USB devices
+that are located on a remote device.  The USB data is transferred
+over a socket using the USBREDIR protocol, which is generally
+used in conjunction with the SPICE project.
+
+You will need the USBREDIR user space tools.  They can
+be found at http://www.spice-space.org/page/UsbRedir.
+

drivers/usb/usbredir/README line 20

Quoted 10 lines
drivers/usb/usbredir/README new file +10 -0
+To use, start the usbredirserver on a remote system.
+For example,
+ ./usbredirserver --port 4000 125f:db8a
+will export my ADATA thumb drive on the remote system.
+
+Next, on the local system, connect a socket and relay that to
+the kernel module.  The connectkernel utility will do this as follows:
+  ./connectkernel adata4000 my.remote.device.com 4000
+
+The device should attach and be usable on the local system.

What is the security story here ? If I am understanding correctly, you have a userspace helper which opens a socket, and does a connect() to establish the connection to the remote system, and then tells the kernel to use the file descriptor associated with the socket.

Assuming that's correct, then this seems to imply that the socket has raw plain text data being sent/received, and thus precludes the possibility of running any security protocol like TLS unless the kernel wants to have an impl of the TLS protocol.

I don't really think it is sensible to be defining & implementing new network services which can't support strong encryption and authentication. Rather than passing the file descriptor to the kernel and having it do the I/O directly, I think it would be better to dissassociate the kernel from the network transport, and thus leave all sockets layer data I/O to userspace daemons so they can layer in TLS or SASL or whatever else is appropriate for the security need.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#12 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 4 lines

Assuming that's correct, then this seems to imply that the socket has raw plain text data being sent/received, and thus precludes the possibility of running any security protocol like TLS unless the kernel wants to have an impl of the TLS protocol.

Good point. For completeness, I'll note that, in a Spice use case, the data would be encrypted by the normal Spice mechanisms. And it would be fairly straight forward to write a user space daemon that would accept TLS and then relay to the unencrypted socket (of course, it would rewrite everything, which would be inefficient).

Quoted 8 lines

I don't really think it is sensible to be defining & implementing new network services which can't support strong encryption and authentication. Rather than passing the file descriptor to the kernel and having it do the I/O directly, I think it would be better to dissassociate the kernel from the network transport, and thus leave all sockets layer data I/O to userspace daemons so they can layer in TLS or SASL or whatever else is appropriate for the security need.

And that would also eliminate the need to copy the parsing code, which would be a nice improvement.

I considered this approach, but discarded it, perhaps wrongly, when my google fu suggested that netlink sockets were the best way to connect user space and a kernel module. (Because I perceived netlink sockets to be functionally equivalent to the relay daemon described, above).

Quoted 1 line

From the user space perspective, the usbredir parser has an interface

that exposes about 20 callback functions, which are invoked with pointers to a variety of structures. The ideal would be to have a mechanism to 'call into' kernel space with those varying interfaces.

Would using ioctls be a reasonable way to achieve this? Is there a better way?

In the other direction, the usbredir hc provides a range of functions; I think most interesting are the urb en/dequeue, hub control, and hub status calls. Some of that can be handled in the driver; some would need to be passed on to user space.

My google fu did not lead me to an obvious way to pass this information to user space. The approach that comes to mind is to use a signal, or woken socket, to instruct user space to poll.

I'd appreciate further comments and advice.

Cheers,

Jeremy

#13 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Hi,

Quoted 41 lines · Jeremy White
Quoted 4 lines

Assuming that's correct, then this seems to imply that the socket has raw plain text data being sent/received, and thus precludes the possibility of running any security protocol like TLS unless the kernel wants to have an impl of the TLS protocol.

Good point. For completeness, I'll note that, in a Spice use case, the data would be encrypted by the normal Spice mechanisms. And it would be fairly straight forward to write a user space daemon that would accept TLS and then relay to the unencrypted socket (of course, it would rewrite everything, which would be inefficient).

Quoted 8 lines

I don't really think it is sensible to be defining & implementing new network services which can't support strong encryption and authentication. Rather than passing the file descriptor to the kernel and having it do the I/O directly, I think it would be better to dissassociate the kernel from the network transport, and thus leave all sockets layer data I/O to userspace daemons so they can layer in TLS or SASL or whatever else is appropriate for the security need.

And that would also eliminate the need to copy the parsing code, which would be a nice improvement.

I considered this approach, but discarded it, perhaps wrongly, when my google fu suggested that netlink sockets were the best way to connect user space and a kernel module. (Because I perceived netlink sockets to be functionally equivalent to the relay daemon described, above).

From the user space perspective, the usbredir parser has an interface
that exposes about 20 callback functions, which are invoked with pointers to a variety of structures. The ideal would be to have a mechanism to 'call into' kernel space with those varying interfaces.

Would using ioctls be a reasonable way to achieve this? Is there a better way?

In the other direction, the usbredir hc provides a range of functions; I think most interesting are the urb en/dequeue, hub control, and hub status calls. Some of that can be handled in the driver; some would need to be passed on to user space.

Quoted 5 lines

My google fu did not lead me to an obvious way to pass this information to user space. The approach that comes to mind is to use a signal, or woken socket, to instruct user space to poll.

I'd appreciate further comments and advice.

I think it makes sense to have the actual usbredir protocol parsing in the kernel, and use a netlink interface, this will make it much easier to deal with protocol extensions (although we have not had any extensions to the usbredir proto in a while), and will be much cleaner then an ioctl interface.

I think that Daniel's concern can easily be fixed by rather then passing the fd of a socket into the kernel to simply forwarding the data back and forth from a socket opened by userspace into the netlink socket. This way SSL, SASL or whatever can be put in between, and you can even built a nice test-suite this way :)

The downside of this is introducing an extra memcpy of all the data, but an ioctl interface has the same problem and is going to be unwieldy, so I advice against that.

As for the extra memcpy I would not worry about that, in all the performance testing I've done it has almost always been all about latency not throughput.

Regards,

Hans

#14 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

In reply to Daniel P. Berrange
Quoted 7 lines · Daniel P. Berrange

I don't really think it is sensible to be defining & implementing new network services which can't support strong encryption and authentication. Rather than passing the file descriptor to the kernel and having it do the I/O directly, I think it would be better to dissassociate the kernel from the network transport, and thus leave all sockets layer data I/O to userspace daemons so they can layer in TLS or SASL or whatever else is appropriate for the security need.

Hi,

this hits a fundamental limit. Block IO must be done entirely in kernel space or the system will deadlock. The USB stack is part of the block layer and the SCSI error handling. Thus if you involve user space you cannot honor memory allocation with GFP_NOFS and you break all APIs where we pass GFP_NOIO in the USB stack.

Supposed you need to reset a storage device for error handling. Your user space programm does a syscall, which allocates memory and needs to launder pages. It proceeds to write to the storage device you wish to reset.

It is the same problem FUSE has with writable mmap. You cannot do block devices in user space sanely.

Sorry
Oliver

#15 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Hi,

Quoted 18 lines · Oliver Neukum
Quoted 7 lines · Daniel P. Berrange

I don't really think it is sensible to be defining & implementing new network services which can't support strong encryption and authentication. Rather than passing the file descriptor to the kernel and having it do the I/O directly, I think it would be better to dissassociate the kernel from the network transport, and thus leave all sockets layer data I/O to userspace daemons so they can layer in TLS or SASL or whatever else is appropriate for the security need.

Hi,

this hits a fundamental limit. Block IO must be done entirely in kernel space or the system will deadlock. The USB stack is part of the block layer and the SCSI error handling. Thus if you involve user space you cannot honor memory allocation with GFP_NOFS and you break all APIs where we pass GFP_NOIO in the USB stack.

Quoted 7 lines

Supposed you need to reset a storage device for error handling. Your user space programm does a syscall, which allocates memory and needs to launder pages. It proceeds to write to the storage device you wish to reset.

It is the same problem FUSE has with writable mmap. You cannot do block devices in user space sanely.

So how is this dealt with for usbip ?

Regards,

Hans

#16 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 26 lines · Hans de Goede

Hi,

Quoted 23 lines · Oliver Neukum
Quoted 7 lines · Daniel P. Berrange

I don't really think it is sensible to be defining & implementing new network services which can't support strong encryption and authentication. Rather than passing the file descriptor to the kernel and having it do the I/O directly, I think it would be better to dissassociate the kernel from the network transport, and thus leave all sockets layer data I/O to userspace daemons so they can layer in TLS or SASL or whatever else is appropriate for the security need.

Hi,

this hits a fundamental limit. Block IO must be done entirely in kernel space or the system will deadlock. The USB stack is part of the block layer and the SCSI error handling. Thus if you involve user space you cannot honor memory allocation with GFP_NOFS and you break all APIs where we pass GFP_NOIO in the USB stack.

Supposed you need to reset a storage device for error handling. Your user space programm does a syscall, which allocates memory and needs to launder pages. It proceeds to write to the storage device you wish to reset.

Quoted 4 lines
Quoted 2 lines

It is the same problem FUSE has with writable mmap. You cannot do block devices in user space sanely.

So how is this dealt with for usbip ?

As far as I can tell, it isn't. Running a storage device over usbip is a bit dangerous.

Regards
Oliver

#17 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 27 lines · Oliver Neukum
Quoted 26 lines · Hans de Goede

Hi,

Quoted 23 lines · Oliver Neukum
Quoted 7 lines · Daniel P. Berrange

I don't really think it is sensible to be defining & implementing new network services which can't support strong encryption and authentication. Rather than passing the file descriptor to the kernel and having it do the I/O directly, I think it would be better to dissassociate the kernel from the network transport, and thus leave all sockets layer data I/O to userspace daemons so they can layer in TLS or SASL or whatever else is appropriate for the security need.

Hi,

this hits a fundamental limit. Block IO must be done entirely in kernel space or the system will deadlock. The USB stack is part of the block layer and the SCSI error handling. Thus if you involve user space you cannot honor memory allocation with GFP_NOFS and you break all APIs where we pass GFP_NOIO in the USB stack.

Supposed you need to reset a storage device for error handling. Your user space programm does a syscall, which allocates memory and needs to launder pages. It proceeds to write to the storage device you wish to reset.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

It is the same problem FUSE has with writable mmap. You cannot do block devices in user space sanely.

So how is this dealt with for usbip ?

As far as I can tell, it isn't. Running a storage device over usbip is a bit dangerous.

I don't follow that analysis. The usbip interactions with the usb stack all seem to be atomic, and never trigger a syscall, as far as I can tell. A port reset will flip a few bits and return. A urb enqueue queues and wakes a different thread, and returns. The alternate thread performs the sendmsg.

I'm not suggesting that running a storage device over usbip is especially safe, but I don't see the limit on the design.

Cheers,

Jeremy

#18 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 36 lines · Jeremy White
Quoted 27 lines · Oliver Neukum
Quoted 26 lines · Hans de Goede

Hi,

Quoted 23 lines · Oliver Neukum
Quoted 7 lines · Daniel P. Berrange

I don't really think it is sensible to be defining & implementing new network services which can't support strong encryption and authentication. Rather than passing the file descriptor to the kernel and having it do the I/O directly, I think it would be better to dissassociate the kernel from the network transport, and thus leave all sockets layer data I/O to userspace daemons so they can layer in TLS or SASL or whatever else is appropriate for the security need.

Hi,

this hits a fundamental limit. Block IO must be done entirely in kernel space or the system will deadlock. The USB stack is part of the block layer and the SCSI error handling. Thus if you involve user space you cannot honor memory allocation with GFP_NOFS and you break all APIs where we pass GFP_NOIO in the USB stack.

Supposed you need to reset a storage device for error handling. Your user space programm does a syscall, which allocates memory and needs to launder pages. It proceeds to write to the storage device you wish to reset.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

It is the same problem FUSE has with writable mmap. You cannot do block devices in user space sanely.

So how is this dealt with for usbip ?

As far as I can tell, it isn't. Running a storage device over usbip is a bit dangerous.

Quoted 8 lines

I don't follow that analysis. The usbip interactions with the usb stack all seem to be atomic, and never trigger a syscall, as far as I can tell. A port reset will flip a few bits and return. A urb enqueue queues and wakes a different thread, and returns. The alternate thread performs the sendmsg.

I'm not suggesting that running a storage device over usbip is especially safe, but I don't see the limit on the design.

Are you referring to the current code or the proposed user space pipe?

Regards
Oliver

#19 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 43 lines · Oliver Neukum
Quoted 42 lines · Jeremy White
Quoted 27 lines · Oliver Neukum
Quoted 26 lines · Hans de Goede

Hi,

Quoted 23 lines · Oliver Neukum
Quoted 7 lines · Daniel P. Berrange

I don't really think it is sensible to be defining & implementing new network services which can't support strong encryption and authentication. Rather than passing the file descriptor to the kernel and having it do the I/O directly, I think it would be better to dissassociate the kernel from the network transport, and thus leave all sockets layer data I/O to userspace daemons so they can layer in TLS or SASL or whatever else is appropriate for the security need.

Hi,

this hits a fundamental limit. Block IO must be done entirely in kernel space or the system will deadlock. The USB stack is part of the block layer and the SCSI error handling. Thus if you involve user space you cannot honor memory allocation with GFP_NOFS and you break all APIs where we pass GFP_NOIO in the USB stack.

Supposed you need to reset a storage device for error handling. Your user space programm does a syscall, which allocates memory and needs to launder pages. It proceeds to write to the storage device you wish to reset.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

It is the same problem FUSE has with writable mmap. You cannot do block devices in user space sanely.

So how is this dealt with for usbip ?

As far as I can tell, it isn't. Running a storage device over usbip is a bit dangerous.

I don't follow that analysis. The usbip interactions with the usb stack all seem to be atomic, and never trigger a syscall, as far as I can tell. A port reset will flip a few bits and return. A urb enqueue queues and wakes a different thread, and returns. The alternate thread performs the sendmsg.

Quoted 4 lines
Quoted 2 lines

I'm not suggesting that running a storage device over usbip is especially safe, but I don't see the limit on the design.

Are you referring to the current code or the proposed user space pipe?

I'm referring to current usbip code. But the proposed driver would have the same behavior.

To be clear, I think the only tangible new proposal is the one Hans put forth, which would modify the driver I originally posted to use a netlink socket instead of a passing a file descriptor in via sysfs. That would allow the user space application responsible for initiating the request to provide TLS as desired. It comes with the expense of an extra memcpy, but I suspect Hans is right in saying the network latencies make that an irrelevant cost.

Cheers,

Jeremy

#20 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 14 lines · Jeremy White
Quoted 10 lines
Quoted 8 lines

I don't follow that analysis. The usbip interactions with the usb stack all seem to be atomic, and never trigger a syscall, as far as I can tell. A port reset will flip a few bits and return. A urb enqueue queues and wakes a different thread, and returns. The alternate thread performs the sendmsg.

I'm not suggesting that running a storage device over usbip is especially safe, but I don't see the limit on the design.

Are you referring to the current code or the proposed user space pipe?

I'm referring to current usbip code. But the proposed driver would have the same behavior.

Quoted 7 lines

To be clear, I think the only tangible new proposal is the one Hans put forth, which would modify the driver I originally posted to use a netlink socket instead of a passing a file descriptor in via sysfs. That would allow the user space application responsible for initiating the request to provide TLS as desired. It comes with the expense of an extra memcpy, but I suspect Hans is right in saying the network latencies make that an irrelevant cost.

Oliver is talking about the danger of having part of the communication path for a block device run through userspace.

Imagine a situation where the client uses a USB storage device provided by the server as a swap device. And suppose a userspace daemon on the client has to process USB packets as they pass between the client and the server. If the daemon is idle for some time, parts of its address space may get stored in the swap area on the server and paged out.

Now consider what happens when those parts of memory need to be paged back in. The client submits a request to read from the swap area. The request is transformed into USB packets and sent through the userspace daemon for transmission to the server. But the daemon can't process the packets because it is waiting for its missing parts to be paged back! Result: deadlock.

Alan Stern

#21 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 33 lines · Alan Stern
Quoted 14 lines · Jeremy White
Quoted 10 lines
Quoted 8 lines

I don't follow that analysis. The usbip interactions with the usb stack all seem to be atomic, and never trigger a syscall, as far as I can tell. A port reset will flip a few bits and return. A urb enqueue queues and wakes a different thread, and returns. The alternate thread performs the sendmsg.

I'm not suggesting that running a storage device over usbip is especially safe, but I don't see the limit on the design.

Are you referring to the current code or the proposed user space pipe?

I'm referring to current usbip code. But the proposed driver would have the same behavior.

Quoted 7 lines

To be clear, I think the only tangible new proposal is the one Hans put forth, which would modify the driver I originally posted to use a netlink socket instead of a passing a file descriptor in via sysfs. That would allow the user space application responsible for initiating the request to provide TLS as desired. It comes with the expense of an extra memcpy, but I suspect Hans is right in saying the network latencies make that an irrelevant cost.

Oliver is talking about the danger of having part of the communication path for a block device run through userspace.

Imagine a situation where the client uses a USB storage device provided by the server as a swap device. And suppose a userspace daemon on the client has to process USB packets as they pass between the client and the server. If the daemon is idle for some time, parts of its address space may get stored in the swap area on the server and paged out.

Quoted 6 lines

Now consider what happens when those parts of memory need to be paged back in. The client submits a request to read from the swap area. The request is transformed into USB packets and sent through the userspace daemon for transmission to the server. But the daemon can't process the packets because it is waiting for its missing parts to be paged back! Result: deadlock.

Right. I followed that. Oliver also asserted that he believed that the current usbip implementation has this flaw; I do not follow that. The concept is that the usbip device driver virtualizes the device behavior; isolating the running kernel from the vagaries of the network transport.
All proposed usbredir implementations, even if they move the network
transport to user space, would retain that behavior.

Cheers,

Jeremy

#22 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 16 lines · Jeremy White
Quoted 9 lines

Oliver is talking about the danger of having part of the communication path for a block device run through userspace.

Imagine a situation where the client uses a USB storage device provided by the server as a swap device. And suppose a userspace daemon on the client has to process USB packets as they pass between the client and the server. If the daemon is idle for some time, parts of its address space may get stored in the swap area on the server and paged out.

Quoted 6 lines

Now consider what happens when those parts of memory need to be paged back in. The client submits a request to read from the swap area. The request is transformed into USB packets and sent through the userspace daemon for transmission to the server. But the daemon can't process the packets because it is waiting for its missing parts to be paged back! Result: deadlock.

Quoted 6 lines

Right. I followed that. Oliver also asserted that he believed that the current usbip implementation has this flaw; I do not follow that. The concept is that the usbip device driver virtualizes the device behavior; isolating the running kernel from the vagaries of the network transport.
All proposed usbredir implementations, even if they move the network
transport to user space, would retain that behavior.

The point is that a device driver like usbip _cannot_ isolate the running kernel from the vagaries of the network transport if part of that transport occurs in userspace.

If any part of the transport passes through userspace, you can end up in a situation like what I outlined above, where a message can't be transported until after its reply has been received. There's no way for a device driver to prevent a deadlock when this occurs, no matter what it virtualizes.

Alan Stern

#23 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 29 lines · Alan Stern
Quoted 16 lines · Jeremy White
Quoted 9 lines

Oliver is talking about the danger of having part of the communication path for a block device run through userspace.

Imagine a situation where the client uses a USB storage device provided by the server as a swap device. And suppose a userspace daemon on the client has to process USB packets as they pass between the client and the server. If the daemon is idle for some time, parts of its address space may get stored in the swap area on the server and paged out.

Quoted 6 lines

Now consider what happens when those parts of memory need to be paged back in. The client submits a request to read from the swap area. The request is transformed into USB packets and sent through the userspace daemon for transmission to the server. But the daemon can't process the packets because it is waiting for its missing parts to be paged back! Result: deadlock.

Quoted 6 lines

Right. I followed that. Oliver also asserted that he believed that the current usbip implementation has this flaw; I do not follow that. The concept is that the usbip device driver virtualizes the device behavior; isolating the running kernel from the vagaries of the network transport.
All proposed usbredir implementations, even if they move the network
transport to user space, would retain that behavior.

The point is that a device driver like usbip _cannot_ isolate the running kernel from the vagaries of the network transport if part of that transport occurs in userspace.

Quoted 6 lines

If any part of the transport passes through userspace, you can end up in a situation like what I outlined above, where a message can't be transported until after its reply has been received. There's no way for a device driver to prevent a deadlock when this occurs, no matter what it virtualizes.

Doesn't we have the same problem with functionfs/gadgetfs and dummy_hcd? Or with fuse?

It's a very generic problem for all "virtualized devices" and it is known for quite a long time. This is why many tutorials about swap warns that swap should be set up only on real block devices which are fully served in kernel.

Signature · 3 lines
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics
#24 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 11 lines · Krzysztof Opasiak
Quoted 10 lines

The point is that a device driver like usbip _cannot_ isolate the running kernel from the vagaries of the network transport if part of that transport occurs in userspace.

If any part of the transport passes through userspace, you can end up in a situation like what I outlined above, where a message can't be transported until after its reply has been received. There's no way for a device driver to prevent a deadlock when this occurs, no matter what it virtualizes.

Quoted 2 lines

Doesn't we have the same problem with functionfs/gadgetfs and dummy_hcd? Or with fuse?

Yes indeed.

Quoted 4 lines

It's a very generic problem for all "virtualized devices" and it is known for quite a long time. This is why many tutorials about swap warns that swap should be set up only on real block devices which are fully served in kernel.

That is good advice. :-)

Alan Stern

#25 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

In reply to Krzysztof Opasiak
Quoted 9 lines · Krzysztof Opasiak

Doesn't we have the same problem with functionfs/gadgetfs and dummy_hcd?
Or with fuse?

It's a very generic problem for all "virtualized devices" and it is known for quite a long time. This is why many tutorials about swap warns
that swap should be set up only on real block devices which are fully served in kernel.

Indeed. But the point is that it isn't limited to swap. As you as a page needs to be laundered the problem exists. Mmapping a file for write (non private) is enough.

Regards
Oliver

#26 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 11 lines · Oliver Neukum
Quoted 9 lines · Krzysztof Opasiak

Doesn't we have the same problem with functionfs/gadgetfs and dummy_hcd?
Or with fuse?

It's a very generic problem for all "virtualized devices" and it is known for quite a long time. This is why many tutorials about swap warns
that swap should be set up only on real block devices which are fully served in kernel.

Quoted 3 lines

Indeed. But the point is that it isn't limited to swap. As you as a page needs to be laundered the problem exists. Mmapping a file for write (non private) is enough.

I'm persuaded to avoid user space in the core design.

Anything else fundamental to usbip that should inform the design of a usbredir driver? usbip appears to be based off a 2004 vintage of dummy_hcd. I'll look thoughtfully at the current dummy_hcd; please let me know if there is anything else I should consider.

Cheers,

Jeremy

#27 lore raw

Re: [Spice-devel] [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 4 lines · Jeremy White

Anything else fundamental to usbip that should inform the design of a usbredir driver? usbip appears to be based off a 2004 vintage of dummy_hcd. I'll look thoughtfully at the current dummy_hcd; please let me know if there is anything else I should consider.

One thing that springs to mind is USB-3 streams. When dummy-hcd was expanded to include USB-3, that was the major new ingredient.

Alan Stern

A message that is not in the archive (sent off-list or not yet received): [email protected]

#29 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 17 lines · Alex Elsayed
Quoted 9 lines · Alan Stern
Quoted 4 lines · Jeremy White

Anything else fundamental to usbip that should inform the design of a usbredir driver? usbip appears to be based off a 2004 vintage of dummy_hcd. I'll look thoughtfully at the current dummy_hcd; please let me know if there is anything else I should consider.

One thing that springs to mind is USB-3 streams. When dummy-hcd was expanded to include USB-3, that was the major new ingredient.

Another thing that comes to mind is that the USB-IF has its own official standard for this kind of thing now, called Media-Agnostic USB[1]. In November of 2014 a driver[2] was posted, followed by a second version[3], and it is apparently being refined inside Intel[4].

Quoted 5 lines

[1]
http://www.usb.org/developers/docs/devclass_docs/Media_Agnostic_USB_v1.0.zip
[2] http://thread.gmane.org/gmane.linux.kernel/1820297
[3] http://thread.gmane.org/gmane.linux.drivers.driver-project.devel/60498
[4] http://article.gmane.org/gmane.linux.drivers.driver-project.devel/60757

Thanks for the pointer, Alex.

I spent some time with the spec and their proposed code. It does seem plausible that XSpice could use a mausb/usbredir protocol converter. So if there was a mausb kernel module, I could potentially implement support in XSpice in user space and not need a usbredir module.

I sent an email to the two developers at Intel to ask if there had been any further progress and if I could collaborate with them. I have not heard back.

The MA spec is substantial and seems well thought out. But the usbredir protocol has the virtue of being relatively mature - it's 5 years old, with code in daily use.

At this point it seems the best path forward is to continue work on the usbredir kernel module, which I will do unless I get some new information.

Cheers,

Jeremy

#30 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 35 lines · Jeremy White
Quoted 17 lines · Alex Elsayed
Quoted 9 lines · Alan Stern
Quoted 4 lines · Jeremy White

Anything else fundamental to usbip that should inform the design of a usbredir driver? usbip appears to be based off a 2004 vintage of dummy_hcd. I'll look thoughtfully at the current dummy_hcd; please let me know if there is anything else I should consider.

One thing that springs to mind is USB-3 streams. When dummy-hcd was expanded to include USB-3, that was the major new ingredient.

Another thing that comes to mind is that the USB-IF has its own official standard for this kind of thing now, called Media-Agnostic USB[1]. In November of 2014 a driver[2] was posted, followed by a second version[3], and it is apparently being refined inside Intel[4].

Quoted 5 lines

[1]
http://www.usb.org/developers/docs/devclass_docs/Media_Agnostic_USB_v1.0.zip
[2] http://thread.gmane.org/gmane.linux.kernel/1820297
[3] http://thread.gmane.org/gmane.linux.drivers.driver-project.devel/60498
[4] http://article.gmane.org/gmane.linux.drivers.driver-project.devel/60757

Thanks for the pointer, Alex.

I spent some time with the spec and their proposed code. It does seem plausible that XSpice could use a mausb/usbredir protocol converter. So if there was a mausb kernel module, I could potentially implement support in XSpice in user space and not need a usbredir module.

I sent an email to the two developers at Intel to ask if there had been any further progress and if I could collaborate with them. I have not heard back.

Quoted 6 lines

The MA spec is substantial and seems well thought out. But the usbredir protocol has the virtue of being relatively mature - it's 5 years old, with code in daily use.

At this point it seems the best path forward is to continue work on the usbredir kernel module, which I will do unless I get some new information.

Please work with the existing people, or with the existing spec, I don't want to be adding multiple versions of this type of protocol to the kernel. As it is, I really don't even want to take your code, given that usbip is already there. Ignoring it isn't ok.

thanks,

greg k-h

#31 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 40 lines · Greg KH
Quoted 39 lines · Jeremy White
Quoted 17 lines · Alex Elsayed
Quoted 9 lines · Alan Stern
Quoted 4 lines · Jeremy White

Anything else fundamental to usbip that should inform the design of a usbredir driver? usbip appears to be based off a 2004 vintage of dummy_hcd. I'll look thoughtfully at the current dummy_hcd; please let me know if there is anything else I should consider.

One thing that springs to mind is USB-3 streams. When dummy-hcd was expanded to include USB-3, that was the major new ingredient.

Another thing that comes to mind is that the USB-IF has its own official standard for this kind of thing now, called Media-Agnostic USB[1]. In November of 2014 a driver[2] was posted, followed by a second version[3], and it is apparently being refined inside Intel[4].

Quoted 5 lines

[1]
http://www.usb.org/developers/docs/devclass_docs/Media_Agnostic_USB_v1.0.zip
[2] http://thread.gmane.org/gmane.linux.kernel/1820297
[3] http://thread.gmane.org/gmane.linux.drivers.driver-project.devel/60498
[4] http://article.gmane.org/gmane.linux.drivers.driver-project.devel/60757

Thanks for the pointer, Alex.

I spent some time with the spec and their proposed code. It does seem plausible that XSpice could use a mausb/usbredir protocol converter. So if there was a mausb kernel module, I could potentially implement support in XSpice in user space and not need a usbredir module.

I sent an email to the two developers at Intel to ask if there had been any further progress and if I could collaborate with them. I have not heard back.

The MA spec is substantial and seems well thought out. But the usbredir protocol has the virtue of being relatively mature - it's 5 years old, with code in daily use.

Quoted 7 lines
Quoted 2 lines

At this point it seems the best path forward is to continue work on the usbredir kernel module, which I will do unless I get some new information.

Please work with the existing people, or with the existing spec, I don't want to be adding multiple versions of this type of protocol to the kernel. As it is, I really don't even want to take your code, given that usbip is already there. Ignoring it isn't ok.

The usbredir spec predates MA-USB by 4 years; it has greater claim to the title 'existing' than does MA-USB. I recognize that does not make it better, and I recognize the value of a spec from a standards body. But I also respect community standards in production use.

And I did not and am not ignoring the MA-USB patch and spec.

I privately wrote to the Intel authors of that patch a week ago; I've publicly included them in this thread as well. As far as I can tell, they've been silent on this front since November; I fear that they may have moved on, or that Intel is not actively working on this. None of the Intel authors listed on the MA-USB specification are kernel contributors, so I did not have a way to reach out to them. If you have the means to engage others, I would appreciate that.

With no other input, my analysis was that it is better to proceed with the existing spec. It has a body of useful code, active users and developers, and I am certain it will solve my problem.

Also, as for usbip, I'll point out that the existence of MA-USB corroborates Hans rationale for the need to supplant usbip.

As I said, I will respond to any new information I receive. It would be great to have a kernel module developed (or at least approved) by seasoned hands at Intel.

But how long should I wait?

Cheers,

Jeremy

#32 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 7 lines · Jeremy White

I privately wrote to the Intel authors of that patch a week ago; I've publicly included them in this thread as well. As far as I can tell, they've been silent on this front since November; I fear that they may have moved on, or that Intel is not actively working on this. None of the Intel authors listed on the MA-USB specification are kernel contributors, so I did not have a way to reach out to them. If you have the means to engage others, I would appreciate that.

Sorry for the delay. The short answer is: Yes, we have been actively working on this driver. Per Greg KH's request, we have been cleaning up the driver internally.
There was a lot to clean up, which is why we have been silent on LKML.

-Sean

#33 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

Quoted 9 lines · Sean O. Stalley
Quoted 7 lines · Jeremy White

I privately wrote to the Intel authors of that patch a week ago; I've publicly included them in this thread as well. As far as I can tell, they've been silent on this front since November; I fear that they may have moved on, or that Intel is not actively working on this. None of the Intel authors listed on the MA-USB specification are kernel contributors, so I did not have a way to reach out to them. If you have the means to engage others, I would appreciate that.

Quoted 3 lines

Sorry for the delay. The short answer is: Yes, we have been actively working on this driver. Per Greg KH's request, we have been cleaning up the driver internally.
There was a lot to clean up, which is why we have been silent on LKML.

Great, thanks. I would appreciate a chance to work with you to make sure it will work well for XSpice. I'm happy to help as much as I can, and please don't feel the need to wait for a final version before reaching out to me.

Cheers,

Jeremy

#34 lore raw

Re: [RFC PATCH 1/1] Add a usbredir kernel module to remotely connect USB devices over IP.

I've parked some working code, and I wanted to leave a pointer to it to end this thread.

That is, the sense was that usbredir was not appropriate for the linux kernel, because Intel was working on a driver implementing the Media Agnostic USB standard, and having a proliferation of drivers didn't make sense.

Stephanie and Sean of Intel tell me that they continue to progress on the ma-usb driver, so that all seems reasonable to me.

However, due to time and customer pressure, I made the usbredir kernel module, and a set of associated utilities, work reasonably well for a small set of use cases.

I've submitted that as an out of tree module build to the spice-devel mailing list. [1]

It works reasonably well, and may benefit someone else that cannot wait for ma-usb.

I felt it would be a courtesy to end this thread with this pointer; forgive me if it's unwanted noise.

Cheers,

Jeremy

[1]
http://lists.freedesktop.org/archives/spice-devel/2015-December/024779.html