{"id":908463,"url":"http://patchwork.ozlabs.org/api/patches/908463/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20180504030811.28111-3-peterx@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20180504030811.28111-3-peterx@redhat.com>","list_archive_url":null,"date":"2018-05-04T03:08:03","name":"[v2,02/10] intel-iommu: remove IntelIOMMUNotifierNode","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"4bbdbd17b1127f1ebb14ef8d0026aa2b0df5531c","submitter":{"id":67717,"url":"http://patchwork.ozlabs.org/api/people/67717/?format=json","name":"Peter Xu","email":"peterx@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20180504030811.28111-3-peterx@redhat.com/mbox/","series":[{"id":42502,"url":"http://patchwork.ozlabs.org/api/series/42502/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=42502","date":"2018-05-04T03:08:01","name":"intel-iommu: nested vIOMMU, cleanups, bug fixes","version":2,"mbox":"http://patchwork.ozlabs.org/series/42502/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/908463/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/908463/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdmarc=fail (p=none dis=none) header.from=redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 40ccW269dbz9s35\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  4 May 2018 13:11:58 +1000 (AEST)","from localhost ([::1]:60177 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1fER8V-0003aE-IE\n\tfor incoming@patchwork.ozlabs.org; Thu, 03 May 2018 23:11:55 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:33188)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <peterx@redhat.com>) id 1fER5I-0001Yj-RD\n\tfor qemu-devel@nongnu.org; Thu, 03 May 2018 23:08:38 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <peterx@redhat.com>) id 1fER5H-0005Ka-ER\n\tfor qemu-devel@nongnu.org; Thu, 03 May 2018 23:08:36 -0400","from mx3-rdu2.redhat.com ([66.187.233.73]:54370\n\thelo=mx1.redhat.com)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <peterx@redhat.com>) id 1fER5H-0005KG-8u\n\tfor qemu-devel@nongnu.org; Thu, 03 May 2018 23:08:35 -0400","from smtp.corp.redhat.com\n\t(int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id EB1098E692;\n\tFri,  4 May 2018 03:08:34 +0000 (UTC)","from xz-mi.redhat.com (ovpn-12-46.pek2.redhat.com [10.72.12.46])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id BE7D5111762B;\n\tFri,  4 May 2018 03:08:31 +0000 (UTC)"],"From":"Peter Xu <peterx@redhat.com>","To":"qemu-devel@nongnu.org","Date":"Fri,  4 May 2018 11:08:03 +0800","Message-Id":"<20180504030811.28111-3-peterx@redhat.com>","In-Reply-To":"<20180504030811.28111-1-peterx@redhat.com>","References":"<20180504030811.28111-1-peterx@redhat.com>","X-Scanned-By":"MIMEDefang 2.78 on 10.11.54.3","X-Greylist":["Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.11.55.2]);\n\tFri, 04 May 2018 03:08:34 +0000 (UTC)","inspected by milter-greylist-4.5.16 (mx1.redhat.com\n\t[10.11.55.2]); \n\tFri, 04 May 2018 03:08:34 +0000 (UTC) for IP:'10.11.54.3'\n\tDOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com'\n\tHELO:'smtp.corp.redhat.com' FROM:'peterx@redhat.com' RCPT:''"],"X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"66.187.233.73","Subject":"[Qemu-devel] [PATCH v2 02/10] intel-iommu: remove\n\tIntelIOMMUNotifierNode","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Tian Kevin <kevin.tian@intel.com>, \"Michael S . Tsirkin\" <mst@redhat.com>,\n\tJason Wang <jasowang@redhat.com>, peterx@redhat.com,\n\tAlex Williamson <alex.williamson@redhat.com>,\n\tJintack Lim <jintack@cs.columbia.edu>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"That is not really necessary.  Removing that node struct and put the\nlist entry directly into VTDAddressSpace.  It simplfies the code a lot.\n\nSigned-off-by: Peter Xu <peterx@redhat.com>\n---\n include/hw/i386/intel_iommu.h |  9 ++------\n hw/i386/intel_iommu.c         | 41 ++++++++++-------------------------\n 2 files changed, 14 insertions(+), 36 deletions(-)","diff":"diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h\nindex 45ec8919b6..220697253f 100644\n--- a/include/hw/i386/intel_iommu.h\n+++ b/include/hw/i386/intel_iommu.h\n@@ -67,7 +67,6 @@ typedef union VTD_IR_TableEntry VTD_IR_TableEntry;\n typedef union VTD_IR_MSIAddress VTD_IR_MSIAddress;\n typedef struct VTDIrq VTDIrq;\n typedef struct VTD_MSIMessage VTD_MSIMessage;\n-typedef struct IntelIOMMUNotifierNode IntelIOMMUNotifierNode;\n \n /* Context-Entry */\n struct VTDContextEntry {\n@@ -93,6 +92,7 @@ struct VTDAddressSpace {\n     MemoryRegion iommu_ir;      /* Interrupt region: 0xfeeXXXXX */\n     IntelIOMMUState *iommu_state;\n     VTDContextCacheEntry context_cache_entry;\n+    QLIST_ENTRY(VTDAddressSpace) next;\n };\n \n struct VTDBus {\n@@ -253,11 +253,6 @@ struct VTD_MSIMessage {\n /* When IR is enabled, all MSI/MSI-X data bits should be zero */\n #define VTD_IR_MSI_DATA          (0)\n \n-struct IntelIOMMUNotifierNode {\n-    VTDAddressSpace *vtd_as;\n-    QLIST_ENTRY(IntelIOMMUNotifierNode) next;\n-};\n-\n /* The iommu (DMAR) device state struct */\n struct IntelIOMMUState {\n     X86IOMMUState x86_iommu;\n@@ -295,7 +290,7 @@ struct IntelIOMMUState {\n     GHashTable *vtd_as_by_busptr;   /* VTDBus objects indexed by PCIBus* reference */\n     VTDBus *vtd_as_by_bus_num[VTD_PCI_BUS_MAX]; /* VTDBus objects indexed by bus number */\n     /* list of registered notifiers */\n-    QLIST_HEAD(, IntelIOMMUNotifierNode) notifiers_list;\n+    QLIST_HEAD(, VTDAddressSpace) notifiers_list;\n \n     /* interrupt remapping */\n     bool intr_enabled;              /* Whether guest enabled IR */\ndiff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c\nindex b359efd6f9..5987b48d43 100644\n--- a/hw/i386/intel_iommu.c\n+++ b/hw/i386/intel_iommu.c\n@@ -1248,10 +1248,10 @@ static void vtd_interrupt_remap_table_setup(IntelIOMMUState *s)\n \n static void vtd_iommu_replay_all(IntelIOMMUState *s)\n {\n-    IntelIOMMUNotifierNode *node;\n+    VTDAddressSpace *vtd_as;\n \n-    QLIST_FOREACH(node, &s->notifiers_list, next) {\n-        memory_region_iommu_replay_all(&node->vtd_as->iommu);\n+    QLIST_FOREACH(vtd_as, &s->notifiers_list, next) {\n+        memory_region_iommu_replay_all(&vtd_as->iommu);\n     }\n }\n \n@@ -1372,7 +1372,6 @@ static void vtd_iotlb_global_invalidate(IntelIOMMUState *s)\n \n static void vtd_iotlb_domain_invalidate(IntelIOMMUState *s, uint16_t domain_id)\n {\n-    IntelIOMMUNotifierNode *node;\n     VTDContextEntry ce;\n     VTDAddressSpace *vtd_as;\n \n@@ -1381,8 +1380,7 @@ static void vtd_iotlb_domain_invalidate(IntelIOMMUState *s, uint16_t domain_id)\n     g_hash_table_foreach_remove(s->iotlb, vtd_hash_remove_by_domain,\n                                 &domain_id);\n \n-    QLIST_FOREACH(node, &s->notifiers_list, next) {\n-        vtd_as = node->vtd_as;\n+    QLIST_FOREACH(vtd_as, &s->notifiers_list, next) {\n         if (!vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus),\n                                       vtd_as->devfn, &ce) &&\n             domain_id == VTD_CONTEXT_ENTRY_DID(ce.hi)) {\n@@ -1402,12 +1400,11 @@ static void vtd_iotlb_page_invalidate_notify(IntelIOMMUState *s,\n                                            uint16_t domain_id, hwaddr addr,\n                                            uint8_t am)\n {\n-    IntelIOMMUNotifierNode *node;\n+    VTDAddressSpace *vtd_as;\n     VTDContextEntry ce;\n     int ret;\n \n-    QLIST_FOREACH(node, &(s->notifiers_list), next) {\n-        VTDAddressSpace *vtd_as = node->vtd_as;\n+    QLIST_FOREACH(vtd_as, &(s->notifiers_list), next) {\n         ret = vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus),\n                                        vtd_as->devfn, &ce);\n         if (!ret && domain_id == VTD_CONTEXT_ENTRY_DID(ce.hi)) {\n@@ -2344,8 +2341,6 @@ static void vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,\n {\n     VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu);\n     IntelIOMMUState *s = vtd_as->iommu_state;\n-    IntelIOMMUNotifierNode *node = NULL;\n-    IntelIOMMUNotifierNode *next_node = NULL;\n \n     if (!s->caching_mode && new & IOMMU_NOTIFIER_MAP) {\n         error_report(\"We need to set caching-mode=1 for intel-iommu to enable \"\n@@ -2354,21 +2349,11 @@ static void vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,\n     }\n \n     if (old == IOMMU_NOTIFIER_NONE) {\n-        node = g_malloc0(sizeof(*node));\n-        node->vtd_as = vtd_as;\n-        QLIST_INSERT_HEAD(&s->notifiers_list, node, next);\n-        return;\n-    }\n-\n-    /* update notifier node with new flags */\n-    QLIST_FOREACH_SAFE(node, &s->notifiers_list, next, next_node) {\n-        if (node->vtd_as == vtd_as) {\n-            if (new == IOMMU_NOTIFIER_NONE) {\n-                QLIST_REMOVE(node, next);\n-                g_free(node);\n-            }\n-            return;\n-        }\n+        /* Insert new ones */\n+        QLIST_INSERT_HEAD(&s->notifiers_list, vtd_as, next);\n+    } else if (new == IOMMU_NOTIFIER_NONE) {\n+        /* Remove old ones */\n+        QLIST_REMOVE(vtd_as, next);\n     }\n }\n \n@@ -2838,12 +2823,10 @@ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n)\n \n static void vtd_address_space_unmap_all(IntelIOMMUState *s)\n {\n-    IntelIOMMUNotifierNode *node;\n     VTDAddressSpace *vtd_as;\n     IOMMUNotifier *n;\n \n-    QLIST_FOREACH(node, &s->notifiers_list, next) {\n-        vtd_as = node->vtd_as;\n+    QLIST_FOREACH(vtd_as, &s->notifiers_list, next) {\n         IOMMU_NOTIFIER_FOREACH(n, &vtd_as->iommu) {\n             vtd_address_space_unmap(vtd_as, n);\n         }\n","prefixes":["v2","02/10"]}