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

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