thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-memory-Skip-bad-range-assertion-if-notifier-is-DEVIO.patch

a19a21
From 8c5154729effda3f762bfb8224f9c61dab8b2986 Mon Sep 17 00:00:00 2001
a19a21
From: eperezma <eperezma@redhat.com>
a19a21
Date: Tue, 12 Jan 2021 14:36:38 -0500
a19a21
Subject: [PATCH 14/17] memory: Skip bad range assertion if notifier is
a19a21
 DEVIOTLB_UNMAP type
a19a21
MIME-Version: 1.0
a19a21
Content-Type: text/plain; charset=UTF-8
a19a21
Content-Transfer-Encoding: 8bit
a19a21
a19a21
RH-Author: eperezma <eperezma@redhat.com>
a19a21
Message-id: <20210112143638.374060-14-eperezma@redhat.com>
a19a21
Patchwork-id: 100606
a19a21
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 13/13] memory: Skip bad range assertion if notifier is DEVIOTLB_UNMAP type
a19a21
Bugzilla: 1843852
a19a21
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
a19a21
RH-Acked-by: Peter Xu <peterx@redhat.com>
a19a21
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
a19a21
a19a21
Device IOTLB invalidations can unmap arbitrary ranges, eiter outside of
a19a21
the memory region or even [0, ~0ULL] for all the space. The assertion
a19a21
could be hit by a guest, and rhel7 guest effectively hit it.
a19a21
a19a21
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
a19a21
Reviewed-by: Peter Xu <peterx@redhat.com>
a19a21
Reviewed-by: Juan Quintela <quintela@redhat.com>
a19a21
Acked-by: Jason Wang <jasowang@redhat.com>
a19a21
Message-Id: <20201116165506.31315-6-eperezma@redhat.com>
a19a21
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
a19a21
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
a19a21
(cherry picked from commit 1804857f19f612f6907832e35599cdb51d4ec764)
a19a21
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
a19a21
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
a19a21
---
a19a21
 memory.c | 11 +++++++++--
a19a21
 1 file changed, 9 insertions(+), 2 deletions(-)
a19a21
a19a21
diff --git a/memory.c b/memory.c
a19a21
index 3bd99b8ac4a..5a4a80842d7 100644
a19a21
--- a/memory.c
a19a21
+++ b/memory.c
a19a21
@@ -1916,6 +1916,7 @@ void memory_region_notify_iommu_one(IOMMUNotifier *notifier,
a19a21
 {
a19a21
     IOMMUTLBEntry *entry = &event->entry;
a19a21
     hwaddr entry_end = entry->iova + entry->addr_mask;
a19a21
+    IOMMUTLBEntry tmp = *entry;
a19a21
 
a19a21
     if (event->type == IOMMU_NOTIFIER_UNMAP) {
a19a21
         assert(entry->perm == IOMMU_NONE);
a19a21
@@ -1929,10 +1930,16 @@ void memory_region_notify_iommu_one(IOMMUNotifier *notifier,
a19a21
         return;
a19a21
     }
a19a21
 
a19a21
-    assert(entry->iova >= notifier->start && entry_end <= notifier->end);
a19a21
+    if (notifier->notifier_flags & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) {
a19a21
+        /* Crop (iova, addr_mask) to range */
a19a21
+        tmp.iova = MAX(tmp.iova, notifier->start);
a19a21
+        tmp.addr_mask = MIN(entry_end, notifier->end) - tmp.iova;
a19a21
+    } else {
a19a21
+        assert(entry->iova >= notifier->start && entry_end <= notifier->end);
a19a21
+    }
a19a21
 
a19a21
     if (event->type & notifier->notifier_flags) {
a19a21
-        notifier->notify(notifier, entry);
a19a21
+        notifier->notify(notifier, &tmp);
a19a21
     }
a19a21
 }
a19a21
 
a19a21
-- 
a19a21
2.27.0
a19a21