Complete the implementation of -accel
cover Complete the implementation of -accel
This series completes the implementation of -accel:
- Alternative accelerators can be specified with multiple -accel options, and each -accel option will configure the respective accelerator. This is implemented in patches 1 to 6, with a small addendum in patch 7.
- Accelerators can now support arbitrary options, which are implemented in terms of QOM properties. This is implemented in patches 8 to 11, together with the conversion of the sole existing "-accel" option to QOM.
- Accelerator-related machine options, and legacy options such as -tb-size, forward to accelerator objects for backwards compatibility, but they do not exist anymore as QOM properties. This is implemented in patch 6 for "-machine accel" and patches 12 to 16 for everything else.
Paolo
Paolo Bonzini (16):
memory: do not look at current_machine->accel
vl: extract accelerator option processing to a separate function
vl: merge -accel processing into configure_accelerators
vl: move icount configuration earlier
vl: introduce object_parse_property_opt
vl: configure accelerators from -accel options
vl: warn for unavailable accelerators, clarify messages
qom: introduce object_register_sugar_prop
qom: add object_new_with_class
accel: pass object to accel_init_machine
tcg: convert "-accel threads" to a QOM property
tcg: add "-accel tcg,tb-size" and deprecate "-tb-size"
xen: convert "-machine igd-passthru" to an accelerator property
kvm: convert "-machine kvm_shadow_mem" to an accelerator property
kvm: introduce kvm_kernel_irqchip_* functions
kvm: convert "-machine kernel_irqchip" to an accelerator property
accel/accel.c | 67 +------------- accel/kvm/kvm-all.c | 117 ++++++++++++++++++++++- accel/tcg/tcg-all.c | 149 +++++++++++++++++++++++++++++- cpus.c | 72 --------------- hw/core/machine.c | 141 ---------------------------- hw/ppc/e500.c | 4 +- hw/ppc/spapr_irq.c | 10 +- hw/xen/xen-common.c | 16 ++++ include/hw/boards.h | 7 -- include/qom/object.h | 13 +++ include/sysemu/accel.h | 4 +- include/sysemu/cpus.h | 2 - include/sysemu/kvm.h | 7 +- memory.c | 5 +- qemu-deprecated.texi | 6 ++ qemu-options.hx | 30 +++--- qom/object.c | 28 +++++- target/arm/kvm.c | 8 +- target/i386/cpu.c | 8 +- target/i386/kvm.c | 6 +- target/mips/kvm.c | 2 +- target/ppc/kvm.c | 2 +- target/s390x/cpu_models.c | 4 +- target/s390x/kvm.c | 2 +- vl.c | 231 ++++++++++++++++++++++++++++++++-------------- 25 files changed, 534 insertions(+), 407 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/16 memory: do not look at current_machine->accel
"info mtree" prints the wrong accelerator name if used with for example "-machine accel=kvm:tcg". The right thing to do is to fetch the name from the AccelClass, which will also work nicely once current_machine->accel stops existing.
--- memory.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
memory.c +1 -4
@@ -2986,7 +2986,6 @@ struct FlatViewInfo {bool dispatch_tree;bool owner;AccelClass *ac; -const char *ac_name; }; static void mtree_print_flatview(gpointer key, gpointer value,
@@ -3056,7 +3055,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,if (fvi->ac->has_memory (current_machine, as,int128_get64 (range->addr.start),MR_SIZE (range->addr.size) +1 )) { -qemu_printf (" %s" , fvi->ac_name); +qemu_printf (" %s" , fvi->ac->name); } } }
@@ -3104,8 +3103,6 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner)if (ac->has_memory) { fvi.ac = ac; - fvi.ac_name = current_machine->accel ? current_machine->accel : -object_class_get_name (OBJECT_CLASS (ac)); }/* Gather all FVs in one table */
Signature · 1 line
1.8.3.1
Re: [PATCH 01/16] memory: do not look at current_machine->accel
Hi
Quoted 24 lines · Paolo Bonzini
"info mtree" prints the wrong accelerator name if used with for example "-machine accel=kvm:tcg". The right thing to do is to fetch the name from the AccelClass, which will also work nicely once
current_machine->accelstops existing.Signed-off-by Paolo Bonzini <[email protected]>--- memory.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)memory.c +0
-1@@ -2986,7 +2986,6 @@ struct FlatViewInfo {bool dispatch_tree;bool owner;AccelClass *ac; -const char *ac_name; }; static void mtree_print_flatview(gpointer key, gpointer value,
memory.c static void mtree_print_flatview(gpointer key, gpointer value, · line 3058
Quoted 5 lines
memory.c +1
-1@@ -3056,7 +3055,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,if (fvi->ac->has_memory (current_machine, as,int128_get64 (range->addr.start),MR_SIZE (range->addr.size) +1 )) { -qemu_printf (" %s" , fvi->ac_name); +qemu_printf (" %s" , fvi->ac->name);
There was a discussion on the original patch that this will have -accel appended.
I don't think that's a big issue, someone can submit another patch later if it's important.
Quoted 17 lines
memory.c +0
-3} } }@@ -3104,8 +3103,6 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner)if (ac->has_memory) { fvi.ac = ac; - fvi.ac_name = current_machine->accel ? current_machine->accel : -object_class_get_name (OBJECT_CLASS (ac)); }/* Gather all FVs in one table */ --1.8.3.1
Signature · 1 line
Marc-André Lureau
Re: [PATCH 01/16] memory: do not look at current_machine->accel
Quoted 4 lines · Marc-André Lureau
Quoted 1 line
+
qemu_printf(" %s", fvi->ac->name);There was a discussion on the original patch that this will have -accel appended.
This is not the class name, it's the name member of AccelClass.
Paolo
Re: [PATCH 01/16] memory: do not look at current_machine->accel
Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Marc-André Lureau
Quoted 1 line
+
qemu_printf(" %s", fvi->ac->name);There was a discussion on the original patch that this will have -accel appended.
This is not the class name, it's the name member of AccelClass.
right, thanks
Signature · 1 line
Marc-André Lureau
Re: [PATCH 01/16] memory: do not look at current_machine->accel
In reply to Paolo BonziniQuoted 2 lines · Paolo Bonzini
"info mtree" prints the wrong accelerator name if used with for example "-machine accel=kvm:tcg".
I had a quick look at the output of "info mtree" with and without "accel=kvm:tcg", but I could not spot any obvious places where it's wrong. Could you give an example?
Thomas
Re: [PATCH 01/16] memory: do not look at current_machine->accel
Quoted 5 lines · Thomas Huth
Quoted 2 lines
"info mtree" prints the wrong accelerator name if used with for example "-machine accel=kvm:tcg".
I had a quick look at the output of "info mtree" with and without "accel=kvm:tcg", but I could not spot any obvious places where it's wrong. Could you give an example?
Indeed the commit message should say "info mtree -f".
$ x86_64-softmmu/qemu-system-x86_64 -M microvm -enable-kvm -machine accel=kvm:tcg -monitor stdio QEMU 4.1.50 monitor - type 'help' for more information (qemu) info mtree -f ... FlatView #1 AS "memory", root: system AS "cpu-memory-0", root: system Root memory region: system 0000000000000000-00000000000effff (prio 0, ram): microvm.ram kvm:tcg 00000000000f0000-00000000000fffff (prio 0, ram): pc.bios kvm:tcg 0000000000100000-0000000007ffffff (prio 0, ram): microvm.ram @0000000000100000 kvm:tcg
Paolo
Thomas Huth
Tested-byRe: [PATCH 01/16] memory: do not look at current_machine->accel
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Thomas Huth
Quoted 2 lines
"info mtree" prints the wrong accelerator name if used with for example "-machine accel=kvm:tcg".
I had a quick look at the output of "info mtree" with and without "accel=kvm:tcg", but I could not spot any obvious places where it's wrong. Could you give an example?
Indeed the commit message should say "info mtree -f".
Right, with "-f" it is obvious. When you added that to the commit message, feel free to add my:
Re: [PATCH 01/16] memory: do not look at current_machine->accel
In reply to Paolo BonziniQuoted 10 lines · Paolo Bonzini
Quoted 5 lines · Thomas Huth
Quoted 2 lines
"info mtree" prints the wrong accelerator name if used with for example "-machine accel=kvm:tcg".
I had a quick look at the output of "info mtree" with and without "accel=kvm:tcg", but I could not spot any obvious places where it's wrong. Could you give an example?
Indeed the commit message should say "info mtree -f".
Quoted 11 lines
$ x86_64-softmmu/qemu-system-x86_64 -M microvm -enable-kvm -machine accel=kvm:tcg -monitor stdio QEMU 4.1.50 monitor - type 'help' for more information (qemu) info mtree -f ... FlatView #1 AS "memory", root: system AS "cpu-memory-0", root: system Root memory region: system 0000000000000000-00000000000effff (prio 0, ram): microvm.ram kvm:tcg 00000000000f0000-00000000000fffff (prio 0, ram): pc.bios kvm:tcg 0000000000100000-0000000007ffffff (prio 0, ram): microvm.ram @0000000000100000 kvm:tcg
Why do we need to print the accelerator name for every memory region? Isn't it just a global property, or at least a property of the CPU ?
thanks
-- PMM
Re: [PATCH 01/16] memory: do not look at current_machine->accel
Quoted 10 lines · Peter Maydell
Quoted 7 lines
FlatView #1
AS "memory", root: system
AS "cpu-memory-0", root: system
Root memory region: system
0000000000000000-00000000000effff (prio 0, ram): microvm.ram kvm:tcg 00000000000f0000-00000000000fffff (prio 0, ram): pc.bios kvm:tcg 0000000000100000-0000000007ffffff (prio 0, ram): microvm.ram @0000000000100000 kvm:tcgWhy do we need to print the accelerator name for every memory region? Isn't it just a global property, or at least a property of the CPU ?
Not all regions are registered with the accelerator, in particular not for devices. So we print it next to regions that are registered.
Paolo
Re: [PATCH 01/16] memory: do not look at current_machine->accel
Quoted 9 lines · Paolo Bonzini
Quoted 7 lines · Peter Maydell
Quoted 7 lines
FlatView #1
AS "memory", root: system
AS "cpu-memory-0", root: system
Root memory region: system
0000000000000000-00000000000effff (prio 0, ram): microvm.ram kvm:tcg 00000000000f0000-00000000000fffff (prio 0, ram): pc.bios kvm:tcg 0000000000100000-0000000007ffffff (prio 0, ram): microvm.ram @0000000000100000 kvm:tcg
Quoted 6 lines
Quoted 3 lines
Why do we need to print the accelerator name for every memory region? Isn't it just a global property, or at least a property of the CPU ?
Not all regions are registered with the accelerator, in particular not for devices. So we print it next to regions that are registered.
Ah, I see -- so it's really saying "this is a kvm memslot"?
thanks
-- PMM
Re: [PATCH 01/16] memory: do not look at current_machine->accel
Quoted 10 lines · Peter Maydell
Quoted 9 lines · Paolo Bonzini
Quoted 7 lines · Peter Maydell
Quoted 7 lines
FlatView #1
AS "memory", root: system
AS "cpu-memory-0", root: system
Root memory region: system
0000000000000000-00000000000effff (prio 0, ram): microvm.ram kvm:tcg 00000000000f0000-00000000000fffff (prio 0, ram): pc.bios kvm:tcg 0000000000100000-0000000007ffffff (prio 0, ram): microvm.ram @0000000000100000 kvm:tcg
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Why do we need to print the accelerator name for every memory region? Isn't it just a global property, or at least a property of the CPU ?
Not all regions are registered with the accelerator, in particular not for devices. So we print it next to regions that are registered.
Ah, I see -- so it's really saying "this is a kvm memslot"?
Yes, exactly.
Paolo
PATCH 2/16 vl: extract accelerator option processing to a separate function
In reply to Paolo BonziniAs a first step towards supporting multiple "-accel" options, push -icount and -accel semantics into a new function, and use qemu_opts_foreach to retrieve the key/value lists instead of stashing them into globals.
--- vl.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-)
vl.c +28 -12
@@ -2827,6 +2827,33 @@ static void user_register_global_props(void) global_init_func, NULL, NULL); } +static int do_configure_icount (void *opaque,QemuOpts *opts,Error **errp) +{ +if (tcg_enabled ()) { +configure_icount (opts, errp); + }else { +error_setg (errp,"-icount is not allowed with hardware virtualization" ); + } +return 0 ; +} + +static int do_configure_accelerator (void *opaque,QemuOpts *opts,Error **errp) +{ +if (tcg_enabled ()) { +qemu_tcg_configure (opts, &error_fatal); + } +return 0 ; +} + +static void configure_accelerators (void ) +{ +qemu_opts_foreach (qemu_find_opts ("icount" ), + do_configure_icount,NULL , &error_fatal); + +qemu_opts_foreach (qemu_find_opts ("accel" ), + do_configure_accelerator,NULL , &error_fatal); +} +int main (int argc,char **argv,char **envp) {int i;
@@ -4241,18 +4268,7 @@ int main(int argc, char **argv, char **envp)qemu_spice_init ();cpu_ticks_init (); -if (icount_opts) { -if (!tcg_enabled ()) { -error_report ("-icount is not allowed with hardware virtualization" ); -exit (1 ); - } -configure_icount (icount_opts, &error_abort); -qemu_opts_del (icount_opts); - } - -if (tcg_enabled ()) { -qemu_tcg_configure (accel_opts, &error_fatal); - } +configure_accelerators ();if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );
Signature · 1 line
1.8.3.1
Re: [PATCH 02/16] vl: extract accelerator option processing to a separate function
Hi
Quoted 33 lines · Paolo Bonzini
As a first step towards supporting multiple "-accel" options, push -icount and -accel semantics into a new function, and use
qemu_opts_foreachto retrieve the key/value lists instead of stashing them into globals.Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-)vl.c +15
-0@@ -2827,6 +2827,33 @@ static void user_register_global_props(void) global_init_func, NULL, NULL); } +static int do_configure_icount (void *opaque,QemuOpts *opts,Error **errp) +{ +if (tcg_enabled ()) { +configure_icount (opts, errp); + }else { +error_setg (errp,"-icount is not allowed with hardware virtualization" ); + } +return 0 ; +} + +static int do_configure_accelerator (void *opaque,QemuOpts *opts,Error **errp) +{ +if (tcg_enabled ()) { +qemu_tcg_configure (opts, &error_fatal); + }
vl.c static void user_register_global_props(void) · line 2854
Quoted 10 lines
vl.c +10
-0+return 0 ; +} + +static void configure_accelerators (void ) +{ +qemu_opts_foreach (qemu_find_opts ("icount" ), + do_configure_icount,NULL , &error_fatal); + +qemu_opts_foreach (qemu_find_opts ("accel" ), + do_configure_accelerator,NULL , &error_fatal);
It used to call qemu_tcg_configure() when no -accel option given. In this case, it still sets mttcg_enabled = default_mttcg_enabled(), but now it misses that. Perhaps it could be set earlier.
Quoted 30 lines
vl.c +3
-13+} +int main (int argc,char **argv,char **envp) {int i;@@ -4241,18 +4268,7 @@ int main(int argc, char **argv, char **envp)qemu_spice_init ();cpu_ticks_init (); -if (icount_opts) { -if (!tcg_enabled ()) { -error_report ("-icount is not allowed with hardware virtualization" ); -exit (1 ); - } -configure_icount (icount_opts, &error_abort); -qemu_opts_del (icount_opts); - } - -if (tcg_enabled ()) { -qemu_tcg_configure (accel_opts, &error_fatal); - } +configure_accelerators ();if (default_net) {QemuOptsList *net =qemu_find_opts ("net" ); --1.8.3.1
Signature · 1 line
Marc-André Lureau
Re: [PATCH 02/16] vl: extract accelerator option processing to a separate function
Quoted 7 lines · Marc-André Lureau
vl.c static void user_register_global_props(void) · line 2854
Quoted 3 lines
vl.c +3
-0+ +qemu_opts_foreach (qemu_find_opts ("accel" ), + do_configure_accelerator,NULL , &error_fatal);It used to call
qemu_tcg_configure()when no -accel option given. In this case, it still setsmttcg_enabled=default_mttcg_enabled(), but now it misses that. Perhaps it could be set earlier.
Oh, right. This is fixed later in the series, but I think in v2 I will move this to the TCG init function.
Paolo
Re: [PATCH 02/16] vl: extract accelerator option processing to a separate function
In reply to Paolo BonziniQuoted 33 lines · Paolo Bonzini
As a first step towards supporting multiple "-accel" options, push -icount and -accel semantics into a new function, and use
qemu_opts_foreachto retrieve the key/value lists instead of stashing them into globals.Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-)vl.c +16
-0@@ -2827,6 +2827,33 @@ static void user_register_global_props(void) global_init_func, NULL, NULL); } +static int do_configure_icount (void *opaque,QemuOpts *opts,Error **errp) +{ +if (tcg_enabled ()) { +configure_icount (opts, errp); + }else { +error_setg (errp,"-icount is not allowed with hardware virtualization" ); + } +return 0 ; +} + +static int do_configure_accelerator (void *opaque,QemuOpts *opts,Error **errp) +{ +if (tcg_enabled ()) { +qemu_tcg_configure (opts, &error_fatal); + } +return 0 ;
vl.c static void user_register_global_props(void) · line 2855
Quoted 10 lines
vl.c +10
-0+} + +static void configure_accelerators (void ) +{ +qemu_opts_foreach (qemu_find_opts ("icount" ), + do_configure_icount,NULL , &error_fatal); + +qemu_opts_foreach (qemu_find_opts ("accel" ), + do_configure_accelerator,NULL , &error_fatal); +}
vl.c is already quite overcrowded ... maybe you could add the new code to accel/accel.c instead? Just my 0.02 €.
Thomas
Re: [PATCH 02/16] vl: extract accelerator option processing to a separate function
Quoted 11 lines · Thomas Huth
vl.c static void user_register_global_props(void) · line 2855
Quoted 8 lines
vl.c +8
-0+static void configure_accelerators (void ) +{ +qemu_opts_foreach (qemu_find_opts ("icount" ), + do_configure_icount,NULL , &error_fatal); + +qemu_opts_foreach (qemu_find_opts ("accel" ), + do_configure_accelerator,NULL , &error_fatal); +}
vl.cis already quite overcrowded ... maybe you could add the new code toaccel/accel.cinstead? Just my 0.02 €.
I liked the idea of keeping all command line parsing in vl.c, especially because all the ugliness for backwards compatibility can then be confined there.
Paolo
PATCH 3/16 vl: merge -accel processing into configure_accelerators
In reply to Paolo BonziniThe next step is to move the parsing of "-machine accel=..." into vl.c, unifying it with the configure_accelerators() function that has just been introduced. This way, we will be able to desugar it into multiple "-accel" options, without polluting accel/accel.c.
The CONFIG_TCG and CONFIG_KVM symbols are not available in vl.c, but we can use accel_find instead to find their value at runtime. Once we know that the binary has one of TCG or KVM, the default accelerator can be expressed simply as "tcg:kvm", because TCG never fails to initialize.
--- accel/accel.c | 63 ++------------------------------------------------ include/sysemu/accel.h | 4 +++- vl.c | 62 +++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 67 deletions(-)
accel/accel.c +2 -61
@@ -44,7 +44,7 @@ static const TypeInfo accel_type = { };/* Lookup AccelClass from opt_name. Returns NULL if not found */ -static AccelClass *accel_find (const char *opt_name) +AccelClass *accel_find (const char *opt_name) {char *class_name =g_strdup_printf (ACCEL_CLASS_NAME ("%s" ), opt_name);AccelClass *ac =ACCEL_CLASS (object_class_by_name (class_name));
@@ -52,7 +52,7 @@ static AccelClass *accel_find(const char *opt_name)return ac; } -static int accel_init_machine (AccelClass *acc,MachineState *ms) +int accel_init_machine (AccelClass *acc,MachineState *ms) {ObjectClass *oc =OBJECT_CLASS (acc);const char *cname =object_class_get_name (oc);
@@ -71,65 +71,6 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms)return ret; } -void configure_accelerator (MachineState *ms,const char *progname) -{ -const char *accel; -char **accel_list, **tmp; -int ret; -bool accel_initialised = false; -bool init_failed = false; -AccelClass *acc =NULL ; - - accel =qemu_opt_get (qemu_get_machine_opts (),"accel" ); -if (accel ==NULL ) { -/* Select the default accelerator */ -int pnlen =strlen (progname); -if (pnlen >=3 &&g_str_equal (&progname[pnlen -3 ],"kvm" )) { -/* If the program name ends with "kvm", we prefer KVM */ - accel ="kvm:tcg" ; - }else { -#if defined(CONFIG_TCG ) - accel ="tcg" ; -#elif defined(CONFIG_KVM ) - accel ="kvm" ; -#else -error_report ("No accelerator selected and" -" no default accelerator available" ); -exit (1 ); -#endif - } - } - - accel_list =g_strsplit (accel,":" ,0 ); - -for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { - acc =accel_find (*tmp); -if (!acc) { -continue ; - } - ret =accel_init_machine (acc, ms); -if (ret <0 ) { - init_failed = true; -error_report ("failed to initialize %s: %s" , - acc->name,strerror (-ret)); - }else { - accel_initialised = true; - } - } -g_strfreev (accel_list); - -if (!accel_initialised) { -if (!init_failed) { -error_report ("-machine accel=%s: No accelerator found" , accel); - } -exit (1 ); - } - -if (init_failed) { -error_report ("Back to %s accelerator" , acc->name); - } -} -void accel_setup_post (MachineState *ms) {AccelState *accel = ms->accelerator;
include/sysemu/accel.h +3 -1
@@ -66,7 +66,9 @@ typedef struct AccelClass {extern unsigned long tcg_tb_size; -void configure_accelerator (MachineState *ms,const char *progname); +AccelClass *accel_find (const char *opt_name); +int accel_init_machine (AccelClass *acc,MachineState *ms); +/* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post (MachineState *ms);
vl.c +57 -5
81 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH 03/16] vl: merge -accel processing into configure_accelerators
Hi
Quoted 11 lines · Paolo Bonzini
The next step is to move the parsing of "-machine accel=..." into
vl.c, unifying it with theconfigure_accelerators()function that has just been introduced. This way, we will be able to desugar it into multiple "-accel" options, without pollutingaccel/accel.c.The
CONFIG_TCGandCONFIG_KVMsymbols are not available invl.c, but we can useaccel_findinstead to find their value at runtime. Once we know that the binary has one of TCG or KVM, the default accelerator can be expressed simply as "tcg:kvm", because TCG never fails to initialize.
Quoted 203 lines
Signed-off-by Paolo Bonzini <[email protected]>--- accel/accel.c | 63 ++------------------------------------------------ include/sysemu/accel.h | 4 +++- vl.c | 62 +++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 67 deletions(-)accel/accel.c +2
-61@@ -44,7 +44,7 @@ static const TypeInfo accel_type = { };/* Lookup AccelClass from opt_name. Returns NULL if not found */ -static AccelClass *accel_find (const char *opt_name) +AccelClass *accel_find (const char *opt_name) {char *class_name =g_strdup_printf (ACCEL_CLASS_NAME ("%s" ), opt_name);AccelClass *ac =ACCEL_CLASS (object_class_by_name (class_name));@@ -52,7 +52,7 @@ static AccelClass *accel_find(const char *opt_name)return ac; } -static int accel_init_machine (AccelClass *acc,MachineState *ms) +int accel_init_machine (AccelClass *acc,MachineState *ms) {ObjectClass *oc =OBJECT_CLASS (acc);const char *cname =object_class_get_name (oc);@@ -71,65 +71,6 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms)return ret; } -void configure_accelerator (MachineState *ms,const char *progname) -{ -const char *accel; -char **accel_list, **tmp; -int ret; -bool accel_initialised = false; -bool init_failed = false; -AccelClass *acc =NULL ; - - accel =qemu_opt_get (qemu_get_machine_opts (),"accel" ); -if (accel ==NULL ) { -/* Select the default accelerator */ -int pnlen =strlen (progname); -if (pnlen >=3 &&g_str_equal (&progname[pnlen -3 ],"kvm" )) { -/* If the program name ends with "kvm", we prefer KVM */ - accel ="kvm:tcg" ; - }else { -#if defined(CONFIG_TCG ) - accel ="tcg" ; -#elif defined(CONFIG_KVM ) - accel ="kvm" ; -#else -error_report ("No accelerator selected and" -" no default accelerator available" ); -exit (1 ); -#endif - } - } - - accel_list =g_strsplit (accel,":" ,0 ); - -for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { - acc =accel_find (*tmp); -if (!acc) { -continue ; - } - ret =accel_init_machine (acc, ms); -if (ret <0 ) { - init_failed = true; -error_report ("failed to initialize %s: %s" , - acc->name,strerror (-ret)); - }else { - accel_initialised = true; - } - } -g_strfreev (accel_list); - -if (!accel_initialised) { -if (!init_failed) { -error_report ("-machine accel=%s: No accelerator found" , accel); - } -exit (1 ); - } - -if (init_failed) { -error_report ("Back to %s accelerator" , acc->name); - } -} -void accel_setup_post (MachineState *ms) {AccelState *accel = ms->accelerator;include/sysemu/accel.h +3
-1@@ -66,7 +66,9 @@ typedef struct AccelClass {extern unsigned long tcg_tb_size; -void configure_accelerator (MachineState *ms,const char *progname); +AccelClass *accel_find (const char *opt_name); +int accel_init_machine (AccelClass *acc,MachineState *ms); +/* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post (MachineState *ms);vl.c +57
-6@@ -2845,8 +2845,62 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } -static void configure_accelerators (void ) +static void configure_accelerators (const char *progname) { +const char *accel; +char **accel_list, **tmp; +int ret; +bool accel_initialised = false; +bool init_failed = false; +AccelClass *acc =NULL ; + + accel =qemu_opt_get (qemu_get_machine_opts (),"accel" ); +if (accel ==NULL ) { +/* Select the default accelerator */ +if (!accel_find ("tcg" ) && !accel_find ("kvm" )) { +error_report ("No accelerator selected and" +" no default accelerator available" ); +exit (1 ); + }else { +int pnlen =strlen (progname); +if (pnlen >=3 &&g_str_equal (&progname[pnlen -3 ],"kvm" )) { +/* If the program name ends with "kvm", we prefer KVM */ + accel ="kvm:tcg" ; + }else { + accel ="tcg:kvm" ; + } + } + } + + accel_list =g_strsplit (accel,":" ,0 ); + +for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { + acc =accel_find (*tmp); +if (!acc) { +continue ; + } + ret =accel_init_machine (acc, current_machine); +if (ret <0 ) { + init_failed = true; +error_report ("failed to initialize %s: %s" , + acc->name,strerror (-ret)); + }else { + accel_initialised = true; + } + } +g_strfreev (accel_list); + +if (!accel_initialised) { +if (!init_failed) { +error_report ("-machine accel=%s: No accelerator found" , accel); + } +exit (1 ); + } + +if (init_failed) { +error_report ("Back to %s accelerator" , acc->name); + } +qemu_opts_foreach (qemu_find_opts ("icount" ), do_configure_icount,NULL , &error_fatal);@@ -4183,7 +4237,8 @@ int main(int argc, char **argv, char **envp)* Note: uses machine properties such as kernel-irqchip, must run * after machine_set_property(). */ -configure_accelerator (current_machine, argv[0 ]); +cpu_ticks_init (); +configure_accelerators (argv[0 ]);/* * Beware, QOM objects created before this point miss global and @@ -4267,9 +4322,6 @@ int main(int argc, char **argv, char **envp)/* spice needs the timers to be initialized by this point */ qemu_spice_init (); -cpu_ticks_init (); -configure_accelerators (); -if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort); --1.8.3.1
Signature · 1 line
Marc-André Lureau
Re: [PATCH 03/16] vl: merge -accel processing into configure_accelerators
In reply to Paolo BonziniQuoted 189 lines · Paolo Bonzini
The next step is to move the parsing of "-machine accel=..." into
vl.c, unifying it with theconfigure_accelerators()function that has just been introduced. This way, we will be able to desugar it into multiple "-accel" options, without pollutingaccel/accel.c.The
CONFIG_TCGandCONFIG_KVMsymbols are not available invl.c, but we can useaccel_findinstead to find their value at runtime. Once we know that the binary has one of TCG or KVM, the default accelerator can be expressed simply as "tcg:kvm", because TCG never fails to initialize.Signed-off-by Paolo Bonzini <[email protected]>--- accel/accel.c | 63 ++------------------------------------------------ include/sysemu/accel.h | 4 +++- vl.c | 62 +++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 67 deletions(-)accel/accel.c +2
-61@@ -44,7 +44,7 @@ static const TypeInfo accel_type = { };/* Lookup AccelClass from opt_name. Returns NULL if not found */ -static AccelClass *accel_find (const char *opt_name) +AccelClass *accel_find (const char *opt_name) {char *class_name =g_strdup_printf (ACCEL_CLASS_NAME ("%s" ), opt_name);AccelClass *ac =ACCEL_CLASS (object_class_by_name (class_name));@@ -52,7 +52,7 @@ static AccelClass *accel_find(const char *opt_name)return ac; } -static int accel_init_machine (AccelClass *acc,MachineState *ms) +int accel_init_machine (AccelClass *acc,MachineState *ms) {ObjectClass *oc =OBJECT_CLASS (acc);const char *cname =object_class_get_name (oc);@@ -71,65 +71,6 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms)return ret; } -void configure_accelerator (MachineState *ms,const char *progname) -{ -const char *accel; -char **accel_list, **tmp; -int ret; -bool accel_initialised = false; -bool init_failed = false; -AccelClass *acc =NULL ; - - accel =qemu_opt_get (qemu_get_machine_opts (),"accel" ); -if (accel ==NULL ) { -/* Select the default accelerator */ -int pnlen =strlen (progname); -if (pnlen >=3 &&g_str_equal (&progname[pnlen -3 ],"kvm" )) { -/* If the program name ends with "kvm", we prefer KVM */ - accel ="kvm:tcg" ; - }else { -#if defined(CONFIG_TCG ) - accel ="tcg" ; -#elif defined(CONFIG_KVM ) - accel ="kvm" ; -#else -error_report ("No accelerator selected and" -" no default accelerator available" ); -exit (1 ); -#endif - } - } - - accel_list =g_strsplit (accel,":" ,0 ); - -for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { - acc =accel_find (*tmp); -if (!acc) { -continue ; - } - ret =accel_init_machine (acc, ms); -if (ret <0 ) { - init_failed = true; -error_report ("failed to initialize %s: %s" , - acc->name,strerror (-ret)); - }else { - accel_initialised = true; - } - } -g_strfreev (accel_list); - -if (!accel_initialised) { -if (!init_failed) { -error_report ("-machine accel=%s: No accelerator found" , accel); - } -exit (1 ); - } - -if (init_failed) { -error_report ("Back to %s accelerator" , acc->name); - } -} -void accel_setup_post (MachineState *ms) {AccelState *accel = ms->accelerator;include/sysemu/accel.h +3
-1@@ -66,7 +66,9 @@ typedef struct AccelClass {extern unsigned long tcg_tb_size; -void configure_accelerator (MachineState *ms,const char *progname); +AccelClass *accel_find (const char *opt_name); +int accel_init_machine (AccelClass *acc,MachineState *ms); +/* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post (MachineState *ms);vl.c +55
-1@@ -2845,8 +2845,62 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } -static void configure_accelerators (void ) +static void configure_accelerators (const char *progname) { +const char *accel; +char **accel_list, **tmp; +int ret; +bool accel_initialised = false; +bool init_failed = false; +AccelClass *acc =NULL ; + + accel =qemu_opt_get (qemu_get_machine_opts (),"accel" ); +if (accel ==NULL ) { +/* Select the default accelerator */ +if (!accel_find ("tcg" ) && !accel_find ("kvm" )) { +error_report ("No accelerator selected and" +" no default accelerator available" ); +exit (1 ); + }else { +int pnlen =strlen (progname); +if (pnlen >=3 &&g_str_equal (&progname[pnlen -3 ],"kvm" )) { +/* If the program name ends with "kvm", we prefer KVM */ + accel ="kvm:tcg" ; + }else { + accel ="tcg:kvm" ; + } + } + } + + accel_list =g_strsplit (accel,":" ,0 ); + +for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { + acc =accel_find (*tmp); +if (!acc) { +continue ; + } + ret =accel_init_machine (acc, current_machine); +if (ret <0 ) { + init_failed = true; +error_report ("failed to initialize %s: %s" , + acc->name,strerror (-ret)); + }else { + accel_initialised = true; + } + } +g_strfreev (accel_list); + +if (!accel_initialised) { +if (!init_failed) { +error_report ("-machine accel=%s: No accelerator found" , accel); + } +exit (1 ); + } + +if (init_failed) { +error_report ("Back to %s accelerator" , acc->name); + } +qemu_opts_foreach (qemu_find_opts ("icount" ), do_configure_icount,NULL , &error_fatal);
vl.c int main(int argc, char **argv, char **envp) · line 4241
Quoted 6 lines
vl.c +2
-1@@ -4183,7 +4237,8 @@ int main(int argc, char **argv, char **envp)* Note: uses machine properties such as kernel-irqchip, must run * after machine_set_property(). */ -configure_accelerator (current_machine, argv[0 ]); +cpu_ticks_init (); +configure_accelerators (argv[0 ]);
The comment about kernel-irqchip obviously rather belongs to configure_accelerators() instead of cpu_ticks_init(), so maybe you should move the cpu_ticks_init() before the comment now? (does it need to be moved here at all? ... it looks pretty independent at a first glance)
Thomas
Re: [PATCH 03/16] vl: merge -accel processing into configure_accelerators
Quoted 9 lines · Thomas Huth
vl.c int main(int argc, char **argv, char **envp) · line 4241
Quoted 6 lines
* Note: uses machine properties such as kernel-irqchip, must run
* aftermachine_set_property().
*/vl.c +2
-1-configure_accelerator (current_machine, argv[0 ]); +cpu_ticks_init (); +configure_accelerators (argv[0 ]);The comment about kernel-irqchip obviously rather belongs to
configure_accelerators()instead ofcpu_ticks_init(), so maybe you should move thecpu_ticks_init()before the comment now?
Ok.
Quoted 2 lines
(does it need
to be moved here at all? ... it looks pretty independent at a first glance)
No, it doesn't. Whether to move it or not is a matter of personal preference, so I can certainly move it back.
Paolo
Re: [PATCH 03/16] vl: merge -accel processing into configure_accelerators
In reply to Paolo BonziniQuoted 10 lines · Paolo Bonzini
The next step is to move the parsing of "-machine accel=..." into
vl.c, unifying it with theconfigure_accelerators()function that has just been introduced. This way, we will be able to desugar it into multiple "-accel" options, without pollutingaccel/accel.c.The
CONFIG_TCGandCONFIG_KVMsymbols are not available invl.c, but we can useaccel_findinstead to find their value at runtime. Once we know that the binary has one of TCG or KVM, the default accelerator can be expressed simply as "tcg:kvm", because TCG never fails to initialize.
Quoted 6 lines
Signed-off-by Paolo Bonzini <[email protected]>--- accel/accel.c | 63 ++------------------------------------------------ include/sysemu/accel.h | 4 +++- vl.c | 62 +++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 67 deletions(-)
Quoted 192 lines
accel/accel.c +2
-61@@ -44,7 +44,7 @@ static const TypeInfo accel_type = { };/* Lookup AccelClass from opt_name. Returns NULL if not found */ -static AccelClass *accel_find (const char *opt_name) +AccelClass *accel_find (const char *opt_name) {char *class_name =g_strdup_printf (ACCEL_CLASS_NAME ("%s" ), opt_name);AccelClass *ac =ACCEL_CLASS (object_class_by_name (class_name));@@ -52,7 +52,7 @@ static AccelClass *accel_find(const char *opt_name)return ac; } -static int accel_init_machine (AccelClass *acc,MachineState *ms) +int accel_init_machine (AccelClass *acc,MachineState *ms) {ObjectClass *oc =OBJECT_CLASS (acc);const char *cname =object_class_get_name (oc);@@ -71,65 +71,6 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms)return ret; } -void configure_accelerator (MachineState *ms,const char *progname) -{ -const char *accel; -char **accel_list, **tmp; -int ret; -bool accel_initialised = false; -bool init_failed = false; -AccelClass *acc =NULL ; - - accel =qemu_opt_get (qemu_get_machine_opts (),"accel" ); -if (accel ==NULL ) { -/* Select the default accelerator */ -int pnlen =strlen (progname); -if (pnlen >=3 &&g_str_equal (&progname[pnlen -3 ],"kvm" )) { -/* If the program name ends with "kvm", we prefer KVM */ - accel ="kvm:tcg" ; - }else { -#if defined(CONFIG_TCG ) - accel ="tcg" ; -#elif defined(CONFIG_KVM ) - accel ="kvm" ; -#else -error_report ("No accelerator selected and" -" no default accelerator available" ); -exit (1 ); -#endif - } - } - - accel_list =g_strsplit (accel,":" ,0 ); - -for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { - acc =accel_find (*tmp); -if (!acc) { -continue ; - } - ret =accel_init_machine (acc, ms); -if (ret <0 ) { - init_failed = true; -error_report ("failed to initialize %s: %s" , - acc->name,strerror (-ret)); - }else { - accel_initialised = true; - } - } -g_strfreev (accel_list); - -if (!accel_initialised) { -if (!init_failed) { -error_report ("-machine accel=%s: No accelerator found" , accel); - } -exit (1 ); - } - -if (init_failed) { -error_report ("Back to %s accelerator" , acc->name); - } -} -void accel_setup_post (MachineState *ms) {AccelState *accel = ms->accelerator;include/sysemu/accel.h +3
-1@@ -66,7 +66,9 @@ typedef struct AccelClass {extern unsigned long tcg_tb_size; -void configure_accelerator (MachineState *ms,const char *progname); +AccelClass *accel_find (const char *opt_name); +int accel_init_machine (AccelClass *acc,MachineState *ms); +/* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post (MachineState *ms);vl.c +57
-5@@ -2845,8 +2845,62 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } -static void configure_accelerators (void ) +static void configure_accelerators (const char *progname) { +const char *accel; +char **accel_list, **tmp; +int ret; +bool accel_initialised = false; +bool init_failed = false; +AccelClass *acc =NULL ; + + accel =qemu_opt_get (qemu_get_machine_opts (),"accel" ); +if (accel ==NULL ) { +/* Select the default accelerator */ +if (!accel_find ("tcg" ) && !accel_find ("kvm" )) { +error_report ("No accelerator selected and" +" no default accelerator available" ); +exit (1 ); + }else { +int pnlen =strlen (progname); +if (pnlen >=3 &&g_str_equal (&progname[pnlen -3 ],"kvm" )) { +/* If the program name ends with "kvm", we prefer KVM */ + accel ="kvm:tcg" ; + }else { + accel ="tcg:kvm" ; + } + } + } + + accel_list =g_strsplit (accel,":" ,0 ); + +for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { + acc =accel_find (*tmp); +if (!acc) { +continue ; + } + ret =accel_init_machine (acc, current_machine); +if (ret <0 ) { + init_failed = true; +error_report ("failed to initialize %s: %s" , + acc->name,strerror (-ret)); + }else { + accel_initialised = true; + } + } +g_strfreev (accel_list); + +if (!accel_initialised) { +if (!init_failed) { +error_report ("-machine accel=%s: No accelerator found" , accel); + } +exit (1 ); + } + +if (init_failed) { +error_report ("Back to %s accelerator" , acc->name); + } +qemu_opts_foreach (qemu_find_opts ("icount" ), do_configure_icount,NULL , &error_fatal);@@ -4183,7 +4237,8 @@ int main(int argc, char **argv, char **envp)* Note: uses machine properties such as kernel-irqchip, must run * after machine_set_property(). */ -configure_accelerator (current_machine, argv[0 ]); +cpu_ticks_init (); +configure_accelerators (argv[0 ]);/* * Beware, QOM objects created before this point miss global and @@ -4267,9 +4322,6 @@ int main(int argc, char **argv, char **envp)/* spice needs the timers to be initialized by this point */ qemu_spice_init (); -cpu_ticks_init (); -configure_accelerators (); -if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );qemu_opts_set (net,NULL ,"type" ,"nic" , &error_abort);
PATCH 4/16 vl: move icount configuration earlier
In reply to Paolo BonziniOnce qemu_tcg_configure is turned into a QOM property setter, it will not be able to set a default value for mttcg_enabled. Setting the default will move to the TCG init_machine method, which currently runs after "-icount" is processed.
However, it is harmless to do configure_icount for all accelerators; we will just fail later if a non-TCG accelerator being selected. So do that.
--- vl.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
vl.c +9 -8
@@ -2829,11 +2829,7 @@ static void user_register_global_props(void)static int do_configure_icount (void *opaque,QemuOpts *opts,Error **errp) { -if (tcg_enabled ()) { -configure_icount (opts, errp); - }else { -error_setg (errp,"-icount is not allowed with hardware virtualization" ); - } +configure_icount (opts, errp);return 0 ; }
@@ -2854,6 +2850,9 @@ static void configure_accelerators(const char *progname)bool init_failed = false;AccelClass *acc =NULL ; +qemu_opts_foreach (qemu_find_opts ("icount" ), + do_configure_icount,NULL , &error_fatal); + accel =qemu_opt_get (qemu_get_machine_opts (),"accel" );if (accel ==NULL ) {/* Select the default accelerator */
@@ -2901,11 +2900,13 @@ static void configure_accelerators(const char *progname)error_report ("Back to %s accelerator" , acc->name); } -qemu_opts_foreach (qemu_find_opts ("icount" ), - do_configure_icount,NULL , &error_fatal); -qemu_opts_foreach (qemu_find_opts ("accel" ), do_configure_accelerator,NULL , &error_fatal); + +if (!tcg_enabled () && use_icount) { +error_report ("-icount is not allowed with hardware virtualization" ); +exit (1 ); + } }int main (int argc,char **argv,char **envp)
Signature · 1 line
1.8.3.1
Re: [PATCH 04/16] vl: move icount configuration earlier
Quoted 10 lines · Paolo Bonzini
Once
qemu_tcg_configureis turned into a QOM property setter, it will not be able to set a default value formttcg_enabled. Setting the default will move to the TCGinit_machinemethod, which currently runs after "-icount" is processed.However, it is harmless to do
configure_icountfor all accelerators; we will just fail later if a non-TCG accelerator being selected. So do that.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 49 lines
--- vl.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)vl.c +9
-9@@ -2829,11 +2829,7 @@ static void user_register_global_props(void)static int do_configure_icount (void *opaque,QemuOpts *opts,Error **errp) { -if (tcg_enabled ()) { -configure_icount (opts, errp); - }else { -error_setg (errp,"-icount is not allowed with hardware virtualization" ); - } +configure_icount (opts, errp);return 0 ; }@@ -2854,6 +2850,9 @@ static void configure_accelerators(const char *progname)bool init_failed = false;AccelClass *acc =NULL ; +qemu_opts_foreach (qemu_find_opts ("icount" ), + do_configure_icount,NULL , &error_fatal); + accel =qemu_opt_get (qemu_get_machine_opts (),"accel" );if (accel ==NULL ) {/* Select the default accelerator */ @@ -2901,11 +2900,13 @@ static void configure_accelerators(const char *progname)error_report ("Back to %s accelerator" , acc->name); } -qemu_opts_foreach (qemu_find_opts ("icount" ), - do_configure_icount,NULL , &error_fatal); -qemu_opts_foreach (qemu_find_opts ("accel" ), do_configure_accelerator,NULL , &error_fatal); + +if (!tcg_enabled () && use_icount) { +error_report ("-icount is not allowed with hardware virtualization" ); +exit (1 ); + } }int main (int argc,char **argv,char **envp) --
Quoted 4 lines
1.8.3.1
--
Marc-André Lureau
Re: [PATCH 04/16] vl: move icount configuration earlier
In reply to Paolo BonziniQuoted 5 lines · Paolo Bonzini
Once
qemu_tcg_configureis turned into a QOM property setter, it will not be able to set a default value formttcg_enabled. Setting the default will move to the TCGinit_machinemethod, which currently runs after "-icount" is processed.
Quoted 7 lines
However, it is harmless to do
configure_icountfor all accelerators; we will just fail later if a non-TCG accelerator being selected. So do that.Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
PATCH 5/16 vl: introduce object_parse_property_opt
In reply to Paolo BonziniWe will reuse the parsing loop of machine_set_property soon for "-accel", but we do not want the "_" -> "-" conversion since "-accel" can just standardize on dashes. We will also add a bunch of legacy option handling to keep the QOM machine object clean. Extract the loop into a separate function, and keep the legacy handling in machine_set_property.
--- vl.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)
vl.c +23 -15
@@ -2617,27 +2617,17 @@ static MachineClass *select_machine(void)return machine_class; } -static int machine_set_property (void *opaque, -const char *name,const char *value, -Error **errp) +static int object_parse_property_opt (Object *obj, +const char *name,const char *value, +const char *skip,Error **errp) { -Object *obj =OBJECT (opaque);Error *local_err =NULL ; -char *p, *qom_name; -if (strcmp (name,"type" ) ==0 ) { +if (g_str_equal (name, skip)) {return 0 ; } - qom_name =g_strdup (name); -for (p = qom_name; *p; p++) { -if (*p =='_' ) { - *p ='-' ; - } - } - -object_property_parse (obj, value, qom_name, &local_err); -g_free (qom_name); +object_property_parse (obj, value, name, &local_err);if (local_err) {error_propagate (errp, local_err);
@@ -2647,6 +2637,24 @@ static int machine_set_property(void *opaque,return 0 ; } +static int machine_set_property (void *opaque, +const char *name,const char *value, +Error **errp) +{ +char *qom_name =g_strdup (name); +char *p; +int r; + +for (p = qom_name; *p; p++) { +if (*p =='_' ) { + *p ='-' ; + } + } + + r =object_parse_property_opt (opaque, name, value,"type" , errp); +g_free (qom_name); +return r; +}/* * Initial object creation happens before all other
Signature · 1 line
1.8.3.1
Re: [PATCH 05/16] vl: introduce object_parse_property_opt
Quoted 50 lines · Paolo Bonzini
We will reuse the parsing loop of
machine_set_propertysoon for "-accel", but we do not want the "_" -> "-" conversion since "-accel" can just standardize on dashes. We will also add a bunch of legacy option handling to keep the QOM machine object clean. Extract the loop into a separate function, and keep the legacy handling inmachine_set_property.Signed-off-by Paolo Bonzini <[email protected]>--- vl.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)vl.c +5
-15@@ -2617,27 +2617,17 @@ static MachineClass *select_machine(void)return machine_class; } -static int machine_set_property (void *opaque, -const char *name,const char *value, -Error **errp) +static int object_parse_property_opt (Object *obj, +const char *name,const char *value, +const char *skip,Error **errp) { -Object *obj =OBJECT (opaque);Error *local_err =NULL ; -char *p, *qom_name; -if (strcmp (name,"type" ) ==0 ) { +if (g_str_equal (name, skip)) {return 0 ; } - qom_name =g_strdup (name); -for (p = qom_name; *p; p++) { -if (*p =='_' ) { - *p ='-' ; - } - } - -object_property_parse (obj, value, qom_name, &local_err); -g_free (qom_name); +object_property_parse (obj, value, name, &local_err);if (local_err) {error_propagate (errp, local_err);
vl.c static int machine_set_property(void *opaque, · line 2644
Quoted 8 lines
vl.c +5
-0@@ -2647,6 +2637,24 @@ static int machine_set_property(void *opaque,return 0 ; } +static int machine_set_property (void *opaque, +const char *name,const char *value, +Error **errp) +{ +char *qom_name =g_strdup (name);
Could use g_autofree, and thus return directly without r.
vl.c static int machine_set_property(void *opaque, · line 2654
Quoted 10 lines
vl.c +10
-0+char *p; +int r; + +for (p = qom_name; *p; p++) { +if (*p =='_' ) { + *p ='-' ; + } + } + + r =object_parse_property_opt (opaque, name, value,"type" , errp);
You want to pass qom_name, I guess
Quoted 11 lines
vl.c +3
-1+g_free (qom_name); +return r; +}/* * Initial object creation happens before all other -- 1.8.3.1
--
Marc-André Lureau
Re: [PATCH 05/16] vl: introduce object_parse_property_opt
Quoted 3 lines · Marc-André Lureau
vl.c static int machine_set_property(void *opaque, · line 2644
Quoted 2 lines
vl.c +2
-0+{ +char *qom_name =g_strdup (name);Could use
g_autofree, and thus return directly without r.
And avoid a bunch of memory leaks in the rest of the series.
Paolo
PATCH 6/16 vl: configure accelerators from -accel options
In reply to Paolo BonziniDrop the "accel" property from MachineState, and instead desugar "-machine accel=" to a list of "-accel" options.
This has a semantic change due to removing merge_lists from -accel. For example:
- "-accel kvm -accel tcg" all but ignored "-accel kvm". This is a bugfix.
- "-accel kvm -accel thread=single" ignored "thread=single", since it applied the option to KVM. Now it fails due to not specifying the accelerator on "-accel thread=single".
- "-accel tcg -accel thread=single" chose single-threaded TCG, while now it will fail due to not specifying the accelerator on "-accel thread=single".
Also, "-machine accel" and "-accel" become incompatible.
--- hw/core/machine.c | 21 ------------ include/hw/boards.h | 1 - vl.c | 93 +++++++++++++++++++++++++++++++---------------------- 3 files changed, 54 insertions(+), 61 deletions(-)
hw/core/machine.c +0 -21
@@ -173,21 +173,6 @@ GlobalProperty hw_compat_2_1[] = { };const size_t hw_compat_2_1_len =G_N_ELEMENTS (hw_compat_2_1); -static char *machine_get_accel (Object *obj,Error **errp) -{ -MachineState *ms =MACHINE (obj); - -return g_strdup (ms->accel); -} - -static void machine_set_accel (Object *obj,const char *value,Error **errp) -{ -MachineState *ms =MACHINE (obj); - -g_free (ms->accel); - ms->accel =g_strdup (value); -} -static void machine_set_kernel_irqchip (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp)
@@ -808,11 +793,6 @@ static void machine_class_init(ObjectClass *oc, void *data) mc->numa_mem_align_shift =23 ; mc->numa_auto_assign_ram = numa_default_auto_assign_ram; -object_class_property_add_str (oc,"accel" , - machine_get_accel, machine_set_accel, &error_abort); -object_class_property_set_description (oc,"accel" , -"Accelerator list" , &error_abort); -object_class_property_add (oc,"kernel-irqchip" ,"on|off|split" ,NULL , machine_set_kernel_irqchip,NULL ,NULL , &error_abort);
@@ -971,7 +951,6 @@ static void machine_finalize(Object *obj) {MachineState *ms =MACHINE (obj); -g_free (ms->accel);g_free (ms->kernel_filename);g_free (ms->initrd_filename);g_free (ms->kernel_cmdline);
include/hw/boards.h +0 -1
@@ -275,7 +275,6 @@ struct MachineState {/*< public >*/ -char *accel;bool kernel_irqchip_allowed;bool kernel_irqchip_required;bool kernel_irqchip_split;
vl.c +54 -39
150 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH 06/16] vl: configure accelerators from -accel options
Quoted 142 lines · Paolo Bonzini
Drop the "accel" property from MachineState, and instead desugar "-machine accel=" to a list of "-accel" options.
This has a semantic change due to removing
merge_listsfrom -accel. For example:- "-accel kvm -accel tcg" all but ignored "-accel kvm". This is a bugfix.
- "-accel kvm -accel thread=single" ignored "thread=single", since it applied the option to KVM. Now it fails due to not specifying the accelerator on "-accel thread=single".
- "-accel tcg -accel thread=single" chose single-threaded TCG, while now it will fail due to not specifying the accelerator on "-accel thread=single".
Also, "-machine accel" and "-accel" become incompatible.
Signed-off-by Paolo Bonzini <[email protected]>--- hw/core/machine.c | 21 ------------ include/hw/boards.h | 1 - vl.c | 93 +++++++++++++++++++++++++++++++---------------------- 3 files changed, 54 insertions(+), 61 deletions(-)hw/core/machine.c +0
-21@@ -173,21 +173,6 @@ GlobalProperty hw_compat_2_1[] = { };const size_t hw_compat_2_1_len =G_N_ELEMENTS (hw_compat_2_1); -static char *machine_get_accel (Object *obj,Error **errp) -{ -MachineState *ms =MACHINE (obj); - -return g_strdup (ms->accel); -} - -static void machine_set_accel (Object *obj,const char *value,Error **errp) -{ -MachineState *ms =MACHINE (obj); - -g_free (ms->accel); - ms->accel =g_strdup (value); -} -static void machine_set_kernel_irqchip (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp)@@ -808,11 +793,6 @@ static void machine_class_init(ObjectClass *oc, void *data) mc->numa_mem_align_shift =23 ; mc->numa_auto_assign_ram = numa_default_auto_assign_ram; -object_class_property_add_str (oc,"accel" , - machine_get_accel, machine_set_accel, &error_abort); -object_class_property_set_description (oc,"accel" , -"Accelerator list" , &error_abort); -object_class_property_add (oc,"kernel-irqchip" ,"on|off|split" ,NULL , machine_set_kernel_irqchip,NULL ,NULL , &error_abort);@@ -971,7 +951,6 @@ static void machine_finalize(Object *obj) {MachineState *ms =MACHINE (obj); -g_free (ms->accel);g_free (ms->kernel_filename);g_free (ms->initrd_filename);g_free (ms->kernel_cmdline);include/hw/boards.h +0
-1@@ -275,7 +275,6 @@ struct MachineState {/*< public >*/ -char *accel;bool kernel_irqchip_allowed;bool kernel_irqchip_required;bool kernel_irqchip_split;vl.c +22
-4@@ -293,7 +293,6 @@ static QemuOptsList qemu_accel_opts = { .name = "accel", .implied_opt_name = "accel", .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head), - .merge_lists = true, .desc = { { .name = "accel",@@ -2651,6 +2650,11 @@ static int machine_set_property(void *opaque, } } +/* Legacy options do not correspond to MachineState properties. */ +if (g_str_equal (qom_name,"accel" )) { +return 0 ; + } + r =object_parse_property_opt (opaque, name, value,"type" , errp);g_free (qom_name);return r;@@ -2843,74 +2847,88 @@ static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp)static int do_configure_accelerator (void *opaque,QemuOpts *opts,Error **errp) { +bool *p_init_failed = opaque; +const char *acc =qemu_opt_get (opts,"accel" ); +AccelClass *ac =accel_find (acc); +int ret; + +if (!ac) { +return 0 ; + } + ret =accel_init_machine (ac, current_machine); +if (ret <0 ) { + *p_init_failed = true; +error_report ("failed to initialize %s: %s" , + acc,strerror (-ret)); +return 0 ; + } +if (tcg_enabled ()) {qemu_tcg_configure (opts, &error_fatal); } -return 0 ; +return 1 ; }static void configure_accelerators (const char *progname) {const char *accel;char **accel_list, **tmp; -int ret;bool accel_initialised = false;bool init_failed = false; -AccelClass *acc =NULL ;
vl.c static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp) · line 2869
Quoted 10 lines
vl.c +0
-5qemu_opts_foreach (qemu_find_opts ("icount" ), do_configure_icount,NULL , &error_fatal); accel =qemu_opt_get (qemu_get_machine_opts (),"accel" ); -if (accel ==NULL ) { -/* Select the default accelerator */ -if (!accel_find ("tcg" ) && !accel_find ("kvm" )) { -error_report ("No accelerator selected and" -" no default accelerator available" );
Perhaps on patch 07 you can also clarify this message, mentioning what's the default accelerator.
Quoted 53 lines
vl.c +27
-20-exit (1 ); - }else { -int pnlen =strlen (progname); -if (pnlen >=3 &&g_str_equal (&progname[pnlen -3 ],"kvm" )) { -/* If the program name ends with "kvm", we prefer KVM */ - accel ="kvm:tcg" ; +if (QTAILQ_EMPTY (&qemu_accel_opts.head)) { +if (accel ==NULL ) { +/* Select the default accelerator */ +if (!accel_find ("tcg" ) && !accel_find ("kvm" )) { +error_report ("No accelerator selected and" +" no default accelerator available" ); +exit (1 ); }else { - accel ="tcg:kvm" ; +int pnlen =strlen (progname); +if (pnlen >=3 &&g_str_equal (&progname[pnlen -3 ],"kvm" )) { +/* If the program name ends with "kvm", we prefer KVM */ + accel ="kvm:tcg" ; + }else { + accel ="tcg:kvm" ; + } } } - } - accel_list =g_strsplit (accel,":" ,0 ); + accel_list =g_strsplit (accel,":" ,0 ); -for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { - acc =accel_find (*tmp); -if (!acc) { -continue ; +for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { +/* +* Filter invalid accelerators here, to prevent obscenities +* such as "-machine accel=tcg,,thread=single". +*/ +if (accel_find (*tmp)) { +qemu_opts_parse_noisily (qemu_find_opts ("accel" ), *tmp, true); + } } - ret =accel_init_machine (acc, current_machine); -if (ret <0 ) { - init_failed = true; -error_report ("failed to initialize %s: %s" , - acc->name,strerror (-ret)); - }else { - accel_initialised = true; + }else { +if (accel !=NULL ) { +error_report ("The -accel and \"-machine accel=\" options are incompatible" ); +exit (1 );
vl.c static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp) · line 2922
Quoted 10 lines
vl.c +3
-3} } -g_strfreev (accel_list); -if (!accel_initialised) { +if (!qemu_opts_foreach (qemu_find_opts ("accel" ), + do_configure_accelerator, &init_failed, &error_fatal)) {if (!init_failed) { -error_report ("-machine accel=%s: No accelerator found" , accel); +error_report ("no accelerator found" );
Likewise.
Thanks,
Wainer
Quoted 26 lines
vl.c +2
-7}exit (1 ); }if (init_failed) { -error_report ("Back to %s accelerator" , acc->name); +AccelClass *ac =ACCEL_GET_CLASS (current_machine->accelerator); +error_report ("Back to %s accelerator" , ac->name); } -qemu_opts_foreach (qemu_find_opts ("accel" ), - do_configure_accelerator,NULL , &error_fatal); -if (!tcg_enabled () && use_icount) {error_report ("-icount is not allowed with hardware virtualization" );exit (1 );@@ -3618,9 +3636,6 @@ int main(int argc, char **argv, char **envp) "use -M accel=... for now instead");exit (1 ); } - opts =qemu_opts_create (qemu_find_opts ("machine" ),NULL , - false, &error_abort); -qemu_opt_set (opts,"accel" , optarg, &error_abort);break ;case QEMU_OPTION_usb: olist =qemu_find_opts ("machine" );
PATCH 7/16 vl: warn for unavailable accelerators, clarify messages
In reply to Paolo BonziniSo far, specifying an accelerator that was not compiled in did not result in an error; fix that.
While at it, clarify the mysterious "Back to TCG" message.
--- vl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
vl.c +6 -1
@@ -2853,6 +2853,8 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)int ret;if (!ac) { + *p_init_failed = true; +error_report ("invalid accelerator %s" , acc);return 0 ; } ret =accel_init_machine (ac, current_machine);
@@ -2907,6 +2909,9 @@ static void configure_accelerators(const char *progname)*/ if (accel_find (*tmp)) {qemu_opts_parse_noisily (qemu_find_opts ("accel" ), *tmp, true); + }else { + init_failed = true; +error_report ("invalid accelerator %s" , *tmp); } } }else {
@@ -2926,7 +2931,7 @@ static void configure_accelerators(const char *progname)if (init_failed) {AccelClass *ac =ACCEL_GET_CLASS (current_machine->accelerator); -error_report ("Back to %s accelerator" , ac->name); +error_report ("falling back to %s" , ac->name); }if (!tcg_enabled () && use_icount) {
Signature · 1 line
1.8.3.1
Re: [PATCH 07/16] vl: warn for unavailable accelerators, clarify messages
Hi
Quoted 5 lines · Paolo Bonzini
So far, specifying an accelerator that was not compiled in did not result in an error; fix that.
While at it, clarify the mysterious "Back to TCG" message.
I was wondering why this was not addressed in previous patch :)
Quoted 2 lines
Signed-off-by Paolo Bonzini <[email protected]>
Quoted 41 lines
--- vl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)vl.c +6
-2@@ -2853,6 +2853,8 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)int ret;if (!ac) { + *p_init_failed = true; +error_report ("invalid accelerator %s" , acc);return 0 ; } ret =accel_init_machine (ac, current_machine);@@ -2907,6 +2909,9 @@ static void configure_accelerators(const char *progname)*/ if (accel_find (*tmp)) {qemu_opts_parse_noisily (qemu_find_opts ("accel" ), *tmp, true); + }else { + init_failed = true; +error_report ("invalid accelerator %s" , *tmp); } } }else {@@ -2926,7 +2931,7 @@ static void configure_accelerators(const char *progname)if (init_failed) {AccelClass *ac =ACCEL_GET_CLASS (current_machine->accelerator); -error_report ("Back to %s accelerator" , ac->name); +error_report ("falling back to %s" , ac->name); }if (!tcg_enabled () && use_icount) { --1.8.3.1
Signature · 1 line
Marc-André Lureau
PATCH 8/16 qom: introduce object_register_sugar_prop
In reply to Paolo BonziniSimilar to the existing "-rtc driftfix" option, we will convert some legacy "-machine" command line options to global properties on accelerators. Because accelerators are not devices, we cannot use qdev_prop_register_global. Instead, provide a slot in the generic object_compat_props arrays for command line syntactic sugar.
--- include/qom/object.h | 1 + qom/object.c | 23 +++++++++++++++++++++-- vl.c | 10 +++------- 3 files changed, 25 insertions(+), 9 deletions(-)
include/qom/object.h +1 -0
@@ -679,6 +679,7 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp);void object_set_machine_compat_props (GPtrArray *compat_props);void object_set_accelerator_compat_props (GPtrArray *compat_props); +void object_register_sugar_prop (const char *driver,const char *prop,const char *value);void object_apply_compat_props (Object *obj);/**
qom/object.c +21 -2
@@ -414,10 +414,29 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp* Global property defaults * Slot 0: accelerator's global property defaults * Slot 1: machine's global property defaults +* Slot 2: global properties from legacy command line option * Each is a GPtrArray of of GlobalProperty. * Applied in order, later entries override earlier ones. */ -static GPtrArray *object_compat_props[2 ]; +static GPtrArray *object_compat_props[3 ]; + +/* +* Retrieve @GPtrArray for global property defined with options +* other than "-global". These are generally used for syntactic +* sugar and legacy command line options. +*/ +void object_register_sugar_prop (const char *driver,const char *prop,const char *value) +{ +GlobalProperty *g; +if (!object_compat_props[2 ]) { + object_compat_props[2 ] =g_ptr_array_new (); + } + g =g_new (GlobalProperty,1 ); + g->driver =g_strdup (driver); + g->property =g_strdup (prop); + g->value =g_strdup (value); +g_ptr_array_add (object_compat_props[2 ], g); +}/* * Set machine's global property defaults to @compat_props.
@@ -445,7 +464,7 @@ void object_apply_compat_props(Object *obj)for (i =0 ; i <ARRAY_SIZE (object_compat_props); i++) {object_apply_global_props (obj, object_compat_props[i], - &error_abort); + i ==2 ? &error_fatal : &error_abort); } }
vl.c +3 -7
@@ -896,13 +896,9 @@ static void configure_rtc(QemuOpts *opts) value =qemu_opt_get (opts,"driftfix" );if (value) {if (!strcmp (value,"slew" )) { -static GlobalProperty slew_lost_ticks = { - .driver ="mc146818rtc" , - .property ="lost_tick_policy" , - .value ="slew" , - }; - -qdev_prop_register_global (&slew_lost_ticks); +object_register_sugar_prop ("mc146818rtc" , +"lost_tick_policy" , +"slew" ); }else if (!strcmp (value,"none" )) {/* discard is default */ }else {
Signature · 1 line
1.8.3.1
Re: [PATCH 08/16] qom: introduce object_register_sugar_prop
Hi
Quoted 8 lines · Paolo Bonzini
Similar to the existing "-rtc driftfix" option, we will convert some legacy "-machine" command line options to global properties on accelerators. Because accelerators are not devices, we cannot use
qdev_prop_register_global. Instead, provide a slot in the genericobject_compat_propsarrays for command line syntactic sugar.Signed-off-by Paolo Bonzini <[email protected]>
sounds reasonable
Quoted 11 lines
--- include/qom/object.h | 1 + qom/object.c | 23 +++++++++++++++++++++-- vl.c | 10 +++------- 3 files changed, 25 insertions(+), 9 deletions(-)include/qom/object.h +0
-0
include/qom/object.h void object_apply_global_props(Object *obj, const GPtrArray *props, · line 682
Quoted 4 lines
include/qom/object.h +1
-0@@ -679,6 +679,7 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp);void object_set_machine_compat_props (GPtrArray *compat_props);void object_set_accelerator_compat_props (GPtrArray *compat_props); +void object_register_sugar_prop (const char *driver,const char *prop,const char *value);
Or simply
void object_add_global_prop(const char *typename, ...) ?
Quoted 39 lines
include/qom/object.h +0
-0void object_apply_compat_props (Object *obj);/** qom/object.c +20
-1@@ -414,10 +414,29 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp* Global property defaults * Slot 0: accelerator's global property defaults * Slot 1: machine's global property defaults +* Slot 2: global properties from legacy command line option * Each is a GPtrArray of of GlobalProperty. * Applied in order, later entries override earlier ones. */ -static GPtrArray *object_compat_props[2 ]; +static GPtrArray *object_compat_props[3 ]; + +/* +* Retrieve @GPtrArray for global property defined with options +* other than "-global". These are generally used for syntactic +* sugar and legacy command line options. +*/ +void object_register_sugar_prop (const char *driver,const char *prop,const char *value) +{ +GlobalProperty *g; +if (!object_compat_props[2 ]) { + object_compat_props[2 ] =g_ptr_array_new (); + } + g =g_new (GlobalProperty,1 ); + g->driver =g_strdup (driver); + g->property =g_strdup (prop); + g->value =g_strdup (value); +g_ptr_array_add (object_compat_props[2 ], g); +}/* * Set machine's global property defaults to @compat_props.
qom/object.c void object_apply_compat_props(Object *obj) · line 467
Quoted 5 lines
qom/object.c +1
-1@@ -445,7 +464,7 @@ void object_apply_compat_props(Object *obj)for (i =0 ; i <ARRAY_SIZE (object_compat_props); i++) {object_apply_global_props (obj, object_compat_props[i], - &error_abort); + i ==2 ? &error_fatal : &error_abort);
Isn't error_abort() appropriate in all cases?
Quoted 11 lines
qom/object.c +0
-0} }vl.c +0
-0@@ -896,13 +896,9 @@ static void configure_rtc(QemuOpts *opts) value =qemu_opt_get (opts,"driftfix" );if (value) {if (!strcmp (value,"slew" )) {
vl.c static void configure_rtc(QemuOpts *opts) · line 901
Quoted 10 lines
vl.c +3
-7-static GlobalProperty slew_lost_ticks = { - .driver ="mc146818rtc" , - .property ="lost_tick_policy" , - .value ="slew" , - }; - -qdev_prop_register_global (&slew_lost_ticks); +object_register_sugar_prop ("mc146818rtc" , +"lost_tick_policy" , +"slew" );
Why do you convert this since it's a device?
Quoted 8 lines
vl.c +0
-1}else if (!strcmp (value,"none" )) {/* discard is default */ }else { --1.8.3.1
Signature · 1 line
Marc-André Lureau
Re: [PATCH 08/16] qom: introduce object_register_sugar_prop
Quoted 17 lines · Marc-André Lureau
Quoted 10 lines
include/qom/object.h | 1 + qom/object.c | 23 +++++++++++++++++++++-- vl.c | 10 +++------- 3 files changed, 25 insertions(+), 9 deletions(-)include/qom/object.h +0
-0include/qom/object.h void object_apply_global_props(Object *obj, const GPtrArray *props, · line 682
Quoted 4 lines
include/qom/object.h +1
-0@@ -679,6 +679,7 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp);void object_set_machine_compat_props (GPtrArray *compat_props);void object_set_accelerator_compat_props (GPtrArray *compat_props); +void object_register_sugar_prop (const char *driver,const char *prop,const char *value);Or simply
Quoted 1 line
void
object_add_global_prop(const char *typename, ...)?
This is actually how I called it first, but I didn't like it because it's prioritized _below_ -global, and it's easy to confuse it with object_add_global_prop.
Quoted 10 lines
include/qom/object.h void object_apply_compat_props(Object *obj) · line 467
Quoted 8 lines
include/qom/object.h +1
-1/* * Set machine's global property defaults to @compat_props. @@ -445,7 +464,7 @@ void object_apply_compat_props(Object *obj)for (i =0 ; i <ARRAY_SIZE (object_compat_props); i++) {object_apply_global_props (obj, object_compat_props[i], - &error_abort); + i ==2 ? &error_fatal : &error_abort);Isn't
error_abort()appropriate in all cases?
Unfortunately not, because otherwise "-accel tcg,tb-size=foo" would crash.
Quoted 15 lines
Quoted 15 lines
include/qom/object.h +0
-0} }vl.c +0
-4@@ -896,13 +896,9 @@ static void configure_rtc(QemuOpts *opts) value =qemu_opt_get (opts,"driftfix" );if (value) {if (!strcmp (value,"slew" )) { -static GlobalProperty slew_lost_ticks = { - .driver ="mc146818rtc" , - .property ="lost_tick_policy" , - .value = "slew",
Quoted 8 lines
vl.c static void configure_rtc(QemuOpts *opts) · line 901
Quoted 6 lines
vl.c +3
-3- }; - -qdev_prop_register_global (&slew_lost_ticks); +object_register_sugar_prop ("mc146818rtc" , +"lost_tick_policy" , +"slew" );Why do you convert this since it's a device?
Not strictly necessary, but it's more compact and it more or less matches the usecase for this function.
Paolo
PATCH 9/16 qom: add object_new_with_class
In reply to Paolo BonziniSimilar to CPU and machine classes, "-accel" class names are mangled, so we have to first get a class via accel_find and then instantiate it. Provide a new function to instantiate a class without going through object_class_get_name, and use it for CPUs and machines already.
--- include/qom/object.h | 12 ++++++++++++ qom/object.c | 5 +++++ target/i386/cpu.c | 8 ++++---- target/s390x/cpu_models.c | 4 ++-- vl.c | 3 +-- 5 files changed, 24 insertions(+), 8 deletions(-)
include/qom/object.h +12 -0
@@ -593,6 +593,18 @@ struct InterfaceClass __FILE__, __LINE__, __func__))/** +* object_new_with_class: +* @klass: The class to instantiate. +* +* This function will initialize a new object using heap allocated memory. +* The returned object has a reference count of 1, and will be freed when +* the last reference is dropped. +* +* Returns: The newly allocated and instantiated object. +*/ +Object *object_new_with_class (ObjectClass *klass); + +/** * object_new: * @typename: The name of the type of the object to instantiate. *
qom/object.c +5 -0
@@ -658,6 +658,11 @@ static Object *object_new_with_type(Type type)return obj; } +Object *object_new_with_class (ObjectClass *klass) +{ +return object_new_with_type (klass->type); +} +Object *object_new (const char *typename) {TypeImpl *ti =type_get_by_name (typename);
target/i386/cpu.c +4 -4
@@ -3881,7 +3881,7 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,return ; } - xc =X86_CPU (object_new (object_class_get_name (OBJECT_CLASS (xcc)))); + xc =X86_CPU (object_new_with_class (OBJECT_CLASS (xcc)));x86_cpu_expand_features (xc, &err);if (err) {
@@ -3952,7 +3952,7 @@ static GSList *get_sorted_cpu_model_list(void)static char *x86_cpu_class_get_model_id (X86CPUClass *xc) { -Object *obj =object_new (object_class_get_name (OBJECT_CLASS (xc))); +Object *obj =object_new_with_class (OBJECT_CLASS (xc));char *r =object_property_get_str (obj,"model-id" , &error_abort);object_unref (obj);return r;
@@ -4333,7 +4333,7 @@ static X86CPU *x86_cpu_from_model(const char *model, QDict *props, Error **errp) goto out; } - xc =X86_CPU (object_new (object_class_get_name (OBJECT_CLASS (xcc)))); + xc =X86_CPU (object_new_with_class (OBJECT_CLASS (xcc)));if (props) {object_apply_props (OBJECT (xc), props, &err);if (err) {
@@ -5177,7 +5177,7 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)APICCommonState *apic;ObjectClass *apic_class =OBJECT_CLASS (apic_get_class ()); - cpu->apic_state =DEVICE (object_new (object_class_get_name (apic_class))); + cpu->apic_state =DEVICE (object_new_with_class (apic_class));object_property_add_child (OBJECT (cpu),"lapic" ,OBJECT (cpu->apic_state), &error_abort);
target/s390x/cpu_models.c +2 -2
@@ -440,7 +440,7 @@ static void create_cpu_model_list(ObjectClass *klass, void *opaque)if (cpu_list_data->model) {Object *obj;S390CPU *sc; - obj =object_new (object_class_get_name (klass)); + obj =object_new_with_class (klass); sc =S390_CPU (obj);if (sc->model) { info->has_unavailable_features = true;
@@ -501,7 +501,7 @@ static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info,error_setg (errp,"The CPU definition '%s' requires KVM" , info->name);return ; } - obj =object_new (object_class_get_name (oc)); + obj =object_new_with_class (oc); cpu =S390_CPU (obj);if (!cpu->model) {
vl.c +1 -2
@@ -3988,8 +3988,7 @@ int main(int argc, char **argv, char **envp) cleanup_add_fd, NULL, &error_fatal);#endif - current_machine =MACHINE (object_new (object_class_get_name ( -OBJECT_CLASS (machine_class)))); + current_machine =MACHINE (object_new_with_class (OBJECT_CLASS (machine_class)));if (machine_help_func (qemu_get_machine_opts (), current_machine)) {exit (0 ); }
Signature · 1 line
1.8.3.1
Re: [PATCH 09/16] qom: add object_new_with_class
Quoted 7 lines · Paolo Bonzini
Similar to CPU and machine classes, "-accel" class names are mangled, so we have to first get a class via
accel_findand then instantiate it. Provide a new function to instantiate a class without going throughobject_class_get_name, and use it for CPUs and machines already.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 128 lines
--- include/qom/object.h | 12 ++++++++++++ qom/object.c | 5 +++++ target/i386/cpu.c | 8 ++++---- target/s390x/cpu_models.c | 4 ++-- vl.c | 3 +-- 5 files changed, 24 insertions(+), 8 deletions(-)include/qom/object.h +12
-0@@ -593,6 +593,18 @@ struct InterfaceClass __FILE__, __LINE__, __func__))/** +* object_new_with_class: +* @klass: The class to instantiate. +* +* This function will initialize a new object using heap allocated memory. +* The returned object has a reference count of 1, and will be freed when +* the last reference is dropped. +* +* Returns: The newly allocated and instantiated object. +*/ +Object *object_new_with_class (ObjectClass *klass); + +/** * object_new: * @typename: The name of the type of the object to instantiate. * qom/object.c +5
-0@@ -658,6 +658,11 @@ static Object *object_new_with_type(Type type)return obj; } +Object *object_new_with_class (ObjectClass *klass) +{ +return object_new_with_type (klass->type); +} +Object *object_new (const char *typename) {TypeImpl *ti =type_get_by_name (typename);target/i386/cpu.c +4
-4@@ -3881,7 +3881,7 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,return ; } - xc =X86_CPU (object_new (object_class_get_name (OBJECT_CLASS (xcc)))); + xc =X86_CPU (object_new_with_class (OBJECT_CLASS (xcc)));x86_cpu_expand_features (xc, &err);if (err) {@@ -3952,7 +3952,7 @@ static GSList *get_sorted_cpu_model_list(void)static char *x86_cpu_class_get_model_id (X86CPUClass *xc) { -Object *obj =object_new (object_class_get_name (OBJECT_CLASS (xc))); +Object *obj =object_new_with_class (OBJECT_CLASS (xc));char *r =object_property_get_str (obj,"model-id" , &error_abort);object_unref (obj);return r;@@ -4333,7 +4333,7 @@ static X86CPU *x86_cpu_from_model(const char *model, QDict *props, Error **errp) goto out; } - xc =X86_CPU (object_new (object_class_get_name (OBJECT_CLASS (xcc)))); + xc =X86_CPU (object_new_with_class (OBJECT_CLASS (xcc)));if (props) {object_apply_props (OBJECT (xc), props, &err);if (err) {@@ -5177,7 +5177,7 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)APICCommonState *apic;ObjectClass *apic_class =OBJECT_CLASS (apic_get_class ()); - cpu->apic_state =DEVICE (object_new (object_class_get_name (apic_class))); + cpu->apic_state =DEVICE (object_new_with_class (apic_class));object_property_add_child (OBJECT (cpu),"lapic" ,OBJECT (cpu->apic_state), &error_abort);target/s390x/cpu_models.c +2
-2@@ -440,7 +440,7 @@ static void create_cpu_model_list(ObjectClass *klass, void *opaque)if (cpu_list_data->model) {Object *obj;S390CPU *sc; - obj =object_new (object_class_get_name (klass)); + obj =object_new_with_class (klass); sc =S390_CPU (obj);if (sc->model) { info->has_unavailable_features = true;@@ -501,7 +501,7 @@ static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info,error_setg (errp,"The CPU definition '%s' requires KVM" , info->name);return ; } - obj =object_new (object_class_get_name (oc)); + obj =object_new_with_class (oc); cpu =S390_CPU (obj);if (!cpu->model) {vl.c +1
-3@@ -3988,8 +3988,7 @@ int main(int argc, char **argv, char **envp) cleanup_add_fd, NULL, &error_fatal);#endif - current_machine =MACHINE (object_new (object_class_get_name ( -OBJECT_CLASS (machine_class)))); + current_machine =MACHINE (object_new_with_class (OBJECT_CLASS (machine_class)));if (machine_help_func (qemu_get_machine_opts (), current_machine)) {exit (0 ); } --1.8.3.1
Signature · 1 line
Marc-André Lureau
PATCH 10/16 accel: pass object to accel_init_machine
In reply to Paolo BonziniWe will have to set QOM properties before accel_init_machine, based on the options provided to -accel. Construct the object outside it so that it will be possible to insert the iteration between object_new_with_class and accel_init_machine.
--- accel/accel.c | 6 ++---- include/sysemu/accel.h | 2 +- vl.c | 4 +++- 3 files changed, 6 insertions(+), 6 deletions(-)
accel/accel.c +2 -4
@@ -52,11 +52,9 @@ AccelClass *accel_find(const char *opt_name)return ac; } -int accel_init_machine (AccelClass *acc,MachineState *ms) +int accel_init_machine (AccelState *accel,MachineState *ms) { -ObjectClass *oc =OBJECT_CLASS (acc); -const char *cname =object_class_get_name (oc); -AccelState *accel =ACCEL (object_new (cname)); +AccelClass *acc =ACCEL_GET_CLASS (accel);int ret; ms->accelerator = accel; *(acc->allowed) = true;
include/sysemu/accel.h +1 -1
@@ -67,7 +67,7 @@ typedef struct AccelClass {extern unsigned long tcg_tb_size;AccelClass *accel_find (const char *opt_name); -int accel_init_machine (AccelClass *acc,MachineState *ms); +int accel_init_machine (AccelState *accel,MachineState *ms);/* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post (MachineState *ms);
vl.c +3 -1
@@ -2846,6 +2846,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)bool *p_init_failed = opaque;const char *acc =qemu_opt_get (opts,"accel" );AccelClass *ac =accel_find (acc); +AccelState *accel;int ret;if (!ac) {
@@ -2853,7 +2854,8 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)error_report ("invalid accelerator %s" , acc);return 0 ; } - ret =accel_init_machine (ac, current_machine); + accel =ACCEL (object_new_with_class (OBJECT_CLASS (ac))); + ret =accel_init_machine (accel, current_machine);if (ret <0 ) { *p_init_failed = true; error_report("failed to initialize %s: %s",
Signature · 1 line
1.8.3.1
Re: [PATCH 10/16] accel: pass object to accel_init_machine
Quoted 7 lines · Paolo Bonzini
We will have to set QOM properties before
accel_init_machine, based on the options provided to -accel. Construct the object outside it so that it will be possible to insert the iteration betweenobject_new_with_classandaccel_init_machine.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 64 lines
--- accel/accel.c | 6 ++---- include/sysemu/accel.h | 2 +- vl.c | 4 +++- 3 files changed, 6 insertions(+), 6 deletions(-)accel/accel.c +2
-4@@ -52,11 +52,9 @@ AccelClass *accel_find(const char *opt_name)return ac; } -int accel_init_machine (AccelClass *acc,MachineState *ms) +int accel_init_machine (AccelState *accel,MachineState *ms) { -ObjectClass *oc =OBJECT_CLASS (acc); -const char *cname =object_class_get_name (oc); -AccelState *accel =ACCEL (object_new (cname)); +AccelClass *acc =ACCEL_GET_CLASS (accel);int ret; ms->accelerator = accel; *(acc->allowed) = true;include/sysemu/accel.h +1
-1@@ -67,7 +67,7 @@ typedef struct AccelClass {extern unsigned long tcg_tb_size;AccelClass *accel_find (const char *opt_name); -int accel_init_machine (AccelClass *acc,MachineState *ms); +int accel_init_machine (AccelState *accel,MachineState *ms);/* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post (MachineState *ms);vl.c +3
-2@@ -2846,6 +2846,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)bool *p_init_failed = opaque;const char *acc =qemu_opt_get (opts,"accel" );AccelClass *ac =accel_find (acc); +AccelState *accel;int ret;if (!ac) {@@ -2853,7 +2854,8 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)error_report ("invalid accelerator %s" , acc);return 0 ; } - ret =accel_init_machine (ac, current_machine); + accel =ACCEL (object_new_with_class (OBJECT_CLASS (ac))); + ret =accel_init_machine (accel, current_machine);if (ret <0 ) { *p_init_failed = true; error_report("failed to initialize %s: %s", --1.8.3.1
Signature · 1 line
Marc-André Lureau
PATCH 11/16 tcg: convert "-accel threads" to a QOM property
In reply to Paolo BonziniReplace the ad-hoc qemu_tcg_configure with generic code invoking QOM property getters and setters. This will be extended in the next patches, which will turn accelerator-related "-machine" options into QOM properties as well.
--- accel/tcg/tcg-all.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++- cpus.c | 72 -------------------------------- include/sysemu/cpus.h | 2 - vl.c | 32 ++++++++------- 4 files changed, 126 insertions(+), 91 deletions(-)
accel/tcg/tcg-all.c +109 -2
@@ -30,6 +30,21 @@#include "cpu.h" #include "sysemu/cpus.h" #include "qemu/main-loop.h" +#include "tcg/tcg.h" +#include "include/qapi/error.h" +#include "include/qemu/error-report.h" +#include "include/hw/boards.h" + +typedef struct TCGState { +AccelState parent_obj; + +bool mttcg_enabled; +}TCGState ; + +#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg") + +#define TCG_STATE (obj) \ + OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL)unsigned long tcg_tb_size;
@@ -58,27 +73,119 @@ static void tcg_handle_interrupt(CPUState *cpu, int mask) } } +/* +* We default to false if we know other options have been enabled +* which are currently incompatible with MTTCG. Otherwise when each +* guest (target) has been updated to support: +* - atomic instructions +* - memory ordering primitives (barriers) +* they can set the appropriate CONFIG flags in ${target}-softmmu.mak +* +* Once a guest architecture has been converted to the new primitives +* there are two remaining limitations to check. +* +* - The guest can't be oversized (e.g. 64 bit guest on 32 bit host) +* - The host must have a stronger memory order than the guest +* +* It may be possible in future to support strong guests on weak hosts +* but that will require tagging all load/stores in a guest with their +* implicit memory order requirements which would likely slow things +* down a lot. +*/ + +static bool check_tcg_memory_orders_compatible (void ) +{ +#if defined(TCG_GUEST_DEFAULT_MO ) && defined(TCG_TARGET_DEFAULT_MO ) +return (TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO ) ==0 ; +#else +return false; +#endif +} + +static bool default_mttcg_enabled (void ) +{ +if (use_icount ||TCG_OVERSIZED_GUEST ) { +return false; + }else { +#ifdef TARGET_SUPPORTS_MTTCG +return check_tcg_memory_orders_compatible (); +#else +return false; +#endif + } +} + +static void tcg_accel_instance_init (Object *obj) +{ +TCGState *s =TCG_STATE (obj); + + s->mttcg_enabled =default_mttcg_enabled (); +} +static int tcg_init (MachineState *ms) { +TCGState *s =TCG_STATE (current_machine->accelerator); +tcg_exec_init (tcg_tb_size *1024 *1024 ); cpu_interrupt_handler = tcg_handle_interrupt; + mttcg_enabled = s->mttcg_enabled;return 0 ; } +static char *tcg_get_thread (Object *obj,Error **errp) +{ +TCGState *s =TCG_STATE (obj); + +return g_strdup (s->mttcg_enabled ?"multi" :"single" ); +} + +static void tcg_set_thread (Object *obj,const char *value,Error **errp) +{ +TCGState *s =TCG_STATE (obj); + +if (strcmp (value,"multi" ) ==0 ) { +if (TCG_OVERSIZED_GUEST ) { +error_setg (errp,"No MTTCG when guest word size > hosts" ); + }else if (use_icount) { +error_setg (errp,"No MTTCG when icount is enabled" ); + }else { +#ifndef TARGET_SUPPORTS_MTTCG +warn_report ("Guest not yet converted to MTTCG - " +"you may get unexpected results" ); +#endif +if (!check_tcg_memory_orders_compatible ()) { +warn_report ("Guest expects a stronger memory ordering " +"than the host provides" ); +error_printf ("This may cause strange/hard to debug errors\n" ); + } + s->mttcg_enabled = true; + } + }else if (strcmp (value,"single" ) ==0 ) { + s->mttcg_enabled = false; + }else { +error_setg (errp,"Invalid 'thread' setting %s" , value); + } +} +static void tcg_accel_class_init (ObjectClass *oc,void *data) {AccelClass *ac =ACCEL_CLASS (oc); ac->name ="tcg" ; ac->init_machine = tcg_init; ac->allowed = &tcg_allowed; -} -#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg") +object_class_property_add_str (oc,"thread" , + tcg_get_thread, + tcg_set_thread, +NULL ); +}static const TypeInfo tcg_accel_type = { .name =TYPE_TCG_ACCEL , .parent =TYPE_ACCEL , + .instance_init = tcg_accel_instance_init, .class_init = tcg_accel_class_init, + .instance_size =sizeof (TCGState), };static void register_accel_types (void )
cpus.c +0 -72
78 lines not on this page · raw message
include/sysemu/cpus.h +0 -2
@@ -40,6 +40,4 @@ extern int smp_threads;void list_cpus (const char *optarg); -void qemu_tcg_configure (QemuOpts *opts,Error **errp); -#endif
vl.c +17 -15
@@ -294,17 +294,12 @@ static QemuOptsList qemu_accel_opts = { .implied_opt_name = "accel", .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head), .desc = { - { - .name = "accel", - .type = QEMU_OPT_STRING, - .help = "Select the type of accelerator", - }, - { - .name = "thread", - .type = QEMU_OPT_STRING, - .help = "Enable/disable multi-threaded TCG", - }, - {/* end of list */ } +/* +* no elements => accept any +* sanity checking will happen later +* when setting accelerator properties +*/ + { } }, };
@@ -2841,6 +2836,13 @@ static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } +static int accelerator_set_property (void *opaque, +const char *name,const char *value, +Error **errp) +{ +return object_parse_property_opt (opaque, name, value,"accel" , errp); +} +static int do_configure_accelerator (void *opaque,QemuOpts *opts,Error **errp) {bool *p_init_failed = opaque;
@@ -2855,6 +2857,10 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } accel =ACCEL (object_new_with_class (OBJECT_CLASS (ac))); +qemu_opt_foreach (opts, accelerator_set_property, + accel, + &error_fatal); + ret =accel_init_machine (accel, current_machine);if (ret <0 ) { *p_init_failed = true;
@@ -2862,10 +2868,6 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) acc, strerror(-ret));return 0 ; } - -if (tcg_enabled ()) { -qemu_tcg_configure (opts, &error_fatal); - }return 1 ; }
Signature · 1 line
1.8.3.1
Re: [PATCH 11/16] tcg: convert "-accel threads" to a QOM property
Quoted 7 lines · Paolo Bonzini
Replace the ad-hoc
qemu_tcg_configurewith generic code invoking QOM property getters and setters. This will be extended in the next patches, which will turn accelerator-related "-machine" options into QOM properties as well.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 318 lines
--- accel/tcg/tcg-all.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++- cpus.c | 72 -------------------------------- include/sysemu/cpus.h | 2 - vl.c | 32 ++++++++------- 4 files changed, 126 insertions(+), 91 deletions(-)accel/tcg/tcg-all.c +109
-2@@ -30,6 +30,21 @@#include "cpu.h" #include "sysemu/cpus.h" #include "qemu/main-loop.h" +#include "tcg/tcg.h" +#include "include/qapi/error.h" +#include "include/qemu/error-report.h" +#include "include/hw/boards.h" + +typedef struct TCGState { +AccelState parent_obj; + +bool mttcg_enabled; +}TCGState ; + +#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg") + +#define TCG_STATE (obj) \ + OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL)unsigned long tcg_tb_size;@@ -58,27 +73,119 @@ static void tcg_handle_interrupt(CPUState *cpu, int mask) } } +/* +* We default to false if we know other options have been enabled +* which are currently incompatible with MTTCG. Otherwise when each +* guest (target) has been updated to support: +* - atomic instructions +* - memory ordering primitives (barriers) +* they can set the appropriate CONFIG flags in ${target}-softmmu.mak +* +* Once a guest architecture has been converted to the new primitives +* there are two remaining limitations to check. +* +* - The guest can't be oversized (e.g. 64 bit guest on 32 bit host) +* - The host must have a stronger memory order than the guest +* +* It may be possible in future to support strong guests on weak hosts +* but that will require tagging all load/stores in a guest with their +* implicit memory order requirements which would likely slow things +* down a lot. +*/ + +static bool check_tcg_memory_orders_compatible (void ) +{ +#if defined(TCG_GUEST_DEFAULT_MO ) && defined(TCG_TARGET_DEFAULT_MO ) +return (TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO ) ==0 ; +#else +return false; +#endif +} + +static bool default_mttcg_enabled (void ) +{ +if (use_icount ||TCG_OVERSIZED_GUEST ) { +return false; + }else { +#ifdef TARGET_SUPPORTS_MTTCG +return check_tcg_memory_orders_compatible (); +#else +return false; +#endif + } +} + +static void tcg_accel_instance_init (Object *obj) +{ +TCGState *s =TCG_STATE (obj); + + s->mttcg_enabled =default_mttcg_enabled (); +} +static int tcg_init (MachineState *ms) { +TCGState *s =TCG_STATE (current_machine->accelerator); +tcg_exec_init (tcg_tb_size *1024 *1024 ); cpu_interrupt_handler = tcg_handle_interrupt; + mttcg_enabled = s->mttcg_enabled;return 0 ; } +static char *tcg_get_thread (Object *obj,Error **errp) +{ +TCGState *s =TCG_STATE (obj); + +return g_strdup (s->mttcg_enabled ?"multi" :"single" ); +} + +static void tcg_set_thread (Object *obj,const char *value,Error **errp) +{ +TCGState *s =TCG_STATE (obj); + +if (strcmp (value,"multi" ) ==0 ) { +if (TCG_OVERSIZED_GUEST ) { +error_setg (errp,"No MTTCG when guest word size > hosts" ); + }else if (use_icount) { +error_setg (errp,"No MTTCG when icount is enabled" ); + }else { +#ifndef TARGET_SUPPORTS_MTTCG +warn_report ("Guest not yet converted to MTTCG - " +"you may get unexpected results" ); +#endif +if (!check_tcg_memory_orders_compatible ()) { +warn_report ("Guest expects a stronger memory ordering " +"than the host provides" ); +error_printf ("This may cause strange/hard to debug errors\n" ); + } + s->mttcg_enabled = true; + } + }else if (strcmp (value,"single" ) ==0 ) { + s->mttcg_enabled = false; + }else { +error_setg (errp,"Invalid 'thread' setting %s" , value); + } +} +static void tcg_accel_class_init (ObjectClass *oc,void *data) {AccelClass *ac =ACCEL_CLASS (oc); ac->name ="tcg" ; ac->init_machine = tcg_init; ac->allowed = &tcg_allowed; -} -#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg") +object_class_property_add_str (oc,"thread" , + tcg_get_thread, + tcg_set_thread, +NULL ); +}static const TypeInfo tcg_accel_type = { .name =TYPE_TCG_ACCEL , .parent =TYPE_ACCEL , + .instance_init = tcg_accel_instance_init, .class_init = tcg_accel_class_init, + .instance_size =sizeof (TCGState), };static void register_accel_types (void )cpus.c +0
-72@@ -165,78 +165,6 @@ typedef struct TimersState {static TimersState timers_state;bool mttcg_enabled; -/* -* We default to false if we know other options have been enabled -* which are currently incompatible with MTTCG. Otherwise when each -* guest (target) has been updated to support: -* - atomic instructions -* - memory ordering primitives (barriers) -* they can set the appropriate CONFIG flags in ${target}-softmmu.mak -* -* Once a guest architecture has been converted to the new primitives -* there are two remaining limitations to check. -* -* - The guest can't be oversized (e.g. 64 bit guest on 32 bit host) -* - The host must have a stronger memory order than the guest -* -* It may be possible in future to support strong guests on weak hosts -* but that will require tagging all load/stores in a guest with their -* implicit memory order requirements which would likely slow things -* down a lot. -*/ - -static bool check_tcg_memory_orders_compatible (void ) -{ -#if defined(TCG_GUEST_DEFAULT_MO ) && defined(TCG_TARGET_DEFAULT_MO ) -return (TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO ) ==0 ; -#else -return false; -#endif -} - -static bool default_mttcg_enabled (void ) -{ -if (use_icount ||TCG_OVERSIZED_GUEST ) { -return false; - }else { -#ifdef TARGET_SUPPORTS_MTTCG -return check_tcg_memory_orders_compatible (); -#else -return false; -#endif - } -} - -void qemu_tcg_configure (QemuOpts *opts,Error **errp) -{ -const char *t =qemu_opt_get (opts,"thread" ); -if (t) { -if (strcmp (t,"multi" ) ==0 ) { -if (TCG_OVERSIZED_GUEST ) { -error_setg (errp,"No MTTCG when guest word size > hosts" ); - }else if (use_icount) { -error_setg (errp,"No MTTCG when icount is enabled" ); - }else { -#ifndef TARGET_SUPPORTS_MTTCG -warn_report ("Guest not yet converted to MTTCG - " -"you may get unexpected results" ); -#endif -if (!check_tcg_memory_orders_compatible ()) { -warn_report ("Guest expects a stronger memory ordering " -"than the host provides" ); -error_printf ("This may cause strange/hard to debug errors\n" ); - } - mttcg_enabled = true; - } - }else if (strcmp (t,"single" ) ==0 ) { - mttcg_enabled = false; - }else { -error_setg (errp,"Invalid 'thread' setting %s" , t); - } - }else { - mttcg_enabled =default_mttcg_enabled (); - } -}/* The current number of executed instructions is based on what we * originally budgeted minus the current state of the decrementing include/sysemu/cpus.h +0
-2@@ -40,6 +40,4 @@ extern int smp_threads;void list_cpus (const char *optarg); -void qemu_tcg_configure (QemuOpts *opts,Error **errp); -#endif vl.c +17
-16@@ -294,17 +294,12 @@ static QemuOptsList qemu_accel_opts = { .implied_opt_name = "accel", .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head), .desc = { - { - .name = "accel", - .type = QEMU_OPT_STRING, - .help = "Select the type of accelerator", - }, - { - .name = "thread", - .type = QEMU_OPT_STRING, - .help = "Enable/disable multi-threaded TCG", - }, - {/* end of list */ } +/* +* no elements => accept any +* sanity checking will happen later +* when setting accelerator properties +*/ + { } }, };@@ -2841,6 +2836,13 @@ static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } +static int accelerator_set_property (void *opaque, +const char *name,const char *value, +Error **errp) +{ +return object_parse_property_opt (opaque, name, value,"accel" , errp); +} +static int do_configure_accelerator (void *opaque,QemuOpts *opts,Error **errp) {bool *p_init_failed = opaque;@@ -2855,6 +2857,10 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } accel =ACCEL (object_new_with_class (OBJECT_CLASS (ac))); +qemu_opt_foreach (opts, accelerator_set_property, + accel, + &error_fatal); + ret =accel_init_machine (accel, current_machine);if (ret <0 ) { *p_init_failed = true;@@ -2862,10 +2868,6 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) acc, strerror(-ret));return 0 ; } - -if (tcg_enabled ()) { -qemu_tcg_configure (opts, &error_fatal); - }return 1 ; } --1.8.3.1
Signature · 1 line
Marc-André Lureau
PATCH 12/16 tcg: add "-accel tcg,tb-size" and deprecate "-tb-size"
In reply to Paolo Bonzini-tb-size fits nicely in the new framework for accelerator-specific options. It is a very niche option, so insta-deprecate the old version.
--- accel/tcg/tcg-all.c | 40 +++++++++++++++++++++++++++++++++++++--- include/sysemu/accel.h | 2 -- qemu-deprecated.texi | 6 ++++++ qemu-options.hx | 6 +++++- vl.c | 8 ++++---- 5 files changed, 52 insertions(+), 10 deletions(-)
accel/tcg/tcg-all.c +37 -3
@@ -34,11 +34,13 @@#include "include/qapi/error.h" #include "include/qemu/error-report.h" #include "include/hw/boards.h" +#include "qapi/qapi-builtin-visit.h" typedef struct TCGState {AccelState parent_obj;bool mttcg_enabled; +unsigned long tb_size; }TCGState ;#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg")
@@ -46,8 +48,6 @@ typedef struct TCGState {#define TCG_STATE (obj) \ OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL) -unsigned long tcg_tb_size; -/* mask must never be zero, except for A20 change call */ static void tcg_handle_interrupt (CPUState *cpu,int mask) {
@@ -126,7 +126,7 @@ static int tcg_init(MachineState *ms) {TCGState *s =TCG_STATE (current_machine->accelerator); -tcg_exec_init (tcg_tb_size *1024 *1024 ); +tcg_exec_init (s->tb_size *1024 *1024 ); cpu_interrupt_handler = tcg_handle_interrupt; mttcg_enabled = s->mttcg_enabled;return 0 ;
@@ -167,6 +167,33 @@ static void tcg_set_thread(Object *obj, const char *value, Error **errp) } } +static void tcg_get_tb_size (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +TCGState *s =TCG_STATE (obj); +uint32_t value = s->tb_size; + +visit_type_uint32 (v, name, &value, errp); +} + +static void tcg_set_tb_size (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +TCGState *s =TCG_STATE (obj); +Error *error =NULL ; +uint32_t value; + +visit_type_uint32 (v, name, &value, &error); +if (error) { +error_propagate (errp, error); +return ; + } + + s->tb_size = value; +} +static void tcg_accel_class_init (ObjectClass *oc,void *data) {AccelClass *ac =ACCEL_CLASS (oc);
@@ -178,6 +205,13 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data) tcg_get_thread, tcg_set_thread, NULL); + +object_class_property_add (oc,"tb-size" ,"int" , + tcg_get_tb_size, tcg_set_tb_size, +NULL ,NULL , &error_abort); +object_class_property_set_description (oc,"tb-size" , +"TCG translation block cache size" , &error_abort); + }static const TypeInfo tcg_accel_type = {
include/sysemu/accel.h +0 -2
@@ -64,8 +64,6 @@ typedef struct AccelClass {#define ACCEL_GET_CLASS (obj) \ OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL) -extern unsigned long tcg_tb_size; -AccelClass *accel_find (const char *opt_name);int accel_init_machine (AccelState *accel,MachineState *ms);
qemu-deprecated.texi +6 -0
@@ -147,6 +147,12 @@ QEMU 4.1 has three options, please migrate to one of these three: to do is specify the kernel they want to boot with the -kernel option 3. ``-bios <file>`` - Tells QEMU to load the specified file as the firmwrae. +@subsection -tb-size option (since 5.0) + +QEMU 5.0 introduced an alternative syntax to specify the size of the translation +block cache, @option{-accel tcg,tb-size=}. The new syntax deprecates the +previously available @option{-tb-size} option. + @section QEMU Machine Protocol (QMP) commands @subsection query-block result field dirty-bitmaps[i].status (since 4.0)
qemu-options.hx +5 -1
@@ -120,6 +120,7 @@ ETEXI DEF("accel", HAS_ARG, QEMU_OPTION_accel, "-accel [accel=]accelerator[,thread=single|multi]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" + " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) STEXI @item -accel @var{name}[,prop=@var{value}[,...]]
@@ -129,6 +130,8 @@ kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If th more than one accelerator specified, the next one is used if the previous one fails to initialize. @table @option +@item tb-size=@var{n} +Controls the size (in MiB) of the TCG translation block cache. @item thread=single|multi Controls number of TCG threads. When the TCG is multi-threaded there will be one thread per vCPU therefor taking advantage of additional host cores. The default
@@ -3995,7 +3998,8 @@ DEF("tb-size", HAS_ARG, QEMU_OPTION_tb_size, \ STEXI @item -tb-size @var{n} @findex -tb-size -Set TB size. +Set TCG translation block cache size. Deprecated, use @samp{-accel tcg,tb-size=@var{n}} +instead. ETEXI DEF("incoming", HAS_ARG, QEMU_OPTION_incoming, \
vl.c +4 -4
@@ -2857,6 +2857,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } accel =ACCEL (object_new_with_class (OBJECT_CLASS (ac))); +object_apply_compat_props (OBJECT (accel));qemu_opt_foreach (opts, accelerator_set_property, accel, &error_fatal);
@@ -2868,6 +2869,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) acc, strerror(-ret));return 0 ; } +return 1 ; }
@@ -3747,10 +3749,8 @@ int main(int argc, char **argv, char **envp)error_report ("TCG is disabled" );exit (1 );#endif -if (qemu_strtoul (optarg,NULL ,0 , &tcg_tb_size) <0 ) { -error_report ("Invalid argument to -tb-size" ); -exit (1 ); - } +warn_report ("The -tb-size option is deprecated, use -accel tcg,tb-size instead" ); +object_register_sugar_prop (ACCEL_CLASS_NAME ("tcg" ),"tb-size" , optarg);break ;case QEMU_OPTION_icount: icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"),
Signature · 1 line
1.8.3.1
Re: [PATCH 12/16] tcg: add "-accel tcg,tb-size" and deprecate "-tb-size"
Quoted 2 lines · Paolo Bonzini
-tb-size fits nicely in the new framework for accelerator-specific options. It is a very niche option, so insta-deprecate the old version.
Good idea!
Quoted 14 lines
Signed-off-by Paolo Bonzini <[email protected]>--- accel/tcg/tcg-all.c | 40 +++++++++++++++++++++++++++++++++++++--- include/sysemu/accel.h | 2 -- qemu-deprecated.texi | 6 ++++++ qemu-options.hx | 6 +++++- vl.c | 8 ++++---- 5 files changed, 52 insertions(+), 10 deletions(-)accel/tcg/tcg-all.c +0
-0
accel/tcg/tcg-all.c line 43
Quoted 10 lines
accel/tcg/tcg-all.c +2
-0@@ -34,11 +34,13 @@#include "include/qapi/error.h" #include "include/qemu/error-report.h" #include "include/hw/boards.h" +#include "qapi/qapi-builtin-visit.h" typedef struct TCGState { AccelState parent_obj; bool mttcg_enabled; + unsigned long tb_size;
So this tb_size is "long" ...
Quoted 13 lines
accel/tcg/tcg-all.c +0
-2} TCGState;#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg")@@ -46,8 +48,6 @@ typedef struct TCGState {#define TCG_STATE (obj) \ OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL) -unsigned long tcg_tb_size; -/* mask must never be zero, except for A20 change call */ static void tcg_handle_interrupt (CPUState *cpu,int mask) {
accel/tcg/tcg-all.c static int tcg_init(MachineState *ms) · line 129
Quoted 5 lines
accel/tcg/tcg-all.c +1
-1@@ -126,7 +126,7 @@ static int tcg_init(MachineState *ms) {TCGState *s =TCG_STATE (current_machine->accelerator); -tcg_exec_init (tcg_tb_size *1024 *1024 ); +tcg_exec_init (s->tb_size *1024 *1024 );
... which is likely ok for this calculation here ...
Quoted 5 lines
accel/tcg/tcg-all.c +0
-0cpu_interrupt_handler = tcg_handle_interrupt; mttcg_enabled = s->mttcg_enabled;return 0 ;@@ -167,6 +167,33 @@ static void tcg_set_thread(Object *obj, const char *value, Error **errp) }
accel/tcg/tcg-all.c static void tcg_set_thread(Object *obj, const char *value, Error **errp) · line 177
Quoted 10 lines
accel/tcg/tcg-all.c +8
-0} +static void tcg_get_tb_size (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +TCGState *s =TCG_STATE (obj); +uint32_t value = s->tb_size; + +visit_type_uint32 (v, name, &value, errp);
... but this is only using 32-bit values.
Should be fine, I guess, but it's a little bit confusing when looking at the code with a quick glance only.
Maybe turn tb_size into a "uint32_t", too, and then use "* MiB" in above calculation instead of "* 1024 * 1024" ?
Quoted 1 line
accel/tcg/tcg-all.c +1
-0+}
[...]
qemu-options.hx ETEXI · line 121
Quoted 7 lines
qemu-options.hx +0
-0@@ -120,6 +120,7 @@ ETEXI DEF("accel", HAS_ARG, QEMU_OPTION_accel, "-accel [accel=]accelerator[,thread=single|multi]\n"
Maybe add the "[,prop[=value]" change from the next patch here already?
Or should we even split it up into separate lines, like we do it for -netdev for example already? i.e.:
-accel tcg,[,thread=single|multi][,tb-size=n]\n
...
-accel xen,[igd-passthrough=...]\n?
Quoted 37 lines
qemu-options.hx +5
-1" select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" + " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) STEXI @item -accel @var{name}[,prop=@var{value}[,...]]@@ -129,6 +130,8 @@ kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If th more than one accelerator specified, the next one is used if the previous one fails to initialize. @table @option +@item tb-size=@var{n} +Controls the size (in MiB) of the TCG translation block cache. @item thread=single|multi Controls number of TCG threads. When the TCG is multi-threaded there will be one thread per vCPU therefor taking advantage of additional host cores. The default@@ -3995,7 +3998,8 @@ DEF("tb-size", HAS_ARG, QEMU_OPTION_tb_size, \ STEXI @item -tb-size @var{n} @findex -tb-size -Set TB size. +Set TCG translation block cache size. Deprecated, use @samp{-accel tcg,tb-size=@var{n}} +instead. ETEXI DEF("incoming", HAS_ARG, QEMU_OPTION_incoming, \vl.c +1
-0@@ -2857,6 +2857,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } accel =ACCEL (object_new_with_class (OBJECT_CLASS (ac))); +object_apply_compat_props (OBJECT (accel));qemu_opt_foreach (opts, accelerator_set_property, accel, &error_fatal);
vl.c static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) · line 2872
Quoted 4 lines
vl.c +1
-0@@ -2868,6 +2869,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) acc, strerror(-ret));return 0 ; } +
Unnecessary white space change.
Quoted 7 lines
vl.c +0
-0return 1 ; }@@ -3747,10 +3749,8 @@ int main(int argc, char **argv, char **envp)error_report ("TCG is disabled" );exit (1 );
vl.c int main(int argc, char **argv, char **envp) · line 3756
Quoted 10 lines
vl.c +2
-4#endif -if (qemu_strtoul (optarg,NULL ,0 , &tcg_tb_size) <0 ) { -error_report ("Invalid argument to -tb-size" ); -exit (1 ); - } +warn_report ("The -tb-size option is deprecated, use -accel tcg,tb-size instead" ); +object_register_sugar_prop (ACCEL_CLASS_NAME ("tcg" ),"tb-size" , optarg);break ;case QEMU_OPTION_icount: icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"),
Thomas
PATCH 13/16 xen: convert "-machine igd-passthru" to an accelerator property
In reply to Paolo BonziniThe first machine property to fall is Xen's Intel integrated graphics passthrough. The "-machine igd-passthru" option does not set anymore a property on the machine object, but desugars to a GlobalProperty on accelerator objects.
The setter is very simple, since the value ends up in a global variable, so this patch also provides an example before the more complicated cases that follow it.
--- hw/core/machine.c | 20 -------------------- hw/xen/xen-common.c | 16 ++++++++++++++++ include/hw/boards.h | 1 - qemu-options.hx | 9 +++++---- vl.c | 14 ++++---------- 5 files changed, 25 insertions(+), 35 deletions(-)
hw/core/machine.c +0 -20
@@ -412,20 +412,6 @@ static void machine_set_graphics(Object *obj, bool value, Error **errp) ms->enable_graphics = value; } -static bool machine_get_igd_gfx_passthru (Object *obj,Error **errp) -{ -MachineState *ms =MACHINE (obj); - -return ms->igd_gfx_passthru; -} - -static void machine_set_igd_gfx_passthru (Object *obj,bool value,Error **errp) -{ -MachineState *ms =MACHINE (obj); - - ms->igd_gfx_passthru = value; -} -static char *machine_get_firmware (Object *obj,Error **errp) {MachineState *ms =MACHINE (obj);
@@ -862,12 +848,6 @@ static void machine_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,"graphics" ,"Set on/off to enable/disable graphics emulation" , &error_abort); -object_class_property_add_bool (oc,"igd-passthru" , - machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru, - &error_abort); -object_class_property_set_description (oc,"igd-passthru" , -"Set on/off to enable/disable igd passthrou" , &error_abort); -object_class_property_add_str (oc,"firmware" , machine_get_firmware, machine_set_firmware, &error_abort);
hw/xen/xen-common.c +16 -0
@@ -124,6 +124,16 @@ static void xen_change_state_handler(void *opaque, int running, } } +static bool xen_get_igd_gfx_passthru (Object *obj,Error **errp) +{ +return has_igd_gfx_passthru; +} + +static void xen_set_igd_gfx_passthru (Object *obj,bool value,Error **errp) +{ + has_igd_gfx_passthru = value; +} +static void xen_setup_post (MachineState *ms,AccelState *accel) {int rc;
@@ -177,6 +187,12 @@ static void xen_accel_class_init(ObjectClass *oc, void *data) ac->compat_props =g_ptr_array_new ();compat_props_add (ac->compat_props, compat,G_N_ELEMENTS (compat)); + +object_class_property_add_bool (oc,"igd-passthru" , + xen_get_igd_gfx_passthru, xen_set_igd_gfx_passthru, + &error_abort); +object_class_property_set_description (oc,"igd-passthru" , +"Set on/off to enable/disable igd passthrou" , &error_abort); }#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
include/hw/boards.h +0 -1
@@ -287,7 +287,6 @@ struct MachineState {bool mem_merge;bool usb;bool usb_disabled; -bool igd_gfx_passthru;char *firmware;bool iommu;bool suppress_vmdesc;
qemu-options.hx +5 -4
@@ -37,7 +37,6 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " kvm_shadow_mem=size of KVM shadow MMU in bytes\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" - " igd-passthru=on|off controls IGD GFX passthrough support (default=off)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n" " suppress-vmdesc=on|off disables self-describing migration (default=off)\n"
@@ -71,8 +70,6 @@ more than one accelerator specified, the next one is used if the previous one fails to initialize. @item kernel_irqchip=on|off Controls in-kernel irqchip support for the chosen accelerator when available. -@item gfx_passthru=on|off -Enables IGD GFX passthrough support for the chosen machine when available. @item vmport=on|off|auto Enables emulation of VMWare IO port, for vmmouse etc. auto says to select the value based on accel. For accel=xen the default is off otherwise the default
@@ -118,8 +115,9 @@ Select CPU model (@code{-cpu help} for list and additional feature selection) ETEXI DEF("accel", HAS_ARG, QEMU_OPTION_accel, - "-accel [accel=]accelerator[,thread=single|multi]\n" + "-accel [accel=]accelerator[,prop[=value][,...]]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" + " igd-passthru=on|off (enable Xen integrated Intel graphics passthrough, default=off)\n" " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) STEXI
@@ -130,6 +128,9 @@ kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If th more than one accelerator specified, the next one is used if the previous one fails to initialize. @table @option +@item igd-passthru=on|off +When Xen is in use, this option controls whether Intel integrated graphics +devices can be passed through to the guest (default=off) @item tb-size=@var{n} Controls the size (in MiB) of the TCG translation block cache. @item thread=single|multi
vl.c +4 -10
@@ -1256,13 +1256,6 @@ static void configure_msg(QemuOpts *opts) } -/* Now we still need this for compatibility with XEN. */ -bool has_igd_gfx_passthru; -static void igd_gfx_passthru (void ) -{ - has_igd_gfx_passthru = current_machine->igd_gfx_passthru; -} -/***********************************************************/ /* USB devices */
@@ -2645,6 +2638,10 @@ static int machine_set_property(void *opaque,if (g_str_equal (qom_name,"accel" )) {return 0 ; } +if (g_str_equal (qom_name,"igd-passthru" )) { +object_register_sugar_prop (ACCEL_CLASS_NAME ("xen" ), qom_name, value); +return 0 ; + } r =object_parse_property_opt (opaque, name, value,"type" , errp);g_free (qom_name);
@@ -4449,9 +4446,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -/* Check if IGD GFX passthrough. */ -igd_gfx_passthru (); -/* init generic devices */ rom_set_order_override (FW_CFG_ORDER_OVERRIDE_DEVICE ); qemu_opts_foreach(qemu_find_opts("device"),
Signature · 1 line
1.8.3.1
Re: [PATCH 13/16] xen: convert "-machine igd-passthru" to an accelerator property
Quoted 11 lines · Paolo Bonzini
The first machine property to fall is Xen's Intel integrated graphics passthrough. The "-machine igd-passthru" option does not set anymore a property on the machine object, but desugars to a GlobalProperty on accelerator objects.
The setter is very simple, since the value ends up in a global variable, so this patch also provides an example before the more complicated cases that follow it.
Signed-off-by Paolo Bonzini <[email protected]>
Did something go wrong with get_maintainers here? The Xen maintainers ought to have been cc-ed. The Xen toolstack will require consequent modification.
Cc-ing (rest of) Xen maintainers and xen-devel manually.
Paul
Quoted 174 lines
--- hw/core/machine.c | 20 -------------------- hw/xen/xen-common.c | 16 ++++++++++++++++ include/hw/boards.h | 1 - qemu-options.hx | 9 +++++---- vl.c | 14 ++++---------- 5 files changed, 25 insertions(+), 35 deletions(-)hw/core/machine.c +0
-20@@ -412,20 +412,6 @@ static void machine_set_graphics(Object *obj, bool value, Error **errp) ms->enable_graphics = value; } -static bool machine_get_igd_gfx_passthru (Object *obj,Error **errp) -{ -MachineState *ms =MACHINE (obj); - -return ms->igd_gfx_passthru; -} - -static void machine_set_igd_gfx_passthru (Object *obj,bool value,Error **errp) -{ -MachineState *ms =MACHINE (obj); - - ms->igd_gfx_passthru = value; -} -static char *machine_get_firmware (Object *obj,Error **errp) {MachineState *ms =MACHINE (obj);@@ -862,12 +848,6 @@ static void machine_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,"graphics" ,"Set on/off to enable/disable graphics emulation" , &error_abort); -object_class_property_add_bool (oc,"igd-passthru" , - machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru, - &error_abort); -object_class_property_set_description (oc,"igd-passthru" , -"Set on/off to enable/disable igd passthrou" , &error_abort); -object_class_property_add_str (oc,"firmware" , machine_get_firmware, machine_set_firmware, &error_abort);hw/xen/xen-common.c +16
-0@@ -124,6 +124,16 @@ static void xen_change_state_handler(void *opaque, int running, } } +static bool xen_get_igd_gfx_passthru (Object *obj,Error **errp) +{ +return has_igd_gfx_passthru; +} + +static void xen_set_igd_gfx_passthru (Object *obj,bool value,Error **errp) +{ + has_igd_gfx_passthru = value; +} +static void xen_setup_post (MachineState *ms,AccelState *accel) {int rc;@@ -177,6 +187,12 @@ static void xen_accel_class_init(ObjectClass *oc, void *data) ac->compat_props =g_ptr_array_new ();compat_props_add (ac->compat_props, compat,G_N_ELEMENTS (compat)); + +object_class_property_add_bool (oc,"igd-passthru" , + xen_get_igd_gfx_passthru, xen_set_igd_gfx_passthru, + &error_abort); +object_class_property_set_description (oc,"igd-passthru" , +"Set on/off to enable/disable igd passthrou" , &error_abort); }#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")include/hw/boards.h +0
-1@@ -287,7 +287,6 @@ struct MachineState {bool mem_merge;bool usb;bool usb_disabled; -bool igd_gfx_passthru;char *firmware;bool iommu;bool suppress_vmdesc;qemu-options.hx +5
-4@@ -37,7 +37,6 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " kvm_shadow_mem=size of KVM shadow MMU in bytes\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" - " igd-passthru=on|off controls IGD GFX passthrough support (default=off)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n" " suppress-vmdesc=on|off disables self-describing migration (default=off)\n"@@ -71,8 +70,6 @@ more than one accelerator specified, the next one is used if the previous one fails to initialize. @item kernel_irqchip=on|off Controls in-kernel irqchip support for the chosen accelerator when available. -@item gfx_passthru=on|off -Enables IGD GFX passthrough support for the chosen machine when available. @item vmport=on|off|auto Enables emulation of VMWare IO port, for vmmouse etc. auto says to select the value based on accel. For accel=xen the default is off otherwise the default@@ -118,8 +115,9 @@ Select CPU model (@code{-cpu help} for list and additional feature selection) ETEXI DEF("accel", HAS_ARG, QEMU_OPTION_accel, - "-accel [accel=]accelerator[,thread=single|multi]\n" + "-accel [accel=]accelerator[,prop[=value][,...]]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" + " igd-passthru=on|off (enable Xen integrated Intel graphics passthrough, default=off)\n" " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) STEXI@@ -130,6 +128,9 @@ kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If th more than one accelerator specified, the next one is used if the previous one fails to initialize. @table @option +@item igd-passthru=on|off +When Xen is in use, this option controls whether Intel integrated graphics +devices can be passed through to the guest (default=off) @item tb-size=@var{n} Controls the size (in MiB) of the TCG translation block cache. @item thread=single|multivl.c +4
-11@@ -1256,13 +1256,6 @@ static void configure_msg(QemuOpts *opts) } -/* Now we still need this for compatibility with XEN. */ -bool has_igd_gfx_passthru; -static void igd_gfx_passthru (void ) -{ - has_igd_gfx_passthru = current_machine->igd_gfx_passthru; -} -/***********************************************************/ /* USB devices */ @@ -2645,6 +2638,10 @@ static int machine_set_property(void *opaque,if (g_str_equal (qom_name,"accel" )) {return 0 ; } +if (g_str_equal (qom_name,"igd-passthru" )) { +object_register_sugar_prop (ACCEL_CLASS_NAME ("xen" ), qom_name, value); +return 0 ; + } r =object_parse_property_opt (opaque, name, value,"type" , errp);g_free (qom_name);@@ -4449,9 +4446,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -/* Check if IGD GFX passthrough. */ -igd_gfx_passthru (); -/* init generic devices */ rom_set_order_override (FW_CFG_ORDER_OVERRIDE_DEVICE ); qemu_opts_foreach(qemu_find_opts("device"), --
Quoted 4 lines
1.8.3.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 13/16] xen: convert "-machine igd-passthru" to an accelerator property
Quoted 11 lines · Paul Durrant
Quoted 10 lines · Paolo Bonzini
The first machine property to fall is Xen's Intel integrated graphics passthrough. The "-machine igd-passthru" option does not set anymore a property on the machine object, but desugars to a GlobalProperty on accelerator objects.
The setter is very simple, since the value ends up in a global variable, so this patch also provides an example before the more complicated cases that follow it.
Quoted 5 lines
Quoted 1 line
Signed-off-by Paolo Bonzini <[email protected]>Did something go wrong with
get_maintainershere? The Xen maintainers ought to have been cc-ed. The Xen toolstack will require consequent modification.
No, I just didn't use getmaintainers, my bad. But backwards-compatible syntactic sugar is provided, so no modifications are needed to Xen. See here in the code:
+ if (g_str_equal(qom_name, "igd-passthru")) {
+ object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, value);
+ return 0;
+ }
Paolo
Quoted 171 lines
Cc-ing (rest of) Xen maintainers and xen-devel manually.
Paul
Quoted 167 lines
--- hw/core/machine.c | 20 -------------------- hw/xen/xen-common.c | 16 ++++++++++++++++ include/hw/boards.h | 1 - qemu-options.hx | 9 +++++---- vl.c | 14 ++++---------- 5 files changed, 25 insertions(+), 35 deletions(-)hw/core/machine.c +0
-20@@ -412,20 +412,6 @@ static void machine_set_graphics(Object *obj, bool value, Error **errp) ms->enable_graphics = value; } -static bool machine_get_igd_gfx_passthru (Object *obj,Error **errp) -{ -MachineState *ms =MACHINE (obj); - -return ms->igd_gfx_passthru; -} - -static void machine_set_igd_gfx_passthru (Object *obj,bool value,Error **errp) -{ -MachineState *ms =MACHINE (obj); - - ms->igd_gfx_passthru = value; -} -static char *machine_get_firmware (Object *obj,Error **errp) {MachineState *ms =MACHINE (obj);@@ -862,12 +848,6 @@ static void machine_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,"graphics" ,"Set on/off to enable/disable graphics emulation" , &error_abort); -object_class_property_add_bool (oc,"igd-passthru" , - machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru, - &error_abort); -object_class_property_set_description (oc,"igd-passthru" , -"Set on/off to enable/disable igd passthrou" , &error_abort); -object_class_property_add_str (oc,"firmware" , machine_get_firmware, machine_set_firmware, &error_abort);hw/xen/xen-common.c +16
-0@@ -124,6 +124,16 @@ static void xen_change_state_handler(void *opaque, int running, } } +static bool xen_get_igd_gfx_passthru (Object *obj,Error **errp) +{ +return has_igd_gfx_passthru; +} + +static void xen_set_igd_gfx_passthru (Object *obj,bool value,Error **errp) +{ + has_igd_gfx_passthru = value; +} +static void xen_setup_post (MachineState *ms,AccelState *accel) {int rc;@@ -177,6 +187,12 @@ static void xen_accel_class_init(ObjectClass *oc, void *data) ac->compat_props =g_ptr_array_new ();compat_props_add (ac->compat_props, compat,G_N_ELEMENTS (compat)); + +object_class_property_add_bool (oc,"igd-passthru" , + xen_get_igd_gfx_passthru, xen_set_igd_gfx_passthru, + &error_abort); +object_class_property_set_description (oc,"igd-passthru" , +"Set on/off to enable/disable igd passthrou" , &error_abort); }#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")include/hw/boards.h +0
-1@@ -287,7 +287,6 @@ struct MachineState {bool mem_merge;bool usb;bool usb_disabled; -bool igd_gfx_passthru;char *firmware;bool iommu;bool suppress_vmdesc;qemu-options.hx +5
-4@@ -37,7 +37,6 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " kvm_shadow_mem=size of KVM shadow MMU in bytes\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" - " igd-passthru=on|off controls IGD GFX passthrough support (default=off)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n" " suppress-vmdesc=on|off disables self-describing migration (default=off)\n"@@ -71,8 +70,6 @@ more than one accelerator specified, the next one is used if the previous one fails to initialize. @item kernel_irqchip=on|off Controls in-kernel irqchip support for the chosen accelerator when available. -@item gfx_passthru=on|off -Enables IGD GFX passthrough support for the chosen machine when available. @item vmport=on|off|auto Enables emulation of VMWare IO port, for vmmouse etc. auto says to select the value based on accel. For accel=xen the default is off otherwise the default@@ -118,8 +115,9 @@ Select CPU model (@code{-cpu help} for list and additional feature selection) ETEXI DEF("accel", HAS_ARG, QEMU_OPTION_accel, - "-accel [accel=]accelerator[,thread=single|multi]\n" + "-accel [accel=]accelerator[,prop[=value][,...]]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" + " igd-passthru=on|off (enable Xen integrated Intel graphics passthrough, default=off)\n" " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) STEXI@@ -130,6 +128,9 @@ kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If th more than one accelerator specified, the next one is used if the previous one fails to initialize. @table @option +@item igd-passthru=on|off +When Xen is in use, this option controls whether Intel integrated graphics +devices can be passed through to the guest (default=off) @item tb-size=@var{n} Controls the size (in MiB) of the TCG translation block cache. @item thread=single|multivl.c +4
-7@@ -1256,13 +1256,6 @@ static void configure_msg(QemuOpts *opts) } -/* Now we still need this for compatibility with XEN. */ -bool has_igd_gfx_passthru; -static void igd_gfx_passthru (void ) -{ - has_igd_gfx_passthru = current_machine->igd_gfx_passthru; -} -/***********************************************************/ /* USB devices */ @@ -2645,6 +2638,10 @@ static int machine_set_property(void *opaque,if (g_str_equal (qom_name,"accel" )) {return 0 ; } +if (g_str_equal (qom_name,"igd-passthru" )) { +object_register_sugar_prop (ACCEL_CLASS_NAME ("xen" ), qom_name, value); +return 0 ; + } r =object_parse_property_opt (opaque, name, value,"type" , errp);g_free (qom_name);@@ -4449,9 +4446,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); }
Quoted 12 lines
Quoted 11 lines
vl.c +0
-4-/* Check if IGD GFX passthrough. */ -igd_gfx_passthru (); -/* init generic devices */ rom_set_order_override (FW_CFG_ORDER_OVERRIDE_DEVICE ); qemu_opts_foreach(qemu_find_opts("device"), --1.8.3.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 13/16] xen: convert "-machine igd-passthru" to an accelerator property
Quoted 23 lines · Paolo Bonzini
Quoted 11 lines · Paul Durrant
Quoted 10 lines · Paolo Bonzini
The first machine property to fall is Xen's Intel integrated graphics passthrough. The "-machine igd-passthru" option does not set anymore a property on the machine object, but desugars to a GlobalProperty on accelerator objects.
The setter is very simple, since the value ends up in a global variable, so this patch also provides an example before the more complicated cases that follow it.
Quoted 5 lines
Quoted 1 line
Signed-off-by Paolo Bonzini <[email protected]>Did something go wrong with
get_maintainershere? The Xen maintainers ought to have been cc-ed. The Xen toolstack will require consequent modification.No, I just didn't use getmaintainers, my bad. But backwards-compatible syntactic sugar is provided, so no modifications are needed to Xen. See here in the code:
vl.c static int machine_set_property(void *opaque, · line 2644
Quoted 4 lines
vl.c +4
-0+if (g_str_equal (qom_name,"igd-passthru" )) { +object_register_sugar_prop (ACCEL_CLASS_NAME ("xen" ), qom_name, value); +return 0 ; + }
Ah, no immediate danger. Thanks for pointing this out.
Cheers,
Paul
Quoted 187 lines
Paolo
Quoted 183 lines
Cc-ing (rest of) Xen maintainers and xen-devel manually.
Paul
Quoted 178 lines
--- hw/core/machine.c | 20 -------------------- hw/xen/xen-common.c | 16 ++++++++++++++++ include/hw/boards.h | 1 - qemu-options.hx | 9 +++++---- vl.c | 14 ++++---------- 5 files changed, 25 insertions(+), 35 deletions(-)hw/core/machine.c +0
-20@@ -412,20 +412,6 @@ static void machine_set_graphics(Object *obj, bool value, Error **errp) ms->enable_graphics = value; } -static bool machine_get_igd_gfx_passthru (Object *obj,Error **errp) -{ -MachineState *ms =MACHINE (obj); - -return ms->igd_gfx_passthru; -} - -static void machine_set_igd_gfx_passthru (Object *obj,bool value,Error **errp) -{ -MachineState *ms =MACHINE (obj); - - ms->igd_gfx_passthru = value; -} -static char *machine_get_firmware (Object *obj,Error **errp) {MachineState *ms =MACHINE (obj);@@ -862,12 +848,6 @@ static void machine_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,"graphics" ,"Set on/off to enable/disable graphics emulation" , &error_abort); -object_class_property_add_bool (oc,"igd-passthru" , - machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru, - &error_abort); -object_class_property_set_description (oc,"igd-passthru" , -"Set on/off to enable/disable igd passthrou" , &error_abort); -object_class_property_add_str (oc,"firmware" , machine_get_firmware, machine_set_firmware, &error_abort);hw/xen/xen-common.c +16
-0@@ -124,6 +124,16 @@ static void xen_change_state_handler(void *opaque, int running, } } +static bool xen_get_igd_gfx_passthru (Object *obj,Error **errp) +{ +return has_igd_gfx_passthru; +} + +static void xen_set_igd_gfx_passthru (Object *obj,bool value,Error **errp) +{ + has_igd_gfx_passthru = value; +} +static void xen_setup_post (MachineState *ms,AccelState *accel) {int rc;@@ -177,6 +187,12 @@ static void xen_accel_class_init(ObjectClass *oc, void *data) ac->compat_props =g_ptr_array_new ();compat_props_add (ac->compat_props, compat,G_N_ELEMENTS (compat)); + +object_class_property_add_bool (oc,"igd-passthru" , + xen_get_igd_gfx_passthru, xen_set_igd_gfx_passthru, + &error_abort); +object_class_property_set_description (oc,"igd-passthru" , +"Set on/off to enable/disable igd passthrou" , &error_abort); }#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")include/hw/boards.h +0
-1@@ -287,7 +287,6 @@ struct MachineState {bool mem_merge;bool usb;bool usb_disabled; -bool igd_gfx_passthru;char *firmware;bool iommu;bool suppress_vmdesc;qemu-options.hx +5
-4@@ -37,7 +37,6 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " kvm_shadow_mem=size of KVM shadow MMU in bytes\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" - " igd-passthru=on|off controls IGD GFX passthrough support (default=off)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n" " suppress-vmdesc=on|off disables self-describing migration (default=off)\n"@@ -71,8 +70,6 @@ more than one accelerator specified, the next one is used if the previous one fails to initialize. @item kernel_irqchip=on|off Controls in-kernel irqchip support for the chosen accelerator when available. -@item gfx_passthru=on|off -Enables IGD GFX passthrough support for the chosen machine when available. @item vmport=on|off|auto Enables emulation of VMWare IO port, for vmmouse etc. auto says to select the value based on accel. For accel=xen the default is off otherwise the default@@ -118,8 +115,9 @@ Select CPU model (@code{-cpu help} for list and additional feature selection) ETEXI DEF("accel", HAS_ARG, QEMU_OPTION_accel, - "-accel [accel=]accelerator[,thread=single|multi]\n" + "-accel [accel=]accelerator[,prop[=value][,...]]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" + " igd-passthru=on|off (enable Xen integrated Intel graphics passthrough, default=off)\n" " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) STEXI@@ -130,6 +128,9 @@ kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If th more than one accelerator specified, the next one is used if the previous one fails to initialize. @table @option +@item igd-passthru=on|off +When Xen is in use, this option controls whether Intel integrated graphics +devices can be passed through to the guest (default=off) @item tb-size=@var{n} Controls the size (in MiB) of the TCG translation block cache. @item thread=single|multivl.c +4
-11@@ -1256,13 +1256,6 @@ static void configure_msg(QemuOpts *opts) } -/* Now we still need this for compatibility with XEN. */ -bool has_igd_gfx_passthru; -static void igd_gfx_passthru (void ) -{ - has_igd_gfx_passthru = current_machine->igd_gfx_passthru; -} -/***********************************************************/ /* USB devices */ @@ -2645,6 +2638,10 @@ static int machine_set_property(void *opaque,if (g_str_equal (qom_name,"accel" )) {return 0 ; } +if (g_str_equal (qom_name,"igd-passthru" )) { +object_register_sugar_prop (ACCEL_CLASS_NAME ("xen" ), qom_name, value); +return 0 ; + } r =object_parse_property_opt (opaque, name, value,"type" , errp);g_free (qom_name);@@ -4449,9 +4446,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -/* Check if IGD GFX passthrough. */ -igd_gfx_passthru (); -/* init generic devices */ rom_set_order_override (FW_CFG_ORDER_OVERRIDE_DEVICE ); qemu_opts_foreach(qemu_find_opts("device"), --1.8.3.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 13/16] xen: convert "-machine igd-passthru" to an accelerator property
In reply to Paolo BonziniQuoted 9 lines · Paolo Bonzini
The first machine property to fall is Xen's Intel integrated graphics passthrough. The "-machine igd-passthru" option does not set anymore a property on the machine object, but desugars to a GlobalProperty on accelerator objects.
The setter is very simple, since the value ends up in a global variable, so this patch also provides an example before the more complicated cases that follow it.
Quoted 8 lines
Signed-off-by Paolo Bonzini <[email protected]>--- hw/core/machine.c | 20 -------------------- hw/xen/xen-common.c | 16 ++++++++++++++++ include/hw/boards.h | 1 - qemu-options.hx | 9 +++++---- vl.c | 14 ++++---------- 5 files changed, 25 insertions(+), 35 deletions(-)
PATCH 14/16 kvm: convert "-machine kvm_shadow_mem" to an accelerator property
In reply to Paolo Bonzini--- accel/kvm/kvm-all.c | 43 +++++++++++++++++++++++++++++++++++++++++++ hw/core/machine.c | 39 --------------------------------------- include/hw/boards.h | 2 -- qemu-options.hx | 6 +++--- target/i386/kvm.c | 2 +- vl.c | 4 ++++ 6 files changed, 51 insertions(+), 45 deletions(-)
accel/kvm/kvm-all.c +43 -0
@@ -41,6 +41,7 @@#include "hw/irq.h" #include "sysemu/sev.h" #include "sysemu/balloon.h" +#include "qapi/visitor.h" #include "hw/boards.h"
@@ -92,6 +93,7 @@ struct KVMStateint max_nested_state_len;int many_ioeventfds;int intx_set_mask; +int kvm_shadow_mem;bool sync_mmu;bool manual_dirty_log_protect;/* The man page (and posix) say ioctl numbers are signed int, but
@@ -2922,6 +2924,40 @@ static bool kvm_accel_has_memory(MachineState *ms, AddressSpace *as,return false; } +static void kvm_get_kvm_shadow_mem (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +KVMState *s =KVM_STATE (obj); +int64_t value = s->kvm_shadow_mem; + +visit_type_int (v, name, &value, errp); +} + +static void kvm_set_kvm_shadow_mem (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +KVMState *s =KVM_STATE (obj); +Error *error =NULL ; +int64_t value; + +visit_type_int (v, name, &value, &error); +if (error) { +error_propagate (errp, error); +return ; + } + + s->kvm_shadow_mem = value; +} + +static void kvm_accel_instance_init (Object *obj) +{ +KVMState *s =KVM_STATE (obj); + + s->kvm_shadow_mem =-1 ; +} +static void kvm_accel_class_init (ObjectClass *oc,void *data) {AccelClass *ac =ACCEL_CLASS (oc);
@@ -2929,11 +2965,18 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data) ac->init_machine = kvm_init; ac->has_memory = kvm_accel_has_memory; ac->allowed = &kvm_allowed; + +object_class_property_add (oc,"kvm-shadow-mem" ,"int" , + kvm_get_kvm_shadow_mem, kvm_set_kvm_shadow_mem, +NULL ,NULL , &error_abort); +object_class_property_set_description (oc,"kvm-shadow-mem" , +"KVM shadow MMU size" , &error_abort); }static const TypeInfo kvm_accel_type = { .name =TYPE_KVM_ACCEL , .parent =TYPE_ACCEL , + .instance_init = kvm_accel_instance_init, .class_init = kvm_accel_class_init, .instance_size =sizeof (KVMState), };
hw/core/machine.c +0 -39
@@ -211,33 +211,6 @@ static void machine_set_kernel_irqchip(Object *obj, Visitor *v, } } -static void machine_get_kvm_shadow_mem (Object *obj,Visitor *v, -const char *name,void *opaque, -Error **errp) -{ -MachineState *ms =MACHINE (obj); -int64_t value = ms->kvm_shadow_mem; - -visit_type_int (v, name, &value, errp); -} - -static void machine_set_kvm_shadow_mem (Object *obj,Visitor *v, -const char *name,void *opaque, -Error **errp) -{ -MachineState *ms =MACHINE (obj); -Error *error =NULL ; -int64_t value; - -visit_type_int (v, name, &value, &error); -if (error) { -error_propagate (errp, error); -return ; - } - - ms->kvm_shadow_mem = value; -} -static char *machine_get_kernel (Object *obj,Error **errp) {MachineState *ms =MACHINE (obj);
@@ -785,12 +758,6 @@ static void machine_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,"kernel-irqchip" ,"Configure KVM in-kernel irqchip" , &error_abort); -object_class_property_add (oc,"kvm-shadow-mem" ,"int" , - machine_get_kvm_shadow_mem, machine_set_kvm_shadow_mem, -NULL ,NULL , &error_abort); -object_class_property_set_description (oc,"kvm-shadow-mem" , -"KVM shadow MMU size" , &error_abort); -object_class_property_add_str (oc,"kernel" , machine_get_kernel, machine_set_kernel, &error_abort); object_class_property_set_description(oc, "kernel",
@@ -892,7 +859,6 @@ static void machine_initfn(Object *obj) ms->kernel_irqchip_allowed = true; ms->kernel_irqchip_split = mc->default_kernel_irqchip_split; - ms->kvm_shadow_mem =-1 ; ms->dump_guest_core = true; ms->mem_merge = true; ms->enable_graphics = true;
@@ -963,11 +929,6 @@ bool machine_kernel_irqchip_split(MachineState *machine)return machine->kernel_irqchip_split; } -int machine_kvm_shadow_mem (MachineState *machine) -{ -return machine->kvm_shadow_mem; -} -int machine_phandle_start (MachineState *machine) {return machine->phandle_start;
include/hw/boards.h +0 -2
@@ -66,7 +66,6 @@ bool machine_usb(MachineState *machine);bool machine_kernel_irqchip_allowed (MachineState *machine);bool machine_kernel_irqchip_required (MachineState *machine);bool machine_kernel_irqchip_split (MachineState *machine); -int machine_kvm_shadow_mem (MachineState *machine);int machine_phandle_start (MachineState *machine);bool machine_dump_guest_core (MachineState *machine);bool machine_mem_merge (MachineState *machine);
@@ -278,7 +277,6 @@ struct MachineState {bool kernel_irqchip_allowed;bool kernel_irqchip_required;bool kernel_irqchip_split; -int kvm_shadow_mem;char *dtb;char *dumpdtb;int phandle_start;
qemu-options.hx +3 -3
@@ -34,7 +34,6 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " supported accelerators are kvm, xen, hax, hvf, whpx or tcg (default: tcg)\n" " kernel_irqchip=on|off|split controls accelerated irqchip support (default=off)\n" " vmport=on|off|auto controls emulation of vmport (default: auto)\n" - " kvm_shadow_mem=size of KVM shadow MMU in bytes\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n"
@@ -74,8 +73,6 @@ Controls in-kernel irqchip support for the chosen accelerator when available. Enables emulation of VMWare IO port, for vmmouse etc. auto says to select the value based on accel. For accel=xen the default is off otherwise the default is on. -@item kvm_shadow_mem=size -Defines the size of the KVM shadow MMU. @item dump-guest-core=on|off Include guest memory in a core dump. The default is on. @item mem-merge=on|off
@@ -118,6 +115,7 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel, "-accel [accel=]accelerator[,prop[=value][,...]]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" " igd-passthru=on|off (enable Xen integrated Intel graphics passthrough, default=off)\n" + " kvm-shadow-mem=size of KVM shadow MMU in bytes\n" " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) STEXI
@@ -131,6 +129,8 @@ fails to initialize. @item igd-passthru=on|off When Xen is in use, this option controls whether Intel integrated graphics devices can be passed through to the guest (default=off) +@item kvm-shadow-mem=size +Defines the size of the KVM shadow MMU. @item tb-size=@var{n} Controls the size (in MiB) of the TCG translation block cache. @item thread=single|multi
target/i386/kvm.c +1 -1
@@ -2159,7 +2159,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) }qemu_register_reset (kvm_unpoison_all,NULL ); - shadow_mem =machine_kvm_shadow_mem (ms); + shadow_mem =object_property_get_int (OBJECT (s),"kvm-shadow-mem" , &error_abort);if (shadow_mem !=-1 ) { shadow_mem /=4096 ; ret =kvm_vm_ioctl (s,KVM_SET_NR_MMU_PAGES , shadow_mem);
vl.c +4 -0
@@ -2642,6 +2642,10 @@ static int machine_set_property(void *opaque,object_register_sugar_prop (ACCEL_CLASS_NAME ("xen" ), qom_name, value);return 0 ; } +if (g_str_equal (qom_name,"kvm-shadow-mem" )) { +object_register_sugar_prop (ACCEL_CLASS_NAME ("kvm" ), qom_name, value); +return 0 ; + } r =object_parse_property_opt (opaque, name, value,"type" , errp);g_free (qom_name);
Signature · 1 line
1.8.3.1
Re: [PATCH 14/16] kvm: convert "-machine kvm_shadow_mem" to an accelerator property
Quoted 23 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- accel/kvm/kvm-all.c | 43 +++++++++++++++++++++++++++++++++++++++++++ hw/core/machine.c | 39 --------------------------------------- include/hw/boards.h | 2 -- qemu-options.hx | 6 +++--- target/i386/kvm.c | 2 +- vl.c | 4 ++++ 6 files changed, 51 insertions(+), 45 deletions(-)accel/kvm/kvm-all.c +1
-0@@ -41,6 +41,7 @@#include "hw/irq.h" #include "sysemu/sev.h" #include "sysemu/balloon.h" +#include "qapi/visitor.h" #include "hw/boards.h"
accel/kvm/kvm-all.c struct KVMState · line 96
Quoted 4 lines
accel/kvm/kvm-all.c +1
-0@@ -92,6 +93,7 @@ struct KVMStateint max_nested_state_len;int many_ioeventfds;int intx_set_mask; +int kvm_shadow_mem;
It's an "int" here...
Quoted 23 lines
accel/kvm/kvm-all.c +16
-0bool sync_mmu;bool manual_dirty_log_protect;/* The man page (and posix) say ioctl numbers are signed int, but @@ -2922,6 +2924,40 @@ static bool kvm_accel_has_memory(MachineState *ms, AddressSpace *as,return false; } +static void kvm_get_kvm_shadow_mem (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +KVMState *s =KVM_STATE (obj); +int64_t value = s->kvm_shadow_mem; + +visit_type_int (v, name, &value, errp); +} + +static void kvm_set_kvm_shadow_mem (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +KVMState *s =KVM_STATE (obj); +Error *error =NULL ;
accel/kvm/kvm-all.c static bool kvm_accel_has_memory(MachineState *ms, AddressSpace *as, · line 2952
Quoted 10 lines
accel/kvm/kvm-all.c +10
-0+int64_t value; + +visit_type_int (v, name, &value, &error); +if (error) { +error_propagate (errp, error); +return ; + } + + s->kvm_shadow_mem = value; +}
... but the get and set functions are using an int64_t internally? Looks somewhat weird. Well, it has been like this in the old code already, but maybe it's now a good point in time to clean this up?
Thomas
PATCH 15/16 kvm: introduce kvm_kernel_irqchip_* functions
In reply to Paolo BonziniThe KVMState struct is opaque, so provide accessors for the fields that will be moved from current_machine to the accelerator. For now they just forward to the machine object, but this will change.
--- accel/kvm/kvm-all.c | 23 +++++++++++++++++++---- hw/ppc/e500.c | 4 ++-- hw/ppc/spapr_irq.c | 10 +++++----- include/sysemu/kvm.h | 7 +++++-- target/arm/kvm.c | 8 ++++---- target/i386/kvm.c | 4 ++-- target/mips/kvm.c | 2 +- target/ppc/kvm.c | 2 +- target/s390x/kvm.c | 2 +- 9 files changed, 40 insertions(+), 22 deletions(-)
accel/kvm/kvm-all.c +19 -4
@@ -1742,7 +1742,7 @@ void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi)g_hash_table_insert (s->gsimap, irq,GINT_TO_POINTER (gsi)); } -static void kvm_irqchip_create (MachineState *machine,KVMState *s) +static void kvm_irqchip_create (KVMState *s) {int ret;
@@ -1760,9 +1760,9 @@ static void kvm_irqchip_create(MachineState *machine, KVMState *s)/* First probe and see if there's a arch-specific hook to create the * in-kernel irqchip for us */ - ret =kvm_arch_irqchip_create (machine, s); + ret =kvm_arch_irqchip_create (s);if (ret ==0 ) { -if (machine_kernel_irqchip_split (machine)) { +if (kvm_kernel_irqchip_split ()) {perror ("Split IRQ chip mode not supported." );exit (1 ); }else {
@@ -2034,7 +2034,7 @@ static int kvm_init(MachineState *ms) }if (machine_kernel_irqchip_allowed (ms)) { -kvm_irqchip_create (ms, s); +kvm_irqchip_create (s); }if (kvm_eventfds_allowed) {
@@ -2951,6 +2951,21 @@ static void kvm_set_kvm_shadow_mem(Object *obj, Visitor *v, s->kvm_shadow_mem = value; } +bool kvm_kernel_irqchip_allowed (void ) +{ +return machine_kernel_irqchip_allowed (current_machine); +} + +bool kvm_kernel_irqchip_required (void ) +{ +return machine_kernel_irqchip_required (current_machine); +} + +bool kvm_kernel_irqchip_split (void ) +{ +return machine_kernel_irqchip_split (current_machine); +} +static void kvm_accel_instance_init (Object *obj) {KVMState *s =KVM_STATE (obj);
hw/ppc/e500.c +2 -2
@@ -801,10 +801,10 @@ static DeviceState *ppce500_init_mpic(PPCE500MachineState *pms,if (kvm_enabled ()) {Error *err =NULL ; -if (machine_kernel_irqchip_allowed (machine)) { +if (kvm_kernel_irqchip_allowed ()) { dev =ppce500_init_mpic_kvm (pmc, irqs, &err); } -if (machine_kernel_irqchip_required (machine) && !dev) { +if (kvm_kernel_irqchip_required () && !dev) {error_reportf_err (err,"kernel_irqchip requested but unavailable: " );exit (1 );
hw/ppc/spapr_irq.c +5 -5
@@ -77,9 +77,9 @@ int spapr_irq_init_kvm(int (*fn)(SpaprInterruptController *, Error **),MachineState *machine =MACHINE (qdev_get_machine ());Error *local_err =NULL ; -if (kvm_enabled () &&machine_kernel_irqchip_allowed (machine)) { +if (kvm_enabled () &&kvm_kernel_irqchip_allowed ()) {if (fn (intc, &local_err) <0 ) { -if (machine_kernel_irqchip_required (machine)) { +if (kvm_kernel_irqchip_required ()) {error_prepend (&local_err,"kernel_irqchip requested but unavailable: " );error_propagate (errp, local_err);
@@ -184,7 +184,7 @@ static int spapr_irq_check(SpaprMachineState *spapr, Error **errp)*/ if (kvm_enabled () && spapr->irq == &spapr_irq_dual && -machine_kernel_irqchip_required (machine) && +kvm_kernel_irqchip_required () &&xics_kvm_has_broken_disconnect (spapr)) {error_setg (errp,"KVM is too old to support ic-mode=dual,kernel-irqchip=on" );return -1 ;
@@ -276,12 +276,12 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)MachineState *machine =MACHINE (spapr);SpaprMachineClass *smc =SPAPR_MACHINE_GET_CLASS (spapr); -if (machine_kernel_irqchip_split (machine)) { +if (kvm_enabled () &&kvm_kernel_irqchip_split ()) {error_setg (errp,"kernel_irqchip split mode not supported on pseries" );return ; } -if (!kvm_enabled () &&machine_kernel_irqchip_required (machine)) { +if (!kvm_enabled () &&kvm_kernel_irqchip_required ()) {error_setg (errp,"kernel_irqchip requested but only available with KVM" );return ;
include/sysemu/kvm.h +5 -2
@@ -514,10 +514,13 @@ void kvm_pc_gsi_handler(void *opaque, int n, int level);void kvm_pc_setup_irq_routing (bool pci_enabled);void kvm_init_irq_routing (KVMState *s); +bool kvm_kernel_irqchip_allowed (void ); +bool kvm_kernel_irqchip_required (void ); +bool kvm_kernel_irqchip_split (void ); +/** * kvm_arch_irqchip_create: * @KVMState: The KVMState pointer -* @MachineState: The MachineState pointer * * Allow architectures to create an in-kernel irq chip themselves. *
@@ -525,7 +528,7 @@ void kvm_init_irq_routing(KVMState *s);* 0: irq chip was not created * > 0: irq chip was created */ -int kvm_arch_irqchip_create (MachineState *ms,KVMState *s); +int kvm_arch_irqchip_create (KVMState *s);/** * kvm_set_one_reg - set a register value in KVM via KVM_SET_ONE_REG ioctl
target/arm/kvm.c +4 -4
@@ -726,11 +726,11 @@ void kvm_arch_init_irq_routing(KVMState *s) { } -int kvm_arch_irqchip_create (MachineState *ms,KVMState *s) +int kvm_arch_irqchip_create (KVMState *s) { -if (machine_kernel_irqchip_split (ms)) { -perror ("-machine kernel_irqchip=split is not supported on ARM." ); -exit (1 ); +if (kvm_kernel_irqchip_split ()) { +perror ("-machine kernel_irqchip=split is not supported on ARM." ); +exit (1 ); }/* If we can create the VGIC using the newer device control API, we
target/i386/kvm.c +2 -2
@@ -4473,10 +4473,10 @@ void kvm_arch_init_irq_routing(KVMState *s) } } -int kvm_arch_irqchip_create (MachineState *ms,KVMState *s) +int kvm_arch_irqchip_create (KVMState *s) {int ret; -if (machine_kernel_irqchip_split (ms)) { +if (kvm_kernel_irqchip_split ()) { ret =kvm_vm_enable_cap (s,KVM_CAP_SPLIT_IRQCHIP ,0 ,24 );if (ret) { error_report("Could not enable split irqchip mode: %s",
target/mips/kvm.c +1 -1
@@ -57,7 +57,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)return 0 ; } -int kvm_arch_irqchip_create (MachineState *ms,KVMState *s) +int kvm_arch_irqchip_create (KVMState *s) {return 0 ; }
target/ppc/kvm.c +1 -1
@@ -152,7 +152,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)return 0 ; } -int kvm_arch_irqchip_create (MachineState *ms,KVMState *s) +int kvm_arch_irqchip_create (KVMState *s) {return 0 ; }
target/s390x/kvm.c +1 -1
@@ -374,7 +374,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)return 0 ; } -int kvm_arch_irqchip_create (MachineState *ms,KVMState *s) +int kvm_arch_irqchip_create (KVMState *s) {return 0 ; }
Signature · 1 line
1.8.3.1
Re: [PATCH 15/16] kvm: introduce kvm_kernel_irqchip_* functions
Quoted 16 lines · Paolo Bonzini
The KVMState struct is opaque, so provide accessors for the fields that will be moved from
current_machineto the accelerator. For now they just forward to the machine object, but this will change.Signed-off-by Paolo Bonzini <[email protected]>--- accel/kvm/kvm-all.c | 23 +++++++++++++++++++---- hw/ppc/e500.c | 4 ++-- hw/ppc/spapr_irq.c | 10 +++++----- include/sysemu/kvm.h | 7 +++++-- target/arm/kvm.c | 8 ++++---- target/i386/kvm.c | 4 ++-- target/mips/kvm.c | 2 +- target/ppc/kvm.c | 2 +- target/s390x/kvm.c | 2 +- 9 files changed, 40 insertions(+), 22 deletions(-)
[...]
Quoted 26 lines
hw/ppc/spapr_irq.c +3
-3@@ -77,9 +77,9 @@ int spapr_irq_init_kvm(int (*fn)(SpaprInterruptController *, Error **),MachineState *machine =MACHINE (qdev_get_machine ());Error *local_err =NULL ; -if (kvm_enabled () &&machine_kernel_irqchip_allowed (machine)) { +if (kvm_enabled () &&kvm_kernel_irqchip_allowed ()) {if (fn (intc, &local_err) <0 ) { -if (machine_kernel_irqchip_required (machine)) { +if (kvm_kernel_irqchip_required ()) {error_prepend (&local_err,"kernel_irqchip requested but unavailable: " );error_propagate (errp, local_err);@@ -184,7 +184,7 @@ static int spapr_irq_check(SpaprMachineState *spapr, Error **errp)*/ if (kvm_enabled () && spapr->irq == &spapr_irq_dual && -machine_kernel_irqchip_required (machine) && +kvm_kernel_irqchip_required () &&xics_kvm_has_broken_disconnect (spapr)) {error_setg (errp,"KVM is too old to support ic-mode=dual,kernel-irqchip=on" );return -1 ;
hw/ppc/spapr_irq.c void spapr_irq_init(SpaprMachineState *spapr, Error **errp) · line 282
Quoted 8 lines
hw/ppc/spapr_irq.c +1
-1@@ -276,12 +276,12 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)MachineState *machine =MACHINE (spapr);SpaprMachineClass *smc =SPAPR_MACHINE_GET_CLASS (spapr); -if (machine_kernel_irqchip_split (machine)) { +if (kvm_enabled () &&kvm_kernel_irqchip_split ()) {error_setg (errp,"kernel_irqchip split mode not supported on pseries" );return ; }
Any reason for the additional kvm_enabled() here? I think it should also be ok without that?
Apart from that question, patch looks fine to me.
Thomas
Re: [PATCH 15/16] kvm: introduce kvm_kernel_irqchip_* functions
Quoted 9 lines · Thomas Huth
hw/ppc/spapr_irq.c void spapr_irq_init(SpaprMachineState *spapr, Error **errp) · line 282
Quoted 5 lines
hw/ppc/spapr_irq.c +1
-1-if (machine_kernel_irqchip_split (machine)) { +if (kvm_enabled () &&kvm_kernel_irqchip_split ()) {error_setg (errp,"kernel_irqchip split mode not supported on pseries" );return ; }Any reason for the additional
kvm_enabled()here? I think it should also be ok without that?Apart from that question, patch looks fine to me.
It won't compile without that, kvm_kernel_irqchip_split() is defined in accel/kvm/kvm-all.c.
Paolo
Thomas Huth
Reviewed-byRe: [PATCH 15/16] kvm: introduce kvm_kernel_irqchip_* functions
Quoted 6 lines · Paolo Bonzini
Quoted 5 lines · Thomas Huth
Quoted 5 lines
hw/ppc/spapr_irq.c +1
-1-if (machine_kernel_irqchip_split (machine)) { +if (kvm_enabled () &&kvm_kernel_irqchip_split ()) {error_setg (errp,"kernel_irqchip split mode not supported on pseries" );return ; }
Quoted 7 lines
Quoted 4 lines
Any reason for the additional
kvm_enabled()here? I think it should also be ok without that?Apart from that question, patch looks fine to me.
It won't compile without that,
kvm_kernel_irqchip_split()is defined inaccel/kvm/kvm-all.c.
Oh, I wonder whether you need a stub for certain compilers? ... but if all our supported compilers are fine with this, I'm fine with it, too.
PATCH 16/16 kvm: convert "-machine kernel_irqchip" to an accelerator property
In reply to Paolo Bonzini--- accel/kvm/kvm-all.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++----- hw/core/machine.c | 61 ----------------------------------------------------- include/hw/boards.h | 3 --- qemu-options.hx | 9 +++++--- vl.c | 3 ++- 5 files changed, 62 insertions(+), 73 deletions(-)
accel/kvm/kvm-all.c +54 -5
@@ -42,6 +42,8 @@#include "sysemu/sev.h" #include "sysemu/balloon.h" #include "qapi/visitor.h" +#include "qapi/qapi-types-common.h" +#include "qapi/qapi-visit-common.h" #include "hw/boards.h"
@@ -94,6 +96,9 @@ struct KVMStateint many_ioeventfds;int intx_set_mask;int kvm_shadow_mem; +bool kernel_irqchip_allowed; +bool kernel_irqchip_required; +bool kernel_irqchip_split;bool sync_mmu;bool manual_dirty_log_protect;/* The man page (and posix) say ioctl numbers are signed int, but
@@ -1762,7 +1767,7 @@ static void kvm_irqchip_create(KVMState *s)* in-kernel irqchip for us */ ret =kvm_arch_irqchip_create (s);if (ret ==0 ) { -if (kvm_kernel_irqchip_split ()) { +if (s->kernel_irqchip_split) {perror ("Split IRQ chip mode not supported." );exit (1 ); }else {
@@ -2033,7 +2038,7 @@ static int kvm_init(MachineState *ms) goto err; } -if (machine_kernel_irqchip_allowed (ms)) { +if (s->kernel_irqchip_allowed) {kvm_irqchip_create (s); }
@@ -2951,19 +2956,57 @@ static void kvm_set_kvm_shadow_mem(Object *obj, Visitor *v, s->kvm_shadow_mem = value; } +static void kvm_set_kernel_irqchip (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +Error *err =NULL ; +KVMState *s =KVM_STATE (obj); +OnOffSplit mode; + +visit_type_OnOffSplit (v, name, &mode, &err); +if (err) { +error_propagate (errp, err); +return ; + }else { +switch (mode) { +case ON_OFF_SPLIT_ON : + s->kernel_irqchip_allowed = true; + s->kernel_irqchip_required = true; + s->kernel_irqchip_split = false; +break ; +case ON_OFF_SPLIT_OFF : + s->kernel_irqchip_allowed = false; + s->kernel_irqchip_required = false; + s->kernel_irqchip_split = false; +break ; +case ON_OFF_SPLIT_SPLIT : + s->kernel_irqchip_allowed = true; + s->kernel_irqchip_required = true; + s->kernel_irqchip_split = true; +break ; +default : +/* The value was checked in visit_type_OnOffSplit() above. If +* we get here, then something is wrong in QEMU. +*/ +abort (); + } + } +} +bool kvm_kernel_irqchip_allowed (void ) { -return machine_kernel_irqchip_allowed (current_machine); +return kvm_state->kernel_irqchip_allowed; }bool kvm_kernel_irqchip_required (void ) { -return machine_kernel_irqchip_required (current_machine); +return kvm_state->kernel_irqchip_required; }bool kvm_kernel_irqchip_split (void ) { -return machine_kernel_irqchip_split (current_machine); +return kvm_state->kernel_irqchip_split; }static void kvm_accel_instance_init (Object *obj)
@@ -2981,6 +3024,12 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data) ac->has_memory = kvm_accel_has_memory; ac->allowed = &kvm_allowed; +object_class_property_add (oc,"kernel-irqchip" ,"on|off|split" , +NULL , kvm_set_kernel_irqchip, +NULL ,NULL , &error_abort); +object_class_property_set_description (oc,"kernel-irqchip" , +"Configure KVM in-kernel irqchip" , &error_abort); +object_class_property_add (oc,"kvm-shadow-mem" ,"int" , kvm_get_kvm_shadow_mem, kvm_set_kvm_shadow_mem,NULL ,NULL , &error_abort);
hw/core/machine.c +0 -61
85 lines not on this page · raw message
include/hw/boards.h +0 -3
@@ -63,9 +63,6 @@ extern MachineState *current_machine;void machine_run_board_init (MachineState *machine);bool machine_usb (MachineState *machine); -bool machine_kernel_irqchip_allowed (MachineState *machine); -bool machine_kernel_irqchip_required (MachineState *machine); -bool machine_kernel_irqchip_split (MachineState *machine);int machine_phandle_start (MachineState *machine);bool machine_dump_guest_core (MachineState *machine);bool machine_mem_merge (MachineState *machine);
qemu-options.hx +6 -3
@@ -32,7 +32,6 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " selects emulated machine ('-machine help' for list)\n" " property accel=accel1[:accel2[:...]] selects accelerator\n" " supported accelerators are kvm, xen, hax, hvf, whpx or tcg (default: tcg)\n" - " kernel_irqchip=on|off|split controls accelerated irqchip support (default=off)\n" " vmport=on|off|auto controls emulation of vmport (default: auto)\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n"
@@ -67,8 +66,6 @@ This is used to enable an accelerator. Depending on the target architecture, kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If there is more than one accelerator specified, the next one is used if the previous one fails to initialize. -@item kernel_irqchip=on|off -Controls in-kernel irqchip support for the chosen accelerator when available. @item vmport=on|off|auto Enables emulation of VMWare IO port, for vmmouse etc. auto says to select the value based on accel. For accel=xen the default is off otherwise the default
@@ -115,6 +112,7 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel, "-accel [accel=]accelerator[,prop[=value][,...]]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" " igd-passthru=on|off (enable Xen integrated Intel graphics passthrough, default=off)\n" + " kernel-irqchip=on|off|split controls accelerated irqchip support (default=on)\n" " kvm-shadow-mem=size of KVM shadow MMU in bytes\n" " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL)
@@ -129,6 +127,11 @@ fails to initialize. @item igd-passthru=on|off When Xen is in use, this option controls whether Intel integrated graphics devices can be passed through to the guest (default=off) +@item kernel-irqchip=on|off|split +Controls KVM in-kernel irqchip support. The default is full acceleration of the +interrupt controllers. On x86, split irqchip reduces the kernel attack +surface, at a performance cost for non-MSI interrupts. Disabling the in-kernel +irqchip completely is not recommended except for debugging purposes. @item kvm-shadow-mem=size Defines the size of the KVM shadow MMU. @item tb-size=@var{n}
vl.c +2 -1
@@ -2642,7 +2642,8 @@ static int machine_set_property(void *opaque,object_register_sugar_prop (ACCEL_CLASS_NAME ("xen" ), qom_name, value);return 0 ; } -if (g_str_equal (qom_name,"kvm-shadow-mem" )) { +if (g_str_equal (qom_name,"kvm-shadow-mem" ) || +g_str_equal (qom_name,"kernel-irqchip" )) {object_register_sugar_prop (ACCEL_CLASS_NAME ("kvm" ), qom_name, value);return 0 ; }
Signature · 1 line
1.8.3.1