vfio/container: Move space field to base container
Move the space field to the base object. Also the VFIOAddressSpace now contains a list of base containers. No functional change intended. Signed-off-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Yi Liu <yi.l.liu@intel.com> Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Reviewed-by: Cédric Le Goater <clg@redhat.com> Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
parent
dddf83ab99
commit
e559706338
@ -84,27 +84,27 @@ static int vfio_eeh_container_op(VFIOContainer *container, uint32_t op)
|
|||||||
static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
|
static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
|
||||||
{
|
{
|
||||||
VFIOAddressSpace *space = vfio_get_address_space(as);
|
VFIOAddressSpace *space = vfio_get_address_space(as);
|
||||||
VFIOContainer *container = NULL;
|
VFIOContainerBase *bcontainer = NULL;
|
||||||
|
|
||||||
if (QLIST_EMPTY(&space->containers)) {
|
if (QLIST_EMPTY(&space->containers)) {
|
||||||
/* No containers to act on */
|
/* No containers to act on */
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
container = QLIST_FIRST(&space->containers);
|
bcontainer = QLIST_FIRST(&space->containers);
|
||||||
|
|
||||||
if (QLIST_NEXT(container, next)) {
|
if (QLIST_NEXT(bcontainer, next)) {
|
||||||
/*
|
/*
|
||||||
* We don't yet have logic to synchronize EEH state across
|
* We don't yet have logic to synchronize EEH state across
|
||||||
* multiple containers
|
* multiple containers
|
||||||
*/
|
*/
|
||||||
container = NULL;
|
bcontainer = NULL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
vfio_put_address_space(space);
|
vfio_put_address_space(space);
|
||||||
return container;
|
return container_of(bcontainer, VFIOContainer, bcontainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool vfio_eeh_as_ok(AddressSpace *as)
|
static bool vfio_eeh_as_ok(AddressSpace *as)
|
||||||
|
@ -145,7 +145,7 @@ void vfio_unblock_multiple_devices_migration(void)
|
|||||||
|
|
||||||
bool vfio_viommu_preset(VFIODevice *vbasedev)
|
bool vfio_viommu_preset(VFIODevice *vbasedev)
|
||||||
{
|
{
|
||||||
return vbasedev->container->space->as != &address_space_memory;
|
return vbasedev->container->bcontainer.space->as != &address_space_memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vfio_set_migration_error(int err)
|
static void vfio_set_migration_error(int err)
|
||||||
@ -922,7 +922,7 @@ static void vfio_dirty_tracking_init(VFIOContainer *container,
|
|||||||
dirty.container = container;
|
dirty.container = container;
|
||||||
|
|
||||||
memory_listener_register(&dirty.listener,
|
memory_listener_register(&dirty.listener,
|
||||||
container->space->as);
|
container->bcontainer.space->as);
|
||||||
|
|
||||||
*ranges = dirty.ranges;
|
*ranges = dirty.ranges;
|
||||||
|
|
||||||
|
@ -31,9 +31,11 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
|
|||||||
return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb);
|
return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vfio_container_init(VFIOContainerBase *bcontainer, const VFIOIOMMUOps *ops)
|
void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space,
|
||||||
|
const VFIOIOMMUOps *ops)
|
||||||
{
|
{
|
||||||
bcontainer->ops = ops;
|
bcontainer->ops = ops;
|
||||||
|
bcontainer->space = space;
|
||||||
QLIST_INIT(&bcontainer->giommu_list);
|
QLIST_INIT(&bcontainer->giommu_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +43,8 @@ void vfio_container_destroy(VFIOContainerBase *bcontainer)
|
|||||||
{
|
{
|
||||||
VFIOGuestIOMMU *giommu, *tmp;
|
VFIOGuestIOMMU *giommu, *tmp;
|
||||||
|
|
||||||
|
QLIST_REMOVE(bcontainer, next);
|
||||||
|
|
||||||
QLIST_FOREACH_SAFE(giommu, &bcontainer->giommu_list, giommu_next, tmp) {
|
QLIST_FOREACH_SAFE(giommu, &bcontainer->giommu_list, giommu_next, tmp) {
|
||||||
memory_region_unregister_iommu_notifier(
|
memory_region_unregister_iommu_notifier(
|
||||||
MEMORY_REGION(giommu->iommu_mr), &giommu->n);
|
MEMORY_REGION(giommu->iommu_mr), &giommu->n);
|
||||||
|
@ -514,7 +514,8 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
|
|||||||
* details once we know which type of IOMMU we are using.
|
* details once we know which type of IOMMU we are using.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QLIST_FOREACH(container, &space->containers, next) {
|
QLIST_FOREACH(bcontainer, &space->containers, next) {
|
||||||
|
container = container_of(bcontainer, VFIOContainer, bcontainer);
|
||||||
if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) {
|
if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) {
|
||||||
ret = vfio_ram_block_discard_disable(container, true);
|
ret = vfio_ram_block_discard_disable(container, true);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@ -550,7 +551,6 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
|
|||||||
}
|
}
|
||||||
|
|
||||||
container = g_malloc0(sizeof(*container));
|
container = g_malloc0(sizeof(*container));
|
||||||
container->space = space;
|
|
||||||
container->fd = fd;
|
container->fd = fd;
|
||||||
container->error = NULL;
|
container->error = NULL;
|
||||||
container->dirty_pages_supported = false;
|
container->dirty_pages_supported = false;
|
||||||
@ -558,7 +558,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
|
|||||||
container->iova_ranges = NULL;
|
container->iova_ranges = NULL;
|
||||||
QLIST_INIT(&container->vrdl_list);
|
QLIST_INIT(&container->vrdl_list);
|
||||||
bcontainer = &container->bcontainer;
|
bcontainer = &container->bcontainer;
|
||||||
vfio_container_init(bcontainer, &vfio_legacy_ops);
|
vfio_container_init(bcontainer, space, &vfio_legacy_ops);
|
||||||
|
|
||||||
ret = vfio_init_container(container, group->fd, errp);
|
ret = vfio_init_container(container, group->fd, errp);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@ -613,14 +613,14 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
|
|||||||
vfio_kvm_device_add_group(group);
|
vfio_kvm_device_add_group(group);
|
||||||
|
|
||||||
QLIST_INIT(&container->group_list);
|
QLIST_INIT(&container->group_list);
|
||||||
QLIST_INSERT_HEAD(&space->containers, container, next);
|
QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
|
||||||
|
|
||||||
group->container = container;
|
group->container = container;
|
||||||
QLIST_INSERT_HEAD(&container->group_list, group, container_next);
|
QLIST_INSERT_HEAD(&container->group_list, group, container_next);
|
||||||
|
|
||||||
container->listener = vfio_memory_listener;
|
container->listener = vfio_memory_listener;
|
||||||
|
|
||||||
memory_listener_register(&container->listener, container->space->as);
|
memory_listener_register(&container->listener, bcontainer->space->as);
|
||||||
|
|
||||||
if (container->error) {
|
if (container->error) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
@ -634,7 +634,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
|
|||||||
return 0;
|
return 0;
|
||||||
listener_release_exit:
|
listener_release_exit:
|
||||||
QLIST_REMOVE(group, container_next);
|
QLIST_REMOVE(group, container_next);
|
||||||
QLIST_REMOVE(container, next);
|
QLIST_REMOVE(bcontainer, next);
|
||||||
vfio_kvm_device_del_group(group);
|
vfio_kvm_device_del_group(group);
|
||||||
memory_listener_unregister(&container->listener);
|
memory_listener_unregister(&container->listener);
|
||||||
if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU ||
|
if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU ||
|
||||||
@ -684,9 +684,7 @@ static void vfio_disconnect_container(VFIOGroup *group)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (QLIST_EMPTY(&container->group_list)) {
|
if (QLIST_EMPTY(&container->group_list)) {
|
||||||
VFIOAddressSpace *space = container->space;
|
VFIOAddressSpace *space = bcontainer->space;
|
||||||
|
|
||||||
QLIST_REMOVE(container, next);
|
|
||||||
|
|
||||||
vfio_container_destroy(bcontainer);
|
vfio_container_destroy(bcontainer);
|
||||||
|
|
||||||
@ -707,7 +705,7 @@ static VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp)
|
|||||||
QLIST_FOREACH(group, &vfio_group_list, next) {
|
QLIST_FOREACH(group, &vfio_group_list, next) {
|
||||||
if (group->groupid == groupid) {
|
if (group->groupid == groupid) {
|
||||||
/* Found it. Now is it already in the right context? */
|
/* Found it. Now is it already in the right context? */
|
||||||
if (group->container->space->as == as) {
|
if (group->container->bcontainer.space->as == as) {
|
||||||
return group;
|
return group;
|
||||||
} else {
|
} else {
|
||||||
error_setg(errp, "group %d used in multiple address spaces",
|
error_setg(errp, "group %d used in multiple address spaces",
|
||||||
|
@ -73,17 +73,10 @@ typedef struct VFIOMigration {
|
|||||||
bool initial_data_sent;
|
bool initial_data_sent;
|
||||||
} VFIOMigration;
|
} VFIOMigration;
|
||||||
|
|
||||||
typedef struct VFIOAddressSpace {
|
|
||||||
AddressSpace *as;
|
|
||||||
QLIST_HEAD(, VFIOContainer) containers;
|
|
||||||
QLIST_ENTRY(VFIOAddressSpace) list;
|
|
||||||
} VFIOAddressSpace;
|
|
||||||
|
|
||||||
struct VFIOGroup;
|
struct VFIOGroup;
|
||||||
|
|
||||||
typedef struct VFIOContainer {
|
typedef struct VFIOContainer {
|
||||||
VFIOContainerBase bcontainer;
|
VFIOContainerBase bcontainer;
|
||||||
VFIOAddressSpace *space;
|
|
||||||
int fd; /* /dev/vfio/vfio, empowered by the attached groups */
|
int fd; /* /dev/vfio/vfio, empowered by the attached groups */
|
||||||
MemoryListener listener;
|
MemoryListener listener;
|
||||||
MemoryListener prereg_listener;
|
MemoryListener prereg_listener;
|
||||||
@ -98,7 +91,6 @@ typedef struct VFIOContainer {
|
|||||||
QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list;
|
QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list;
|
||||||
QLIST_HEAD(, VFIOGroup) group_list;
|
QLIST_HEAD(, VFIOGroup) group_list;
|
||||||
QLIST_HEAD(, VFIORamDiscardListener) vrdl_list;
|
QLIST_HEAD(, VFIORamDiscardListener) vrdl_list;
|
||||||
QLIST_ENTRY(VFIOContainer) next;
|
|
||||||
QLIST_HEAD(, VFIODevice) device_list;
|
QLIST_HEAD(, VFIODevice) device_list;
|
||||||
GList *iova_ranges;
|
GList *iova_ranges;
|
||||||
} VFIOContainer;
|
} VFIOContainer;
|
||||||
|
@ -24,12 +24,20 @@ typedef struct {
|
|||||||
hwaddr pages;
|
hwaddr pages;
|
||||||
} VFIOBitmap;
|
} VFIOBitmap;
|
||||||
|
|
||||||
|
typedef struct VFIOAddressSpace {
|
||||||
|
AddressSpace *as;
|
||||||
|
QLIST_HEAD(, VFIOContainerBase) containers;
|
||||||
|
QLIST_ENTRY(VFIOAddressSpace) list;
|
||||||
|
} 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 {
|
||||||
const VFIOIOMMUOps *ops;
|
const VFIOIOMMUOps *ops;
|
||||||
|
VFIOAddressSpace *space;
|
||||||
QLIST_HEAD(, VFIOGuestIOMMU) giommu_list;
|
QLIST_HEAD(, VFIOGuestIOMMU) giommu_list;
|
||||||
|
QLIST_ENTRY(VFIOContainerBase) next;
|
||||||
} VFIOContainerBase;
|
} VFIOContainerBase;
|
||||||
|
|
||||||
typedef struct VFIOGuestIOMMU {
|
typedef struct VFIOGuestIOMMU {
|
||||||
@ -48,6 +56,7 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
|
|||||||
IOMMUTLBEntry *iotlb);
|
IOMMUTLBEntry *iotlb);
|
||||||
|
|
||||||
void vfio_container_init(VFIOContainerBase *bcontainer,
|
void vfio_container_init(VFIOContainerBase *bcontainer,
|
||||||
|
VFIOAddressSpace *space,
|
||||||
const VFIOIOMMUOps *ops);
|
const VFIOIOMMUOps *ops);
|
||||||
void vfio_container_destroy(VFIOContainerBase *bcontainer);
|
void vfio_container_destroy(VFIOContainerBase *bcontainer);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user