[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH QEMU v25 11/17] vfio: Get migration capability flags for cont
From: |
Cornelia Huck |
Subject: |
Re: [PATCH QEMU v25 11/17] vfio: Get migration capability flags for container |
Date: |
Wed, 24 Jun 2020 10:43:50 +0200 |
On Sun, 21 Jun 2020 01:51:20 +0530
Kirti Wankhede <kwankhede@nvidia.com> wrote:
> Added helper functions to get IOMMU info capability chain.
> Added function to get migration capability information from that
> capability chain for IOMMU container.
>
> Similar change was proposed earlier:
> https://lists.gnu.org/archive/html/qemu-devel/2018-05/msg03759.html
>
> Signed-off-by: Kirti Wankhede <kwankhede@nvidia.com>
> Cc: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
> Cc: Eric Auger <eric.auger@redhat.com>
> ---
> hw/vfio/common.c | 91
> +++++++++++++++++++++++++++++++++++++++----
> include/hw/vfio/vfio-common.h | 3 ++
> 2 files changed, 86 insertions(+), 8 deletions(-)
>
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 90e9a854d82c..e0d3d4585a65 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -1229,6 +1229,75 @@ static int vfio_init_container(VFIOContainer
> *container, int group_fd,
> return 0;
> }
>
> +static int vfio_get_iommu_info(VFIOContainer *container,
> + struct vfio_iommu_type1_info **info)
> +{
> +
> + size_t argsz = sizeof(struct vfio_iommu_type1_info);
> +
> + *info = g_new0(struct vfio_iommu_type1_info, 1);
> +again:
> + (*info)->argsz = argsz;
> +
> + if (ioctl(container->fd, VFIO_IOMMU_GET_INFO, *info)) {
> + g_free(*info);
> + *info = NULL;
> + return -errno;
> + }
> +
> + if (((*info)->argsz > argsz)) {
> + argsz = (*info)->argsz;
> + *info = g_realloc(*info, argsz);
Do we need to guard against getting a bogus argsz value causing a huge
allocation that might fail and crash the program?
> + goto again;
> + }
> +
> + return 0;
> +}
(...)
> @@ -1314,15 +1384,20 @@ static int vfio_connect_container(VFIOGroup *group,
> AddressSpace *as,
> * existing Type1 IOMMUs generally support any IOVA we're
> * going to actually try in practice.
> */
> - info.argsz = sizeof(info);
> - ret = ioctl(fd, VFIO_IOMMU_GET_INFO, &info);
> - /* Ignore errors */
> - if (ret || !(info.flags & VFIO_IOMMU_INFO_PGSIZES)) {
> + ret = vfio_get_iommu_info(container, &info);
Previously, we ignored errors from the IOMMU_GET_INFO ioctl, now we
error out. Was that change intended?
> + if (ret) {
> + goto free_container_exit;
> + }
> +
> + if (!(info->flags & VFIO_IOMMU_INFO_PGSIZES)) {
> /* Assume 4k IOVA page size */
> - info.iova_pgsizes = 4096;
> + info->iova_pgsizes = 4096;
> }
> - vfio_host_win_add(container, 0, (hwaddr)-1, info.iova_pgsizes);
> - container->pgsizes = info.iova_pgsizes;
> + vfio_host_win_add(container, 0, (hwaddr)-1, info->iova_pgsizes);
> + container->pgsizes = info->iova_pgsizes;
> +
> + vfio_get_iommu_info_migration(container, info);
> + g_free(info);
> break;
> }
> case VFIO_SPAPR_TCE_v2_IOMMU:
(...)
[PATCH QEMU v25 10/17] memory: Set DIRTY_MEMORY_MIGRATION when IOMMU is enabled, Kirti Wankhede, 2020/06/20
[PATCH QEMU v25 11/17] vfio: Get migration capability flags for container, Kirti Wankhede, 2020/06/20
[PATCH QEMU v25 12/17] vfio: Add function to start and stop dirty pages tracking, Kirti Wankhede, 2020/06/20
Re: [PATCH QEMU v25 12/17] vfio: Add function to start and stop dirty pages tracking, Alex Williamson, 2020/06/24
[PATCH QEMU v25 13/17] vfio: create mapped iova list when vIOMMU is enabled, Kirti Wankhede, 2020/06/20