From: Jason Gunthorpe <jgg@nvidia.com>
To: Jean-Philippe Brucker <jean-philippe@linaro.org>
Cc: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com,
eric.auger@redhat.com, virtualization@lists.linux-foundation.org,
iommu@lists.linux.dev, akihiko.odaki@daynix.com
Subject: Re: [PATCH v2 2/2] iommu/virtio: Return size mapped for a detached domain
Date: Wed, 17 May 2023 13:41:57 -0300 [thread overview]
Message-ID: <ZGUD1efvOttujDPp@nvidia.com> (raw)
In-Reply-To: <20230515113946.1017624-3-jean-philippe@linaro.org>
On Mon, May 15, 2023 at 12:39:50PM +0100, Jean-Philippe Brucker wrote:
> When map() is called on a detached domain, the domain does not exist in
> the device so we do not send a MAP request, but we do update the
> internal mapping tree, to be replayed on the next attach. Since this
> constitutes a successful iommu_map() call, return *mapped in this case
> too.
>
> Fixes: 7e62edd7a33a ("iommu/virtio: Add map/unmap_pages() callbacks implementation")
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---
> drivers/iommu/virtio-iommu.c | 33 +++++++++++++++++----------------
> 1 file changed, 17 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
> index fd316a37d7562..3551ed057774e 100644
> --- a/drivers/iommu/virtio-iommu.c
> +++ b/drivers/iommu/virtio-iommu.c
> @@ -833,25 +833,26 @@ static int viommu_map_pages(struct iommu_domain *domain, unsigned long iova,
> if (ret)
> return ret;
>
> - map = (struct virtio_iommu_req_map) {
> - .head.type = VIRTIO_IOMMU_T_MAP,
> - .domain = cpu_to_le32(vdomain->id),
> - .virt_start = cpu_to_le64(iova),
> - .phys_start = cpu_to_le64(paddr),
> - .virt_end = cpu_to_le64(end),
> - .flags = cpu_to_le32(flags),
> - };
> + if (vdomain->nr_endpoints) {
> + map = (struct virtio_iommu_req_map) {
> + .head.type = VIRTIO_IOMMU_T_MAP,
> + .domain = cpu_to_le32(vdomain->id),
> + .virt_start = cpu_to_le64(iova),
> + .phys_start = cpu_to_le64(paddr),
> + .virt_end = cpu_to_le64(end),
> + .flags = cpu_to_le32(flags),
> + };
>
> - if (!vdomain->nr_endpoints)
> - return 0;
> -
> - ret = viommu_send_req_sync(vdomain->viommu, &map, sizeof(map));
> - if (ret)
> - viommu_del_mappings(vdomain, iova, end);
> - else if (mapped)
> + ret = viommu_send_req_sync(vdomain->viommu, &map, sizeof(map));
> + if (ret) {
> + viommu_del_mappings(vdomain, iova, end);
> + return ret;
> + }
> + }
> + if (mapped)
> *mapped = size;
This looks right
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
But your unmap looks troubled:
unmapped = viommu_del_mappings(vdomain, iova, iova + size - 1);
if (unmapped < size)
return 0;
It shouldn't unmap something and then return 0...
Also, these days this driver be much better to use a multi-order
xarray than in interval tree..
Jason
next prev parent reply other threads:[~2023-05-17 16:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-15 11:39 [PATCH v2 0/2] iommu/virtio: Fixes Jean-Philippe Brucker
2023-05-15 11:39 ` Jean-Philippe Brucker
2023-05-15 11:39 ` [PATCH v2 1/2] iommu/virtio: Detach domain on endpoint release Jean-Philippe Brucker
2023-05-15 11:39 ` Jean-Philippe Brucker
2023-05-15 11:39 ` [PATCH v2 2/2] iommu/virtio: Return size mapped for a detached domain Jean-Philippe Brucker
2023-05-15 11:39 ` Jean-Philippe Brucker
2023-05-17 16:41 ` Jason Gunthorpe [this message]
2023-05-23 6:19 ` [PATCH v2 0/2] iommu/virtio: Fixes Joerg Roedel
2023-05-23 6:19 ` Joerg Roedel
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=ZGUD1efvOttujDPp@nvidia.com \
--to=jgg@nvidia.com \
--cc=akihiko.odaki@daynix.com \
--cc=eric.auger@redhat.com \
--cc=iommu@lists.linux.dev \
--cc=jean-philippe@linaro.org \
--cc=joro@8bytes.org \
--cc=robin.murphy@arm.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=will@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.