Blame SOURCES/kvm-intel-iommu-remove-IntelIOMMUNotifierNode.patch

357786
From fd9f21135b1317ddfdf70d5d749e9c2ef51e4c22 Mon Sep 17 00:00:00 2001
357786
From: Peter Xu <peterx@redhat.com>
357786
Date: Mon, 3 Sep 2018 04:52:34 +0200
357786
Subject: [PATCH 19/29] intel-iommu: remove IntelIOMMUNotifierNode
357786
357786
RH-Author: Peter Xu <peterx@redhat.com>
357786
Message-id: <20180903045241.6456-3-peterx@redhat.com>
357786
Patchwork-id: 82023
357786
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 2/9] intel-iommu: remove IntelIOMMUNotifierNode
357786
Bugzilla: 1623859
357786
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
357786
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
357786
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
357786
357786
That is not really necessary.  Removing that node struct and put the
357786
list entry directly into VTDAddressSpace.  It simplfies the code a lot.
357786
Since at it, rename the old notifiers_list into vtd_as_with_notifiers.
357786
357786
CC: QEMU Stable <qemu-stable@nongnu.org>
357786
Signed-off-by: Peter Xu <peterx@redhat.com>
357786
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
357786
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
357786
(cherry picked from commit b4a4ba0d68f50f218ee3957b6638dbee32a5eeef)
357786
Signed-off-by: Peter Xu <peterx@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 hw/i386/intel_iommu.c         | 41 +++++++++++------------------------------
357786
 include/hw/i386/intel_iommu.h |  9 ++-------
357786
 2 files changed, 13 insertions(+), 37 deletions(-)
357786
357786
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
357786
index b359efd..3df9045 100644
357786
--- a/hw/i386/intel_iommu.c
357786
+++ b/hw/i386/intel_iommu.c
357786
@@ -1248,10 +1248,10 @@ static void vtd_interrupt_remap_table_setup(IntelIOMMUState *s)
357786
 
357786
 static void vtd_iommu_replay_all(IntelIOMMUState *s)
357786
 {
357786
-    IntelIOMMUNotifierNode *node;
357786
+    VTDAddressSpace *vtd_as;
357786
 
357786
-    QLIST_FOREACH(node, &s->notifiers_list, next) {
357786
-        memory_region_iommu_replay_all(&node->vtd_as->iommu);
357786
+    QLIST_FOREACH(vtd_as, &s->vtd_as_with_notifiers, next) {
357786
+        memory_region_iommu_replay_all(&vtd_as->iommu);
357786
     }
357786
 }
357786
 
357786
@@ -1372,7 +1372,6 @@ static void vtd_iotlb_global_invalidate(IntelIOMMUState *s)
357786
 
357786
 static void vtd_iotlb_domain_invalidate(IntelIOMMUState *s, uint16_t domain_id)
357786
 {
357786
-    IntelIOMMUNotifierNode *node;
357786
     VTDContextEntry ce;
357786
     VTDAddressSpace *vtd_as;
357786
 
357786
@@ -1381,8 +1380,7 @@ static void vtd_iotlb_domain_invalidate(IntelIOMMUState *s, uint16_t domain_id)
357786
     g_hash_table_foreach_remove(s->iotlb, vtd_hash_remove_by_domain,
357786
                                 &domain_id);
357786
 
357786
-    QLIST_FOREACH(node, &s->notifiers_list, next) {
357786
-        vtd_as = node->vtd_as;
357786
+    QLIST_FOREACH(vtd_as, &s->vtd_as_with_notifiers, next) {
357786
         if (!vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus),
357786
                                       vtd_as->devfn, &ce) &&
357786
             domain_id == VTD_CONTEXT_ENTRY_DID(ce.hi)) {
357786
@@ -1402,12 +1400,11 @@ static void vtd_iotlb_page_invalidate_notify(IntelIOMMUState *s,
357786
                                            uint16_t domain_id, hwaddr addr,
357786
                                            uint8_t am)
357786
 {
357786
-    IntelIOMMUNotifierNode *node;
357786
+    VTDAddressSpace *vtd_as;
357786
     VTDContextEntry ce;
357786
     int ret;
357786
 
357786
-    QLIST_FOREACH(node, &(s->notifiers_list), next) {
357786
-        VTDAddressSpace *vtd_as = node->vtd_as;
357786
+    QLIST_FOREACH(vtd_as, &(s->vtd_as_with_notifiers), next) {
357786
         ret = vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus),
357786
                                        vtd_as->devfn, &ce);
357786
         if (!ret && domain_id == VTD_CONTEXT_ENTRY_DID(ce.hi)) {
357786
@@ -2344,8 +2341,6 @@ static void vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
357786
 {
357786
     VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu);
357786
     IntelIOMMUState *s = vtd_as->iommu_state;
357786
-    IntelIOMMUNotifierNode *node = NULL;
357786
-    IntelIOMMUNotifierNode *next_node = NULL;
357786
 
357786
     if (!s->caching_mode && new & IOMMU_NOTIFIER_MAP) {
357786
         error_report("We need to set caching-mode=1 for intel-iommu to enable "
357786
@@ -2354,21 +2349,9 @@ static void vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
357786
     }
357786
 
357786
     if (old == IOMMU_NOTIFIER_NONE) {
357786
-        node = g_malloc0(sizeof(*node));
357786
-        node->vtd_as = vtd_as;
357786
-        QLIST_INSERT_HEAD(&s->notifiers_list, node, next);
357786
-        return;
357786
-    }
357786
-
357786
-    /* update notifier node with new flags */
357786
-    QLIST_FOREACH_SAFE(node, &s->notifiers_list, next, next_node) {
357786
-        if (node->vtd_as == vtd_as) {
357786
-            if (new == IOMMU_NOTIFIER_NONE) {
357786
-                QLIST_REMOVE(node, next);
357786
-                g_free(node);
357786
-            }
357786
-            return;
357786
-        }
357786
+        QLIST_INSERT_HEAD(&s->vtd_as_with_notifiers, vtd_as, next);
357786
+    } else if (new == IOMMU_NOTIFIER_NONE) {
357786
+        QLIST_REMOVE(vtd_as, next);
357786
     }
357786
 }
357786
 
357786
@@ -2838,12 +2821,10 @@ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n)
357786
 
357786
 static void vtd_address_space_unmap_all(IntelIOMMUState *s)
357786
 {
357786
-    IntelIOMMUNotifierNode *node;
357786
     VTDAddressSpace *vtd_as;
357786
     IOMMUNotifier *n;
357786
 
357786
-    QLIST_FOREACH(node, &s->notifiers_list, next) {
357786
-        vtd_as = node->vtd_as;
357786
+    QLIST_FOREACH(vtd_as, &s->vtd_as_with_notifiers, next) {
357786
         IOMMU_NOTIFIER_FOREACH(n, &vtd_as->iommu) {
357786
             vtd_address_space_unmap(vtd_as, n);
357786
         }
357786
@@ -3088,7 +3069,7 @@ static void vtd_realize(DeviceState *dev, Error **errp)
357786
         return;
357786
     }
357786
 
357786
-    QLIST_INIT(&s->notifiers_list);
357786
+    QLIST_INIT(&s->vtd_as_with_notifiers);
357786
     memset(s->vtd_as_by_bus_num, 0, sizeof(s->vtd_as_by_bus_num));
357786
     memory_region_init_io(&s->csrmem, OBJECT(s), &vtd_mem_ops, s,
357786
                           "intel_iommu", DMAR_REG_SIZE);
357786
diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h
357786
index 45ec891..032e33b 100644
357786
--- a/include/hw/i386/intel_iommu.h
357786
+++ b/include/hw/i386/intel_iommu.h
357786
@@ -67,7 +67,6 @@ typedef union VTD_IR_TableEntry VTD_IR_TableEntry;
357786
 typedef union VTD_IR_MSIAddress VTD_IR_MSIAddress;
357786
 typedef struct VTDIrq VTDIrq;
357786
 typedef struct VTD_MSIMessage VTD_MSIMessage;
357786
-typedef struct IntelIOMMUNotifierNode IntelIOMMUNotifierNode;
357786
 
357786
 /* Context-Entry */
357786
 struct VTDContextEntry {
357786
@@ -93,6 +92,7 @@ struct VTDAddressSpace {
357786
     MemoryRegion iommu_ir;      /* Interrupt region: 0xfeeXXXXX */
357786
     IntelIOMMUState *iommu_state;
357786
     VTDContextCacheEntry context_cache_entry;
357786
+    QLIST_ENTRY(VTDAddressSpace) next;
357786
 };
357786
 
357786
 struct VTDBus {
357786
@@ -253,11 +253,6 @@ struct VTD_MSIMessage {
357786
 /* When IR is enabled, all MSI/MSI-X data bits should be zero */
357786
 #define VTD_IR_MSI_DATA          (0)
357786
 
357786
-struct IntelIOMMUNotifierNode {
357786
-    VTDAddressSpace *vtd_as;
357786
-    QLIST_ENTRY(IntelIOMMUNotifierNode) next;
357786
-};
357786
-
357786
 /* The iommu (DMAR) device state struct */
357786
 struct IntelIOMMUState {
357786
     X86IOMMUState x86_iommu;
357786
@@ -295,7 +290,7 @@ struct IntelIOMMUState {
357786
     GHashTable *vtd_as_by_busptr;   /* VTDBus objects indexed by PCIBus* reference */
357786
     VTDBus *vtd_as_by_bus_num[VTD_PCI_BUS_MAX]; /* VTDBus objects indexed by bus number */
357786
     /* list of registered notifiers */
357786
-    QLIST_HEAD(, IntelIOMMUNotifierNode) notifiers_list;
357786
+    QLIST_HEAD(, VTDAddressSpace) vtd_as_with_notifiers;
357786
 
357786
     /* interrupt remapping */
357786
     bool intr_enabled;              /* Whether guest enabled IR */
357786
-- 
357786
1.8.3.1
357786