Skip to contentSkip to conversation

vhost_dev_unassign_memory() don't assert if removing first entry in list.

PATCH In review [email protected] 2 participants 4 messages Jul 23, 2010 – Jul 26, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost_dev_unassign_memory() don't assert if removing first entry in list.

From: Jes Sorensen <[email protected]>

If removing an entry from the list which is fully included in the region and this is the first entry in the list. In this case 'to' can go to -1, which is perfectly valid. Don't assert() on this case.

---
 hw/vhost.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
hw/vhost.c +0 -1
index d37a66e..f30cf91 100644
@@ -119,7 +119,6 @@ static void vhost_dev_unassign_memory(struct vhost_dev *dev,
         if (start_addr <= reg->guest_phys_addr && memlast >= reglast) {
             --dev->mem->nregions;
             --to;
-            assert(to >= 0);
             ++overlap_middle;
             continue;
         }
Signature · 1 line
1.7.1.1
#1 lore raw
Quoted 16 lines · On Fri, Jul 23, 2010 at 05:16:42PM +0200, [email protected] wrote:

From: Jes Sorensen <[email protected]>

If removing an entry from the list which is fully included in the region and this is the first entry in the list. In this case 'to' can go to -1, which is perfectly valid. Don't assert() on this case.

---
 hw/vhost.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
hw/vhost.c +0 -0
index d37a66e..f30cf91 100644

hw/vhost.c static void vhost_dev_unassign_memory(struct vhost_dev *dev, · line 124

Quoted 7 lines
hw/vhost.c +0 -1
@@ -119,7 +119,6 @@ static void vhost_dev_unassign_memory(struct vhost_dev *dev,
         if (start_addr <= reg->guest_phys_addr && memlast >= reglast) {
             --dev->mem->nregions;
             --to;
-            assert(to >= 0);
             ++overlap_middle;
             continue;
         }

Good catch.
I think I must have meant dev->mem->nregions >= 0. Does this work if you put in that assertion, or did I miss something else?

Quoted 2 lines
Signature · 1 line
1.7.1.1
#2 lore raw
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · On Fri, Jul 23, 2010 at 05:16:42PM +0200, [email protected] wrote:

From: Jes Sorensen <[email protected]>

hw/vhost.c +0 -0
index d37a66e..f30cf91 100644
@@ -119,7 +119,6 @@ static void vhost_dev_unassign_memory(struct vhost_dev *dev,
         if (start_addr <= reg->guest_phys_addr && memlast >= reglast) {
             --dev->mem->nregions;
             --to;
Quoted 8 lines

hw/vhost.c static void vhost_dev_unassign_memory(struct vhost_dev *dev, · line 124

Quoted 4 lines
hw/vhost.c +0 -1
-            assert(to >= 0);
             ++overlap_middle;
             continue;
         }

Good catch.
I think I must have meant dev->mem->nregions >= 0. Does this work if you put in that assertion, or did I miss something else?

It should work, but I don't see the point in adding the assert for that case since the loop shouldn't be able to run down to nregions < 0.

Cheers,
Jes

#3 lore raw
Quoted 20 lines · Jes Sorensen
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · On Fri, Jul 23, 2010 at 05:16:42PM +0200, [email protected] wrote:

From: Jes Sorensen <[email protected]>

hw/vhost.c +0 -0
index d37a66e..f30cf91 100644
@@ -119,7 +119,6 @@ static void vhost_dev_unassign_memory(struct vhost_dev *dev,
         if (start_addr <= reg->guest_phys_addr && memlast >= reglast) {
             --dev->mem->nregions;
             --to;
Quoted 8 lines

hw/vhost.c static void vhost_dev_unassign_memory(struct vhost_dev *dev, · line 124

Quoted 4 lines
hw/vhost.c +0 -1
-            assert(to >= 0);
             ++overlap_middle;
             continue;
         }

Good catch.
I think I must have meant dev->mem->nregions >= 0. Does this work if you put in that assertion, or did I miss something else?

Quoted 2 lines

It should work, but I don't see the point in adding the assert for that case since the loop shouldn't be able to run down to nregions < 0.

Yes, we never decrement twice for the same region, so it will never become negative. Unless there's a bug in code. Which is exactly what assert guards against.
This can also be seen as a form of documentation which checks itself for currectness.
Maybe we should have assert(to >= -1) as well.

But I don't feel strongly about these asserts, if you dislike them, let me know and I'll apply as is.

Quoted 2 lines

Cheers,
Jes