From: "Cédric Le Goater" <clg@redhat.com>
To: Zhenzhong Duan <zhenzhong.duan@intel.com>, qemu-devel@nongnu.org
Cc: alex.williamson@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com,
joao.m.martins@oracle.com, eric.auger@redhat.com,
peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com,
yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com,
"Yi Sun" <yi.y.sun@linux.intel.com>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"Cédric Le Goater" <clg@kaod.org>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
"open list:sPAPR (pseries)" <qemu-ppc@nongnu.org>
Subject: Re: [PATCH v3 10/37] vfio/container: Move space field to base container
Date: Fri, 27 Oct 2023 16:46:14 +0200 [thread overview]
Message-ID: <a8c2f432-71ba-4c20-9506-e404e7b1d35e@redhat.com> (raw)
In-Reply-To: <20231026103104.1686921-11-zhenzhong.duan@intel.com>
On 10/26/23 12:30, Zhenzhong Duan wrote:
> From: Eric Auger <eric.auger@redhat.com>
>
> Move the space field to the base object. Also the VFIOAddressSpace
> now contains a list of base containers.
>
> No fucntional 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>
> [ clg: context changes ]
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
> include/hw/vfio/vfio-common.h | 8 --------
> include/hw/vfio/vfio-container-base.h | 9 +++++++++
> hw/ppc/spapr_pci_vfio.c | 10 +++++-----
> hw/vfio/common.c | 4 ++--
> hw/vfio/container-base.c | 6 +++++-
> hw/vfio/container.c | 18 +++++++++---------
> 6 files changed, 30 insertions(+), 25 deletions(-)
>
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index fcb4003a21..857d2b8076 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -73,17 +73,10 @@ typedef struct VFIOMigration {
> bool initial_data_sent;
> } VFIOMigration;
>
> -typedef struct VFIOAddressSpace {
> - AddressSpace *as;
> - QLIST_HEAD(, VFIOContainer) containers;
> - QLIST_ENTRY(VFIOAddressSpace) list;
> -} VFIOAddressSpace;
> -
> struct VFIOGroup;
>
> typedef struct VFIOContainer {
> VFIOContainerBase bcontainer;
> - VFIOAddressSpace *space;
> int fd; /* /dev/vfio/vfio, empowered by the attached groups */
> MemoryListener listener;
> MemoryListener prereg_listener;
> @@ -98,7 +91,6 @@ typedef struct VFIOContainer {
> QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list;
> QLIST_HEAD(, VFIOGroup) group_list;
> QLIST_HEAD(, VFIORamDiscardListener) vrdl_list;
> - QLIST_ENTRY(VFIOContainer) next;
> QLIST_HEAD(, VFIODevice) device_list;
> GList *iova_ranges;
> } VFIOContainer;
> diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
> index 71e1e4324e..a5fef3e6a8 100644
> --- a/include/hw/vfio/vfio-container-base.h
> +++ b/include/hw/vfio/vfio-container-base.h
> @@ -38,12 +38,20 @@ typedef struct {
> hwaddr pages;
> } VFIOBitmap;
>
> +typedef struct VFIOAddressSpace {
> + AddressSpace *as;
> + QLIST_HEAD(, VFIOContainerBase) containers;
> + QLIST_ENTRY(VFIOAddressSpace) list;
> +} VFIOAddressSpace;
> +
> /*
> * This is the base object for vfio container backends
> */
> typedef struct VFIOContainerBase {
> const VFIOIOMMUOps *ops;
> + VFIOAddressSpace *space;
> QLIST_HEAD(, VFIOGuestIOMMU) giommu_list;
> + QLIST_ENTRY(VFIOContainerBase) next;
> } VFIOContainerBase;
>
> typedef struct VFIOGuestIOMMU {
> @@ -62,6 +70,7 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
> IOMMUTLBEntry *iotlb);
>
> void vfio_container_init(VFIOContainerBase *bcontainer,
> + VFIOAddressSpace *space,
> const VFIOIOMMUOps *ops);
> void vfio_container_destroy(VFIOContainerBase *bcontainer);
>
> diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
> index f283f7e38d..d1d07bec46 100644
> --- a/hw/ppc/spapr_pci_vfio.c
> +++ b/hw/ppc/spapr_pci_vfio.c
> @@ -84,27 +84,27 @@ static int vfio_eeh_container_op(VFIOContainer *container, uint32_t op)
> static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
> {
> VFIOAddressSpace *space = vfio_get_address_space(as);
> - VFIOContainer *container = NULL;
> + VFIOContainerBase *bcontainer = NULL;
>
> if (QLIST_EMPTY(&space->containers)) {
> /* No containers to act on */
> 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
> * multiple containers
> */
> - container = NULL;
> + bcontainer = NULL;
> goto out;
> }
>
> out:
> vfio_put_address_space(space);
> - return container;
> + return container_of(bcontainer, VFIOContainer, bcontainer);
> }
>
> static bool vfio_eeh_as_ok(AddressSpace *as)
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 4f130ad87c..f87a0dcec3 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -145,7 +145,7 @@ void vfio_unblock_multiple_devices_migration(void)
>
> 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)
> @@ -924,7 +924,7 @@ static void vfio_dirty_tracking_init(VFIOContainer *container,
> dirty.container = container;
>
> memory_listener_register(&dirty.listener,
> - container->space->as);
> + container->bcontainer.space->as);
Could we introduce an helper returning :
container->bcontainer.space->as
The rest looks OK.
Thanks,
C.
>
> *ranges = dirty.ranges;
>
> diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
> index 6be7ce65ad..99b2957d7b 100644
> --- a/hw/vfio/container-base.c
> +++ b/hw/vfio/container-base.c
> @@ -48,9 +48,11 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
> 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->space = space;
> QLIST_INIT(&bcontainer->giommu_list);
> }
>
> @@ -58,6 +60,8 @@ void vfio_container_destroy(VFIOContainerBase *bcontainer)
> {
> VFIOGuestIOMMU *giommu, *tmp;
>
> + QLIST_REMOVE(bcontainer, next);
> +
> QLIST_FOREACH_SAFE(giommu, &bcontainer->giommu_list, giommu_next, tmp) {
> memory_region_unregister_iommu_notifier(
> MEMORY_REGION(giommu->iommu_mr), &giommu->n);
> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
> index b2b6e05287..761310fa51 100644
> --- a/hw/vfio/container.c
> +++ b/hw/vfio/container.c
> @@ -514,7 +514,8 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
> * 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)) {
> ret = vfio_ram_block_discard_disable(container, true);
> if (ret) {
> @@ -550,7 +551,6 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
> }
>
> container = g_malloc0(sizeof(*container));
> - container->space = space;
> container->fd = fd;
> container->error = NULL;
> container->dirty_pages_supported = false;
> @@ -558,7 +558,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
> container->iova_ranges = NULL;
> QLIST_INIT(&container->vrdl_list);
> 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);
> if (ret) {
> @@ -613,14 +613,15 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
> vfio_kvm_device_add_group(group);
>
> QLIST_INIT(&container->group_list);
> - QLIST_INSERT_HEAD(&space->containers, container, next);
> + QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
>
> group->container = container;
> QLIST_INSERT_HEAD(&container->group_list, group, container_next);
>
> container->listener = vfio_memory_listener;
>
> - memory_listener_register(&container->listener, container->space->as);
> + memory_listener_register(&container->listener,
> + container->bcontainer.space->as);
>
> if (container->error) {
> ret = -1;
> @@ -634,7 +635,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
> return 0;
> listener_release_exit:
> QLIST_REMOVE(group, container_next);
> - QLIST_REMOVE(container, next);
> + QLIST_REMOVE(bcontainer, next);
> vfio_kvm_device_del_group(group);
> memory_listener_unregister(&container->listener);
> if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU ||
> @@ -684,9 +685,8 @@ static void vfio_disconnect_container(VFIOGroup *group)
> }
>
> if (QLIST_EMPTY(&container->group_list)) {
> - VFIOAddressSpace *space = container->space;
> + VFIOAddressSpace *space = container->bcontainer.space;
>
> - QLIST_REMOVE(container, next);
> vfio_container_destroy(bcontainer);
>
> trace_vfio_disconnect_container(container->fd);
> @@ -706,7 +706,7 @@ static VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp)
> QLIST_FOREACH(group, &vfio_group_list, next) {
> if (group->groupid == groupid) {
> /* 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;
> } else {
> error_setg(errp, "group %d used in multiple address spaces",
next prev parent reply other threads:[~2023-10-27 14:46 UTC|newest]
Thread overview: 95+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-26 10:30 [PATCH v3 00/37] vfio: Adopt iommufd Zhenzhong Duan
2023-10-26 10:30 ` [PATCH v3 01/37] vfio/container: Move IBM EEH related functions into spapr_pci_vfio.c Zhenzhong Duan
2023-10-26 14:23 ` Eric Farman
2023-10-27 9:19 ` Cédric Le Goater
2023-10-26 10:30 ` [PATCH v3 02/37] vfio/container: Move vfio_container_add/del_section_window into spapr.c Zhenzhong Duan
2023-10-27 9:19 ` Cédric Le Goater
2023-10-26 10:30 ` [PATCH v3 03/37] vfio/container: Move spapr specific init/deinit " Zhenzhong Duan
2023-10-27 9:27 ` Cédric Le Goater
2023-10-26 10:30 ` [PATCH v3 04/37] vfio/spapr: Make vfio_spapr_create/remove_window static Zhenzhong Duan
2023-10-27 9:27 ` Cédric Le Goater
2023-10-26 10:30 ` [PATCH v3 05/37] vfio/common: Move vfio_host_win_add/del into spapr.c Zhenzhong Duan
2023-10-27 9:30 ` Cédric Le Goater
2023-10-26 10:30 ` [PATCH v3 06/37] vfio: Introduce base object for VFIOContainer and targetted interface Zhenzhong Duan
2023-10-27 14:02 ` Cédric Le Goater
2023-10-30 2:40 ` Duan, Zhenzhong
2023-10-31 7:57 ` Cédric Le Goater
2023-10-31 8:31 ` Duan, Zhenzhong
2023-10-26 10:30 ` [PATCH v3 07/37] vfio/container: Introduce a empty VFIOIOMMUOps Zhenzhong Duan
2023-10-27 14:20 ` Cédric Le Goater
2023-10-30 2:43 ` Duan, Zhenzhong
2023-10-31 8:21 ` Cédric Le Goater
2023-10-26 10:30 ` [PATCH v3 08/37] vfio/container: Switch to dma_map|unmap API Zhenzhong Duan
2023-10-27 14:26 ` Cédric Le Goater
2023-10-30 2:48 ` Duan, Zhenzhong
2023-10-26 10:30 ` [PATCH v3 09/37] vfio/common: Move giommu_list in base container Zhenzhong Duan
2023-10-27 14:38 ` Cédric Le Goater
2023-10-30 2:48 ` Duan, Zhenzhong
2023-10-26 10:30 ` [PATCH v3 10/37] vfio/container: Move space field to " Zhenzhong Duan
2023-10-27 14:46 ` Cédric Le Goater [this message]
2023-10-30 2:51 ` Duan, Zhenzhong
2023-10-31 8:24 ` Cédric Le Goater
2023-10-26 10:30 ` [PATCH v3 11/37] vfio/container: Switch to IOMMU BE set_dirty_page_tracking/query_dirty_bitmap API Zhenzhong Duan
2023-10-27 14:53 ` Cédric Le Goater
2023-10-30 2:53 ` Duan, Zhenzhong
2023-10-26 10:30 ` [PATCH v3 12/37] vfio/container: Move per container device list in base container Zhenzhong Duan
2023-10-27 15:03 ` Cédric Le Goater
2023-10-26 10:30 ` [PATCH v3 13/37] vfio/container: Convert functions to " Zhenzhong Duan
2023-10-27 15:03 ` Cédric Le Goater
2023-10-26 10:30 ` [PATCH v3 14/37] vfio/container: Move vrdl_list, pgsizes and dma_max_mappings " Zhenzhong Duan
2023-10-27 15:52 ` Cédric Le Goater
2023-10-30 3:14 ` Duan, Zhenzhong
2023-10-31 8:26 ` Cédric Le Goater
2023-10-26 10:30 ` [PATCH v3 15/37] vfio/container: Move listener " Zhenzhong Duan
2023-10-26 10:30 ` [PATCH v3 16/37] vfio/container: Move dirty_pgsizes and max_dirty_bitmap_size " Zhenzhong Duan
2023-10-27 16:01 ` Cédric Le Goater
2023-10-26 10:30 ` [PATCH v3 17/37] vfio/container: Move iova_ranges " Zhenzhong Duan
2023-10-26 10:30 ` [PATCH v3 18/37] vfio/container: Implement attach/detach_device Zhenzhong Duan
2023-10-27 16:04 ` Cédric Le Goater
2023-10-27 16:06 ` Cédric Le Goater
2023-10-30 3:20 ` Duan, Zhenzhong
2023-10-26 10:30 ` [PATCH v3 19/37] vfio/spapr: Introduce spapr backend and target interface Zhenzhong Duan
2023-10-27 16:04 ` Cédric Le Goater
2023-10-30 3:15 ` Duan, Zhenzhong
2023-10-26 10:30 ` [PATCH v3 20/37] vfio/spapr: switch to spapr IOMMU BE add/del_section_window Zhenzhong Duan
2023-10-26 10:30 ` [PATCH v3 21/37] vfio/spapr: Move prereg_listener into spapr container Zhenzhong Duan
2023-10-26 10:30 ` [PATCH v3 22/37] vfio/spapr: Move hostwin_list " Zhenzhong Duan
2023-10-26 10:30 ` [PATCH v3 23/37] Add iommufd configure option Zhenzhong Duan
2023-10-31 8:58 ` Cédric Le Goater
2023-10-31 10:52 ` Duan, Zhenzhong
2023-10-31 11:25 ` Cédric Le Goater
2023-10-26 10:30 ` [PATCH v3 24/37] backends/iommufd: Introduce the iommufd object Zhenzhong Duan
2023-10-26 13:27 ` Markus Armbruster
2023-10-27 7:50 ` Duan, Zhenzhong
2023-10-27 8:30 ` Markus Armbruster
2023-10-27 9:41 ` Duan, Zhenzhong
2023-10-26 10:30 ` [PATCH v3 25/37] util/char_dev: Add open_cdev() Zhenzhong Duan
2023-10-30 14:53 ` Cédric Le Goater
2023-10-31 1:59 ` Duan, Zhenzhong
2023-10-26 10:30 ` [PATCH v3 26/37] vfio/iommufd: Implement the iommufd backend Zhenzhong Duan
2023-10-26 10:30 ` [PATCH v3 27/37] vfio/iommufd: Switch to manual hwpt allocation Zhenzhong Duan
2023-10-30 13:52 ` Cédric Le Goater
2023-10-31 2:02 ` Duan, Zhenzhong
2023-10-26 10:30 ` [PATCH v3 28/37] vfio/iommufd: Add support for iova_ranges Zhenzhong Duan
2023-10-26 10:30 ` [PATCH v3 29/37] vfio/iommufd: Bypass EEH if iommufd backend Zhenzhong Duan
2023-10-30 13:56 ` Cédric Le Goater
2023-10-31 2:26 ` Duan, Zhenzhong
2023-10-31 9:01 ` Cédric Le Goater
2023-10-31 9:06 ` Duan, Zhenzhong
2023-10-26 10:30 ` [PATCH v3 30/37] vfio/pci: Extract out a helper vfio_pci_get_pci_hot_reset_info Zhenzhong Duan
2023-10-30 13:59 ` Cédric Le Goater
2023-10-31 2:30 ` Duan, Zhenzhong
2023-10-26 10:30 ` [PATCH v3 31/37] vfio/pci: Adapt vfio pci hot reset support with iommufd BE Zhenzhong Duan
2023-10-30 14:04 ` Cédric Le Goater
2023-10-31 2:27 ` Duan, Zhenzhong
2023-10-26 10:30 ` [PATCH v3 32/37] vfio/pci: Allow the selection of a given iommu backend Zhenzhong Duan
2023-10-26 10:31 ` [PATCH v3 33/37] vfio/pci: Make vfio cdev pre-openable by passing a file handle Zhenzhong Duan
2023-10-26 10:31 ` [PATCH v3 34/37] vfio: Allow the selection of a given iommu backend for platform ap and ccw Zhenzhong Duan
2023-10-26 10:31 ` [PATCH v3 35/37] vfio/platform: Make vfio cdev pre-openable by passing a file handle Zhenzhong Duan
2023-10-26 10:31 ` [PATCH v3 36/37] vfio/ap: " Zhenzhong Duan
2023-10-26 10:31 ` [PATCH v3 37/37] vfio/ccw: " Zhenzhong Duan
2023-10-26 13:27 ` [PATCH v3 00/37] vfio: Adopt iommufd Markus Armbruster
2023-10-27 6:17 ` Duan, Zhenzhong
2023-10-27 7:45 ` Cédric Le Goater
2023-10-27 8:16 ` Duan, Zhenzhong
2023-10-27 13:43 ` Cédric Le Goater
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a8c2f432-71ba-4c20-9506-e404e7b1d35e@redhat.com \
--to=clg@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=chao.p.peng@intel.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=eric.auger@redhat.com \
--cc=harshpb@linux.ibm.com \
--cc=jasowang@redhat.com \
--cc=jgg@nvidia.com \
--cc=joao.m.martins@oracle.com \
--cc=kevin.tian@intel.com \
--cc=nicolinc@nvidia.com \
--cc=npiggin@gmail.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=yi.l.liu@intel.com \
--cc=yi.y.sun@intel.com \
--cc=yi.y.sun@linux.intel.com \
--cc=zhenzhong.duan@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).