qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Zhenzhong Duan <zhenzhong.duan@intel.com>
To: qemu-devel@nongnu.org
Cc: alex.williamson@redhat.com, clg@redhat.com,
	eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com,
	jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com,
	joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com,
	kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com,
	Zhenzhong Duan <zhenzhong.duan@intel.com>
Subject: [PATCH v7 06/17] vfio/container: Implement HostIOMMUDeviceClass::realize() handler
Date: Wed,  5 Jun 2024 16:30:32 +0800	[thread overview]
Message-ID: <20240605083043.317831-7-zhenzhong.duan@intel.com> (raw)
In-Reply-To: <20240605083043.317831-1-zhenzhong.duan@intel.com>

The realize function populates the capabilities. For now only the
aw_bits caps is computed for legacy backend.

Introduce a helper function vfio_device_get_aw_bits() which calls
range_get_last_bit() to get host aw_bits and package it in
HostIOMMUDeviceCaps for query with .get_cap(). This helper will
also be used by iommufd backend.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 include/hw/vfio/vfio-common.h |  1 +
 hw/vfio/container.c           | 19 +++++++++++++++++++
 hw/vfio/helpers.c             | 17 +++++++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 56d1717211..105b8b7e80 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -289,4 +289,5 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
 void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
 void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops,
                       DeviceState *dev, bool ram_discard);
+int vfio_device_get_aw_bits(VFIODevice *vdev);
 #endif /* HW_VFIO_VFIO_COMMON_H */
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index c4fca2dfca..2f62c13214 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -1136,6 +1136,24 @@ 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;
+
+    hiod->name = g_strdup(vdev->name);
+    hiod->caps.aw_bits = vfio_device_get_aw_bits(vdev);
+
+    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,
@@ -1144,6 +1162,7 @@ static const TypeInfo types[] = {
     }, {
         .name = TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO,
         .parent = TYPE_HOST_IOMMU_DEVICE,
+        .class_init = hiod_legacy_vfio_class_init,
     }
 };
 
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
index 27ea26aa48..b14edd46ed 100644
--- a/hw/vfio/helpers.c
+++ b/hw/vfio/helpers.c
@@ -658,3 +658,20 @@ void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops,
 
     vbasedev->ram_block_discard_allowed = ram_discard;
 }
+
+int vfio_device_get_aw_bits(VFIODevice *vdev)
+{
+    /*
+     * iova_ranges is a sorted list. For old kernels that support
+     * VFIO but not support query of iova ranges, iova_ranges is NULL,
+     * in this case HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX(64) is returned.
+     */
+    GList *l = g_list_last(vdev->bcontainer->iova_ranges);
+
+    if (l) {
+        Range *range = l->data;
+        return range_get_last_bit(range) + 1;
+    }
+
+    return HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX;
+}
-- 
2.34.1



  parent reply	other threads:[~2024-06-05  8:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-05  8:30 [PATCH v7 00/17] Add a host IOMMU device abstraction to check with vIOMMU Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 01/17] backends: Introduce HostIOMMUDevice abstract Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 02/17] backends/host_iommu_device: Introduce HostIOMMUDeviceCaps Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 03/17] vfio/container: Introduce TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO device Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 04/17] backends/iommufd: Introduce TYPE_HOST_IOMMU_DEVICE_IOMMUFD[_VFIO] devices Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 05/17] range: Introduce range_get_last_bit() Zhenzhong Duan
2024-06-05  8:30 ` Zhenzhong Duan [this message]
2024-06-05  8:30 ` [PATCH v7 07/17] backends/iommufd: Introduce helper function iommufd_backend_get_device_info() Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 08/17] vfio/iommufd: Implement HostIOMMUDeviceClass::realize() handler Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 09/17] vfio/container: Implement HostIOMMUDeviceClass::get_cap() handler Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 10/17] backends/iommufd: " Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 11/17] vfio: Create host IOMMU device instance Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 12/17] hw/pci: Introduce helper function pci_device_get_iommu_bus_devfn() Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 13/17] hw/pci: Introduce pci_device_[set|unset]_iommu_device() Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 14/17] vfio/pci: Pass HostIOMMUDevice to vIOMMU Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 15/17] intel_iommu: Extract out vtd_cap_init() to initialize cap/ecap Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 16/17] intel_iommu: Implement [set|unset]_iommu_device() callbacks Zhenzhong Duan
2024-06-05  8:30 ` [PATCH v7 17/17] intel_iommu: Check compatibility with host IOMMU capabilities Zhenzhong Duan
2024-06-07 15:00 ` [PATCH v7 00/17] Add a host IOMMU device abstraction to check with vIOMMU Eric Auger
2024-06-11  2:32   ` Duan, Zhenzhong
2024-06-17 17:36 ` Cédric Le Goater
2024-06-24 10:26 ` Michael S. Tsirkin
2024-06-24 15:12   ` Cédric Le Goater
2024-06-24 15:24     ` Michael S. Tsirkin
2024-06-24 21:16 ` 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=20240605083043.317831-7-zhenzhong.duan@intel.com \
    --to=zhenzhong.duan@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=chao.p.peng@intel.com \
    --cc=clement.mathieu--drif@eviden.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 \
    /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).