aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhenzhong Duan <zhenzhong.duan@intel.com>2023-10-09 11:09:15 +0200
committerCédric Le Goater <clg@redhat.com>2023-10-18 10:10:49 +0200
commit0bddd88027679d3c34b7c754a13c7af002adbd99 (patch)
treee87a064e1e9a085e21fb524a730c898928f36b4c
parent7103ef7e765dfdf84ba7042f46d3cc0da682cb89 (diff)
downloadqemu-0bddd88027679d3c34b7c754a13c7af002adbd99.zip
qemu-0bddd88027679d3c34b7c754a13c7af002adbd99.tar.gz
qemu-0bddd88027679d3c34b7c754a13c7af002adbd99.tar.bz2
vfio/common: Store the parent container in VFIODevice
let's store the parent contaienr within the VFIODevice. This simplifies the logic in vfio_viommu_preset() and brings the benefice to hide the group specificity which is useful for IOMMUFD migration. Signed-off-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Signed-off-by: Cédric Le Goater <clg@redhat.com>
-rw-r--r--hw/vfio/common.c8
-rw-r--r--include/hw/vfio/vfio-common.h1
2 files changed, 8 insertions, 1 deletions
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index ef9dc7c..55f8a11 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -184,7 +184,7 @@ void vfio_unblock_multiple_devices_migration(void)
bool vfio_viommu_preset(VFIODevice *vbasedev)
{
- return vbasedev->group->container->space->as != &address_space_memory;
+ return vbasedev->container->space->as != &address_space_memory;
}
static void vfio_set_migration_error(int err)
@@ -2655,6 +2655,7 @@ int vfio_attach_device(char *name, VFIODevice *vbasedev,
}
container = group->container;
+ vbasedev->container = container;
QLIST_INSERT_HEAD(&container->device_list, vbasedev, container_next);
return ret;
@@ -2664,7 +2665,12 @@ void vfio_detach_device(VFIODevice *vbasedev)
{
VFIOGroup *group = vbasedev->group;
+ if (!vbasedev->container) {
+ return;
+ }
+
QLIST_REMOVE(vbasedev, container_next);
+ vbasedev->container = NULL;
trace_vfio_detach_device(vbasedev->name, group->groupid);
vfio_put_base_device(vbasedev);
vfio_put_group(group);
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 8ca70dd..bf12e40 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -132,6 +132,7 @@ typedef struct VFIODevice {
QLIST_ENTRY(VFIODevice) next;
QLIST_ENTRY(VFIODevice) container_next;
struct VFIOGroup *group;
+ VFIOContainer *container;
char *sysfsdev;
char *name;
DeviceState *dev;