qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Auger Eric <eric.auger@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: peter.maydell@linaro.org, kevin.tian@intel.com,
	tnowicki@marvell.com, quintela@redhat.com, mst@redhat.com,
	qemu-devel@nongnu.org, dgilbert@redhat.com,
	bharatb.linux@gmail.com, qemu-arm@nongnu.org,
	jean-philippe@linaro.org, eric.auger.pro@gmail.com
Subject: Re: [PATCH v14 03/11] virtio-iommu: Implement attach/detach command
Date: Sat, 8 Feb 2020 12:50:34 +0100	[thread overview]
Message-ID: <b0ae352f-aee2-345a-743d-51bf67f640f8@redhat.com> (raw)
In-Reply-To: <20200207202601.GD720553@xz-x1>

Hi Peter,

On 2/7/20 9:26 PM, Peter Xu wrote:
> 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.
You're fully right :-(
> 
> To make this simpler, maybe we can destroy the mappings at [1] above.
> Then we can remove line [2] below too.
Yes I chose to destroy the mappings in the put_domain and remove [2].
> 
>> +            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.

Thank you for the careful review.

Eric
> 
> Thanks,
> 



  reply	other threads:[~2020-02-08 11:51 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
2020-02-08 11:50     ` Auger Eric [this message]
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=b0ae352f-aee2-345a-743d-51bf67f640f8@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=bharatb.linux@gmail.com \
    --cc=dgilbert@redhat.com \
    --cc=eric.auger.pro@gmail.com \
    --cc=jean-philippe@linaro.org \
    --cc=kevin.tian@intel.com \
    --cc=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --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).