Skip to content

Commit

Permalink
vfio/spapr: Extend VFIOIOMMUOps with a release handler
Browse files Browse the repository at this point in the history
This allows to abstract a bit more the sPAPR IOMMU support in the
legacy IOMMU backend.

Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Tested-by: Eric Farman <farman@linux.ibm.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
  • Loading branch information
legoater committed Jan 5, 2024
1 parent 0c1eccd commit 001a013
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
10 changes: 4 additions & 6 deletions hw/vfio/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,8 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
QLIST_REMOVE(bcontainer, next);
vfio_kvm_device_del_group(group);
memory_listener_unregister(&bcontainer->listener);
if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU ||
container->iommu_type == VFIO_SPAPR_TCE_IOMMU) {
vfio_spapr_container_deinit(container);
if (bcontainer->ops->release) {
bcontainer->ops->release(bcontainer);
}

enable_discards_exit:
Expand Down Expand Up @@ -667,9 +666,8 @@ static void vfio_disconnect_container(VFIOGroup *group)
*/
if (QLIST_EMPTY(&container->group_list)) {
memory_listener_unregister(&bcontainer->listener);
if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU ||
container->iommu_type == VFIO_SPAPR_TCE_IOMMU) {
vfio_spapr_container_deinit(container);
if (bcontainer->ops->release) {
bcontainer->ops->release(bcontainer);
}
}

Expand Down
35 changes: 19 additions & 16 deletions hw/vfio/spapr.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,32 @@ vfio_spapr_container_del_section_window(VFIOContainerBase *bcontainer,
}
}

static void vfio_spapr_container_release(VFIOContainerBase *bcontainer)
{
VFIOContainer *container = container_of(bcontainer, VFIOContainer,
bcontainer);
VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
container);
VFIOHostDMAWindow *hostwin, *next;

if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU) {
memory_listener_unregister(&scontainer->prereg_listener);
}
QLIST_FOREACH_SAFE(hostwin, &scontainer->hostwin_list, hostwin_next,
next) {
QLIST_REMOVE(hostwin, hostwin_next);
g_free(hostwin);
}
}

static VFIOIOMMUOps vfio_iommu_spapr_ops;

static void setup_spapr_ops(VFIOContainerBase *bcontainer)
{
vfio_iommu_spapr_ops = *bcontainer->ops;
vfio_iommu_spapr_ops.add_window = vfio_spapr_container_add_section_window;
vfio_iommu_spapr_ops.del_window = vfio_spapr_container_del_section_window;
vfio_iommu_spapr_ops.release = vfio_spapr_container_release;
bcontainer->ops = &vfio_iommu_spapr_ops;
}

Expand Down Expand Up @@ -527,19 +546,3 @@ int vfio_spapr_container_init(VFIOContainer *container, Error **errp)
}
return ret;
}

void vfio_spapr_container_deinit(VFIOContainer *container)
{
VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
container);
VFIOHostDMAWindow *hostwin, *next;

if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU) {
memory_listener_unregister(&scontainer->prereg_listener);
}
QLIST_FOREACH_SAFE(hostwin, &scontainer->hostwin_list, hostwin_next,
next) {
QLIST_REMOVE(hostwin, hostwin_next);
g_free(hostwin);
}
}
1 change: 1 addition & 0 deletions include/hw/vfio/vfio-container-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@ struct VFIOIOMMUOps {
Error **errp);
void (*del_window)(VFIOContainerBase *bcontainer,
MemoryRegionSection *section);
void (*release)(VFIOContainerBase *bcontainer);
};
#endif /* HW_VFIO_VFIO_CONTAINER_BASE_H */

0 comments on commit 001a013

Please sign in to comment.