[libvirt] [PATCH v2 9/9] Wait for iommmu device to go away before reprobing the host driver
Peter Krempa
pkrempa at redhat.com
Mon Nov 2 09:46:05 UTC 2015
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 at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20151102/ef81600b/attachment-0001.sig>
More information about the libvir-list
mailing list