public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: linux-usb@vger.kernel.org,
	Sarah Sharp <sarah.a.sharp@linux.intel.com>,
	linux-media@vger.kernel.org, libusb-devel@lists.sourceforge.net,
	Alexander Graf <agraf@suse.de>, Gerd Hoffmann <kraxel@redhat.com>,
	hector@marcansoft.com, Jan Kiszka <jan.kiszka@siemens.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	pbonzini@redhat.com, Anthony Liguori <aliguori@us.ibm.com>,
	Jes Sorensen <Jes.Sorensen@redhat.com>,
	Oliver Neukum <oliver@neukum.org>, Greg KH <greg@kroah.com>,
	Felipe Balbi <balbi@ti.com>,
	Mauro Carvalho Chehab <mchehab@infradead.org>,
	Clemens Ladisch <clemens@ladisch.de>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Subject: Re: Improving kernel -> userspace (usbfs)  usb device hand off
Date: Sat, 11 Jun 2011 11:15:58 +0200	[thread overview]
Message-ID: <4DF3324E.3050506@redhat.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1106101023330.1921-100000@iolanthe.rowland.org>

Hi,

Given the many comments in this thread, I'm just
going reply to this one, and try to also answer any
other ones in this mail.

As far as the dual mode camera is involved, I agree
that that should be fixed in the existing v4l2
drivers + libgphoto. I think that Felipe's solution
to also handle the stillcam part in kernel space for
dual mode cameras (and add a libgphoto cam driver which
knows how to talk the new kernel API for this), is
the best solution. Unfortunately this will involve
quite a bit of work, but so be it.


On 06/10/2011 04:48 PM, Alan Stern wrote:
> On Fri, 10 Jun 2011, Hans de Goede wrote:
>
>> Hi all,
>>
>> The current API for managing kernel ->  userspace is a bit
>> rough around the edges, so I would like to discuss extending
>> the API.
>>
>> First of all an example use case scenarios where the current API
>> falls short.
>>
>> 1) Redirection of USB devices to a virtual machine, qemu, vbox, etc.
>> all have the ability to redirect a USB device to the virtual machine,
>> and they all use usbfs for this. The first thing which will happen
>> here when the user selects a device to redirect is a
>> IOCTL_USBFS_DISCONNECT. This causes the kernel driver to see a
>> device unplug, with no chances for the kernel driver to do anything
>> against this.
>>
>> Now lets say the user does the following:
>> -write a file to a usb flash disk
>> -redirect the flash disk to a vm
>>
>> Currently this will cause the usb mass storage driver to see a
>> disconnect, and any possible still pending writes are lost ...
>>
>> This is IMHO unacceptable, but currently there is nothing we can
>> do to avoid this.
>
> You haven't given a proper description of the problem.  See below.

I think I've given an excellent description of the problem, drivers
can be unbound from devices, and there is no way for drivers to block
this. All I'm asking for is for a new usbfs try_disconnect ioctl which
the currently bound driver has a chance blocking nothing more nothing
less.

<snip dual mode camera stuff>

>> So what do we need to make this situation better:
>> 1) A usb_driver callback alternative to the disconnect callback,
>>      I propose to call this soft_disconnect. This serves 2 purposes
>>      a) It will allow the driver to tell the caller that that is not
>>         a good idea by returning an error code (think usb mass storage
>>         driver and mounted filesystem
>
> Not feasible.  usb-storage has no idea whether or not a device it
> controls has a mounted filesystem.  (All it does is send SCSI commands
> to a device and get back the results.)  Since that's the main use
> case you're interested in, this part of the proposal seems destined to
> fail.
>

This is not completely true, I cannot rmmod usb-storage as long as
disks using it are mounted. I know this is done through the global
module usage count, so this is not per usb-storage device. But extending
the ref counting to be per usb-storage device should not be hard.

All the accounting is already done for this.

> But userspace _does_ know where the mounted filesystems are.
> Therefore userspace should be responsible for avoiding programs that
> want to take control of devices holding these filesystems.  That's the
> reason why usbfs device nodes are owned by root and have 0644 mode;
> there're can be written to only by programs with superuser privileges
> -- and such programs are supposed to be careful about what they do.
>

Yes, and what I'm asking for is for an easy way for these programs to
be careful. A way for them to ask the kernel, which in general is
responsible for things like this and traditionally does resource
management and things which come with that like refcounting: "unbind
the driver from this device unless the device is currently in use".

Why can't this be done in userspace, simply put:
1) Process a checks if the usb-storage device is not used
2) Process b mounts it after the check
3) Process a unbinds the driver

Yes this can be avoided if all binding/unbinding and all mounting
happens under control of a single instance. However this requires
completely re-inventing userspace...

Also note that the notion of this can be extended to other devices,
want to ubs-redirect a usb printer to a vm better not do it halfway
through a printjob being spooled. Want to usb-redirect a usb webcam
to a vm, better not do it while something is streaming video from
the webcam, etc. etc.

And please don't come with the inevitable "if it hurts do not do
that" argument. We want to provide this kind of functionality to
non tech savy computer users, and things should just work, including
telling the user that the device is currently in use rather then
wrecking his printjob or filesystem.

Regards,

Hans

  parent reply	other threads:[~2011-06-11  9:15 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-10  0:21 USB mini-summit at LinuxCon Vancouver Sarah Sharp
2011-06-10  3:18 ` Greg KH
2011-06-10  6:59   ` Gerd Hoffmann
2011-06-10 19:48   ` Sarah Sharp
2011-06-10 20:50     ` Greg KH
2011-06-13 10:44       ` Alexander Graf
2011-06-13 16:29         ` Greg KH
2011-06-13 17:11           ` Alexander Graf
2011-06-10  7:19 ` Hans de Goede
2011-06-10  7:55 ` Improving kernel -> userspace (usbfs) usb device hand off Hans de Goede
2011-06-10  8:22   ` Felipe Balbi
2011-06-10  8:36     ` Hans de Goede
2011-06-10  8:42       ` Felipe Balbi
2011-06-10 12:19         ` Hans de Goede
2011-06-10 12:28           ` Felipe Balbi
2011-06-10 14:48   ` Alan Stern
2011-06-10 15:07     ` Mauro Carvalho Chehab
2011-06-10 15:21       ` Alan Stern
2011-06-11  9:15     ` Hans de Goede [this message]
2011-06-11 16:19       ` Theodore Kilgore
2011-06-12 11:43         ` Hans de Goede
2011-06-12 21:20           ` Theodore Kilgore
2011-06-13  2:03             ` Xiaofan Chen
2011-06-13  2:27               ` [Libusb-devel] " Michael Bender
2011-06-11 16:57       ` Alan Stern
2011-06-10 18:16   ` Theodore Kilgore
2011-06-10 18:34     ` Felipe Balbi
2011-06-10 21:18       ` Alan Stern
2011-06-10 21:46         ` Felipe Balbi
2011-06-10 22:46         ` Theodore Kilgore
2011-06-10 22:43       ` Theodore Kilgore
2011-06-11  1:30         ` Xiaofan Chen
2011-06-11  4:17           ` Theodore Kilgore
2011-06-13  9:05         ` Felipe Balbi
2011-06-13 13:06           ` Mauro Carvalho Chehab
2011-06-13 13:12             ` Felipe Balbi
2011-08-04 22:21 ` USB mini-summit at LinuxCon Vancouver Mauro Carvalho Chehab
2011-08-04 22:56   ` Greg KH
     [not found]     ` <CAA6KcBBZv7bvVxvEWOYL83igpNZHyzh=bcGxh6Dr5aKsvJK5Cg@mail.gmail.com>
2011-08-05  0:33       ` Mauro Carvalho Chehab
2011-08-05  2:56     ` Theodore Kilgore
2011-08-05  6:57     ` Oliver Neukum
2011-08-05 17:38       ` Theodore Kilgore
2011-08-05  7:45     ` Hans de Goede
2011-08-05  7:59       ` USB mini-summit at LinuxCon Vancouveroliver Oliver Neukum
2011-08-05  8:18         ` Hans de Goede
2011-08-05 13:07       ` USB mini-summit at LinuxCon Vancouver Mauro Carvalho Chehab
2011-08-08 17:58       ` Sarah Sharp
2011-08-08 18:23         ` Theodore Kilgore
2011-08-08 18:32           ` Sarah Sharp
2011-08-08 19:37         ` Mauro Carvalho Chehab
2011-08-09  7:52         ` Hans de Goede
2011-08-09 14:19           ` Alan Stern
2011-08-09 15:03             ` Marko Ristola
2011-08-09 19:57             ` Hans de Goede
2011-08-09 20:31               ` Adam Baker
2011-08-09 20:57                 ` Hans de Goede
2011-08-10  2:05                   ` Xiaofan Chen
2011-08-10 23:04                   ` Adam Baker
2011-08-11  8:14                     ` Hans de Goede
2011-08-09 23:05               ` Theodore Kilgore
2011-08-10 14:19               ` Alan Stern
2011-08-10 15:03                 ` Theodore Kilgore
2011-08-10 16:09                   ` Alan Stern
2011-08-10 18:33                     ` Theodore Kilgore
2011-08-10 19:39                       ` Hans Verkuil
2011-08-10 19:43                       ` Greg KH
2011-08-10 20:34                         ` Theodore Kilgore
2011-08-10 20:14                       ` Mauro Carvalho Chehab
2011-08-10 20:39                         ` Theodore Kilgore
2011-08-11  8:14                     ` Hans de Goede
2011-08-11 14:56                       ` Alan Stern
2011-08-11 15:13                         ` Mauro Carvalho Chehab
2011-08-11 15:25                           ` Alan Cox
2011-08-11 15:49                             ` Alan Stern
2011-08-11 20:01                               ` Theodore Kilgore
2011-08-11 20:32                                 ` Mauro Carvalho Chehab
2011-08-11 23:13                                   ` Theodore Kilgore
2011-08-12  7:16                                   ` Hans de Goede
2011-08-12 10:11                                   ` Alan Cox
2011-08-12  1:07                                 ` Alan Stern
2011-08-12  2:38                                   ` Theodore Kilgore
2011-08-11 15:44                           ` Alan Stern
2011-08-12  7:26                         ` Hans de Goede
2011-08-12 15:36                           ` Alan Stern
2011-08-09 17:10           ` Sarah Sharp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DF3324E.3050506@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=Jes.Sorensen@redhat.com \
    --cc=agraf@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=balbi@ti.com \
    --cc=clemens@ladisch.de \
    --cc=greg@kroah.com \
    --cc=hector@marcansoft.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kraxel@redhat.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=libusb-devel@lists.sourceforge.net \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=oliver@neukum.org \
    --cc=pbonzini@redhat.com \
    --cc=perex@perex.cz \
    --cc=sarah.a.sharp@linux.intel.com \
    --cc=stefanha@linux.vnet.ibm.com \
    --cc=stern@rowland.harvard.edu \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox