Skip to contentSkip to conversation

memory: warning on out of scope notification

PATCH Superseded Yan Zhao 2 participants 3 messages Jun 24, 2019

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Yan Zhao

author
#0 lore raw

PATCH 1/1 memory: warning on out of scope notification

if an entry has parts out of scope of notifier's range, print warning message.

Out of scope mapping/unmapping would cause problem, as in below case:

1. initially there are two notifiers with ranges 0-0xfedfffff, 0xfef00000-0xffffffffffffffff,
IOVAs from 0x3c000000 - 0x3c1fffff is in shadow page table.

2. in vfio, memory_region_register_iommu_notifier() is followed by memory_region_iommu_replay(), which will first call address space unmap,
and walk and add back all entries in vtd shadow page table. e.g.
(1) for notifier 0-0xfedfffff,

    IOVAs from 0 - 0xffffffff get unmapped,
    and IOVAs from 0x3c000000 - 0x3c1fffff get mapped
(2) for notifier 0xfef00000-0xffffffffffffffff
    IOVAs from 0 - 0x7fffffffff get unmapped,
    but IOVAs from 0x3c000000 - 0x3c1fffff cannot get mapped back.
---
 memory.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
memory.c +10 -0
index 0a089a7..18927f2 100644
@@ -1953,6 +1953,16 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
         request_flags = IOMMU_NOTIFIER_UNMAP;
     }
 
+    if (entry->iova < notifier->start ||
+            entry->iova + entry->addr_mask > notifier->end) {
+        warn_report("%s IOMMUTLBEntry %lx-%lx outside of "
+                "notifier scope %lx-%lx",
+                (request_flags == IOMMU_NOTIFIER_MAP) ?
+                "Mapping" : "Unmapping",
+                entry->iova, entry->iova + entry->addr_mask,
+                notifier->start, notifier->end);
+    }
+
     if (notifier->notifier_flags & request_flags) {
         notifier->notify(notifier, entry);
     }
Signature · 1 line
2.7.4
#1 lore raw

Hi Yan,

Quoted 31 lines · Yan Zhao

if an entry has parts out of scope of notifier's range, print warning message.

Out of scope mapping/unmapping would cause problem, as in below case:

1. initially there are two notifiers with ranges 0-0xfedfffff, 0xfef00000-0xffffffffffffffff,
IOVAs from 0x3c000000 - 0x3c1fffff is in shadow page table.

2. in vfio, memory_region_register_iommu_notifier() is followed by memory_region_iommu_replay(), which will first call address space unmap,
and walk and add back all entries in vtd shadow page table. e.g.
(1) for notifier 0-0xfedfffff,

    IOVAs from 0 - 0xffffffff get unmapped,
    and IOVAs from 0x3c000000 - 0x3c1fffff get mapped
(2) for notifier 0xfef00000-0xffffffffffffffff
    IOVAs from 0 - 0x7fffffffff get unmapped,
    but IOVAs from 0x3c000000 - 0x3c1fffff cannot get mapped back.
---
 memory.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
memory.c +0 -0
index 0a089a7..18927f2 100644

memory.c void memory_region_notify_one(IOMMUNotifier *notifier, · line 1954

Quoted 2 lines
memory.c +0 -0
@@ -1953,6 +1953,16 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
         request_flags = IOMMU_NOTIFIER_UNMAP;
     }

I think introducing a local variable for entry end would be worth now

memory.c void memory_region_notify_one(IOMMUNotifier *notifier, · line 1959

Quoted 5 lines
memory.c +4 -0
+    if (entry->iova < notifier->start ||
+            entry->iova + entry->addr_mask > notifier->end) {
+        warn_report("%s IOMMUTLBEntry %lx-%lx outside of "
+                "notifier scope %lx-%lx",

Also I think you should use PRIx64 instead.

Thanks

Eric

Quoted 10 lines
memory.c +6 -0
+                (request_flags == IOMMU_NOTIFIER_MAP) ?
+                "Mapping" : "Unmapping",
+                entry->iova, entry->iova + entry->addr_mask,
+                notifier->start, notifier->end);
+    }
+
     if (notifier->notifier_flags & request_flags) {
         notifier->notify(notifier, entry);
     }
 
author
#2 lore raw
Quoted 38 lines · Auger Eric

Hi Yan,

Quoted 31 lines · Yan Zhao

if an entry has parts out of scope of notifier's range, print warning message.

Out of scope mapping/unmapping would cause problem, as in below case:

1. initially there are two notifiers with ranges 0-0xfedfffff, 0xfef00000-0xffffffffffffffff,
IOVAs from 0x3c000000 - 0x3c1fffff is in shadow page table.

2. in vfio, memory_region_register_iommu_notifier() is followed by memory_region_iommu_replay(), which will first call address space unmap,
and walk and add back all entries in vtd shadow page table. e.g.
(1) for notifier 0-0xfedfffff,

    IOVAs from 0 - 0xffffffff get unmapped,
    and IOVAs from 0x3c000000 - 0x3c1fffff get mapped
(2) for notifier 0xfef00000-0xffffffffffffffff
    IOVAs from 0 - 0x7fffffffff get unmapped,
    but IOVAs from 0x3c000000 - 0x3c1fffff cannot get mapped back.
---
 memory.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
memory.c +0 -0
index 0a089a7..18927f2 100644

memory.c void memory_region_notify_one(IOMMUNotifier *notifier, · line 1954

Quoted 2 lines
memory.c +0 -0
@@ -1953,6 +1953,16 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
         request_flags = IOMMU_NOTIFIER_UNMAP;
     }

I think introducing a local variable for entry end would be worth now

Quoted 1 line
Quoted 6 lines

memory.c void memory_region_notify_one(IOMMUNotifier *notifier, · line 1959

Quoted 4 lines
memory.c +4 -0
+    if (entry->iova < notifier->start ||
+            entry->iova + entry->addr_mask > notifier->end) {
+        warn_report("%s IOMMUTLBEntry %lx-%lx outside of "
+                "notifier scope %lx-%lx",

Also I think you should use PRIx64 instead.

Got it!
Thanks :)

Quoted 13 lines

Thanks

Eric

Quoted 10 lines
memory.c +6 -0
+                (request_flags == IOMMU_NOTIFIER_MAP) ?
+                "Mapping" : "Unmapping",
+                entry->iova, entry->iova + entry->addr_mask,
+                notifier->start, notifier->end);
+    }
+
     if (notifier->notifier_flags & request_flags) {
         notifier->notify(notifier, entry);
     }