Skip to contentSkip to conversation

memory: remove assert to avoid unnecessary coredump

PATCH In review Yi Sun 2 participants 4 messages Mar 3, 2020

lore
Share & tools
lore

Yi Sun

author
#0 lore raw

PATCH 1/1 memory: remove assert to avoid unnecessary coredump

It is too strict to use assert to make qemu coredump if the notification does not overlap with registered range. Skip it is fine enough.

During test, we found such a case for vhost net device:

    memory_region_notify_one: entry->iova=0xfee00000, entry_end=0xfeffffff, notifier->start=0xfef00000, notifier->end=0xffffffffffffffff

Skip this notification but not coredump makes everything work well.

---
 memory.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
memory.c +2 -3
index 06484c2bff..62ad0f3377 100644
@@ -1921,12 +1921,11 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
      * Skip the notification if the notification does not overlap
      * with registered range.
      */
-    if (notifier->start > entry_end || notifier->end < entry->iova) {
+    if (notifier->start > entry_end || notifier->end < entry->iova ||
+        entry->iova < notifier->start || entry_end > notifier->end) {
         return;
     }
 
-    assert(entry->iova >= notifier->start && entry_end <= notifier->end);
-
     if (entry->perm & IOMMU_RW) {
         request_flags = IOMMU_NOTIFIER_MAP;
     } else {
Signature · 1 line
2.15.1
#1 lore raw
Quoted 7 lines · Yi Sun

It is too strict to use assert to make qemu coredump if the notification does not overlap with registered range. Skip it is fine enough.

During test, we found such a case for vhost net device:

    memory_region_notify_one: entry->iova=0xfee00000, entry_end=0xfeffffff, notifier->start=0xfef00000, notifier->end=0xffffffffffffffff

so for range from 0xfef00000 to 0xfefffff, would notification for this range get lost?

Thanks
Yan

Quoted 30 lines

Skip this notification but not coredump makes everything work well.

---
 memory.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
memory.c +2 -3
index 06484c2bff..62ad0f3377 100644
@@ -1921,12 +1921,11 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
      * Skip the notification if the notification does not overlap
      * with registered range.
      */
-    if (notifier->start > entry_end || notifier->end < entry->iova) {
+    if (notifier->start > entry_end || notifier->end < entry->iova ||
+        entry->iova < notifier->start || entry_end > notifier->end) {
         return;
     }
 
-    assert(entry->iova >= notifier->start && entry_end <= notifier->end);
-
     if (entry->perm & IOMMU_RW) {
         request_flags = IOMMU_NOTIFIER_MAP;
     } else {
Signature · 1 line
2.15.1
author
#2 lore raw
Quoted 11 lines · Yan Zhao
Quoted 7 lines · Yi Sun

It is too strict to use assert to make qemu coredump if the notification does not overlap with registered range. Skip it is fine enough.

During test, we found such a case for vhost net device:

    memory_region_notify_one: entry->iova=0xfee00000, entry_end=0xfeffffff, notifier->start=0xfef00000, notifier->end=0xffffffffffffffff

so for range from 0xfef00000 to 0xfefffff, would notification for this range get lost?

Yes, that is an issue although there is no any problem found during test with this fix.

I think we should notify the intersection between entry and notifier. How do you think?

Quoted 33 lines

Thanks
Yan

Quoted 30 lines

Skip this notification but not coredump makes everything work well.

---
 memory.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
memory.c +2 -3
index 06484c2bff..62ad0f3377 100644
@@ -1921,12 +1921,11 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
      * Skip the notification if the notification does not overlap
      * with registered range.
      */
-    if (notifier->start > entry_end || notifier->end < entry->iova) {
+    if (notifier->start > entry_end || notifier->end < entry->iova ||
+        entry->iova < notifier->start || entry_end > notifier->end) {
         return;
     }
 
-    assert(entry->iova >= notifier->start && entry_end <= notifier->end);
-
     if (entry->perm & IOMMU_RW) {
         request_flags = IOMMU_NOTIFIER_MAP;
     } else {
Signature · 1 line
2.15.1
#3 lore raw
Quoted 9 lines · Yi Sun
Quoted 8 lines · Yan Zhao
Quoted 7 lines · Yi Sun

It is too strict to use assert to make qemu coredump if the notification does not overlap with registered range. Skip it is fine enough.

During test, we found such a case for vhost net device:

    memory_region_notify_one: entry->iova=0xfee00000, entry_end=0xfeffffff, notifier->start=0xfef00000, notifier->end=0xffffffffffffffff
Quoted 9 lines
Quoted 3 lines

so for range from 0xfef00000 to 0xfefffff, would notification for this range get lost?

Yes, that is an issue although there is no any problem found during test with this fix.

I think we should notify the intersection between entry and notifier. How do you think?

no. please refer to the link below.
https://lists.gnu.org/archive/html/qemu-devel/2019-06/msg04218.html

Thanks
Yan

Quoted 33 lines
Quoted 33 lines

Thanks
Yan

Quoted 30 lines

Skip this notification but not coredump makes everything work well.

---
 memory.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
memory.c +2 -3
index 06484c2bff..62ad0f3377 100644
@@ -1921,12 +1921,11 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
      * Skip the notification if the notification does not overlap
      * with registered range.
      */
-    if (notifier->start > entry_end || notifier->end < entry->iova) {
+    if (notifier->start > entry_end || notifier->end < entry->iova ||
+        entry->iova < notifier->start || entry_end > notifier->end) {
         return;
     }
 
-    assert(entry->iova >= notifier->start && entry_end <= notifier->end);
-
     if (entry->perm & IOMMU_RW) {
         request_flags = IOMMU_NOTIFIER_MAP;
     } else {
Signature · 1 line
2.15.1