All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Duan, Zhenzhong" <zhenzhong.duan@intel.com>
To: "eric.auger@redhat.com" <eric.auger@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "alex.williamson@redhat.com" <alex.williamson@redhat.com>,
	"clg@redhat.com" <clg@redhat.com>,
	"peterx@redhat.com" <peterx@redhat.com>,
	"jasowang@redhat.com" <jasowang@redhat.com>,
	"mst@redhat.com" <mst@redhat.com>,
	"jgg@nvidia.com" <jgg@nvidia.com>,
	"nicolinc@nvidia.com" <nicolinc@nvidia.com>,
	"joao.m.martins@oracle.com" <joao.m.martins@oracle.com>,
	"Tian, Kevin" <kevin.tian@intel.com>,
	"Liu, Yi L" <yi.l.liu@intel.com>,
	"Sun, Yi Y" <yi.y.sun@intel.com>,
	"Peng, Chao P" <chao.p.peng@intel.com>
Subject: RE: [PATCH v1 05/11] vfio: Introduce host_iommu_device_create callback
Date: Tue, 19 Mar 2024 05:44:48 +0000	[thread overview]
Message-ID: <SJ0PR11MB67448B4FB9B8E10A2F0DCEB6922C2@SJ0PR11MB6744.namprd11.prod.outlook.com> (raw)
In-Reply-To: <49c49a2e-859e-45bb-b281-0ed9c72ecf9c@redhat.com>



>-----Original Message-----
>From: Eric Auger <eric.auger@redhat.com>
>Subject: Re: [PATCH v1 05/11] vfio: Introduce host_iommu_device_create
>callback
>
>
>
>On 2/28/24 04:58, Zhenzhong Duan wrote:
>> Introduce host_iommu_device_create callback and a wrapper for it.
>>
>> This callback is used to allocate a host iommu device instance and
>> initialize it based on type.
>>
>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>> ---
>>  include/hw/vfio/vfio-common.h         | 1 +
>>  include/hw/vfio/vfio-container-base.h | 1 +
>>  hw/vfio/common.c                      | 8 ++++++++
>>  3 files changed, 10 insertions(+)
>>
>> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-
>common.h
>> index b6676c9f79..9fefea4b89 100644
>> --- a/include/hw/vfio/vfio-common.h
>> +++ b/include/hw/vfio/vfio-common.h
>> @@ -208,6 +208,7 @@ struct vfio_device_info *vfio_get_device_info(int
>fd);
>>  int vfio_attach_device(char *name, VFIODevice *vbasedev,
>>                         AddressSpace *as, Error **errp);
>>  void vfio_detach_device(VFIODevice *vbasedev);
>> +void host_iommu_device_create(VFIODevice *vbasedev);
>>
>>  int vfio_kvm_device_add_fd(int fd, Error **errp);
>>  int vfio_kvm_device_del_fd(int fd, Error **errp);
>> diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-
>container-base.h
>> index b2813b0c11..dc003f6eb2 100644
>> --- a/include/hw/vfio/vfio-container-base.h
>> +++ b/include/hw/vfio/vfio-container-base.h
>> @@ -120,6 +120,7 @@ struct VFIOIOMMUClass {
>>      int (*attach_device)(const char *name, VFIODevice *vbasedev,
>>                           AddressSpace *as, Error **errp);
>>      void (*detach_device)(VFIODevice *vbasedev);
>> +    void (*host_iommu_device_create)(VFIODevice *vbasedev);
>Maybe return an int instead. It is common the allocation can fail and
>the deallocation cannot. While at it I would also pass an errp in case
>it fails

Currently host_iommu_device_create implementation only calls g_malloc0,
so never fails, so I returned void.

I'm fine to return an int, will be like below, take iommufd for example:

--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -651,7 +651,7 @@ static IOMMUFDDeviceOps vfio_iommufd_device_ops = {
     .detach_hwpt = vfio_iommufd_device_detach_hwpt,
 };

-static void vfio_cdev_host_iommu_device_create(VFIODevice *vbasedev)
+static int vfio_cdev_host_iommu_device_create(VFIODevice *vbasedev, Error **errp)
 {
     IOMMUFDDevice *idev = g_malloc0(sizeof(IOMMUFDDevice));
     VFIOIOMMUFDContainer *container = container_of(vbasedev->bcontainer,
@@ -661,6 +661,8 @@ static void vfio_cdev_host_iommu_device_create(VFIODevice *vbasedev)

     iommufd_device_init(idev, vbasedev->iommufd, vbasedev->devid,
                         container->ioas_id, vbasedev, &vfio_iommufd_device_ops);
+
+    return 0;
 }

Thanks
Zhenzhong

>
>Eric
>>      /* migration feature */
>>      int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer,
>>                                     bool start);
>> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
>> index 059bfdc07a..41e9031c59 100644
>> --- a/hw/vfio/common.c
>> +++ b/hw/vfio/common.c
>> @@ -1521,3 +1521,11 @@ void vfio_detach_device(VFIODevice
>*vbasedev)
>>      }
>>      vbasedev->bcontainer->ops->detach_device(vbasedev);
>>  }
>> +
>> +void host_iommu_device_create(VFIODevice *vbasedev)
>> +{
>> +    const VFIOIOMMUClass *ops = vbasedev->bcontainer->ops;
>> +
>> +    assert(ops->host_iommu_device_create);
>> +    ops->host_iommu_device_create(vbasedev);
>> +}


  reply	other threads:[~2024-03-19  5:46 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28  3:58 [PATCH v1 00/11] Add a host IOMMU device abstraction Zhenzhong Duan
2024-02-28  3:58 ` [PATCH v1 01/11] Introduce a common abstract struct HostIOMMUDevice Zhenzhong Duan
2024-03-18 14:23   ` Eric Auger
2024-03-19  3:48     ` Duan, Zhenzhong
2024-03-19  8:16   ` Cédric Le Goater
2024-03-19 11:58     ` Duan, Zhenzhong
2024-03-27 10:25       ` Cédric Le Goater
2024-03-28  3:06         ` Duan, Zhenzhong
2024-03-29 15:30           ` Cédric Le Goater
2024-04-01  3:59             ` Duan, Zhenzhong
2024-02-28  3:58 ` [PATCH v1 02/11] backends/iommufd: Introduce IOMMUFDDevice Zhenzhong Duan
2024-02-28  3:58 ` [PATCH v1 03/11] vfio: Introduce IOMMULegacyDevice Zhenzhong Duan
2024-02-28  3:58 ` [PATCH v1 04/11] vfio: Add HostIOMMUDevice handle into VFIODevice Zhenzhong Duan
2024-03-18 13:49   ` Eric Auger
2024-03-19  3:05     ` Duan, Zhenzhong
2024-02-28  3:58 ` [PATCH v1 05/11] vfio: Introduce host_iommu_device_create callback Zhenzhong Duan
2024-03-18 13:52   ` Eric Auger
2024-03-18 14:23     ` Eric Auger
2024-03-19  3:14       ` Duan, Zhenzhong
2024-03-19  3:12     ` Duan, Zhenzhong
2024-03-18 14:32   ` Eric Auger
2024-03-19  5:44     ` Duan, Zhenzhong [this message]
2024-03-19  7:16       ` Eric Auger
2024-02-28  3:58 ` [PATCH v1 06/11] vfio/container: Implement host_iommu_device_create callback in legacy mode Zhenzhong Duan
2024-02-28  3:58 ` [PATCH v1 07/11] vfio/iommufd: Implement host_iommu_device_create callback in iommufd mode Zhenzhong Duan
2024-02-28  3:58 ` [PATCH v1 08/11] vfio/pci: Allocate and initialize HostIOMMUDevice after attachment Zhenzhong Duan
2024-03-18 14:27   ` Eric Auger
2024-03-19  3:46     ` Duan, Zhenzhong
2024-03-19  7:18       ` Eric Auger
2024-02-28  3:58 ` [PATCH v1 09/11] hw/pci: Introduce pci_device_set/unset_iommu_device() Zhenzhong Duan
2024-03-12 16:55   ` Michael S. Tsirkin
2024-03-12 17:10     ` Michael S. Tsirkin
2024-03-18 14:49   ` Eric Auger
2024-03-19  6:16     ` Duan, Zhenzhong
2024-02-28  3:58 ` [PATCH v1 10/11] vfio: Pass HostIOMMUDevice to vIOMMU Zhenzhong Duan
2024-02-28  3:59 ` [PATCH v1 11/11] backends/iommufd: Introduce helper function iommufd_device_get_info() Zhenzhong Duan
2024-03-18 14:54   ` Eric Auger
2024-03-18 15:09     ` Joao Martins
2024-03-18 15:11       ` Eric Auger
2024-03-19  6:25         ` Duan, Zhenzhong
2024-03-18 14:57 ` [PATCH v1 00/11] Add a host IOMMU device abstraction Eric Auger
2024-03-19  6:26   ` Duan, Zhenzhong

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=SJ0PR11MB67448B4FB9B8E10A2F0DCEB6922C2@SJ0PR11MB6744.namprd11.prod.outlook.com \
    --to=zhenzhong.duan@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=chao.p.peng@intel.com \
    --cc=clg@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=joao.m.martins@oracle.com \
    --cc=kevin.tian@intel.com \
    --cc=mst@redhat.com \
    --cc=nicolinc@nvidia.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yi.l.liu@intel.com \
    --cc=yi.y.sun@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.