Skip to contentSkip to conversation

check if we have space left for hotplugged memory

PATCH In review Hu Tao 3 participants 5 messages Jun 25, 2014

lore
Share & tools
lore

Hu Tao

author
#0 lore raw

PATCH 1/1 check if we have space left for hotplugged memory

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.

---
 hw/i386/pc.c     | 5 +++++
 hw/mem/pc-dimm.c | 5 +++++
 2 files changed, 10 insertions(+)
hw/i386/pc.c +5 -0
index 2cf22b1..1a0d96e 100644
@@ -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,
hw/mem/pc-dimm.c +5 -0
index ad176b7..59ed9c0 100644
@@ -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);
 
Signature · 1 line
1.9.3
#1 lore raw
Quoted 17 lines · Hu Tao

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.

---
 hw/i386/pc.c     | 5 +++++
 hw/mem/pc-dimm.c | 5 +++++
 2 files changed, 10 insertions(+)
hw/i386/pc.c +0 -0
index 2cf22b1..1a0d96e 100644
@@ -1566,6 +1566,11 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
         goto out;

hw/i386/pc.c static void pc_dimm_plug(HotplugHandler *hotplug_dev, · line 1576

Quoted 10 lines
hw/i386/pc.c +5 -0
     }
 
+    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?

Quoted 6 lines
hw/mem/pc-dimm.c +0 -0
index ad176b7..59ed9c0 100644
@@ -146,6 +146,11 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
     uint64_t new_addr, ret = 0;

hw/mem/pc-dimm.c uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, · line 156

Quoted 10 lines
hw/mem/pc-dimm.c +5 -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?

Quoted 2 lines
Signature · 1 line
1.9.3
author
#2 lore raw
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Hu Tao

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.

---
 hw/i386/pc.c     | 5 +++++
 hw/mem/pc-dimm.c | 5 +++++
 2 files changed, 10 insertions(+)
hw/i386/pc.c +0 -0
index 2cf22b1..1a0d96e 100644
@@ -1566,6 +1566,11 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
         goto out;
     }
 
Quoted 11 lines

hw/i386/pc.c static void pc_dimm_plug(HotplugHandler *hotplug_dev, · line 1576

Quoted 8 lines
hw/i386/pc.c +5 -0
+    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.

Quoted 9 lines
Quoted 9 lines
hw/mem/pc-dimm.c +0 -0
index ad176b7..59ed9c0 100644
@@ -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;
 
Quoted 11 lines

hw/mem/pc-dimm.c uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, · line 156

Quoted 8 lines
hw/mem/pc-dimm.c +5 -0
+    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

#3 lore raw
Quoted 33 lines · On Wed, 25 Jun 2014 17:33:31 +0800 Hu Tao <[email protected]> wrote:
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Hu Tao

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.

---
 hw/i386/pc.c     | 5 +++++
 hw/mem/pc-dimm.c | 5 +++++
 2 files changed, 10 insertions(+)
hw/i386/pc.c +0 -0
index 2cf22b1..1a0d96e 100644
@@ -1566,6 +1566,11 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
         goto out;
     }
 
Quoted 11 lines

hw/i386/pc.c static void pc_dimm_plug(HotplugHandler *hotplug_dev, · line 1576

Quoted 8 lines
hw/i386/pc.c +5 -0
+    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?

Quoted 3 lines

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()

Quoted 33 lines
Quoted 10 lines
Quoted 10 lines
hw/mem/pc-dimm.c +0 -0
index ad176b7..59ed9c0 100644
@@ -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;
 
Quoted 11 lines

hw/mem/pc-dimm.c uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, · line 156

Quoted 8 lines
hw/mem/pc-dimm.c +5 -0
+    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

#4 lore raw
In reply to Hu Tao
Quoted 58 lines · Hu Tao
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Hu Tao

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.

---
 hw/i386/pc.c     | 5 +++++
 hw/mem/pc-dimm.c | 5 +++++
 2 files changed, 10 insertions(+)
hw/i386/pc.c +0 -0
index 2cf22b1..1a0d96e 100644
@@ -1566,6 +1566,11 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
         goto out;
     }
 
Quoted 11 lines

hw/i386/pc.c static void pc_dimm_plug(HotplugHandler *hotplug_dev, · line 1576

Quoted 8 lines
hw/i386/pc.c +5 -0
+    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.

Quoted 9 lines
Quoted 9 lines
hw/mem/pc-dimm.c +0 -0
index ad176b7..59ed9c0 100644
@@ -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;
 
Quoted 11 lines

hw/mem/pc-dimm.c uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, · line 156

Quoted 8 lines
hw/mem/pc-dimm.c +5 -0
+    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?

Quoted 5 lines

What about:

no space left for hotplugged memory, please check maxmem option

?

Maybe "please increase the maxmem value"?

Quoted 6 lines

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

Hu