qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] vhost_dev_unassign_memory() don't assert if removing first entry in list.
@ 2010-07-23 15:16 Jes.Sorensen
  2010-07-24 19:03 ` [Qemu-devel] " Michael S. Tsirkin
  0 siblings, 1 reply; 4+ messages in thread
From: Jes.Sorensen @ 2010-07-23 15:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst

From: Jes Sorensen <Jes.Sorensen@redhat.com>

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 <Jes.Sorensen@redhat.com>
---
 hw/vhost.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/hw/vhost.c b/hw/vhost.c
index d37a66e..f30cf91 100644
--- a/hw/vhost.c
+++ b/hw/vhost.c
@@ -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;
         }
-- 
1.7.1.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [PATCH] vhost_dev_unassign_memory() don't assert if removing first entry in list.
  2010-07-23 15:16 [Qemu-devel] [PATCH] vhost_dev_unassign_memory() don't assert if removing first entry in list Jes.Sorensen
@ 2010-07-24 19:03 ` Michael S. Tsirkin
  2010-07-26  6:49   ` Jes Sorensen
  0 siblings, 1 reply; 4+ messages in thread
From: Michael S. Tsirkin @ 2010-07-24 19:03 UTC (permalink / raw)
  To: Jes.Sorensen; +Cc: qemu-devel

On Fri, Jul 23, 2010 at 05:16:42PM +0200, Jes.Sorensen@redhat.com wrote:
> From: Jes Sorensen <Jes.Sorensen@redhat.com>
> 
> 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 <Jes.Sorensen@redhat.com>
> ---
>  hw/vhost.c |    1 -
>  1 files changed, 0 insertions(+), 1 deletions(-)
> 
> diff --git a/hw/vhost.c b/hw/vhost.c
> index d37a66e..f30cf91 100644
> --- a/hw/vhost.c
> +++ b/hw/vhost.c
> @@ -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?

> -- 
> 1.7.1.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [PATCH] vhost_dev_unassign_memory() don't assert if removing first entry in list.
  2010-07-24 19:03 ` [Qemu-devel] " Michael S. Tsirkin
@ 2010-07-26  6:49   ` Jes Sorensen
  2010-07-26  9:30     ` Michael S. Tsirkin
  0 siblings, 1 reply; 4+ messages in thread
From: Jes Sorensen @ 2010-07-26  6:49 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: qemu-devel

On 07/24/10 21:03, Michael S. Tsirkin wrote:
> On Fri, Jul 23, 2010 at 05:16:42PM +0200, Jes.Sorensen@redhat.com wrote:
>> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>> diff --git a/hw/vhost.c b/hw/vhost.c
>> index d37a66e..f30cf91 100644
>> --- a/hw/vhost.c
>> +++ b/hw/vhost.c
>> @@ -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?

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [PATCH] vhost_dev_unassign_memory() don't assert if removing first entry in list.
  2010-07-26  6:49   ` Jes Sorensen
@ 2010-07-26  9:30     ` Michael S. Tsirkin
  0 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2010-07-26  9:30 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: qemu-devel

On Mon, Jul 26, 2010 at 08:49:19AM +0200, Jes Sorensen wrote:
> On 07/24/10 21:03, Michael S. Tsirkin wrote:
> > On Fri, Jul 23, 2010 at 05:16:42PM +0200, Jes.Sorensen@redhat.com wrote:
> >> From: Jes Sorensen <Jes.Sorensen@redhat.com>
> >> diff --git a/hw/vhost.c b/hw/vhost.c
> >> index d37a66e..f30cf91 100644
> >> --- a/hw/vhost.c
> >> +++ b/hw/vhost.c
> >> @@ -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?
> 
> 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.


> Cheers,
> Jes

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-07-26  9:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-23 15:16 [Qemu-devel] [PATCH] vhost_dev_unassign_memory() don't assert if removing first entry in list Jes.Sorensen
2010-07-24 19:03 ` [Qemu-devel] " Michael S. Tsirkin
2010-07-26  6:49   ` Jes Sorensen
2010-07-26  9:30     ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).