diff mbox series

[RFC,v6,10/13] memory: Notify IOMMU IOTLB based on entry type, not permissions

Message ID 20200826143651.7915-11-eperezma@redhat.com (mailing list archive)
State New, archived
Headers show
Series memory: Delete assertion in memory_region_unregister_iommu_notifier | expand

Commit Message

Eugenio Perez Martin Aug. 26, 2020, 2:36 p.m. UTC
This way the intention is much clearer.

Signed-off-by: Eugenio PĂ©rez <eperezma@redhat.com>
---
 softmmu/memory.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/softmmu/memory.c b/softmmu/memory.c
index 961c25b42f..3e68442ca6 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1890,10 +1890,27 @@  void memory_region_unregister_iommu_notifier(MemoryRegion *mr,
     memory_region_update_iommu_notify_flags(iommu_mr, NULL);
 }
 
+static IOMMUNotifierFlag notifier_type_iommu(const IOMMUNotifier *notifier)
+{
+    return notifier->notifier_flags & IOMMU_NOTIFIER_ALL;
+}
+
+static bool memory_region_notify(const IOMMUNotifier *notifier,
+                                 const IOMMUTLBEntry *entry)
+{
+    switch(entry->type) {
+    case IOMMU_IOTLB_MAP:
+        return notifier_type_iommu(notifier) == IOMMU_NOTIFIER_MAP;
+    case IOMMU_IOTLB_UNMAP:
+        return notifier_type_iommu(notifier) == IOMMU_NOTIFIER_UNMAP;
+    default:
+        return false;
+    };
+}
+
 void memory_region_notify_iommu_one(IOMMUNotifier *notifier,
                                     IOMMUTLBEntry *entry)
 {
-    IOMMUNotifierFlag request_flags;
     hwaddr entry_end = entry->iova + entry->addr_mask;
 
     /*
@@ -1906,13 +1923,7 @@  void memory_region_notify_iommu_one(IOMMUNotifier *notifier,
 
     assert(entry->iova >= notifier->start && entry_end <= notifier->end);
 
-    if (entry->perm & IOMMU_RW) {
-        request_flags = IOMMU_NOTIFIER_MAP;
-    } else {
-        request_flags = IOMMU_NOTIFIER_UNMAP;
-    }
-
-    if (notifier->notifier_flags & request_flags) {
+    if (memory_region_notify(notifier, entry)) {
         notifier->notify(notifier, entry);
     }
 }