Message ID | 20240429065046.3688701-8-zhenzhong.duan@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add a host IOMMU device abstraction to check with vIOMMU | expand |
On 4/29/24 08:50, Zhenzhong Duan wrote: > Utilize range_get_last_bit() to get host IOMMU address width and > package it in HostIOMMUDeviceCaps for query with .check_cap(). > > Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> > --- > hw/vfio/container.c | 29 +++++++++++++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/hw/vfio/container.c b/hw/vfio/container.c > index 3b6826996a..863eec3943 100644 > --- a/hw/vfio/container.c > +++ b/hw/vfio/container.c > @@ -1143,6 +1143,34 @@ static void vfio_iommu_legacy_class_init(ObjectClass *klass, void *data) > vioc->pci_hot_reset = vfio_legacy_pci_hot_reset; > }; > > +static bool hiod_legacy_vfio_realize(HostIOMMUDevice *hiod, void *opaque, > + Error **errp) > +{ > + VFIODevice *vdev = opaque; > + /* iova_ranges is a sorted list */ > + GList *l = g_list_last(vdev->bcontainer->iova_ranges); > + > + /* There is no VFIO uAPI to query host platform IOMMU type */ > + hiod->caps.type = IOMMU_HW_INFO_TYPE_NONE; > + HOST_IOMMU_DEVICE_IOMMUFD_VFIO(hiod)->vdev = vdev; cast uses the wrong type and I am not sure the ->vdev is useful. Thanks, C. > + > + if (l) { > + Range *range = l->data; > + hiod->caps.aw_bits = range_get_last_bit(range) + 1; > + } else { > + hiod->caps.aw_bits = 0xff; > + } > + > + return true; > +} > + > +static void hiod_legacy_vfio_class_init(ObjectClass *oc, void *data) > +{ > + HostIOMMUDeviceClass *hioc = HOST_IOMMU_DEVICE_CLASS(oc); > + > + hioc->realize = hiod_legacy_vfio_realize; > +}; > + > static const TypeInfo types[] = { > { > .name = TYPE_VFIO_IOMMU_LEGACY, > @@ -1152,6 +1180,7 @@ static const TypeInfo types[] = { > .name = TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO, > .parent = TYPE_HOST_IOMMU_DEVICE, > .instance_size = sizeof(HostIOMMUDeviceLegacyVFIO), > + .class_init = hiod_legacy_vfio_class_init, > } > }; >
>-----Original Message----- >From: Cédric Le Goater <clg@redhat.com> >Subject: Re: [PATCH v3 07/19] vfio/container: Implement >HostIOMMUDeviceClass::realize() handler > >On 4/29/24 08:50, Zhenzhong Duan wrote: >> Utilize range_get_last_bit() to get host IOMMU address width and >> package it in HostIOMMUDeviceCaps for query with .check_cap(). >> >> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> >> --- >> hw/vfio/container.c | 29 +++++++++++++++++++++++++++++ >> 1 file changed, 29 insertions(+) >> >> diff --git a/hw/vfio/container.c b/hw/vfio/container.c >> index 3b6826996a..863eec3943 100644 >> --- a/hw/vfio/container.c >> +++ b/hw/vfio/container.c >> @@ -1143,6 +1143,34 @@ static void >vfio_iommu_legacy_class_init(ObjectClass *klass, void *data) >> vioc->pci_hot_reset = vfio_legacy_pci_hot_reset; >> }; >> >> +static bool hiod_legacy_vfio_realize(HostIOMMUDevice *hiod, void >*opaque, >> + Error **errp) >> +{ >> + VFIODevice *vdev = opaque; >> + /* iova_ranges is a sorted list */ >> + GList *l = g_list_last(vdev->bcontainer->iova_ranges); >> + >> + /* There is no VFIO uAPI to query host platform IOMMU type */ >> + hiod->caps.type = IOMMU_HW_INFO_TYPE_NONE; >> + HOST_IOMMU_DEVICE_IOMMUFD_VFIO(hiod)->vdev = vdev; > >cast uses the wrong type and I am not sure the ->vdev is useful. Good catch, will remove vdev as you suggested. Thanks Zhenzhong > > >Thanks, > >C. > > >> + >> + if (l) { >> + Range *range = l->data; >> + hiod->caps.aw_bits = range_get_last_bit(range) + 1; >> + } else { >> + hiod->caps.aw_bits = 0xff; >> + } >> + >> + return true; >> +} >> + >> +static void hiod_legacy_vfio_class_init(ObjectClass *oc, void *data) >> +{ >> + HostIOMMUDeviceClass *hioc = HOST_IOMMU_DEVICE_CLASS(oc); >> + >> + hioc->realize = hiod_legacy_vfio_realize; >> +}; >> + >> static const TypeInfo types[] = { >> { >> .name = TYPE_VFIO_IOMMU_LEGACY, >> @@ -1152,6 +1180,7 @@ static const TypeInfo types[] = { >> .name = TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO, >> .parent = TYPE_HOST_IOMMU_DEVICE, >> .instance_size = sizeof(HostIOMMUDeviceLegacyVFIO), >> + .class_init = hiod_legacy_vfio_class_init, >> } >> }; >>
diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 3b6826996a..863eec3943 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1143,6 +1143,34 @@ static void vfio_iommu_legacy_class_init(ObjectClass *klass, void *data) vioc->pci_hot_reset = vfio_legacy_pci_hot_reset; }; +static bool hiod_legacy_vfio_realize(HostIOMMUDevice *hiod, void *opaque, + Error **errp) +{ + VFIODevice *vdev = opaque; + /* iova_ranges is a sorted list */ + GList *l = g_list_last(vdev->bcontainer->iova_ranges); + + /* There is no VFIO uAPI to query host platform IOMMU type */ + hiod->caps.type = IOMMU_HW_INFO_TYPE_NONE; + HOST_IOMMU_DEVICE_IOMMUFD_VFIO(hiod)->vdev = vdev; + + if (l) { + Range *range = l->data; + hiod->caps.aw_bits = range_get_last_bit(range) + 1; + } else { + hiod->caps.aw_bits = 0xff; + } + + return true; +} + +static void hiod_legacy_vfio_class_init(ObjectClass *oc, void *data) +{ + HostIOMMUDeviceClass *hioc = HOST_IOMMU_DEVICE_CLASS(oc); + + hioc->realize = hiod_legacy_vfio_realize; +}; + static const TypeInfo types[] = { { .name = TYPE_VFIO_IOMMU_LEGACY, @@ -1152,6 +1180,7 @@ static const TypeInfo types[] = { .name = TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO, .parent = TYPE_HOST_IOMMU_DEVICE, .instance_size = sizeof(HostIOMMUDeviceLegacyVFIO), + .class_init = hiod_legacy_vfio_class_init, } };
Utilize range_get_last_bit() to get host IOMMU address width and package it in HostIOMMUDeviceCaps for query with .check_cap(). Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> --- hw/vfio/container.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)