Skip to contentSkip to conversation

hw/arm/virt: fix cmdline parsing bug with CPU options and smp > 1

PATCH Applied Ard Biesheuvel 3 participants 5 messages Mar 3, 2015 – Mar 10, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/arm/virt: fix cmdline parsing bug with CPU options and smp > 1

The recently introduced feature that allows 32 bit guests to be executed under KVM on a 64-bit host incorrectly handles the case where more than 1 cpu is specified using '-smp N'

For instance, this invocation of qemu

qemu-system-aarch64 -M virt -cpu cortex-a57,aarch64=off -smp 2

produces the following error

qemu-system-aarch64: Expected key=value format, found aarch64

which is caused by the destructive parsing performed by cpu_common_parse_features(), resulting in subsequent attempts to parse the CPU option string (for each additional CPU) to fail.

So duplicate the string before parsing it, and free it directly afterwards.

---
 hw/arm/virt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/arm/virt.c +3 -1
index 69f51ac0da58..f8a6c46323dc 100644
@@ -758,6 +758,7 @@ static void machvirt_init(MachineState *machine)
         CPUClass *cc = CPU_CLASS(oc);
         Object *cpuobj;
         Error *err = NULL;
+        char *cpuopts = g_strdup(cpustr[1]);
 
         if (!oc) {
             fprintf(stderr, "Unable to find CPU definition\n");
@@ -766,7 +767,8 @@ static void machvirt_init(MachineState *machine)
         cpuobj = object_new(object_class_get_name(oc));
 
         /* Handle any CPU options specified by the user */
-        cc->parse_features(CPU(cpuobj), cpustr[1], &err);
+        cc->parse_features(CPU(cpuobj), cpuopts, &err);
+        g_free(cpuopts);
         if (err) {
             error_report("%s", error_get_pretty(err));
             exit(1);
Signature · 1 line
1.8.3.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 49 lines · Ard Biesheuvel

The recently introduced feature that allows 32 bit guests to be executed under KVM on a 64-bit host incorrectly handles the case where more than 1 cpu is specified using '-smp N'

For instance, this invocation of qemu

qemu-system-aarch64 -M virt -cpu cortex-a57,aarch64=off -smp 2

produces the following error

qemu-system-aarch64: Expected key=value format, found aarch64

which is caused by the destructive parsing performed by cpu_common_parse_features(), resulting in subsequent attempts to parse the CPU option string (for each additional CPU) to fail.

So duplicate the string before parsing it, and free it directly afterwards.

---
 hw/arm/virt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/arm/virt.c +3 -2
index 69f51ac0da58..f8a6c46323dc 100644
@@ -758,6 +758,7 @@ static void machvirt_init(MachineState *machine)
         CPUClass *cc = CPU_CLASS(oc);
         Object *cpuobj;
         Error *err = NULL;
+        char *cpuopts = g_strdup(cpustr[1]);
 
         if (!oc) {
             fprintf(stderr, "Unable to find CPU definition\n");
@@ -766,7 +767,8 @@ static void machvirt_init(MachineState *machine)
         cpuobj = object_new(object_class_get_name(oc));
 
         /* Handle any CPU options specified by the user */
-        cc->parse_features(CPU(cpuobj), cpustr[1], &err);
+        cc->parse_features(CPU(cpuobj), cpuopts, &err);
+        g_free(cpuopts);
         if (err) {
             error_report("%s", error_get_pretty(err));
             exit(1);
--

1.8.3.2

Quoted 1 line

​​

​Saw your patch after I sent mine out, roughly same fix...

#2 lore raw
Quoted 5 lines · Greg Bellows
Quoted 1 line · Ard Biesheuvel
Quoted 8 lines
Quoted 8 lines

The recently introduced feature that allows 32 bit guests to be executed under KVM on a 64-bit host incorrectly handles the case where more than 1 cpu is specified using '-smp N'

For instance, this invocation of qemu

qemu-system-aarch64 -M virt -cpu cortex-a57,aarch64=off -smp 2

This is incorrect: it is the command line I used for reproducing the issue while working on the bug, after removing the KVM check. So this should read

Quoted 46 lines
Quoted 42 lines

qemu-system-aarch64 -M virt -enable-kvm -cpu host,aarch64=off -smp 2

produces the following error

qemu-system-aarch64: Expected key=value format, found aarch64

which is caused by the destructive parsing performed by cpu_common_parse_features(), resulting in subsequent attempts to parse the CPU option string (for each additional CPU) to fail.

So duplicate the string before parsing it, and free it directly afterwards.

---
 hw/arm/virt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/arm/virt.c +3 -2
index 69f51ac0da58..f8a6c46323dc 100644
@@ -758,6 +758,7 @@ static void machvirt_init(MachineState *machine)
         CPUClass *cc = CPU_CLASS(oc);
         Object *cpuobj;
         Error *err = NULL;
+        char *cpuopts = g_strdup(cpustr[1]);
 
         if (!oc) {
             fprintf(stderr, "Unable to find CPU definition\n");
@@ -766,7 +767,8 @@ static void machvirt_init(MachineState *machine)
         cpuobj = object_new(object_class_get_name(oc));
 
         /* Handle any CPU options specified by the user */
-        cc->parse_features(CPU(cpuobj), cpustr[1], &err);
+        cc->parse_features(CPU(cpuobj), cpuopts, &err);
+        g_free(cpuopts);
         if (err) {
             error_report("%s", error_get_pretty(err));
             exit(1);
--
Quoted 2 lines

1.8.3.2

Saw your patch after I sent mine out, roughly same fix...

Quoted 2 lines

Thanks.

Let's leave it up to Peter which version he is most happy with

Signature · 1 line
Ard.
#3 lore raw
Quoted 65 lines · Ard Biesheuvel
Quoted 5 lines · Greg Bellows
Quoted 1 line · Ard Biesheuvel
Quoted 8 lines
Quoted 8 lines

The recently introduced feature that allows 32 bit guests to be executed under KVM on a 64-bit host incorrectly handles the case where more than 1 cpu is specified using '-smp N'

For instance, this invocation of qemu

qemu-system-aarch64 -M virt -cpu cortex-a57,aarch64=off -smp 2

This is incorrect: it is the command line I used for reproducing the issue while working on the bug, after removing the KVM check. So this should read

Quoted 46 lines
Quoted 42 lines

qemu-system-aarch64 -M virt -enable-kvm -cpu host,aarch64=off -smp 2

produces the following error

qemu-system-aarch64: Expected key=value format, found aarch64

which is caused by the destructive parsing performed by cpu_common_parse_features(), resulting in subsequent attempts to parse the CPU option string (for each additional CPU) to fail.

So duplicate the string before parsing it, and free it directly afterwards.

---
 hw/arm/virt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/arm/virt.c +3 -2
index 69f51ac0da58..f8a6c46323dc 100644
@@ -758,6 +758,7 @@ static void machvirt_init(MachineState *machine)
         CPUClass *cc = CPU_CLASS(oc);
         Object *cpuobj;
         Error *err = NULL;
+        char *cpuopts = g_strdup(cpustr[1]);
 
         if (!oc) {
             fprintf(stderr, "Unable to find CPU definition\n");
@@ -766,7 +767,8 @@ static void machvirt_init(MachineState *machine)
         cpuobj = object_new(object_class_get_name(oc));
 
         /* Handle any CPU options specified by the user */
-        cc->parse_features(CPU(cpuobj), cpustr[1], &err);
+        cc->parse_features(CPU(cpuobj), cpuopts, &err);
+        g_free(cpuopts);
         if (err) {
             error_report("%s", error_get_pretty(err));
             exit(1);
--
Quoted 2 lines

1.8.3.2

Saw your patch after I sent mine out, roughly same fix...

Quoted 7 lines
Quoted 2 lines

Thanks.

Let's leave it up to Peter which version he is most happy with

Ping?

#4 lore raw
Quoted 1 line · Ard Biesheuvel

Ping?

Applied this one to target-arm.next, thanks.

(I've been on holiday and not doing patch review or target-arm subtree handling, but am back at work now...)

-- PMM