Skip to contentSkip to conversation

pc: fix crash in rtc_set_memory() if initial cpu is marked as hotplugged

PATCH In review Igor Mammedov 4 participants 4 messages Dec 30, 2016 – Jan 10, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pc: fix crash in rtc_set_memory() if initial cpu is marked as hotplugged

'hotplugged' propperty is meant to be used on migration side when migrating source with hotplugged devices.
However though it not exacly correct usage of 'hotplugged' property it's possible to set generic hotplugged property for CPU using
-cpu foo,hotplugged=on
or
-global foo.hotplugged=on

in this case qemu crashes with following backtrace:

...

because pc_cpu_plug() assumes that hotplugged CPU could appear only after rtc/fw_cfg are initialized.
Fix crash by replacing assumption with explicit checks of rtc/fw_cfg and updating them only if they were initialized.

---
 hw/i386/pc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/i386/pc.c +3 -1
index f3d7ad4..7b7e126 100644
@@ -1810,8 +1810,10 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 
     /* increment the number of CPUs */
     pcms->boot_cpus++;
-    if (dev->hotplugged) {
+    if (pcms->rtc) {
         rtc_set_cpus_count(pcms->rtc, pcms->boot_cpus);
+    }
+    if (pcms->fw_cfg) {
         fw_cfg_modify_i16(pcms->fw_cfg, FW_CFG_NB_CPUS, pcms->boot_cpus);
     }
 
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Igor Mammedov

'hotplugged' propperty is meant to be used on migration side when migrating source with hotplugged devices.
However though it not exacly correct usage of 'hotplugged' property it's possible to set generic hotplugged property for CPU using
-cpu foo,hotplugged=on
or
-global foo.hotplugged=on

in this case qemu crashes with following backtrace:

...

Quoted 7 lines

because pc_cpu_plug() assumes that hotplugged CPU could appear only after rtc/fw_cfg are initialized.
Fix crash by replacing assumption with explicit checks of rtc/fw_cfg and updating them only if they were initialized.

I like how the new code doesn't depend on DeviceState::hotplugged at all.

But I would like to understand better how the "hotplugged" property is really supposed to be used. I am not aware of any existing case where the user needs to set "hotplugged" directly and it works.

Quoted 23 lines
---
 hw/i386/pc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/i386/pc.c +3 -1
index f3d7ad4..7b7e126 100644
@@ -1810,8 +1810,10 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 
     /* increment the number of CPUs */
     pcms->boot_cpus++;
-    if (dev->hotplugged) {
+    if (pcms->rtc) {
         rtc_set_cpus_count(pcms->rtc, pcms->boot_cpus);
+    }
+    if (pcms->fw_cfg) {
         fw_cfg_modify_i16(pcms->fw_cfg, FW_CFG_NB_CPUS, pcms->boot_cpus);
     }
 
Signature · 1 line
2.7.4
Signature · 1 line
Eduardo
#2 lore raw
In reply to Igor Mammedov
Quoted 30 lines · Igor Mammedov

'hotplugged' propperty is meant to be used on migration side when migrating source with hotplugged devices.
However though it not exacly correct usage of 'hotplugged' property it's possible to set generic hotplugged property for CPU using
-cpu foo,hotplugged=on
or
-global foo.hotplugged=on

in this case qemu crashes with following backtrace:

...

because pc_cpu_plug() assumes that hotplugged CPU could appear only after rtc/fw_cfg are initialized.
Fix crash by replacing assumption with explicit checks of rtc/fw_cfg and updating them only if they were initialized.

---
 hw/i386/pc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/i386/pc.c +0 -0
index f3d7ad4..7b7e126 100644
@@ -1810,8 +1810,10 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 

hw/i386/pc.c static void pc_cpu_plug(HotplugHandler *hotplug_dev, · line 1819

Quoted 10 lines
hw/i386/pc.c +3 -1
     /* increment the number of CPUs */
     pcms->boot_cpus++;
-    if (dev->hotplugged) {
+    if (pcms->rtc) {
         rtc_set_cpus_count(pcms->rtc, pcms->boot_cpus);
+    }
+    if (pcms->fw_cfg) {
         fw_cfg_modify_i16(pcms->fw_cfg, FW_CFG_NB_CPUS, pcms->boot_cpus);
     }
 

Looks good - adding qemu-stable too.

Paolo

Reviewed-by on v1 1/1
#3 lore raw
In reply to Igor Mammedov
Quoted 12 lines · Igor Mammedov

'hotplugged' propperty is meant to be used on migration side when migrating source with hotplugged devices.
However though it not exacly correct usage of 'hotplugged' property it's possible to set generic hotplugged property for CPU using
-cpu foo,hotplugged=on
or
-global foo.hotplugged=on

in this case qemu crashes with following backtrace:

...

Quoted 7 lines

because pc_cpu_plug() assumes that hotplugged CPU could appear only after rtc/fw_cfg are initialized.
Fix crash by replacing assumption with explicit checks of rtc/fw_cfg and updating them only if they were initialized.

Looks like Paolo is merging this.

Quoted 22 lines
---
 hw/i386/pc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/i386/pc.c +3 -1
index f3d7ad4..7b7e126 100644
@@ -1810,8 +1810,10 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 
     /* increment the number of CPUs */
     pcms->boot_cpus++;
-    if (dev->hotplugged) {
+    if (pcms->rtc) {
         rtc_set_cpus_count(pcms->rtc, pcms->boot_cpus);
+    }
+    if (pcms->fw_cfg) {
         fw_cfg_modify_i16(pcms->fw_cfg, FW_CFG_NB_CPUS, pcms->boot_cpus);
     }
 
Signature · 1 line
2.7.4