vfio/container: Change VFIOContainerBase to use QOM

VFIOContainerBase was made a QOM interface because we believed that a
QOM object would expose all the IOMMU backends to the QEMU machine and
human interface. This only applies to user creatable devices or objects.

Change the VFIOContainerBase nature from interface to object and make
the necessary adjustments in the VFIO_IOMMU hierarchy.

Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Tested-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
Cédric Le Goater 2024-06-17 08:34:03 +02:00
parent 9550fdfd29
commit 504d297e10
6 changed files with 15 additions and 10 deletions

View File

@ -102,8 +102,10 @@ void vfio_container_destroy(VFIOContainerBase *bcontainer)
static const TypeInfo types[] = { static const TypeInfo types[] = {
{ {
.name = TYPE_VFIO_IOMMU, .name = TYPE_VFIO_IOMMU,
.parent = TYPE_INTERFACE, .parent = TYPE_OBJECT,
.instance_size = sizeof(VFIOContainerBase),
.class_size = sizeof(VFIOIOMMUClass), .class_size = sizeof(VFIOIOMMUClass),
.abstract = true,
}, },
}; };

View File

@ -1196,6 +1196,7 @@ static const TypeInfo types[] = {
{ {
.name = TYPE_VFIO_IOMMU_LEGACY, .name = TYPE_VFIO_IOMMU_LEGACY,
.parent = TYPE_VFIO_IOMMU, .parent = TYPE_VFIO_IOMMU,
.instance_size = sizeof(VFIOContainer),
.class_init = vfio_iommu_legacy_class_init, .class_init = vfio_iommu_legacy_class_init,
}, { }, {
.name = TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO, .name = TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO,

View File

@ -672,6 +672,7 @@ static const TypeInfo types[] = {
{ {
.name = TYPE_VFIO_IOMMU_IOMMUFD, .name = TYPE_VFIO_IOMMU_IOMMUFD,
.parent = TYPE_VFIO_IOMMU, .parent = TYPE_VFIO_IOMMU,
.instance_size = sizeof(VFIOIOMMUFDContainer),
.class_init = vfio_iommu_iommufd_class_init, .class_init = vfio_iommu_iommufd_class_init,
}, { }, {
.name = TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO, .name = TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO,

View File

@ -30,6 +30,8 @@ typedef struct VFIOSpaprContainer {
QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list; QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list;
} VFIOSpaprContainer; } VFIOSpaprContainer;
OBJECT_DECLARE_SIMPLE_TYPE(VFIOSpaprContainer, VFIO_IOMMU_SPAPR);
static bool vfio_prereg_listener_skipped_section(MemoryRegionSection *section) static bool vfio_prereg_listener_skipped_section(MemoryRegionSection *section)
{ {
if (memory_region_is_iommu(section->mr)) { if (memory_region_is_iommu(section->mr)) {
@ -548,6 +550,7 @@ static const TypeInfo types[] = {
{ {
.name = TYPE_VFIO_IOMMU_SPAPR, .name = TYPE_VFIO_IOMMU_SPAPR,
.parent = TYPE_VFIO_IOMMU_LEGACY, .parent = TYPE_VFIO_IOMMU_LEGACY,
.instance_size = sizeof(VFIOSpaprContainer),
.class_init = vfio_iommu_spapr_class_init, .class_init = vfio_iommu_spapr_class_init,
}, },
}; };

View File

@ -84,6 +84,8 @@ typedef struct VFIOContainer {
QLIST_HEAD(, VFIOGroup) group_list; QLIST_HEAD(, VFIOGroup) group_list;
} VFIOContainer; } VFIOContainer;
OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY);
typedef struct VFIOHostDMAWindow { typedef struct VFIOHostDMAWindow {
hwaddr min_iova; hwaddr min_iova;
hwaddr max_iova; hwaddr max_iova;
@ -99,6 +101,8 @@ typedef struct VFIOIOMMUFDContainer {
uint32_t ioas_id; uint32_t ioas_id;
} VFIOIOMMUFDContainer; } VFIOIOMMUFDContainer;
OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer, VFIO_IOMMU_IOMMUFD);
typedef struct VFIODeviceOps VFIODeviceOps; typedef struct VFIODeviceOps VFIODeviceOps;
typedef struct VFIODevice { typedef struct VFIODevice {

View File

@ -34,6 +34,7 @@ typedef struct VFIOAddressSpace {
* This is the base object for vfio container backends * This is the base object for vfio container backends
*/ */
typedef struct VFIOContainerBase { typedef struct VFIOContainerBase {
Object parent;
const VFIOIOMMUClass *ops; const VFIOIOMMUClass *ops;
VFIOAddressSpace *space; VFIOAddressSpace *space;
MemoryListener listener; MemoryListener listener;
@ -96,17 +97,10 @@ void vfio_container_destroy(VFIOContainerBase *bcontainer);
#define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU "-spapr" #define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU "-spapr"
#define TYPE_VFIO_IOMMU_IOMMUFD TYPE_VFIO_IOMMU "-iommufd" #define TYPE_VFIO_IOMMU_IOMMUFD TYPE_VFIO_IOMMU "-iommufd"
/* OBJECT_DECLARE_TYPE(VFIOContainerBase, VFIOIOMMUClass, VFIO_IOMMU)
* VFIOContainerBase is not an abstract QOM object because it felt
* unnecessary to expose all the IOMMU backends to the QEMU machine
* and human interface. However, we can still abstract the IOMMU
* backend handlers using a QOM interface class. This provides more
* flexibility when referencing the various implementations.
*/
DECLARE_CLASS_CHECKERS(VFIOIOMMUClass, VFIO_IOMMU, TYPE_VFIO_IOMMU)
struct VFIOIOMMUClass { struct VFIOIOMMUClass {
InterfaceClass parent_class; ObjectClass parent_class;
/* Properties */ /* Properties */
const char *hiod_typename; const char *hiod_typename;