From: Alex Williamson <alex.williamson@redhat.com>
To: Steve Sistare <steven.sistare@oracle.com>
Cc: kvm@vger.kernel.org, Cornelia Huck <cohuck@redhat.com>,
Kirti Wankhede <kwankhede@nvidia.com>
Subject: Re: [PATCH V3 5/9] vfio/type1: massage unmap iteration
Date: Fri, 29 Jan 2021 14:56:12 -0700 [thread overview]
Message-ID: <20210129145612.0b507334@omen.home.shazbot.org> (raw)
In-Reply-To: <1611939252-7240-6-git-send-email-steven.sistare@oracle.com>
On Fri, 29 Jan 2021 08:54:08 -0800
Steve Sistare <steven.sistare@oracle.com> wrote:
> Modify the iteration in vfio_dma_do_unmap so it does not depend on deletion
> of each dma entry. Add a variant of vfio_find_dma that returns the entry
> with the lowest iova in the search range to initialize the iteration. No
> externally visible change, but this behavior is needed in the subsequent
> update-vaddr patch.
>
> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
> ---
> drivers/vfio/vfio_iommu_type1.c | 35 ++++++++++++++++++++++++++++++++++-
> 1 file changed, 34 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index 407f0f7..5823607 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -173,6 +173,31 @@ static struct vfio_dma *vfio_find_dma(struct vfio_iommu *iommu,
> return NULL;
> }
>
> +static struct rb_node *vfio_find_dma_first(struct vfio_iommu *iommu,
> + dma_addr_t start, size_t size)
Nit, we return an rb_node rather than a vfio_dma now, but the naming is
still pretty similar to vfio_find_dma(). Can I change it to
vfio_find_dma_first_node() (yes, getting wordy)? Thanks,
Alex
> +{
> + struct rb_node *res = NULL;
> + struct rb_node *node = iommu->dma_list.rb_node;
> + struct vfio_dma *dma_res = NULL;
> +
> + while (node) {
> + struct vfio_dma *dma = rb_entry(node, struct vfio_dma, node);
> +
> + if (start < dma->iova + dma->size) {
> + res = node;
> + dma_res = dma;
> + if (start >= dma->iova)
> + break;
> + node = node->rb_left;
> + } else {
> + node = node->rb_right;
> + }
> + }
> + if (res && size && dma_res->iova >= start + size)
> + res = NULL;
> + return res;
> +}
> +
> static void vfio_link_dma(struct vfio_iommu *iommu, struct vfio_dma *new)
> {
> struct rb_node **link = &iommu->dma_list.rb_node, *parent = NULL;
> @@ -1078,6 +1103,7 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,
> dma_addr_t iova = unmap->iova;
> unsigned long size = unmap->size;
> bool unmap_all = !!(unmap->flags & VFIO_DMA_UNMAP_FLAG_ALL);
> + struct rb_node *n;
>
> mutex_lock(&iommu->lock);
>
> @@ -1148,7 +1174,13 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,
> }
>
> ret = 0;
> - while ((dma = vfio_find_dma(iommu, iova, size))) {
> + n = vfio_find_dma_first(iommu, iova, size);
> +
> + while (n) {
> + dma = rb_entry(n, struct vfio_dma, node);
> + if (dma->iova >= iova + size)
> + break;
> +
> if (!iommu->v2 && iova > dma->iova)
> break;
> /*
> @@ -1193,6 +1225,7 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,
> }
>
> unmapped += dma->size;
> + n = rb_next(n);
> vfio_remove_dma(iommu, dma);
> }
>
next prev parent reply other threads:[~2021-01-29 21:58 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-29 16:54 [PATCH V3 0/9] vfio virtual address update Steve Sistare
2021-01-29 16:54 ` [PATCH V3 1/9] vfio: option to unmap all Steve Sistare
2021-02-01 11:42 ` Cornelia Huck
2021-02-01 12:52 ` Steven Sistare
2021-02-01 13:13 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 2/9] vfio/type1: unmap cleanup Steve Sistare
2021-02-01 11:50 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 3/9] vfio/type1: implement unmap all Steve Sistare
2021-02-01 11:59 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 4/9] vfio: interfaces to update vaddr Steve Sistare
2021-02-01 13:13 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 5/9] vfio/type1: massage unmap iteration Steve Sistare
2021-01-29 21:56 ` Alex Williamson [this message]
2021-01-30 16:51 ` Steven Sistare
2021-02-01 12:11 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 6/9] vfio/type1: implement interfaces to update vaddr Steve Sistare
2021-01-29 21:56 ` Alex Williamson
2021-01-30 16:51 ` Steven Sistare
2021-02-01 12:27 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 7/9] vfio: iommu driver notify callback Steve Sistare
2021-01-29 21:57 ` Alex Williamson
2021-01-30 16:51 ` Steven Sistare
2021-02-01 12:34 ` Cornelia Huck
2021-02-01 12:52 ` Steven Sistare
2021-02-01 13:17 ` Cornelia Huck
2021-02-01 13:17 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 8/9] vfio/type1: implement " Steve Sistare
2021-02-01 12:40 ` Cornelia Huck
2021-01-29 16:54 ` [PATCH V3 9/9] vfio/type1: block on invalid vaddr Steve Sistare
2021-02-01 12:47 ` Cornelia Huck
2021-01-29 21:55 ` [PATCH V3 0/9] vfio virtual address update Alex Williamson
2021-01-29 22:14 ` Steven Sistare
2021-01-30 16:54 ` Steven Sistare
2021-02-01 20:23 ` Alex Williamson
2021-02-01 21:13 ` Steven Sistare
2021-02-02 7:54 ` Cornelia Huck
2021-02-02 17:21 ` Alex Williamson
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=20210129145612.0b507334@omen.home.shazbot.org \
--to=alex.williamson@redhat.com \
--cc=cohuck@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
--cc=steven.sistare@oracle.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).