From: Peter Xu <peterx@redhat.com>
To: Eric Auger <eric.auger@redhat.com>
Cc: peter.maydell@linaro.org, kevin.tian@intel.com,
tnowicki@marvell.com, jean-philippe@linaro.org,
quintela@redhat.com, qemu-devel@nongnu.org, dgilbert@redhat.com,
bharatb.linux@gmail.com, qemu-arm@nongnu.org, mst@redhat.com,
eric.auger.pro@gmail.com
Subject: Re: [PATCH v14 03/11] virtio-iommu: Implement attach/detach command
Date: Fri, 7 Feb 2020 15:26:01 -0500 [thread overview]
Message-ID: <20200207202601.GD720553@xz-x1> (raw)
In-Reply-To: <20200207093203.3788-4-eric.auger@redhat.com>
On Fri, Feb 07, 2020 at 10:31:55AM +0100, Eric Auger wrote:
[...]
> v13 -> v14:
> - in virtio_iommu_put_endpoint, if the EP is attached to a
> domain, call virtio_iommu_detach_endpoint_from_domain()
> - remove domain ref counting and simply delete the mappings
> gtree when the last EP is detached from the domain
Yeh this looks a good optimization! Ref counting protects the domain
from being gone when there's still EP in the domain, but since we've
got the ep_list in domain after all so it seems to be safe and clearer.
> - in virtio_iommu_detach_endpoint_from_domain(), return if the
> ep's domain is unset.
[...]
> +static void virtio_iommu_put_domain(gpointer data)
> +{
> + VirtIOIOMMUDomain *domain = (VirtIOIOMMUDomain *)data;
> + VirtIOIOMMUEndpoint *iter, *tmp;
> +
> + QLIST_FOREACH_SAFE(iter, &domain->endpoint_list, next, tmp) {
> + virtio_iommu_detach_endpoint_from_domain(iter);
> + }
> + trace_virtio_iommu_put_domain(domain->id);
[1]
> + g_free(domain);
> +}
[...]
> static int virtio_iommu_attach(VirtIOIOMMU *s,
> struct virtio_iommu_req_attach *req)
> {
> uint32_t domain_id = le32_to_cpu(req->domain);
> uint32_t ep_id = le32_to_cpu(req->endpoint);
> + VirtIOIOMMUDomain *domain;
> + VirtIOIOMMUEndpoint *ep;
>
> trace_virtio_iommu_attach(domain_id, ep_id);
>
> - return VIRTIO_IOMMU_S_UNSUPP;
> + ep = virtio_iommu_get_endpoint(s, ep_id);
> + if (!ep) {
> + return VIRTIO_IOMMU_S_NOENT;
> + }
> +
> + if (ep->domain) {
> + VirtIOIOMMUDomain *previous_domain = ep->domain;
> + /*
> + * the device is already attached to a domain,
> + * detach it first
> + */
> + virtio_iommu_detach_endpoint_from_domain(ep);
> + if (QLIST_EMPTY(&previous_domain->endpoint_list)) {
I feel like we still need:
g_tree_destroy(previous_domain->mappings);
Or the mappings will be leaked.
To make this simpler, maybe we can destroy the mappings at [1] above.
Then we can remove line [2] below too.
> + g_tree_remove(s->domains, GUINT_TO_POINTER(previous_domain->id));
> + }
> + }
> +
> + domain = virtio_iommu_get_domain(s, domain_id);
> + QLIST_INSERT_HEAD(&domain->endpoint_list, ep, next);
> +
> + ep->domain = domain;
> +
> + return VIRTIO_IOMMU_S_OK;
> }
>
> static int virtio_iommu_detach(VirtIOIOMMU *s,
> @@ -50,10 +268,29 @@ static int virtio_iommu_detach(VirtIOIOMMU *s,
> {
> uint32_t domain_id = le32_to_cpu(req->domain);
> uint32_t ep_id = le32_to_cpu(req->endpoint);
> + VirtIOIOMMUDomain *domain;
> + VirtIOIOMMUEndpoint *ep;
>
> trace_virtio_iommu_detach(domain_id, ep_id);
>
> - return VIRTIO_IOMMU_S_UNSUPP;
> + ep = g_tree_lookup(s->endpoints, GUINT_TO_POINTER(ep_id));
> + if (!ep) {
> + return VIRTIO_IOMMU_S_NOENT;
> + }
> +
> + domain = ep->domain;
> +
> + if (!domain || domain->id != domain_id) {
> + return VIRTIO_IOMMU_S_INVAL;
> + }
> +
> + virtio_iommu_detach_endpoint_from_domain(ep);
> +
> + if (QLIST_EMPTY(&domain->endpoint_list)) {
> + g_tree_destroy(domain->mappings);
[2]
> + g_tree_remove(s->domains, GUINT_TO_POINTER(domain->id));
> + }
> + return VIRTIO_IOMMU_S_OK;
> }
>
> static int virtio_iommu_map(VirtIOIOMMU *s,
> @@ -172,6 +409,27 @@ out:
> }
> }
Other than that, the whole patch looks good to me.
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2020-02-07 20:26 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-07 9:31 [PATCH v14 00/11] VIRTIO-IOMMU device Eric Auger
2020-02-07 9:31 ` [PATCH v14 01/11] virtio-iommu: Add skeleton Eric Auger
2020-02-07 9:31 ` [PATCH v14 02/11] virtio-iommu: Decode the command payload Eric Auger
2020-02-07 9:31 ` [PATCH v14 03/11] virtio-iommu: Implement attach/detach command Eric Auger
2020-02-07 20:26 ` Peter Xu [this message]
2020-02-08 11:50 ` Auger Eric
2020-02-07 9:31 ` [PATCH v14 04/11] virtio-iommu: Implement map/unmap Eric Auger
2020-02-07 9:31 ` [PATCH v14 05/11] virtio-iommu: Implement translate Eric Auger
2020-02-07 9:31 ` [PATCH v14 06/11] virtio-iommu: Implement fault reporting Eric Auger
2020-02-07 9:31 ` [PATCH v14 07/11] virtio-iommu-pci: Add virtio iommu pci support Eric Auger
2020-02-07 9:32 ` [PATCH v14 08/11] virtio-iommu-pci: Introduce the x-dt-binding option Eric Auger
2020-02-07 10:05 ` Jean-Philippe Brucker
2020-02-07 10:19 ` Auger Eric
2020-02-07 10:24 ` Michael S. Tsirkin
2020-02-07 10:33 ` Auger Eric
2020-02-07 23:04 ` Peter Xu
2020-02-09 20:58 ` Michael S. Tsirkin
2020-02-10 16:48 ` Peter Xu
2020-02-07 10:23 ` Michael S. Tsirkin
2020-02-07 10:51 ` Auger Eric
2020-02-07 11:15 ` Jean-Philippe Brucker
2020-02-07 13:36 ` Auger Eric
2020-02-07 12:00 ` Michael S. Tsirkin
2020-02-07 13:38 ` Auger Eric
2020-02-07 9:32 ` [PATCH v14 09/11] hw/arm/virt: Add the virtio-iommu device tree mappings Eric Auger
2020-02-07 9:32 ` [PATCH v14 10/11] virtio-iommu: Support migration Eric Auger
2020-02-07 9:32 ` [PATCH v14 11/11] tests: Add virtio-iommu test Eric Auger
2020-02-07 10:11 ` [PATCH v14 00/11] VIRTIO-IOMMU device no-reply
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=20200207202601.GD720553@xz-x1 \
--to=peterx@redhat.com \
--cc=bharatb.linux@gmail.com \
--cc=dgilbert@redhat.com \
--cc=eric.auger.pro@gmail.com \
--cc=eric.auger@redhat.com \
--cc=jean-philippe@linaro.org \
--cc=kevin.tian@intel.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=tnowicki@marvell.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).