All of lore.kernel.org
 help / color / mirror / Atom feed
From: George Dunlap <george.dunlap@citrix.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>
Cc: Juergen Gross <jgross@suse.com>, Wei Liu <wei.liu2@citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>,
	Chunyan Liu <cyliu@suse.com>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>,
	Jim Fehlig <jfehlig@suse.com>, Simon Cao <caobosimon@gmail.com>
Subject: Re: [PATCH V13 3/5] libxl: add pvusb API
Date: Wed, 3 Feb 2016 14:33:48 +0000	[thread overview]
Message-ID: <56B20FCC.3010308@citrix.com> (raw)
In-Reply-To: <22192.61775.427189.268007@mariner.uk.xensource.com>

On 02/02/16 18:11, Ian Jackson wrote:
> George Dunlap writes ("Re: [Xen-devel] [PATCH V13 3/5] libxl: add pvusb API"):
>> There are effectively four states a device can be in, from the
>> 'assignment' point of view:
>>
>> 1. Assigned to the normal Linux device driver(s) for the USB device
>>
>> 2. Assigned to no driver
>>
>> 3. Assigned to usbback, but not yet assigned to any guest
>>
>> 4. Assigned to a guest
> 
> Thanks for your clear explanation (of which I will snip much).
> 
>> Additionally, each USB "device" has one or more "interfaces".  To
>> assign a "device" to usbback in the sysfs case means assigning all of
>> the "interfaces".  The code seems to assume that different interfaces
>> from the same device can be assigned to different drivers.
> 
> It is indeed the case that in principle a single USB device with
> multiple interfaces can be assigned to multiple different drivers.
> 
>> Regarding Ian's comments:
>>
>> Since "assigned to the guest" and "listed under the pvusb xenstore
>> node" are the same thing, is it even *possible* to (safely) unassign
>> the device from usbback before removing the xenstore nodes?
> 
> It might be possible to remove some of the xenstore nodes but leave
> others present, so that usbback detaches, but enough information
> remains for libxl to know that Xen still `owns' the device.
> 
> But, surely usbback needs to cope with the notion that the device
> might disappear.  USB devices can disappear at any time.

That's true. But if the USB device has actually disappeared, the device
is in fact "safe" from usbback.  I think I might consider state 2 safe
to go to, but I definitely wouldn't consider state 1 safe with the
xenstore nodes still in place.

> 
>> It's not clear to me under what conditions 3->2 might fail,
> 
> As an example, someone might press ^C on `xl usb-detach'.

*grumble*

>> or what could be done about it if it did fail.
> 
> The most obvious reason for it failing is that something somewhere
> still held onto the device.  (For umounting filesystems, and detaching
> block devices, this happens a lot.)  So if the detach from usbback
> fails would probably be possible to simply retry it.

I'm not sure what this means in the context of moving from 3 (assigned
to usbback) to 2 (unassigned).  usbback will definitely not use the
device to mount something in dom0; and I'm pretty sure has no visibility
as to whether it's being used as a filesystem in the domU.

(Moving from 1 -> 2 of course would be subject to this sort of thing,
but that's a different issue.)

>> Regarding 2->1, again it's not clear that there's anything libxl can
>> do.  Reloading the driver's module might reset it enough to pick up
>> the (now unassigned) USB devices again; other than that, rebooting is
>> probably the best option.
> 
> I think re-attempting the bind may work.  USB devices can be flaky.
> 
>> It's also not clear to me, if some functions succeed in being
>> reassigned and others fail, whether it's best to just try to assign as
>> many as we can, or better to go back and un-assign all the ones that
>> succeeded.
> 
> Unless explicitly requested, I don't think the system should create
> situations some interfaces are assigned to host drivers and some to
> usbback.

I was talking here about whether it would be better to have some
interfaces assigned to the original drivers and some interfaces left
unassigned, or to try to leave all interfaces unassigned if any of the
assignments fail.

I agree, it would be better to try to avoid the possibility of having
some interfaces bound to usbback and some interfaces bound to the
original drivers.

> And, I'm a fan of `crash-only software': in general, if a failure
> occurs, the situation should just be left as-is.  The intermediate
> state needs to be visible and rectifiable.
> 
> This approach to software state machines avoids bugs where the system
> gets into `impossible' states, recovery from which is impossible
> because the designers didn't anticipate them.
> 
> It would be tolerable if the recovery sometimes involves `lsusb' and
> echoing things into sysfs, but it would be better if not.

Right -- so what about this.  When removing a USB device:

* First modify the pvusb xenstore nodes such that 1) it's safe to
attempt removing the interfaces from usbback, but 2) they still show up
in usb-list.  (This may be a noop.)

* Attempt to remove all interfaces from usbback; if any of these fail,
stop and report an error.  Possible recovery options:
 - Re-try the usb_remove command
 - Re-load usbback (obviously disruptive to other VMs)
 - Reboot the host
 - Manually try unbinding with sysfs

* Remove the remaining pvusb xenstore nodes.  If this fails, stop and
report the error.  Possible recovery options:
 - Re-try the usb_remove command

= REBIND OPTION 1: Do the best we can without extra commands

* Attempt to re-bind the interfaces to the original drivers, as recorded
in the libxl usb xenstore nodes.  If any of these fail, report an error
but continue to try the rest of the interfaces, and remove the xenstore
nodes containing information about the original drivers.  Possible
recovery options for the user:
 - Reload the original drivers
 - Reboot the host
 - Manually try rebinding with sysfs

= REBIND OPTION 2: Include a recovery command, usb-retry-rebind

* Attempt to re-bind the interfaces to the original drivers, as recorded
in the libxl usb xenstore nodes.  If any of these fail, stop immediately
and report an error; do not remove the xenstore nodes containing the
original drivers of any interfaces that failed to rebind.  Possible
recovery options for the user:
 - Run 'xl usbdev-retry-rebind', which will just execute this step again
 - Unload and reload original host drivers
 - Reboot the host

Both of these:

1. Will avoid the state of some interfaces bound to usbback, some
rebound to the original drivers

2. Give the user a convenient way to re-try unbinding from usbback it failed

3. Give the user out-of-xl ways to attempt to recover the state other
than messing around with sysfs.

Rebind option 2 will give the user a convenient way to retry rebinding
to the original driver via xl if that step failed.

I'm inclined to suggest rebind option #1 for now, just to keep things
simple.

Thoughts?

Chunyan, would the first half of that (removing from usbback before
removing the pvusb xenstore nodes) actually work?

 -George

  parent reply	other threads:[~2016-02-03 14:33 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-19  8:39 [PATCH V13 0/5] xen pvusb toolstack work Chunyan Liu
2016-01-19  8:39 ` [PATCH V13 1/5] libxl: export some functions for pvusb use Chunyan Liu
2016-01-19  8:39 ` [PATCH V13 2/5] libxl_utils: add internal function to read sysfs file contents Chunyan Liu
2016-01-19  8:39 ` [PATCH V13 3/5] libxl: add pvusb API Chunyan Liu
2016-01-19 15:48   ` Ian Jackson
2016-02-02 16:26     ` George Dunlap
2016-02-02 18:11       ` Ian Jackson
2016-02-03  7:34         ` Chun Yan Liu
2016-02-03 14:38           ` George Dunlap
2016-02-04  1:44             ` Chun Yan Liu
2016-02-03 14:33         ` George Dunlap [this message]
2016-02-04  1:53           ` Chun Yan Liu
     [not found]           ` <56B31FAB02000066000A6596@suse.com>
2016-02-04 14:39             ` Juergen Gross
2016-02-08 14:07               ` George Dunlap
2016-02-08 14:32                 ` Ian Jackson
2016-02-02 16:48     ` George Dunlap
2016-02-03  8:25       ` Chun Yan Liu
2016-01-26 16:12   ` Olaf Hering
2016-01-27  2:29     ` Chun Yan Liu
2016-01-19  8:39 ` [PATCH V13 4/5] domcreate: support pvusb in configuration file Chunyan Liu
2016-01-19 18:08   ` Ian Jackson
2016-01-19  8:39 ` [PATCH V13 5/5] xl: add pvusb commands Chunyan Liu
2016-01-19 18:11   ` Ian Jackson
2016-01-20  3:10     ` Jim Fehlig
2016-01-21 12:12       ` Wei Liu
2016-01-21 12:21         ` Ian Campbell
2016-01-21 12:29           ` Wei Liu
2016-01-21 17:37             ` Ian Jackson
2016-02-16 17:53       ` Ian Jackson
2016-02-17 11:43         ` Wei Liu
2016-02-17 12:17           ` Ian Jackson
2016-02-16 16:56   ` Olaf Hering
2016-02-17  6:14     ` Chun Yan Liu
2016-02-19 10:43     ` Chun Yan Liu
2016-02-19 10:52       ` Olaf Hering
2016-02-19 12:07         ` Olaf Hering
2016-02-24 12:03           ` Wei Liu
2016-02-24 12:52             ` Olaf Hering
     [not found] <569F8391020000660009E667@relay2.provo.novell.com>
2016-01-20  4:56 ` [PATCH V13 3/5] libxl: add pvusb API Chun Yan Liu
2016-01-26  7:43   ` Chun Yan Liu
2016-01-26 16:21     ` George Dunlap
     [not found] <56B0843302000066000A4C90@relay2.provo.novell.com>
2016-02-02  2:36 ` Chun Yan Liu

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=56B20FCC.3010308@citrix.com \
    --to=george.dunlap@citrix.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=caobosimon@gmail.com \
    --cc=cyliu@suse.com \
    --cc=ian.campbell@citrix.com \
    --cc=jfehlig@suse.com \
    --cc=jgross@suse.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.