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,
	joao.m.martins@oracle.com
Subject: Re: [PATCH 1/2] vfio/container: Support unmap all in one ioctl()
Date: Tue, 30 Sep 2025 17:26:59 +0200	[thread overview]
Message-ID: <01f0b0eb-b036-4823-8020-fd6962b26d9d@redhat.com> (raw)
In-Reply-To: <20250924070254.1550014-2-zhenzhong.duan@intel.com>

On 9/24/25 09:02, Zhenzhong Duan wrote:
> VFIO type1 kernel uAPI supports unmapping whole address space in one call
> since commit c19650995374 ("vfio/type1: implement unmap all"). use the
> unmap_all variant whenever it's supported in kernel.
> 
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
>   hw/vfio/container.c | 33 ++++++++++++++++++++-------------
>   1 file changed, 20 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
> index 030c6d3f89..2e13f04803 100644
> --- a/hw/vfio/container.c
> +++ b/hw/vfio/container.c
> @@ -122,12 +122,12 @@ unmap_exit:
>   
>   static int vfio_legacy_dma_unmap_one(const VFIOContainerBase *bcontainer,

Side note for rebase :

I would prefer internal routines of file hw/vfio/container.c,
which was renamed recently to hw/vfio/container-legacy.c, to
take a 'VFIOLegacyContainer *container' parameter.

The 'VFIOContainer *bcontainer' parameter should be kept for
high-level routines that wrap the IOMMU backend implementation.

>                                        hwaddr iova, ram_addr_t size,
> -                                     IOMMUTLBEntry *iotlb)
> +                                     uint32_t flags, IOMMUTLBEntry *iotlb)
>   {
>       const VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       struct vfio_iommu_type1_dma_unmap unmap = {
>           .argsz = sizeof(unmap),
> -        .flags = 0,
> +        .flags = flags,
>           .iova = iova,>           .size = size,
>       };
> @@ -187,25 +187,32 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,
>                                    hwaddr iova, ram_addr_t size,
>                                    IOMMUTLBEntry *iotlb, bool unmap_all)
>   {
> +    uint32_t flags = 0;
>       int ret;
>   
>       if (unmap_all) {
> -        /* The unmap ioctl doesn't accept a full 64-bit span. */
> -        Int128 llsize = int128_rshift(int128_2_64(), 1);
> +        const VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>   
> -        ret = vfio_legacy_dma_unmap_one(bcontainer, 0, int128_get64(llsize),
> -                                        iotlb);
> +        assert(!iova && !size);

The assert deserves an explanation and so probably a new patch.

    
> -        if (ret == 0) {
> -            ret = vfio_legacy_dma_unmap_one(bcontainer, int128_get64(llsize),
> -                                            int128_get64(llsize), iotlb);
> -        }
> +        ret = ioctl(container->fd, VFIO_CHECK_EXTENSION, VFIO_UNMAP_ALL);
> +        if (ret) {
> +            flags = VFIO_DMA_UNMAP_FLAG_ALL;
> +        } else {
> +            /* The unmap ioctl doesn't accept a full 64-bit span. */
> +            Int128 llsize = int128_rshift(int128_2_64(), 1);
> +            size = int128_get64(llsize);
> +
> +            ret = vfio_legacy_dma_unmap_one(bcontainer, 0, size, flags, iotlb);
> +            if (ret) {
> +                return ret;
> +            }

Could we introduce an helper to test 'unmap_all' support in the host
kernel ? The result would be something like :

   if (unmap_all) {
         if (vfio_legacy_has_unmap_all(VFIO_IOMMU_LEGACY(bcontainer))) {
             flags = VFIO_DMA_UNMAP_FLAG_ALL;
         } else {
             /* The unmap ioctl doesn't accept a full 64-bit span. */
             Int128 llsize = int128_rshift(int128_2_64(), 1);
             ...
         }
   }


Thanks,

C.




> -    } else {
> -        ret = vfio_legacy_dma_unmap_one(bcontainer, iova, size, iotlb);
> +            iova = size;
> +        }
>       }
>   
> -    return ret;
> +    return vfio_legacy_dma_unmap_one(bcontainer, iova, size, flags, iotlb);
>   }
>   
>   static int vfio_legacy_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,



  reply	other threads:[~2025-09-30 15:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-24  7:02 [PATCH 0/2] Optimize unmap_all with one ioctl() Zhenzhong Duan
2025-09-24  7:02 ` [PATCH 1/2] vfio/container: Support unmap all in " Zhenzhong Duan
2025-09-30 15:26   ` Cédric Le Goater [this message]
2025-09-30 22:04     ` John Levon
2025-10-01  6:58       ` Cédric Le Goater
2025-10-08 10:18         ` Duan, Zhenzhong
2025-10-08 13:01           ` Cédric Le Goater
2025-10-08 13:11             ` John Levon
2025-10-08 13:26               ` Cédric Le Goater
2025-10-08 10:17     ` Duan, Zhenzhong
2025-09-24  7:02 ` [PATCH 2/2] vfio/iommufd: " Zhenzhong Duan

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=01f0b0eb-b036-4823-8020-fd6962b26d9d@redhat.com \
    --to=clg@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=joao.m.martins@oracle.com \
    --cc=qemu-devel@nongnu.org \
    --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).