memory: do not notify for non inclusive overlap entry
PATCH v5 1/1 memory: do not notify for non inclusive overlap entry
if an entry has non inclusive overlap with the notifier, print warning message and do not do notification for it.
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.---
v5:
1. still using warn_report instead of "assert"
2. returning at the end to refuse notification for entry which has non inclusive overlap with the notifier.
3. updated commit title and warning message.
v4:
1. modified commit title
2. using "assert" instead of printing warning message
v3:
refined code style and message format
v2:
1. added a local variable entry_end (Eric Auger)
2. using PRIx64 as format for address range in warning message (Eric Auger)
--- memory.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
memory.c +14 -2
@@ -1937,13 +1937,13 @@ void memory_region_notify_one(IOMMUNotifier *notifier, IOMMUTLBEntry *entry) {IOMMUNotifierFlag request_flags; +hwaddr entry_end = entry->iova + entry->addr_mask;/* * Skip the notification if the notification does not overlap * with registered range. */ -if (notifier->start > entry->iova + entry->addr_mask || - notifier->end < entry->iova) { +if (notifier->start > entry_end || notifier->end < entry->iova) {return ; }
@@ -1953,6 +1953,18 @@ void memory_region_notify_one(IOMMUNotifier *notifier, request_flags =IOMMU_NOTIFIER_UNMAP ; } +if (entry->iova < notifier->start || entry_end > notifier->end) { +warn_report ("IOMMUTLBEntry 0x%" PRIx64" - 0x%" PRIx64 +" has non inclusive overlap with notifier 0x%" PRIx64 +" - 0x%" PRIx64". %s is not allowed." +" Try to divide it into smaller sections." , + entry->iova, entry_end, + notifier->start, notifier->end, + (request_flags ==IOMMU_NOTIFIER_MAP ) ? +"Mapping" :"Unmapping" ); +return ; + } +if (notifier->notifier_flags & request_flags) { notifier->notify (notifier, entry); }
Signature · 1 line
2.7.4
Hi Yan,
Quoted 20 lines · Yan Zhao
if an entry has non inclusive overlap with the notifier, print warning message and do not do notification for it.
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 from0x3c000000-0x3c1fffffis in shadow page table.2. in vfio,
memory_region_register_iommu_notifier()is followed bymemory_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.
Quoted 3 lines
Cc Eric Auger <[email protected]>Cc Peter Xu <[email protected]>Signed-off-by Yan Zhao <[email protected]>
Thanks
Eric
Quoted 63 lines
---
v5:
1. still usingwarn_reportinstead of "assert"
2. returning at the end to refuse notification for entry which has non inclusive overlap with the notifier.
3. updated commit title and warning message.v4:
1. modified commit title
2. using "assert" instead of printing warning messagev3:
refined code style and message formatv2:
1. added a local variableentry_end(Eric Auger)
2. using PRIx64 as format for address range in warning message (Eric Auger)--- memory.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)memory.c +14
-2@@ -1937,13 +1937,13 @@ void memory_region_notify_one(IOMMUNotifier *notifier, IOMMUTLBEntry *entry) {IOMMUNotifierFlag request_flags; +hwaddr entry_end = entry->iova + entry->addr_mask;/* * Skip the notification if the notification does not overlap * with registered range. */ -if (notifier->start > entry->iova + entry->addr_mask || - notifier->end < entry->iova) { +if (notifier->start > entry_end || notifier->end < entry->iova) {return ; }@@ -1953,6 +1953,18 @@ void memory_region_notify_one(IOMMUNotifier *notifier, request_flags =IOMMU_NOTIFIER_UNMAP ; } +if (entry->iova < notifier->start || entry_end > notifier->end) { +warn_report ("IOMMUTLBEntry 0x%" PRIx64" - 0x%" PRIx64 +" has non inclusive overlap with notifier 0x%" PRIx64 +" - 0x%" PRIx64". %s is not allowed." +" Try to divide it into smaller sections." , + entry->iova, entry_end, + notifier->start, notifier->end, + (request_flags ==IOMMU_NOTIFIER_MAP ) ? +"Mapping" :"Unmapping" ); +return ; + } +if (notifier->notifier_flags & request_flags) { notifier->notify (notifier, entry); }
Quoted 23 lines · Auger Eric
Hi Yan,
Quoted 20 lines · Yan Zhao
if an entry has non inclusive overlap with the notifier, print warning message and do not do notification for it.
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 from0x3c000000-0x3c1fffffis in shadow page table.2. in vfio,
memory_region_register_iommu_notifier()is followed bymemory_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.
Quoted 8 lines
Quoted 3 lines
Cc Eric Auger <[email protected]>Cc Peter Xu <[email protected]>Signed-off-by Yan Zhao <[email protected]>Reviewed-by Eric Auger <[email protected]>Thanks
Eric
Thank you, Eric :)
Yan
Quoted 63 lines
Quoted 63 lines
---
v5:
1. still usingwarn_reportinstead of "assert"
2. returning at the end to refuse notification for entry which has non inclusive overlap with the notifier.
3. updated commit title and warning message.v4:
1. modified commit title
2. using "assert" instead of printing warning messagev3:
refined code style and message formatv2:
1. added a local variableentry_end(Eric Auger)
2. using PRIx64 as format for address range in warning message (Eric Auger)--- memory.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)memory.c +14
-2@@ -1937,13 +1937,13 @@ void memory_region_notify_one(IOMMUNotifier *notifier, IOMMUTLBEntry *entry) {IOMMUNotifierFlag request_flags; +hwaddr entry_end = entry->iova + entry->addr_mask;/* * Skip the notification if the notification does not overlap * with registered range. */ -if (notifier->start > entry->iova + entry->addr_mask || - notifier->end < entry->iova) { +if (notifier->start > entry_end || notifier->end < entry->iova) {return ; }@@ -1953,6 +1953,18 @@ void memory_region_notify_one(IOMMUNotifier *notifier, request_flags =IOMMU_NOTIFIER_UNMAP ; } +if (entry->iova < notifier->start || entry_end > notifier->end) { +warn_report ("IOMMUTLBEntry 0x%" PRIx64" - 0x%" PRIx64 +" has non inclusive overlap with notifier 0x%" PRIx64 +" - 0x%" PRIx64". %s is not allowed." +" Try to divide it into smaller sections." , + entry->iova, entry_end, + notifier->start, notifier->end, + (request_flags ==IOMMU_NOTIFIER_MAP ) ? +"Mapping" :"Unmapping" ); +return ; + } +if (notifier->notifier_flags & request_flags) { notifier->notify (notifier, entry); }