All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Jason Wang <jasowang@redhat.com>
Cc: mst@redhat.com, qemu-devel@nongnu.org, eric.auger@redhat.com,
	viktor@daynix.com
Subject: Re: [PATCH 3/3] intel-iommu: build iova tree during IOMMU translation
Date: Tue, 6 Dec 2022 08:58:10 -0500	[thread overview]
Message-ID: <Y49Kcr4ivGGZ2hhF@x1n> (raw)
In-Reply-To: <CACGkMEut82E-c_w_0MUPOwYDLkcM+mt127dbs3bkhATDSr6JQg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 878 bytes --]

On Tue, Dec 06, 2022 at 11:18:03AM +0800, Jason Wang wrote:
> On Tue, Dec 6, 2022 at 7:19 AM Peter Xu <peterx@redhat.com> wrote:
> >
> > Jason,
> >
> > On Mon, Dec 05, 2022 at 12:12:04PM +0800, Jason Wang wrote:
> > > I'm fine to go without iova-tree. Would you mind to post patches for
> > > fix? I can test and include it in this series then.
> >
> > One sample patch attached, only compile tested.
> 
> I don't see any direct connection between the attached patch and the
> intel-iommu?

Sorry!  Wrong tree dumped...  Trying again.

> 
> >
> > I can also work on this but I'll be slow in making progress, so I'll add it
> > into my todo.  If you can help to fix this issue it'll be more than great.
> 
> Ok, let me try but it might take some time :)

Sure. :)

I'll also add it into my todo (and I think the other similar one has been
there for a while.. :( ).

-- 
Peter Xu

[-- Attachment #2: 0001-intel-iommu-Send-unmap-notifications-for-domain-or-g.patch --]
[-- Type: text/plain, Size: 3728 bytes --]

From 37c743761d20c16891856c5bef2e7b3fb89893b6 Mon Sep 17 00:00:00 2001
From: Peter Xu <peterx@redhat.com>
Date: Mon, 5 Dec 2022 18:11:36 -0500
Subject: [PATCH] intel-iommu: Send unmap notifications for domain or global
 inv desc
Content-type: text/plain

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 hw/i386/intel_iommu.c | 41 +++++++++++++++++++++++++----------------
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index a08ee85edf..2c6ca68df0 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -206,6 +206,23 @@ static inline gboolean vtd_as_has_map_notifier(VTDAddressSpace *as)
     return as->notifier_flags & IOMMU_NOTIFIER_MAP;
 }
 
+static void vtd_as_notify_unmap(VTDAddressSpace *as, hwaddr iova,
+                                hwaddr addr_mask)
+{
+    IOMMUTLBEvent event = {
+        .type = IOMMU_NOTIFIER_UNMAP,
+        .entry = {
+            .target_as = &address_space_memory,
+            .iova = iova,
+            .translated_addr = 0,
+            .addr_mask = addr_mask,
+            .perm = IOMMU_NONE,
+        },
+    };
+
+    memory_region_notify_iommu(&as->iommu, 0, event);
+}
+
 /* GHashTable functions */
 static gboolean vtd_iotlb_equal(gconstpointer v1, gconstpointer v2)
 {
@@ -1530,13 +1547,15 @@ static int vtd_sync_shadow_page_table_range(VTDAddressSpace *vtd_as,
     return vtd_page_walk(s, ce, addr, addr + size, &info, vtd_as->pasid);
 }
 
-static int vtd_sync_shadow_page_table(VTDAddressSpace *vtd_as)
+static int vtd_address_space_sync(VTDAddressSpace *vtd_as)
 {
     int ret;
     VTDContextEntry ce;
     IOMMUNotifier *n;
 
-    if (!(vtd_as->iommu.iommu_notify_flags & IOMMU_NOTIFIER_IOTLB_EVENTS)) {
+    /* If no MAP notifier registered, we simply invalidate all the cache */
+    if (!vtd_as_has_map_notifier(vtd_as)) {
+        vtd_as_notify_unmap(vtd_as, 0, HWADDR_MAX);
         return 0;
     }
 
@@ -2000,7 +2019,7 @@ static void vtd_iommu_replay_all(IntelIOMMUState *s)
     VTDAddressSpace *vtd_as;
 
     QLIST_FOREACH(vtd_as, &s->vtd_as_with_notifiers, next) {
-        vtd_sync_shadow_page_table(vtd_as);
+        vtd_address_space_sync(vtd_as);
     }
 }
 
@@ -2082,7 +2101,7 @@ static void vtd_context_device_invalidate(IntelIOMMUState *s,
              * framework will skip MAP notifications if that
              * happened.
              */
-            vtd_sync_shadow_page_table(vtd_as);
+            vtd_address_space_sync(vtd_as);
         }
     }
 }
@@ -2140,7 +2159,7 @@ static void vtd_iotlb_domain_invalidate(IntelIOMMUState *s, uint16_t domain_id)
         if (!vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus),
                                       vtd_as->devfn, &ce) &&
             domain_id == vtd_get_domain_id(s, &ce, vtd_as->pasid)) {
-            vtd_sync_shadow_page_table(vtd_as);
+            vtd_address_space_sync(vtd_as);
         }
     }
 }
@@ -2174,17 +2193,7 @@ static void vtd_iotlb_page_invalidate_notify(IntelIOMMUState *s,
                  * page tables.  We just deliver the PSI down to
                  * invalidate caches.
                  */
-                IOMMUTLBEvent event = {
-                    .type = IOMMU_NOTIFIER_UNMAP,
-                    .entry = {
-                        .target_as = &address_space_memory,
-                        .iova = addr,
-                        .translated_addr = 0,
-                        .addr_mask = size - 1,
-                        .perm = IOMMU_NONE,
-                    },
-                };
-                memory_region_notify_iommu(&vtd_as->iommu, 0, event);
+                vtd_as_notify_unmap(vtd_as, addr, size - 1);
             }
         }
     }
-- 
2.37.3


  reply	other threads:[~2022-12-06 13:59 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29  8:10 [PATCH 0/3] Fix UNMAP notifier for intel-iommu Jason Wang
2022-11-29  8:10 ` [PATCH 1/3] intel-iommu: fail MAP notifier without caching mode Jason Wang
2022-11-29 15:35   ` Peter Xu
2022-11-30  6:23     ` Jason Wang
2022-11-30 15:06       ` Peter Xu
2022-12-01  8:46         ` Jason Wang
2022-12-06 13:23   ` Eric Auger
2022-11-29  8:10 ` [PATCH 2/3] intel-iommu: fail DEVIOTLB_UNMAP without dt mode Jason Wang
2022-11-29 15:38   ` Peter Xu
2022-12-01 16:03   ` Peter Xu
2023-02-23  3:19     ` Jason Wang
2022-12-06 13:33   ` Eric Auger
2023-02-03  9:08   ` Laurent Vivier
2023-02-07 16:17     ` Laurent Vivier
2023-02-07 16:35       ` Peter Xu
2022-11-29  8:10 ` [PATCH 3/3] intel-iommu: build iova tree during IOMMU translation Jason Wang
2022-11-29 15:57   ` Peter Xu
2022-11-30  6:33     ` Jason Wang
2022-11-30 15:17       ` Peter Xu
2022-12-01  8:35         ` Jason Wang
2022-12-01 14:58           ` Peter Xu
2022-12-05  4:12             ` Jason Wang
2022-12-05 23:18               ` Peter Xu
2022-12-06  3:18                 ` Jason Wang
2022-12-06 13:58                   ` Peter Xu [this message]
2022-12-23  8:02                     ` Jason Wang
2022-12-23 16:22                       ` Peter Xu
2022-11-30 16:37 ` [PATCH 0/3] Fix UNMAP notifier for intel-iommu Michael S. Tsirkin
2022-12-01  8:29   ` Jason Wang
2022-12-20 13:53 ` Michael S. Tsirkin
2022-12-21  3:17   ` Jason Wang
2023-01-15 23:30 ` Viktor Prutyanov
2023-01-16  7:06   ` Jason Wang
2023-01-27 13:17     ` Michael S. Tsirkin
2023-01-29  5:43       ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y49Kcr4ivGGZ2hhF@x1n \
    --to=peterx@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=viktor@daynix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.