diff mbox

check if we have space left for hotplugged memory

Message ID 1403686864-13567-1-git-send-email-hutao@cn.fujitsu.com
State New
Headers show

Commit Message

Hu Tao June 25, 2014, 9:01 a.m. UTC
If pc-dimm is specified on qemu command line, but only with
-m size (aka not -m size,maxmem,slots) then qemu will core dump.

This patch fixes the problem.

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 hw/i386/pc.c     | 5 +++++
 hw/mem/pc-dimm.c | 5 +++++
 2 files changed, 10 insertions(+)

Comments

Michael S. Tsirkin June 25, 2014, 9:17 a.m. UTC | #1
On Wed, Jun 25, 2014 at 05:01:04PM +0800, Hu Tao wrote:
> If pc-dimm is specified on qemu command line, but only with
> -m size (aka not -m size,maxmem,slots) then qemu will core dump.
> 
> This patch fixes the problem.
> 
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> ---
>  hw/i386/pc.c     | 5 +++++
>  hw/mem/pc-dimm.c | 5 +++++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index 2cf22b1..1a0d96e 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -1566,6 +1566,11 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
>          goto out;
>      }
>  
> +    if (memory_region_size(&pcms->hotplug_memory) == 0) {
> +        error_setg(&local_err, "no space left for hotplugged memory.");
> +        goto out;
> +    }
> +
>      addr = pc_dimm_get_free_addr(pcms->hotplug_memory_base,
>                                   memory_region_size(&pcms->hotplug_memory),
>                                   !addr ? NULL : &addr,


Why two errors in two places?

> diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
> index ad176b7..59ed9c0 100644
> --- a/hw/mem/pc-dimm.c
> +++ b/hw/mem/pc-dimm.c
> @@ -146,6 +146,11 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
>      uint64_t new_addr, ret = 0;
>      uint64_t address_space_end = address_space_start + address_space_size;
>  
> +    if (address_space_size == 0) {
> +        error_setg(errp, "no space left for hotplugged memory.");
> +        goto out;
> +    }
> +
>      assert(address_space_end > address_space_size);
>      object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &list);
>  


Didn't we want a more specific message?

> -- 
> 1.9.3
Hu Tao June 25, 2014, 9:33 a.m. UTC | #2
On Wed, Jun 25, 2014 at 12:17:57PM +0300, Michael S. Tsirkin wrote:
> On Wed, Jun 25, 2014 at 05:01:04PM +0800, Hu Tao wrote:
> > If pc-dimm is specified on qemu command line, but only with
> > -m size (aka not -m size,maxmem,slots) then qemu will core dump.
> > 
> > This patch fixes the problem.
> > 
> > Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> > ---
> >  hw/i386/pc.c     | 5 +++++
> >  hw/mem/pc-dimm.c | 5 +++++
> >  2 files changed, 10 insertions(+)
> > 
> > diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> > index 2cf22b1..1a0d96e 100644
> > --- a/hw/i386/pc.c
> > +++ b/hw/i386/pc.c
> > @@ -1566,6 +1566,11 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
> >          goto out;
> >      }
> >  
> > +    if (memory_region_size(&pcms->hotplug_memory) == 0) {
> > +        error_setg(&local_err, "no space left for hotplugged memory.");
> > +        goto out;
> > +    }
> > +
> >      addr = pc_dimm_get_free_addr(pcms->hotplug_memory_base,
> >                                   memory_region_size(&pcms->hotplug_memory),
> >                                   !addr ? NULL : &addr,
> 
> 
> Why two errors in two places?

This is what Igor suggested(IIUC) which I think is reasonable. The check
here prevents further operation even if there is no call to
pc_dimm_get_free_addr.

> 
> > diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
> > index ad176b7..59ed9c0 100644
> > --- a/hw/mem/pc-dimm.c
> > +++ b/hw/mem/pc-dimm.c
> > @@ -146,6 +146,11 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
> >      uint64_t new_addr, ret = 0;
> >      uint64_t address_space_end = address_space_start + address_space_size;
> >  
> > +    if (address_space_size == 0) {
> > +        error_setg(errp, "no space left for hotplugged memory.");
> > +        goto out;
> > +    }
> > +
> >      assert(address_space_end > address_space_size);
> >      object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &list);
> >  
> 
> 
> Didn't we want a more specific message?

What about:

  no space left for hotplugged memory, please check maxmem option

?

Igor pointed out that explicitly state "-m maxmem=maxmem" here may not
sync with future -m change.


Hu
Michael S. Tsirkin June 25, 2014, 9:46 a.m. UTC | #3
On Wed, Jun 25, 2014 at 05:33:31PM +0800, Hu Tao wrote:
> On Wed, Jun 25, 2014 at 12:17:57PM +0300, Michael S. Tsirkin wrote:
> > On Wed, Jun 25, 2014 at 05:01:04PM +0800, Hu Tao wrote:
> > > If pc-dimm is specified on qemu command line, but only with
> > > -m size (aka not -m size,maxmem,slots) then qemu will core dump.
> > > 
> > > This patch fixes the problem.
> > > 
> > > Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> > > ---
> > >  hw/i386/pc.c     | 5 +++++
> > >  hw/mem/pc-dimm.c | 5 +++++
> > >  2 files changed, 10 insertions(+)
> > > 
> > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> > > index 2cf22b1..1a0d96e 100644
> > > --- a/hw/i386/pc.c
> > > +++ b/hw/i386/pc.c
> > > @@ -1566,6 +1566,11 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
> > >          goto out;
> > >      }
> > >  
> > > +    if (memory_region_size(&pcms->hotplug_memory) == 0) {
> > > +        error_setg(&local_err, "no space left for hotplugged memory.");
> > > +        goto out;
> > > +    }
> > > +
> > >      addr = pc_dimm_get_free_addr(pcms->hotplug_memory_base,
> > >                                   memory_region_size(&pcms->hotplug_memory),
> > >                                   !addr ? NULL : &addr,
> > 
> > 
> > Why two errors in two places?
> 
> This is what Igor suggested(IIUC) which I think is reasonable. The check
> here prevents further operation even if there is no call to
> pc_dimm_get_free_addr.
> 
> > 
> > > diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
> > > index ad176b7..59ed9c0 100644
> > > --- a/hw/mem/pc-dimm.c
> > > +++ b/hw/mem/pc-dimm.c
> > > @@ -146,6 +146,11 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
> > >      uint64_t new_addr, ret = 0;
> > >      uint64_t address_space_end = address_space_start + address_space_size;
> > >  
> > > +    if (address_space_size == 0) {
> > > +        error_setg(errp, "no space left for hotplugged memory.");
> > > +        goto out;
> > > +    }
> > > +
> > >      assert(address_space_end > address_space_size);
> > >      object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &list);
> > >  
> > 
> > 
> > Didn't we want a more specific message?
> 
> What about:
> 
>   no space left for hotplugged memory, please check maxmem option
> 
> ?

Maybe "please increase the maxmem value"?

> 
> Igor pointed out that explicitly state "-m maxmem=maxmem" here may not
> sync with future -m change.
> 
> 
> Hu
Igor Mammedov June 25, 2014, 9:56 a.m. UTC | #4
On Wed, 25 Jun 2014 17:33:31 +0800
Hu Tao <hutao@cn.fujitsu.com> wrote:

> On Wed, Jun 25, 2014 at 12:17:57PM +0300, Michael S. Tsirkin wrote:
> > On Wed, Jun 25, 2014 at 05:01:04PM +0800, Hu Tao wrote:
> > > If pc-dimm is specified on qemu command line, but only with
> > > -m size (aka not -m size,maxmem,slots) then qemu will core dump.
> > > 
> > > This patch fixes the problem.
> > > 
> > > Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> > > ---
> > >  hw/i386/pc.c     | 5 +++++
> > >  hw/mem/pc-dimm.c | 5 +++++
> > >  2 files changed, 10 insertions(+)
> > > 
> > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> > > index 2cf22b1..1a0d96e 100644
> > > --- a/hw/i386/pc.c
> > > +++ b/hw/i386/pc.c
> > > @@ -1566,6 +1566,11 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
> > >          goto out;
> > >      }
> > >  
> > > +    if (memory_region_size(&pcms->hotplug_memory) == 0) {
> > > +        error_setg(&local_err, "no space left for hotplugged memory.");
> > > +        goto out;
> > > +    }
> > > +
> > >      addr = pc_dimm_get_free_addr(pcms->hotplug_memory_base,
> > >                                   memory_region_size(&pcms->hotplug_memory),
> > >                                   !addr ? NULL : &addr,
> > 
> > 
> > Why two errors in two places?
> 
> This is what Igor suggested(IIUC) which I think is reasonable. The check
> here prevents further operation even if there is no call to
> pc_dimm_get_free_addr.
I'd prefer error out from pc_dimm_get_free_addr()

> 
> > 
> > > diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
> > > index ad176b7..59ed9c0 100644
> > > --- a/hw/mem/pc-dimm.c
> > > +++ b/hw/mem/pc-dimm.c
> > > @@ -146,6 +146,11 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
> > >      uint64_t new_addr, ret = 0;
> > >      uint64_t address_space_end = address_space_start + address_space_size;
> > >  
> > > +    if (address_space_size == 0) {
> > > +        error_setg(errp, "no space left for hotplugged memory.");
> > > +        goto out;
> > > +    }
> > > +
> > >      assert(address_space_end > address_space_size);
> > >      object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &list);
> > >  
> > 
> > 
> > Didn't we want a more specific message?
> 
> What about:
> 
>   no space left for hotplugged memory, please check maxmem option
> 
> ?
> 
> Igor pointed out that explicitly state "-m maxmem=maxmem" here may not
> sync with future -m change.
> 
> 
> Hu
diff mbox

Patch

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 2cf22b1..1a0d96e 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1566,6 +1566,11 @@  static void pc_dimm_plug(HotplugHandler *hotplug_dev,
         goto out;
     }
 
+    if (memory_region_size(&pcms->hotplug_memory) == 0) {
+        error_setg(&local_err, "no space left for hotplugged memory.");
+        goto out;
+    }
+
     addr = pc_dimm_get_free_addr(pcms->hotplug_memory_base,
                                  memory_region_size(&pcms->hotplug_memory),
                                  !addr ? NULL : &addr,
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index ad176b7..59ed9c0 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -146,6 +146,11 @@  uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
     uint64_t new_addr, ret = 0;
     uint64_t address_space_end = address_space_start + address_space_size;
 
+    if (address_space_size == 0) {
+        error_setg(errp, "no space left for hotplugged memory.");
+        goto out;
+    }
+
     assert(address_space_end > address_space_size);
     object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &list);