
On Mon, Nov 02, 2015 at 03:28:00 +0530, Shivaprasad G Bhat wrote:
There could be a delay of 1 or 2 seconds before the vfio-pci driver is unbound and the device file /dev/vfio/<iommu> is actually removed. If the file exists, the host driver probing the device can lead to crash. So, wait and avoid the crash.
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com> --- src/util/virpci.c | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/virpcimock.c | 14 ++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/src/util/virpci.c b/src/util/virpci.c index 0bb465b..68fd54c 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1098,6 +1098,43 @@ virPCIIsAKnownStub(char *driver) return ret; }
+#define VFIO_UNBIND_TIMEOUT 10 + +/* It is not safe to initiate host driver probe if the vfio driver has not + * completely unbound the device. Usual wait time is 1 to 2 seconds. + * So, return if the unbind didn't complete in 10 seconds. + */ +static int +virPCIWaitForVFIOUnbindCompletion(virPCIDevicePtr dev) +{ + int retry = 0; + int ret = -1; + char *path = NULL; + + if (!(path = virPCIDeviceGetIOMMUGroupDev(dev))) + goto cleanup; + + while (retry++ < VFIO_UNBIND_TIMEOUT) { + if (!virFileExists(path)) + break; + sleep(1);
I don't particularly like the 1 second sleep granularity here. I'd rather see a 1/10s or 1/100s delay so that if the time will be decreased in the future we will not have to wait for a full second. Peter