yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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