[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 06/14] vfio-user: find and init PCI device
From: |
Stefan Hajnoczi |
Subject: |
Re: [PATCH v4 06/14] vfio-user: find and init PCI device |
Date: |
Thu, 16 Dec 2021 10:39:48 +0000 |
On Wed, Dec 15, 2021 at 10:35:30AM -0500, Jagannathan Raman wrote:
> @@ -150,6 +157,38 @@ static void vfu_object_init_ctx(VfuObject *o, Error
> **errp)
> + o->pci_dev = PCI_DEVICE(dev);
...
> @@ -190,6 +229,8 @@ static void vfu_object_finalize(Object *obj)
>
> o->device = NULL;
>
> + o->pci_dev = NULL;
We need to consider how this interacts with device_del hot unplug.
o->pci_dev is a pointer and we don't hold a refcount, so I think
o->pci_dev could disappear at any moment.
A pair of object_ref/unref(OBJECT(o->pci_dev)) calls would not be enough
because device_del will still unrealize the device that's in use by the
vfio-user server.
I suggest adding a check to qdev_unplug() that prevents unplug when the
device is in use by the vfio-user server. That's similar to the code in
that function for preventing unplug during migration.
One way to do that is by adding a new API:
/*
* Register an Error that is raised when unplug is attempted on a
* device. If another blocker has already been registered then that
* Error may be raised during unplug instead.
*
* qdev_del_unplug_blocker() must be called to remove this blocker.
*/
void qdev_add_unplug_blocker(DeviceState *dev, Error *blocker);
/*
* Deregister an Error that was previously registered with
* qdev_add_unplug_blocker().
*/
void qdev_del_unplug_blocker(DeviceState *dev, Error *blocker);
The vfio-user server then needs to add an Error *unplug_blocker field to
VfuObject and call qdev_add/del_unplug_blocker() on the PCI device.
>From a user perspective this means that device_del fails with "Device
currently in use by vfio-user server '%s'".
Stefan
signature.asc
Description: PGP signature
- [PATCH v4 01/14] configure, meson: override C compiler for cmake, (continued)
- [PATCH v4 01/14] configure, meson: override C compiler for cmake, Jagannathan Raman, 2021/12/15
- [PATCH v4 02/14] tests/avocado: Specify target VM argument to helper routines, Jagannathan Raman, 2021/12/15
- [PATCH v4 03/14] vfio-user: build library, Jagannathan Raman, 2021/12/15
- [PATCH v4 05/14] vfio-user: instantiate vfio-user context, Jagannathan Raman, 2021/12/15
- [PATCH v4 06/14] vfio-user: find and init PCI device, Jagannathan Raman, 2021/12/15
- Re: [PATCH v4 06/14] vfio-user: find and init PCI device,
Stefan Hajnoczi <=
- [PATCH v4 07/14] vfio-user: run vfio-user context, Jagannathan Raman, 2021/12/15
[PATCH v4 08/14] vfio-user: handle PCI config space accesses, Jagannathan Raman, 2021/12/15