vhost_dev_unassign_memory() don't assert if removing first entry in list.
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
@@ -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
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.Signed-off-by Jes Sorensen <[email protected]>--- hw/vhost.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)hw/vhost.c +0
-0
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
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@@ -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 meantdev->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
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@@ -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 meantdev->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