qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: Zhenzhong Duan <zhenzhong.duan@intel.com>, qemu-devel@nongnu.org
Cc: alex.williamson@redhat.com, eric.auger@redhat.com,
	peterx@redhat.com, jasowang@redhat.com, mst@redhat.com,
	jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com,
	kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com
Subject: Re: [PATCH v2 05/10] vfio: Implement get_host_iommu_info() callback
Date: Mon, 15 Apr 2024 15:15:44 +0200	[thread overview]
Message-ID: <e9b75cf0-49f4-4773-98c3-ec765c3adbb0@redhat.com> (raw)
In-Reply-To: <20240408081230.1030078-6-zhenzhong.duan@intel.com>

On 4/8/24 10:12, Zhenzhong Duan wrote:
> Utilize iova_ranges to calculate host IOMMU address width and
> package it in HIOD_LEGACY_INFO for vIOMMU usage.
> 
> HIOD_LEGACY_INFO will be used by both VFIO and VDPA so declare
> it in host_iommu_device.h.
> 
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
>   include/sysemu/host_iommu_device.h | 10 ++++++++++
>   hw/vfio/container.c                | 24 ++++++++++++++++++++++++
>   2 files changed, 34 insertions(+)
> 
> diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu_device.h
> index 22ccbe3a5d..beb8be8231 100644
> --- a/include/sysemu/host_iommu_device.h
> +++ b/include/sysemu/host_iommu_device.h
> @@ -16,4 +16,14 @@ struct HostIOMMUDeviceClass {
>       int (*get_host_iommu_info)(HostIOMMUDevice *hiod, void *data, uint32_t len,
>                                  Error **errp);
>   };
> +
> +/*
> + * Define the format of host IOMMU related info that current VFIO
> + * or VDPA can privode to vIOMMU.
> + *
> + * @aw_bits: Host IOMMU address width. 0xff if no limitation.
> + */
> +typedef struct HIOD_LEGACY_INFO {

Please use CamelCase names.

> +    uint8_t aw_bits;
> +} HIOD_LEGACY_INFO;
>   #endif
> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
> index 44018ef085..ba0ad4a41b 100644
> --- a/hw/vfio/container.c
> +++ b/hw/vfio/container.c
> @@ -1143,8 +1143,32 @@ static void vfio_iommu_legacy_class_init(ObjectClass *klass, void *data)
>       vioc->pci_hot_reset = vfio_legacy_pci_hot_reset;
>   };
>   
> +static int hiod_legacy_vfio_get_host_iommu_info(HostIOMMUDevice *hiod,
> +                                                void *data, uint32_t len,
> +                                                Error **errp)
> +{
> +    VFIODevice *vbasedev = HIOD_LEGACY_VFIO(hiod)->vdev;
> +    /* iova_ranges is a sorted list */
> +    GList *l = g_list_last(vbasedev->bcontainer->iova_ranges);
> +    HIOD_LEGACY_INFO *info = data;
> +
> +    assert(sizeof(HIOD_LEGACY_INFO) <= len);
> +
> +    if (l) {
> +        Range *range = l->data;
> +        info->aw_bits = find_last_bit(&range->upb, BITS_PER_LONG) + 1;

There is a comment in range.h saying:

     /*
      * Do not access members directly, use the functions!

Please introduce a new helper.


Thanks,

C.



> +    } else {
> +        info->aw_bits = 0xff;
> +    }
> +
> +    return 0;
> +}
> +
>   static void hiod_legacy_vfio_class_init(ObjectClass *oc, void *data)
>   {
> +    HostIOMMUDeviceClass *hioc = HOST_IOMMU_DEVICE_CLASS(oc);
> +
> +    hioc->get_host_iommu_info = hiod_legacy_vfio_get_host_iommu_info;
>   };
>   
>   static const TypeInfo types[] = {



  reply	other threads:[~2024-04-15 13:17 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08  8:12 [PATCH v2 00/10] Add a host IOMMU device abstraction Zhenzhong Duan
2024-04-08  8:12 ` [PATCH v2 01/10] backends: Introduce abstract HostIOMMUDevice Zhenzhong Duan
2024-04-15  8:09   ` Cédric Le Goater
2024-04-15  9:57     ` Duan, Zhenzhong
2024-04-15  9:18   ` Philippe Mathieu-Daudé
2024-04-15  9:58     ` Duan, Zhenzhong
2024-04-08  8:12 ` [PATCH v2 02/10] vfio: Introduce HIODLegacyVFIO device Zhenzhong Duan
2024-04-15  9:19   ` Philippe Mathieu-Daudé
2024-04-15 10:10     ` Duan, Zhenzhong
2024-04-15 11:12       ` Philippe Mathieu-Daudé
2024-04-15 12:12         ` Duan, Zhenzhong
2024-04-15 12:47   ` Cédric Le Goater
2024-04-16  3:41     ` Duan, Zhenzhong
2024-04-16 13:53       ` Cédric Le Goater
2024-04-17  4:22         ` Duan, Zhenzhong
2024-04-08  8:12 ` [PATCH v2 03/10] backends/iommufd: Introduce abstract HIODIOMMUFD device Zhenzhong Duan
2024-04-09  3:41   ` Duan, Zhenzhong
2024-04-15 13:07   ` Cédric Le Goater
2024-04-16  4:09     ` Duan, Zhenzhong
2024-04-08  8:12 ` [PATCH v2 04/10] vfio/iommufd: Introduce HIODIOMMUFDVFIO device Zhenzhong Duan
2024-04-08  8:12 ` [PATCH v2 05/10] vfio: Implement get_host_iommu_info() callback Zhenzhong Duan
2024-04-15 13:15   ` Cédric Le Goater [this message]
2024-04-16  5:58     ` Duan, Zhenzhong
2024-04-08  8:12 ` [PATCH v2 06/10] backends/iommufd: Introduce helper function iommufd_backend_get_device_info() Zhenzhong Duan
2024-04-15 13:22   ` Cédric Le Goater
2024-04-16  6:07     ` Duan, Zhenzhong
2024-04-08  8:12 ` [PATCH v2 07/10] backends/iommufd: Implement get_host_iommu_info() callback Zhenzhong Duan
2024-04-15 13:23   ` Cédric Le Goater
2024-04-16  6:10     ` Duan, Zhenzhong
2024-04-08  8:12 ` [PATCH v2 08/10] vfio: Create host IOMMU device instance Zhenzhong Duan
2024-04-15 13:25   ` Cédric Le Goater
2024-04-16  6:11     ` Duan, Zhenzhong
2024-04-08  8:12 ` [PATCH v2 09/10] hw/pci: Introduce pci_device_set/unset_iommu_device() Zhenzhong Duan
2024-04-15 13:34   ` Cédric Le Goater
2024-04-16  6:11     ` Duan, Zhenzhong
2024-04-08  8:12 ` [PATCH v2 10/10] vfio: Pass HostIOMMUDevice to vIOMMU Zhenzhong Duan
2024-04-15 13:37   ` 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=e9b75cf0-49f4-4773-98c3-ec765c3adbb0@redhat.com \
    --to=clg@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=chao.p.peng@intel.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=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).