Patchwork qemu-kvm: fix unmatched RAM alloction/free

login
register
mail settings
Submitter Hao, Xudong
Date Jan. 17, 2009, 11:13 p.m.
Message ID <1232233990-20383-1-git-send-email-xudong.hao@intel.com>
Download mbox | patch
Permalink /patch/245793/
State New
Headers show

Comments

Hao, Xudong - Jan. 17, 2009, 11:13 p.m.
mmap is used in qemu_vmalloc function instead of qemu_memalign(commit
7dda5dc8), so it should change qemu_vfree to munmap to fix a unmatched
issue.

This issue appears when a PCI device is being assigned to KVM guest,
failure to read PCI rom file will bring RAM free, then the incorrect
qemu_vfree calling will cause a segment fault.

Signed-off-by: Xudong Hao <xudong.hao@intel.com>
---
 exec.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
Paolo Bonzini - May 23, 2013, 5:13 p.m.
> mmap is used in qemu_vmalloc function instead of qemu_memalign(commit
> 7dda5dc8), so it should change qemu_vfree to munmap to fix a unmatched
> issue.
> 
> This issue appears when a PCI device is being assigned to KVM guest,
> failure to read PCI rom file will bring RAM free, then the incorrect
> qemu_vfree calling will cause a segment fault.
> 
> Signed-off-by: Xudong Hao <xudong.hao@intel.com>
> ---
>  exec.c |    6 +-----
>  1 files changed, 1 insertions(+), 5 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index fa1e0c3..d40d237 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1152,15 +1152,11 @@ void qemu_ram_free(ram_addr_t addr)
>                  abort();
>  #endif
>              } else {
> -#if defined(TARGET_S390X) && defined(CONFIG_KVM)
> -                munmap(block->host, block->length);
> -#else
>                  if (xen_enabled()) {
>                      xen_invalidate_map_cache_entry(block->host);
>                  } else {
> -                    qemu_vfree(block->host);
> +                    munmap(block->host, block->length);
>                  }
> -#endif
>              }
>              g_free(block);
>              break;

Just "git pull". :)  This is very similar to commit e7a09b9 (osdep: introduce
qemu_anon_ram_free to free qemu_anon_ram_alloc-ed memory, 2013-05-13)

Paolo
Hao, Xudong - May 24, 2013, 1:21 a.m.
> -----Original Message-----

> From: Paolo Bonzini [mailto:pbonzini@redhat.com]

> Sent: Friday, May 24, 2013 1:13 AM

> To: Hao, Xudong

> Cc: kvm@vger.kernel.org; gleb@redhat.com; qemu-devel@nongnu.org

> Subject: Re: [PATCH] qemu-kvm: fix unmatched RAM alloction/free

> 

> > mmap is used in qemu_vmalloc function instead of qemu_memalign(commit

> > 7dda5dc8), so it should change qemu_vfree to munmap to fix a unmatched

> > issue.

> >

> > This issue appears when a PCI device is being assigned to KVM guest,

> > failure to read PCI rom file will bring RAM free, then the incorrect

> > qemu_vfree calling will cause a segment fault.

> >

> > Signed-off-by: Xudong Hao <xudong.hao@intel.com>

> > ---

> >  exec.c |    6 +-----

> >  1 files changed, 1 insertions(+), 5 deletions(-)

> >

> > diff --git a/exec.c b/exec.c

> > index fa1e0c3..d40d237 100644

> > --- a/exec.c

> > +++ b/exec.c

> > @@ -1152,15 +1152,11 @@ void qemu_ram_free(ram_addr_t addr)

> >                  abort();

> >  #endif

> >              } else {

> > -#if defined(TARGET_S390X) && defined(CONFIG_KVM)

> > -                munmap(block->host, block->length);

> > -#else

> >                  if (xen_enabled()) {

> >                      xen_invalidate_map_cache_entry(block->host);

> >                  } else {

> > -                    qemu_vfree(block->host);

> > +                    munmap(block->host, block->length);

> >                  }

> > -#endif

> >              }

> >              g_free(block);

> >              break;

> 

> Just "git pull". :)  This is very similar to commit e7a09b9 (osdep: introduce

> qemu_anon_ram_free to free qemu_anon_ram_alloc-ed memory, 2013-05-13)

> 


OK, this commit do the same thing as my patch, I did not notice qemu upstream tree, just take a look at qemu-kvm tree, but I think this commit should be backport to qemu-kvm tree, because many user are using qemu-kvm for KVM. 

Anyway please ignore this patch.

Thanks,
-Xudong
Eric Blake - May 24, 2013, 1:08 p.m.
On 05/23/2013 07:21 PM, Hao, Xudong wrote:
>> Just "git pull". :)  This is very similar to commit e7a09b9 (osdep: introduce
>> qemu_anon_ram_free to free qemu_anon_ram_alloc-ed memory, 2013-05-13)
>>
> 
> OK, this commit do the same thing as my patch, I did not notice qemu upstream tree, just take a look at qemu-kvm tree, but I think this commit should be backport to qemu-kvm tree, because many user are using qemu-kvm for KVM. 

That argues that the qemu-kvm tree needs one final commit that wipes
everything and replaces it with a readme file that tells users to
upgrade to the qemu upstream tree, now that the qemu-kvm tree has been
merged upstream and is no longer actively maintained.
Michael Tokarev - May 28, 2013, 6:34 p.m.
Um, something's wrong with the Date.  Care to resend with that fixed?

Thanks,

/mjt

18.01.2009 02:13, Xudong Hao wrote:
> mmap is used in qemu_vmalloc function instead of qemu_memalign(commit
> 7dda5dc8), so it should change qemu_vfree to munmap to fix a unmatched
> issue.
[...]
Hao, Xudong - May 29, 2013, 2:37 a.m.
> -----Original Message-----
> From: Michael Tokarev [mailto:mjt@tls.msk.ru]
> Sent: Wednesday, May 29, 2013 2:34 AM
> To: Hao, Xudong
> Cc: kvm@vger.kernel.org; gleb@redhat.com; pbonzini@redhat.com;
> qemu-devel@nongnu.org
> Subject: Re: [PATCH] qemu-kvm: fix unmatched RAM alloction/free
> 
> Um, something's wrong with the Date.  Care to resend with that fixed?
> 

Because the similar fix are already in qemu upstream, seems we need not this patch longer.

> Thanks,
> 
> /mjt
> 
> 18.01.2009 02:13, Xudong Hao wrote:
> > mmap is used in qemu_vmalloc function instead of qemu_memalign(commit
> > 7dda5dc8), so it should change qemu_vfree to munmap to fix a unmatched
> > issue.
> [...]

Patch

diff --git a/exec.c b/exec.c
index fa1e0c3..d40d237 100644
--- a/exec.c
+++ b/exec.c
@@ -1152,15 +1152,11 @@  void qemu_ram_free(ram_addr_t addr)
                 abort();
 #endif
             } else {
-#if defined(TARGET_S390X) && defined(CONFIG_KVM)
-                munmap(block->host, block->length);
-#else
                 if (xen_enabled()) {
                     xen_invalidate_map_cache_entry(block->host);
                 } else {
-                    qemu_vfree(block->host);
+                    munmap(block->host, block->length);
                 }
-#endif
             }
             g_free(block);
             break;