qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Bharat Bhushan <bbhushan2@marvell.com>,
	Jean-Philippe Brucker <jean-philippe@linaro.org>,
	Eric Auger <eric.auger@redhat.com>
Subject: [PULL v3 15/31] virtio-iommu: Add memory notifiers for map/unmap
Date: Wed, 4 Nov 2020 13:41:59 -0500	[thread overview]
Message-ID: <20201104184040.285057-16-mst@redhat.com> (raw)
In-Reply-To: <20201104184040.285057-1-mst@redhat.com>

From: Bharat Bhushan <bbhushan2@marvell.com>

Extend VIRTIO_IOMMU_T_MAP/UNMAP request to notify memory listeners. It
will call VFIO notifier to map/unmap regions in the physical IOMMU.

Signed-off-by: Bharat Bhushan <bbhushan2@marvell.com>
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Message-Id: <20201030180510.747225-4-jean-philippe@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio/virtio-iommu.c | 56 ++++++++++++++++++++++++++++++++++++++++
 hw/virtio/trace-events   |  2 ++
 2 files changed, 58 insertions(+)

diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index a5c2d69aad..7dd15c5eac 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -125,6 +125,51 @@ static gint interval_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
     }
 }
 
+static void virtio_iommu_notify_map(IOMMUMemoryRegion *mr, hwaddr virt_start,
+                                    hwaddr virt_end, hwaddr paddr,
+                                    uint32_t flags)
+{
+    IOMMUTLBEntry entry;
+    IOMMUAccessFlags perm = IOMMU_ACCESS_FLAG(flags & VIRTIO_IOMMU_MAP_F_READ,
+                                              flags & VIRTIO_IOMMU_MAP_F_WRITE);
+
+    if (!(mr->iommu_notify_flags & IOMMU_NOTIFIER_MAP) ||
+        (flags & VIRTIO_IOMMU_MAP_F_MMIO) || !perm) {
+        return;
+    }
+
+    trace_virtio_iommu_notify_map(mr->parent_obj.name, virt_start, virt_end,
+                                  paddr, perm);
+
+    entry.target_as = &address_space_memory;
+    entry.addr_mask = virt_end - virt_start;
+    entry.iova = virt_start;
+    entry.perm = perm;
+    entry.translated_addr = paddr;
+
+    memory_region_notify_iommu(mr, 0, entry);
+}
+
+static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr virt_start,
+                                      hwaddr virt_end)
+{
+    IOMMUTLBEntry entry;
+
+    if (!(mr->iommu_notify_flags & IOMMU_NOTIFIER_UNMAP)) {
+        return;
+    }
+
+    trace_virtio_iommu_notify_unmap(mr->parent_obj.name, virt_start, virt_end);
+
+    entry.target_as = &address_space_memory;
+    entry.addr_mask = virt_end - virt_start;
+    entry.iova = virt_start;
+    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) {
@@ -315,6 +360,7 @@ static int virtio_iommu_map(VirtIOIOMMU *s,
     VirtIOIOMMUDomain *domain;
     VirtIOIOMMUInterval *interval;
     VirtIOIOMMUMapping *mapping;
+    VirtIOIOMMUEndpoint *ep;
 
     if (flags & ~VIRTIO_IOMMU_MAP_F_MASK) {
         return VIRTIO_IOMMU_S_INVAL;
@@ -344,6 +390,11 @@ static int virtio_iommu_map(VirtIOIOMMU *s,
 
     g_tree_insert(domain->mappings, interval, mapping);
 
+    QLIST_FOREACH(ep, &domain->endpoint_list, next) {
+        virtio_iommu_notify_map(ep->iommu_mr, virt_start, virt_end, phys_start,
+                                flags);
+    }
+
     return VIRTIO_IOMMU_S_OK;
 }
 
@@ -356,6 +407,7 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s,
     VirtIOIOMMUMapping *iter_val;
     VirtIOIOMMUInterval interval, *iter_key;
     VirtIOIOMMUDomain *domain;
+    VirtIOIOMMUEndpoint *ep;
     int ret = VIRTIO_IOMMU_S_OK;
 
     trace_virtio_iommu_unmap(domain_id, virt_start, virt_end);
@@ -373,6 +425,10 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s,
         uint64_t current_high = iter_key->high;
 
         if (interval.low <= current_low && interval.high >= current_high) {
+            QLIST_FOREACH(ep, &domain->endpoint_list, next) {
+                virtio_iommu_notify_unmap(ep->iommu_mr, current_low,
+                                          current_high);
+            }
             g_tree_remove(domain->mappings, iter_key);
             trace_virtio_iommu_unmap_done(domain_id, current_low, current_high);
         } else {
diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
index cf1e59de30..b87a397406 100644
--- a/hw/virtio/trace-events
+++ b/hw/virtio/trace-events
@@ -106,6 +106,8 @@ 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_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t start, uint64_t end) "dev= %d, type=%d start=0x%"PRIx64" end=0x%"PRIx64
+virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64" flags=%d"
+virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t virt_end) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64
 
 # virtio-mem.c
 virtio_mem_send_response(uint16_t type) "type=%" PRIu16
-- 
MST



  parent reply	other threads:[~2020-11-04 18:45 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-04 18:41 [PULL v3 00/31] pc,pci,vhost,virtio: fixes Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 01/31] pc: comment style fixup Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 02/31] virtio-mem: Make sure "addr" is always multiples of the block size Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 03/31] virtio-mem: Make sure "usable_region_size" " Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 04/31] virtio-mem: Probe THP size to determine default " Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 05/31] memory-device: Support big alignment requirements Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 06/31] memory-device: Add get_min_alignment() callback Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 07/31] virito-mem: Implement get_min_alignment() Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 08/31] hw/acpi : Don't use '#' flag of printf format Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 09/31] hw/acpi : add space before the open parenthesis '(' Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 10/31] hw/acpi : add spaces around operator Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 11/31] hw/virtio/vhost-backend: Fix Coverity CID 1432871 Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 12/31] hw/smbios: Fix leaked fd in save_opt_one() error path Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 13/31] virtio-iommu: Fix virtio_iommu_mr() Michael S. Tsirkin
2020-11-04 18:41 ` [PULL v3 14/31] virtio-iommu: Store memory region in endpoint struct Michael S. Tsirkin
2020-11-04 18:41 ` Michael S. Tsirkin [this message]
2020-11-04 18:42 ` [PULL v3 16/31] virtio-iommu: Call memory notifiers in attach/detach Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 17/31] virtio-iommu: Add replay() memory region callback Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 18/31] virtio-iommu: Add notify_flag_changed() " Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 19/31] memory: Add interface to set iommu page size mask Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 20/31] vfio: Set IOMMU page size as per host supported page size Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 21/31] virtio-iommu: Set supported page size mask Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 22/31] vfio: Don't issue full 2^64 unmap Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 23/31] vhost-vdpa: Add qemu_close in vhost_vdpa_cleanup Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 24/31] net: Add vhost-vdpa in show_netdevs() Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 25/31] Revert "vhost-blk: set features before setting inflight feature" Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 26/31] vhost-blk: set features before setting inflight feature Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 27/31] libvhost-user: follow QEMU comment style Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 28/31] configure: introduce --enable-vhost-user-blk-server Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 29/31] block/export: make vhost-user-blk config space little-endian Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 30/31] block/export: fix vhost-user-blk get_config() information leak Michael S. Tsirkin
2020-11-04 18:42 ` [PULL v3 31/31] contrib/vhost-user-blk: fix " Michael S. Tsirkin
2020-11-05 16:14 ` [PULL v3 00/31] pc,pci,vhost,virtio: fixes Peter Maydell

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=20201104184040.285057-16-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=bbhushan2@marvell.com \
    --cc=eric.auger@redhat.com \
    --cc=jean-philippe@linaro.org \
    --cc=peter.maydell@linaro.org \
    --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 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).