Skip to contentSkip to conversation

vl: exit if a bad property value is passed to -global

PATCH In review Greg Kurz 4 participants 5 messages Jul 13, 2016 – Jul 21, 2016

lore
Share & tools
lore

Greg Kurz

author
#0 lore raw

PATCH 1/1 vl: exit if a bad property value is passed to -global

When passing '-global driver=host-powerpc64-cpu,property=compat,value=foo' on the command line, without this patch, we get the following warning per device (which means many lines if the guests has many cpus):

qemu-system-ppc64: Warning: can't apply global host-powerpc64-cpu.compat=foo:
Invalid compatibility mode "foo"

... and QEMU continues execution, ignoring the property.

With this patch, we get a single line:

qemu-system-ppc64: can't apply global host-powerpc64-cpu.compat=foo:
Invalid compatibility mode "foo"

... and QEMU exits.

---
 vl.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
vl.c +2 -1
index 356713ea075c..a7cc92781687 100644
@@ -2922,6 +2922,7 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
     g->user_provided = true;
+    g->errp = errp;
     qdev_prop_register_global(g);
     return 0;
 }
@@ -4451,7 +4452,7 @@ int main(int argc, char **argv, char **envp)
     machine_register_compat_props(current_machine);
 
     qemu_opts_foreach(qemu_find_opts("global"),
-                      global_init_func, NULL, NULL);
+                      global_init_func, NULL, &error_fatal);
 
     /* This checkpoint is required by replay to separate prior clock
        reading from the other reads, because timer polling functions query
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Greg Kurz

When passing '-global driver=host-powerpc64-cpu,property=compat,value=foo' on the command line, without this patch, we get the following warning per device (which means many lines if the guests has many cpus):

qemu-system-ppc64: Warning: can't apply global host-powerpc64-cpu.compat=foo:
Invalid compatibility mode "foo"

... and QEMU continues execution, ignoring the property.

Quoted 8 lines

With this patch, we get a single line:

qemu-system-ppc64: can't apply global host-powerpc64-cpu.compat=foo:
Invalid compatibility mode "foo"

... and QEMU exits.

Not really up to me to decide if this is the right approach for global option handling, but it seems like the way to go to me.

Quoted 26 lines
---
 vl.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
vl.c +2 -1
index 356713ea075c..a7cc92781687 100644
@@ -2922,6 +2922,7 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
     g->user_provided = true;
+    g->errp = errp;
     qdev_prop_register_global(g);
     return 0;
 }
@@ -4451,7 +4452,7 @@ int main(int argc, char **argv, char **envp)
     machine_register_compat_props(current_machine);
 
     qemu_opts_foreach(qemu_find_opts("global"),
-                      global_init_func, NULL, NULL);
+                      global_init_func, NULL, &error_fatal);
 
     /* This checkpoint is required by replay to separate prior clock
        reading from the other reads, because timer polling functions query
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#2 lore raw
Quoted 15 lines · On Thu, 14 Jul 2016 11:42:40 +1000 David Gibson <[email protected]>…
Quoted 14 lines · Greg Kurz

When passing '-global driver=host-powerpc64-cpu,property=compat,value=foo' on the command line, without this patch, we get the following warning per device (which means many lines if the guests has many cpus):

qemu-system-ppc64: Warning: can't apply global host-powerpc64-cpu.compat=foo:
Invalid compatibility mode "foo"

... and QEMU continues execution, ignoring the property.

With this patch, we get a single line:

qemu-system-ppc64: can't apply global host-powerpc64-cpu.compat=foo:
Invalid compatibility mode "foo"

Quoted 8 lines
Quoted 3 lines

... and QEMU exits.

Not really up to me to decide if this is the right approach for global option handling, but it seems like the way to go to me.

CCing Eduardo
as he basically rewrote that path several times and might know why it's this way now.

Quoted 28 lines
Quoted 27 lines
---
 vl.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
vl.c +2 -1
index 356713ea075c..a7cc92781687 100644
@@ -2922,6 +2922,7 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
     g->user_provided = true;
+    g->errp = errp;
     qdev_prop_register_global(g);
     return 0;
 }
@@ -4451,7 +4452,7 @@ int main(int argc, char **argv, char **envp)
     machine_register_compat_props(current_machine);
 
     qemu_opts_foreach(qemu_find_opts("global"),
-                      global_init_func, NULL, NULL);
+                      global_init_func, NULL, &error_fatal);
 
     /* This checkpoint is required by replay to separate prior clock
        reading from the other reads, because timer polling functions query
#3 lore raw

Sorry for the long delay:

Quoted 34 lines · Igor Mammedov
Quoted 15 lines · On Thu, 14 Jul 2016 11:42:40 +1000 David Gibson <[email protected]>…
Quoted 14 lines · Greg Kurz

When passing '-global driver=host-powerpc64-cpu,property=compat,value=foo' on the command line, without this patch, we get the following warning per device (which means many lines if the guests has many cpus):

qemu-system-ppc64: Warning: can't apply global host-powerpc64-cpu.compat=foo:
Invalid compatibility mode "foo"

... and QEMU continues execution, ignoring the property.

With this patch, we get a single line:

qemu-system-ppc64: can't apply global host-powerpc64-cpu.compat=foo:
Invalid compatibility mode "foo"

Quoted 8 lines
Quoted 3 lines

... and QEMU exits.

Not really up to me to decide if this is the right approach for global option handling, but it seems like the way to go to me.

CCing Eduardo
as he basically rewrote that path several times and might know why it's this way now.

Quoted 5 lines
Quoted 5 lines
---
 vl.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 9 lines
Quoted 9 lines

vl.c static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) · line 2925

Quoted 9 lines
vl.c +1 -0
index 356713ea075c..a7cc92781687 100644
@@ -2922,6 +2922,7 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
     g->user_provided = true;
+    g->errp = errp;

Exiting QEMU like you suggest is valid, but we can't set errp to error_fatal here, because it could make QEMU abort when using device_add.

Probably the simplest solution is to ignore GlobalProperty.errp in qdev_prop_set_globals_for_type() if dev->hotplugged is set. Then we can safely set errp here.

Signature · 1 line
Eduardo
author
#4 lore raw
Quoted 37 lines · On Wed, 20 Jul 2016 17:18:26 -0300 Eduardo Habkost <[email protected]> wrote:

Sorry for the long delay:

Quoted 34 lines · Igor Mammedov
Quoted 15 lines · On Thu, 14 Jul 2016 11:42:40 +1000 David Gibson <[email protected]>…
Quoted 14 lines · Greg Kurz

When passing '-global driver=host-powerpc64-cpu,property=compat,value=foo' on the command line, without this patch, we get the following warning per device (which means many lines if the guests has many cpus):

qemu-system-ppc64: Warning: can't apply global host-powerpc64-cpu.compat=foo:
Invalid compatibility mode "foo"

... and QEMU continues execution, ignoring the property.

With this patch, we get a single line:

qemu-system-ppc64: can't apply global host-powerpc64-cpu.compat=foo:
Invalid compatibility mode "foo"

Quoted 8 lines
Quoted 3 lines

... and QEMU exits.

Not really up to me to decide if this is the right approach for global option handling, but it seems like the way to go to me.

CCing Eduardo
as he basically rewrote that path several times and might know why it's this way now.

Quoted 5 lines
Quoted 5 lines
  
---
 vl.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines
Quoted 9 lines
Quoted 9 lines

vl.c static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) · line 2925

Quoted 9 lines
vl.c +1 -0
index 356713ea075c..a7cc92781687 100644
@@ -2922,6 +2922,7 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
     g->user_provided = true;
+    g->errp = errp;  

Exiting QEMU like you suggest is valid, but we can't set errp to error_fatal here, because it could make QEMU abort when using device_add.

Indeed QEMU exits :\

Quoted 4 lines

Probably the simplest solution is to ignore GlobalProperty.errp in qdev_prop_set_globals_for_type() if dev->hotplugged is set. Then we can safely set errp here.

That should do the trick. I'll send a v2.

Thanks !

--
Greg