From: Eric Auger <eric.auger@redhat.com>
To: Joao Martins <joao.m.martins@oracle.com>, qemu-devel@nongnu.org
Cc: Yi Liu <yi.l.liu@intel.com>,
Zhenzhong Duan <zhenzhong.duan@intel.com>,
Alex Williamson <alex.williamson@redhat.com>,
Cedric Le Goater <clg@redhat.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Avihai Horon <avihaih@nvidia.com>
Subject: Re: [PATCH v6 4/9] vfio/{iommufd,container}: Invoke HostIOMMUDevice::realize() during attach_device()
Date: Tue, 23 Jul 2024 09:38:34 +0200 [thread overview]
Message-ID: <a1cc917a-7fa7-43da-b7b7-1b69308400b0@redhat.com> (raw)
In-Reply-To: <20240722211326.70162-5-joao.m.martins@oracle.com>
Hi Joao,
On 7/22/24 23:13, Joao Martins wrote:
> Move the HostIOMMUDevice::realize() to be invoked during the attach of the device
> before we allocate IOMMUFD hardware pagetable objects (HWPT). This allows the use
> of the hw_caps obtained by IOMMU_GET_HW_INFO that essentially tell if the IOMMU
> behind the device supports dirty tracking.
>
> Note: The HostIOMMUDevice data from legacy backend is static and doesn't
> need any information from the (type1-iommu) backend to be initialized.
> In contrast however, the IOMMUFD HostIOMMUDevice data requires the
> iommufd FD to be connected and having a devid to be able to successfully
Nit: maybe this comment shall be also added in iommufd.c before the call
to vfio_device_hiod_realize() to avoid someone else to move that call
earlier at some point
> GET_HW_INFO. This means vfio_device_hiod_realize() is called in
> different places within the backend .attach_device() implementation.
>
> Suggested-by: Cédric Le Goater <clg@redhat.cm>
> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
> include/hw/vfio/vfio-common.h | 1 +
> hw/vfio/common.c | 16 ++++++----------
> hw/vfio/container.c | 4 ++++
> hw/vfio/helpers.c | 11 +++++++++++
> hw/vfio/iommufd.c | 4 ++++
> 5 files changed, 26 insertions(+), 10 deletions(-)
>
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index 1a96678f8c38..4e44b26d3c45 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -242,6 +242,7 @@ void vfio_region_finalize(VFIORegion *region);
> void vfio_reset_handler(void *opaque);
> struct vfio_device_info *vfio_get_device_info(int fd);
> bool vfio_device_is_mdev(VFIODevice *vbasedev);
> +bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp);
> bool vfio_attach_device(char *name, VFIODevice *vbasedev,
> AddressSpace *as, Error **errp);
> void vfio_detach_device(VFIODevice *vbasedev);
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 784e266e6aab..da12cbd56408 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -1537,7 +1537,7 @@ bool vfio_attach_device(char *name, VFIODevice *vbasedev,
> {
> const VFIOIOMMUClass *ops =
> VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY));
> - HostIOMMUDevice *hiod;
> + HostIOMMUDevice *hiod = NULL;
>
> if (vbasedev->iommufd) {
> ops = VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD));
> @@ -1545,21 +1545,17 @@ bool vfio_attach_device(char *name, VFIODevice *vbasedev,
>
> assert(ops);
>
> - if (!ops->attach_device(name, vbasedev, as, errp)) {
> - return false;
> - }
>
> - if (vbasedev->mdev) {
> - return true;
> + if (!vbasedev->mdev) {
> + hiod = HOST_IOMMU_DEVICE(object_new(ops->hiod_typename));
> + vbasedev->hiod = hiod;
> }
>
> - hiod = HOST_IOMMU_DEVICE(object_new(ops->hiod_typename));
> - if (!HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp)) {
> + if (!ops->attach_device(name, vbasedev, as, errp)) {
> object_unref(hiod);
> - ops->detach_device(vbasedev);
> + vbasedev->hiod = NULL;
> return false;
> }
> - vbasedev->hiod = hiod;
>
> return true;
> }
> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
> index 10cb4b4320ac..9ccdb639ac84 100644
> --- a/hw/vfio/container.c
> +++ b/hw/vfio/container.c
> @@ -914,6 +914,10 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev,
>
> trace_vfio_attach_device(vbasedev->name, groupid);
>
> + if (!vfio_device_hiod_realize(vbasedev, errp)) {
> + return false;
don't you want to go to err_alloc_ioas instead?
> + }
> +
> group = vfio_get_group(groupid, as, errp);
> if (!group) {
> return false;
> diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
> index 7e23e9080c9d..ea15c79db0a3 100644
> --- a/hw/vfio/helpers.c
> +++ b/hw/vfio/helpers.c
> @@ -689,3 +689,14 @@ bool vfio_device_is_mdev(VFIODevice *vbasedev)
> subsys = realpath(tmp, NULL);
> return subsys && (strcmp(subsys, "/sys/bus/mdev") == 0);
> }
> +
> +bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp)
> +{
> + HostIOMMUDevice *hiod = vbasedev->hiod;
> +
> + if (!hiod) {
> + return true;
> + }
> +
> + return HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp);
> +}
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index 5e2fc1ce089d..2324bf892c56 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -403,6 +403,10 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
>
> space = vfio_get_address_space(as);
>
> + if (!vfio_device_hiod_realize(vbasedev, errp)) {
> + return false;
> + }
> +
> /* try to attach to an existing container in this space */
> QLIST_FOREACH(bcontainer, &space->containers, next) {
> container = container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer);
Eric
next prev parent reply other threads:[~2024-07-23 7:39 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-22 21:13 [PATCH v6 0/9] hw/iommufd: IOMMUFD Dirty Tracking Joao Martins
2024-07-22 21:13 ` [PATCH v6 1/9] vfio/iommufd: Introduce auto domain creation Joao Martins
2024-07-23 4:38 ` Duan, Zhenzhong
2024-07-23 6:57 ` Cédric Le Goater
2024-07-23 7:18 ` Eric Auger
2024-07-22 21:13 ` [PATCH v6 2/9] vfio/{iommufd,container}: Remove caps::aw_bits Joao Martins
2024-07-23 7:21 ` Eric Auger
2024-07-22 21:13 ` [PATCH v6 3/9] vfio/iommufd: Add hw_caps field to HostIOMMUDeviceCaps Joao Martins
2024-07-23 5:11 ` Duan, Zhenzhong
2024-07-23 7:26 ` Eric Auger
2024-07-22 21:13 ` [PATCH v6 4/9] vfio/{iommufd, container}: Invoke HostIOMMUDevice::realize() during attach_device() Joao Martins via
2024-07-23 7:38 ` Eric Auger [this message]
2024-07-23 7:44 ` [PATCH v6 4/9] vfio/{iommufd,container}: " Cédric Le Goater
2024-07-23 7:55 ` Eric Auger
2024-07-23 8:05 ` Joao Martins
2024-07-23 8:08 ` Cédric Le Goater
2024-07-23 8:10 ` Eric Auger
2024-07-23 8:20 ` Duan, Zhenzhong
2024-07-23 8:24 ` Eric Auger
2024-07-23 8:26 ` Joao Martins
2024-07-23 7:53 ` Joao Martins
2024-07-23 8:00 ` Cédric Le Goater
2024-07-22 21:13 ` [PATCH v6 5/9] vfio/iommufd: Probe and request hwpt dirty tracking capability Joao Martins
2024-07-23 5:11 ` Duan, Zhenzhong
2024-07-23 6:13 ` Joao Martins
2024-07-23 6:57 ` Cédric Le Goater
2024-07-23 7:02 ` Duan, Zhenzhong
2024-07-23 7:50 ` Eric Auger
2024-07-23 8:00 ` Joao Martins
2024-07-23 8:09 ` Eric Auger
2024-07-23 8:17 ` Joao Martins
2024-07-23 11:59 ` Jason Gunthorpe
2024-07-22 21:13 ` [PATCH v6 6/9] vfio/iommufd: Implement VFIOIOMMUClass::set_dirty_tracking support Joao Martins
2024-07-23 8:03 ` Eric Auger
2024-07-23 8:14 ` Joao Martins
2024-07-23 8:17 ` Eric Auger
2024-07-22 21:13 ` [PATCH v6 7/9] vfio/iommufd: Implement VFIOIOMMUClass::query_dirty_bitmap support Joao Martins
2024-07-22 21:13 ` [PATCH v6 8/9] vfio/migration: Don't block migration device dirty tracking is unsupported Joao Martins
2024-07-23 4:45 ` Duan, Zhenzhong
2024-07-23 8:22 ` Eric Auger
2024-07-22 21:13 ` [PATCH v6 9/9] vfio/common: Allow disabling device dirty page tracking Joao Martins
2024-07-23 5:05 ` Duan, Zhenzhong
2024-07-23 8:31 ` Eric Auger
2024-07-23 8:42 ` Joao Martins
2024-07-23 10:11 ` Eric Auger
2024-07-23 8:35 ` [PATCH v6 0/9] hw/iommufd: IOMMUFD Dirty Tracking Cédric Le Goater
2024-07-23 8:56 ` Joao Martins
2024-07-23 9:08 ` Cédric Le Goater
2024-07-23 14:23 ` Yi Liu
2024-07-23 14:21 ` Joao Martins
2024-07-23 14:24 ` 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=a1cc917a-7fa7-43da-b7b7-1b69308400b0@redhat.com \
--to=eric.auger@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=avihaih@nvidia.com \
--cc=clg@redhat.com \
--cc=jgg@nvidia.com \
--cc=joao.m.martins@oracle.com \
--cc=qemu-devel@nongnu.org \
--cc=yi.l.liu@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).