vfio: Add device tracking during unbind
authorAlex Williamson <alex.williamson@redhat.com>
Fri, 6 Feb 2015 22:05:06 +0000 (15:05 -0700)
committerAlex Williamson <alex.williamson@redhat.com>
Fri, 6 Feb 2015 22:05:06 +0000 (15:05 -0700)
commit60720a0fc6469e8f924f85510c2a24ecc7bdaf9c
treed6adf501a76c7ba94c2fef6465082a49c23885f2
parentc5e6688752c25434d71920bc969f9fab60353c5e
vfio: Add device tracking during unbind

There's a small window between the vfio bus driver calling
vfio_del_group_dev() and the device being completely unbound where
the vfio group appears to be non-viable.  This creates a race for
users like QEMU/KVM where the kvm-vfio module tries to get an
external reference to the group in order to match and release an
existing reference, while the device is potentially being removed
from the vfio bus driver.  If the group is momentarily non-viable,
kvm-vfio may not be able to release the group reference until VM
shutdown, making the group unusable until that point.

Bridge the gap between device removal from the group and completion
of the driver unbind by tracking it in a list.  The device is added
to the list before the bus driver reference is released and removed
using the existing unbind notifier.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/vfio.c