• M
    qdev: defer DEVICE_DEL event until instance_finalize() · f7b879e0
    Michael Roth 提交于
    DEVICE_DEL is currently emitted when a Device is unparented, as
    opposed to when it is finalized. The main design motivation for this
    seems to be that after unparent()/unrealize(), the Device is no
    longer visible to the guest, and thus the operation is complete
    from the perspective of management.
    
    However, there are cases where remaining host-side cleanup is also
    pertinent to management. The is generally handled by treating these
    resources as aspects of the "backend", which can be managed via
    separate interfaces/events, such as blockdev_add/del, netdev_add/del,
    object_add/del, etc, but some devices do not have this level of
    compartmentalization, namely vfio-pci, and possibly to lend themselves
    well to it.
    
    In the case of vfio-pci, the "backend" cleanup happens as part of
    the finalization of the vfio-pci device itself, in particular the
    cleanup of the VFIO group FD. Failing to wait for this cleanup can
    result in tools like libvirt attempting to rebind the device to
    the host while it's still being used by VFIO, which can result in
    host crashes or other misbehavior depending on the host driver.
    
    Deferring DEVICE_DEL still affords us the ability to manage backends
    explicitly, while also addressing cases like vfio-pci's, so we
    implement that approach here.
    
    An alternative proposal involving having VFIO emit a separate event
    to denote completion of host-side cleanup was discussed, but the
    prevailing opinion seems to be that it is not worth the added
    complexity, and leaves the issue open for other Device implementations
    to solve in the future.
    Signed-off-by: NMichael Roth <mdroth@linux.vnet.ibm.com>
    Reviewed-by: NGreg Kurz <groug@kaod.org>
    Tested-by: NEric Auger <eric.auger@redhat.com>
    Reviewed-by: NDavid Gibson <david@gibson.dropbear.id.au>
    Message-Id: <20171016222315.407-4-mdroth@linux.vnet.ibm.com>
    Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
    f7b879e0
qdev.c 33.5 KB