the vfio_pci_hot_reset differentiate the single and multi in-used devices for reset. but in multi case, when some dependent devices are not assigned to VM, the devices can not be recovered by driver.
Signed-off-by: Chen Fan <chen.fan.f...@cn.fujitsu.com> --- hw/vfio/pci.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 7cc81ae..aeb489e 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3311,6 +3311,7 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) PCIHostDeviceAddress host; VFIOPCIDevice *tmp; VFIODevice *vbasedev_iter; + bool found; host.domain = devices[i].segment; host.bus = devices[i].bus; @@ -3340,6 +3341,7 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) goto out; } + found = false; /* Prep dependent devices for reset and clear our marker. */ QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { if (vbasedev_iter->type != VFIO_DEVICE_TYPE_PCI) { @@ -3351,12 +3353,23 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) ret = -EINVAL; goto out_single; } + found = true; vfio_pci_pre_reset(tmp); tmp->vbasedev.needs_reset = false; multi = true; break; } } + + /* + * If the dependent device is not assigned to VM, we should + * not call hot bus reset, otherwise, the dependent device + * can not be used in the future. + */ + if (!single && !found) { + ret = -EINVAL; + goto out_single; + } } if (!single && !multi) { -- 1.9.3