All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Auger <eric.auger@redhat.com>
To: Jean-Philippe Brucker <jean-philippe@linaro.org>
Cc: qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [PATCH 3/3] virtio-iommu: Support bypass domain
Date: Wed, 6 Oct 2021 15:10:22 +0200	[thread overview]
Message-ID: <6efa6f64-d410-9732-15ba-7651c3e9fd76@redhat.com> (raw)
In-Reply-To: <20210930185050.262759-4-jean-philippe@linaro.org>

Hi jean,

On 9/30/21 8:50 PM, Jean-Philippe Brucker wrote:
> The driver can create a bypass domain by passing the
> VIRTIO_IOMMU_ATTACH_F_BYPASS flag on the ATTACH request. Bypass domains
> perform slightly better than domains with identity mappings since they
> skip translation.
>
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---
>  hw/virtio/virtio-iommu.c | 32 ++++++++++++++++++++++++++++++--
>  1 file changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
> index 82edeaa101..4f0207a3eb 100644
> --- a/hw/virtio/virtio-iommu.c
> +++ b/hw/virtio/virtio-iommu.c
> @@ -42,6 +42,7 @@
>  
>  typedef struct VirtIOIOMMUDomain {
>      uint32_t id;
> +    bool bypass;
>      GTree *mappings;
>      QLIST_HEAD(, VirtIOIOMMUEndpoint) endpoint_list;
>  } VirtIOIOMMUDomain;
> @@ -257,12 +258,16 @@ static void virtio_iommu_put_endpoint(gpointer data)
>  }
>  
>  static VirtIOIOMMUDomain *virtio_iommu_get_domain(VirtIOIOMMU *s,
> -                                                  uint32_t domain_id)
> +                                                  uint32_t domain_id,
> +                                                  bool bypass)
>  {
>      VirtIOIOMMUDomain *domain;
>  
>      domain = g_tree_lookup(s->domains, GUINT_TO_POINTER(domain_id));
>      if (domain) {
> +        if (domain->bypass != bypass) {
> +            return NULL;
> +        }
>          return domain;
>      }
>      domain = g_malloc0(sizeof(*domain));
> @@ -270,6 +275,7 @@ static VirtIOIOMMUDomain *virtio_iommu_get_domain(VirtIOIOMMU *s,
>      domain->mappings = g_tree_new_full((GCompareDataFunc)interval_cmp,
>                                     NULL, (GDestroyNotify)g_free,
>                                     (GDestroyNotify)g_free);
> +    domain->bypass = bypass;
>      g_tree_insert(s->domains, GUINT_TO_POINTER(domain_id), domain);
>      QLIST_INIT(&domain->endpoint_list);
>      trace_virtio_iommu_get_domain(domain_id);
> @@ -333,11 +339,16 @@ static int virtio_iommu_attach(VirtIOIOMMU *s,
>  {
>      uint32_t domain_id = le32_to_cpu(req->domain);
>      uint32_t ep_id = le32_to_cpu(req->endpoint);
> +    uint32_t flags = le32_to_cpu(req->flags);
>      VirtIOIOMMUDomain *domain;
>      VirtIOIOMMUEndpoint *ep;
>  
>      trace_virtio_iommu_attach(domain_id, ep_id);
>  
> +    if (flags & ~VIRTIO_IOMMU_ATTACH_F_BYPASS) {
> +        return VIRTIO_IOMMU_S_INVAL;
> +    }
> +
>      ep = virtio_iommu_get_endpoint(s, ep_id);
>      if (!ep) {
>          return VIRTIO_IOMMU_S_NOENT;
> @@ -355,7 +366,12 @@ static int virtio_iommu_attach(VirtIOIOMMU *s,
>          }
>      }
>  
> -    domain = virtio_iommu_get_domain(s, domain_id);
> +    domain = virtio_iommu_get_domain(s, domain_id,
> +                                     flags & VIRTIO_IOMMU_ATTACH_F_BYPASS);
> +    if (!domain) {
> +        /* Incompatible flags */
Incompatible bypass flag
> +        return VIRTIO_IOMMU_S_INVAL;
> +    }
>      QLIST_INSERT_HEAD(&domain->endpoint_list, ep, next);
>  
>      ep->domain = domain;
> @@ -418,6 +434,10 @@ static int virtio_iommu_map(VirtIOIOMMU *s,
>          return VIRTIO_IOMMU_S_NOENT;
>      }
>  
> +    if (domain->bypass) {
> +        return VIRTIO_IOMMU_S_INVAL;
> +    }
> +
>      interval = g_malloc0(sizeof(*interval));
>  
>      interval->low = virt_start;
> @@ -463,6 +483,11 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s,
>      if (!domain) {
>          return VIRTIO_IOMMU_S_NOENT;
>      }
> +
> +    if (domain->bypass) {
> +        return VIRTIO_IOMMU_S_INVAL;
> +    }
> +
>      interval.low = virt_start;
>      interval.high = virt_end;
>  
> @@ -779,6 +804,9 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr,
>              entry.perm = flag;
>          }
>          goto unlock;
> +    } else if (ep->domain->bypass) {
> +        entry.perm = flag;
> +        goto unlock;
>      }
>  
>      found = g_tree_lookup_extended(ep->domain->mappings, (gpointer)(&interval),
Otherwise looks good to me.

Eric



  reply	other threads:[~2021-10-06 13:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-30 18:50 [PATCH 0/3] virtio-iommu: Support VIRTIO_IOMMU_F_BYPASS_CONFIG Jean-Philippe Brucker
2021-09-30 18:50 ` [PATCH 1/3] NOMERGE: virtio-iommu: Add definitions for VIRTIO_IOMMU_F_BYPASS_CONFIG Jean-Philippe Brucker
2021-09-30 18:50 ` [PATCH 2/3] virtio-iommu: Default to bypass during boot Jean-Philippe Brucker
2021-10-06 13:04   ` Eric Auger
2021-10-08 10:21     ` Jean-Philippe Brucker
2021-09-30 18:50 ` [PATCH 3/3] virtio-iommu: Support bypass domain Jean-Philippe Brucker
2021-10-06 13:10   ` Eric Auger [this message]
2022-01-11  9:02 ` [PATCH 0/3] virtio-iommu: Support VIRTIO_IOMMU_F_BYPASS_CONFIG Eric Auger
2022-01-11 10:13   ` Jean-Philippe Brucker
2022-01-11 10:33     ` Eric Auger
2022-01-11 15:40   ` Michael S. Tsirkin
2022-01-11 16:24     ` Jean-Philippe Brucker

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=6efa6f64-d410-9732-15ba-7651c3e9fd76@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=jean-philippe@linaro.org \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.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.