yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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