qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Auger Eric <eric.auger@redhat.com>
To: Bharat Bhushan <bbhushan2@marvell.com>,
	peter.maydell@linaro.org, peterx@redhat.com,
	eric.auger.pro@gmail.com, alex.williamson@redhat.com,
	kevin.tian@intel.com, mst@redhat.com, tnowicki@marvell.com,
	drjones@redhat.com, linuc.decode@gmail.com,
	qemu-devel@nongnu.org, qemu-arm@nongnu.org,
	bharatb.linux@gmail.com
Subject: Re: [PATCH v7 2/5] virtio-iommu: Add iommu notifier for map/unmap
Date: Fri, 13 Mar 2020 15:25:09 +0100	[thread overview]
Message-ID: <369b162f-3a0c-6861-0737-96aa8914b915@redhat.com> (raw)
In-Reply-To: <20200313074811.27175-3-bbhushan2@marvell.com>

Hi Bharat,
On 3/13/20 8:48 AM, Bharat Bhushan wrote:
> This patch extends VIRTIO_IOMMU_T_MAP/UNMAP request to
> notify registered iommu-notifier. Which will call vfio
s/iommu-notifier/iommu-notifiers
> notifier to map/unmap region in iommu.
can be any notifier (vhost/vfio).
> 
> Signed-off-by: Bharat Bhushan <bbhushan2@marvell.com>
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
> ---
>  hw/virtio/trace-events           |  2 +
>  hw/virtio/virtio-iommu.c         | 66 +++++++++++++++++++++++++++++++-
>  include/hw/virtio/virtio-iommu.h |  6 +++
>  3 files changed, 73 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
> index e83500bee9..d94a1cd8a3 100644
> --- a/hw/virtio/trace-events
> +++ b/hw/virtio/trace-events
> @@ -73,3 +73,5 @@ virtio_iommu_get_domain(uint32_t domain_id) "Alloc domain=%d"
>  virtio_iommu_put_domain(uint32_t domain_id) "Free domain=%d"
>  virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%d"
>  virtio_iommu_report_fault(uint8_t reason, uint32_t flags, uint32_t endpoint, uint64_t addr) "FAULT reason=%d flags=%d endpoint=%d address =0x%"PRIx64
> +virtio_iommu_notify_map(const char *name, uint64_t iova, uint64_t paddr, uint64_t map_size) "mr=%s iova=0x%"PRIx64" pa=0x%" PRIx64" size=0x%"PRIx64
> +virtio_iommu_notify_unmap(const char *name, uint64_t iova, uint64_t map_size) "mr=%s iova=0x%"PRIx64" size=0x%"PRIx64
> diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
> index 4cee8083bc..e51344a53e 100644
> --- a/hw/virtio/virtio-iommu.c
> +++ b/hw/virtio/virtio-iommu.c
> @@ -123,6 +123,38 @@ static gint interval_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
>      }
>  }
>  
> +static void virtio_iommu_notify_map(IOMMUMemoryRegion *mr, hwaddr iova,
> +                                    hwaddr paddr, hwaddr size)
> +{
> +    IOMMUTLBEntry entry;
> +
> +    entry.target_as = &address_space_memory;
> +    entry.addr_mask = size - 1;
> +
> +    entry.iova = iova;
> +    trace_virtio_iommu_notify_map(mr->parent_obj.name, iova, paddr, size);
> +    entry.perm = IOMMU_RW;
> +    entry.translated_addr = paddr;
> +
> +    memory_region_notify_iommu(mr, 0, entry);
> +}
> +
> +static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr iova,
> +                                      hwaddr size)
> +{
> +    IOMMUTLBEntry entry;
> +
> +    entry.target_as = &address_space_memory;
> +    entry.addr_mask = size - 1;
> +
> +    entry.iova = iova;
> +    trace_virtio_iommu_notify_unmap(mr->parent_obj.name, iova, size);
> +    entry.perm = IOMMU_NONE;
> +    entry.translated_addr = 0;
> +
> +    memory_region_notify_iommu(mr, 0, entry);
> +}
> +
>  static void virtio_iommu_detach_endpoint_from_domain(VirtIOIOMMUEndpoint *ep)
>  {
>      if (!ep->domain) {
> @@ -307,9 +339,12 @@ static int virtio_iommu_map(VirtIOIOMMU *s,
>      uint64_t virt_start = le64_to_cpu(req->virt_start);
>      uint64_t virt_end = le64_to_cpu(req->virt_end);
>      uint32_t flags = le32_to_cpu(req->flags);
> +    hwaddr size = virt_end - virt_start + 1;
> +    VirtioIOMMUNotifierNode *node;
>      VirtIOIOMMUDomain *domain;
>      VirtIOIOMMUInterval *interval;
>      VirtIOIOMMUMapping *mapping;
> +    VirtIOIOMMUEndpoint *ep;
>  
>      if (flags & ~VIRTIO_IOMMU_MAP_F_MASK) {
>          return VIRTIO_IOMMU_S_INVAL;
> @@ -339,9 +374,37 @@ static int virtio_iommu_map(VirtIOIOMMU *s,
>  
>      g_tree_insert(domain->mappings, interval, mapping);
>  
> +    /* All devices in an address-space share mapping */
> +    QLIST_FOREACH(node, &s->notifiers_list, next) {
> +        QLIST_FOREACH(ep, &domain->endpoint_list, next) {
> +            if (ep->id == node->iommu_dev->devfn) {
> +                virtio_iommu_notify_map(&node->iommu_dev->iommu_mr,
> +                                        virt_start, phys_start, size);
> +            }
> +        }
> +    }
> +
>      return VIRTIO_IOMMU_S_OK;
>  }
>  
> +static void virtio_iommu_remove_mapping(VirtIOIOMMU *s, VirtIOIOMMUDomain *domain,
> +                                        VirtIOIOMMUInterval *interval)
> +{
> +    VirtioIOMMUNotifierNode *node;
> +    VirtIOIOMMUEndpoint *ep;
> +
> +    QLIST_FOREACH(node, &s->notifiers_list, next) {
> +        QLIST_FOREACH(ep, &domain->endpoint_list, next) {
> +            if (ep->id == node->iommu_dev->devfn) {
> +                virtio_iommu_notify_unmap(&node->iommu_dev->iommu_mr,
> +                                          interval->low,
> +                                          interval->high - interval->low + 1);
> +            }
> +        }
> +    }
> +    g_tree_remove(domain->mappings, (gpointer)(interval));
> +}
What about virtio_iommu_put_domain() where you destroy the mapping
gtree. I guess you also need to send invalidations there?
> +
>  static int virtio_iommu_unmap(VirtIOIOMMU *s,
>                                struct virtio_iommu_req_unmap *req)
>  {
> @@ -368,7 +431,7 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s,
>          uint64_t current_high = iter_key->high;
>  
>          if (interval.low <= current_low && interval.high >= current_high) {
> -            g_tree_remove(domain->mappings, iter_key);
> +            virtio_iommu_remove_mapping(s, domain, iter_key);
>              trace_virtio_iommu_unmap_done(domain_id, current_low, current_high);
>          } else {
>              ret = VIRTIO_IOMMU_S_RANGE;
> @@ -655,6 +718,7 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)
>      VirtIODevice *vdev = VIRTIO_DEVICE(dev);
>      VirtIOIOMMU *s = VIRTIO_IOMMU(dev);
>  
> +    QLIST_INIT(&s->notifiers_list);
>      virtio_init(vdev, "virtio-iommu", VIRTIO_ID_IOMMU,
>                  sizeof(struct virtio_iommu_config));
>  
> diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-iommu.h
> index 6f67f1020a..4539c8ae72 100644
> --- a/include/hw/virtio/virtio-iommu.h
> +++ b/include/hw/virtio/virtio-iommu.h
> @@ -44,6 +44,11 @@ typedef struct IOMMUPciBus {
>      IOMMUDevice  *pbdev[0]; /* Parent array is sparse, so dynamically alloc */
>  } IOMMUPciBus;
>  
> +typedef struct VirtioIOMMUNotifierNode {
> +    IOMMUDevice *iommu_dev;
> +    QLIST_ENTRY(VirtioIOMMUNotifierNode) next;
> +} VirtioIOMMUNotifierNode;
You may use scripts/git.orderfile for a better diff ordering.
> +
>  typedef struct VirtIOIOMMU {
>      VirtIODevice parent_obj;
>      VirtQueue *req_vq;
> @@ -56,6 +61,7 @@ typedef struct VirtIOIOMMU {
>      GTree *domains;
>      QemuMutex mutex;
>      GTree *endpoints;
> +    QLIST_HEAD(, VirtioIOMMUNotifierNode) notifiers_list;
See what was done in smmuv3 and intel. We now directly use a list of
IOMMUDevice directly. VirtioIOMMUNotifierNode does not bring anything extra.
>  } VirtIOIOMMU;
>  
>  #endif
> 

Thanks

Eric



  reply	other threads:[~2020-03-13 14:26 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-13  7:48 [PATCH v7 0/5] virtio-iommu: VFIO integration Bharat Bhushan
2020-03-13  7:48 ` [PATCH v7 1/5] hw/vfio/common: Remove error print on mmio region translation by viommu Bharat Bhushan
2020-03-13  7:48 ` [PATCH v7 2/5] virtio-iommu: Add iommu notifier for map/unmap Bharat Bhushan
2020-03-13 14:25   ` Auger Eric [this message]
2020-03-16  6:36     ` Bharat Bhushan
2020-03-16  7:32       ` Auger Eric
2020-03-13  7:48 ` [PATCH v7 3/5] virtio-iommu: Call iommu notifier for attach/detach Bharat Bhushan
2020-03-13 14:41   ` Auger Eric
2020-03-16  6:41     ` Bharat Bhushan
2020-03-16  7:32       ` Auger Eric
2020-03-16  7:45         ` Bharat Bhushan
2020-03-16  8:58           ` Bharat Bhushan
2020-03-16  9:04             ` Auger Eric
2020-03-16  9:10               ` Bharat Bhushan
2020-03-16 10:11                 ` Jean-Philippe Brucker
2020-03-17  7:10                   ` Bharat Bhushan
2020-03-17  8:25                     ` Auger Eric
2020-03-17  8:53                     ` Jean-Philippe Brucker
2020-03-17  9:16                       ` Bharat Bhushan
2020-03-17 15:59                         ` Jean-Philippe Brucker
2020-03-18 10:17                           ` Bharat Bhushan
2020-03-18 11:17                             ` Jean-Philippe Brucker
2020-03-18 11:20                               ` [EXT] " Bharat Bhushan
2020-03-18 11:42                                 ` Auger Eric
2020-03-18 12:00                                   ` Jean-Philippe Brucker
2020-03-13  7:48 ` [PATCH v7 4/5] virtio-iommu: add iommu replay Bharat Bhushan
2020-03-13  7:48 ` [PATCH v7 5/5] virtio-iommu: add iommu notifier memory-region Bharat Bhushan

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=369b162f-3a0c-6861-0737-96aa8914b915@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=bbhushan2@marvell.com \
    --cc=bharatb.linux@gmail.com \
    --cc=drjones@redhat.com \
    --cc=eric.auger.pro@gmail.com \
    --cc=kevin.tian@intel.com \
    --cc=linuc.decode@gmail.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=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).