hw/accel: Exit gracefully when accelerator is invalid
v2 cover hw/accel: Exit gracefully when accelerator is invalid
Hi,
This series aims to improve user experience by providing a better error message when the user tries to enable KVM on machines not supporting it.
Since v1:
- added missing x86 arch (Peter)
- consider all accelerators (Daniel and Peter)
- do not enable KVM on sbsa-ref (Leif)
- updated 'query-machines' (Daniel)
- new patch for XenPV
Supersedes: <[email protected]>
Philippe Mathieu-Daudé (11):
accel/kvm: Check MachineClass kvm_type() return value hw/boards: Introduce machine_class_valid_for_accelerator() hw/core: Restrict 'query-machines' to those supported by current accel hw/arm: Restrit KVM to the virt & versal machines
hw/mips: Restrict KVM to the malta & virt machines
hw/ppc: Restrict KVM to various PPC machines
hw/s390x: Explicit the s390-ccw-virtio machines support TCG and KVM hw/i386: Explicit x86 machines support all current accelerators hw/xenpv: Restrict Xen Para-virtualized machine to Xen accelerator hw/board: Only allow TCG accelerator by default softmmu/vl: Exit gracefully when accelerator is not supported
include/hw/boards.h | 27 ++++++++++++++++++++++++++- accel/kvm/kvm-all.c | 6 ++++++ hw/arm/virt.c | 5 +++++ hw/arm/xlnx-versal-virt.c | 5 +++++ hw/core/machine-qmp-cmds.c | 4 ++++ hw/core/machine.c | 26 ++++++++++++++++++++++++++ hw/i386/x86.c | 5 +++++ hw/mips/loongson3_virt.c | 5 +++++ hw/mips/malta.c | 5 +++++ hw/ppc/e500plat.c | 5 +++++ hw/ppc/mac_newworld.c | 6 ++++++ hw/ppc/mac_oldworld.c | 5 +++++ hw/ppc/mpc8544ds.c | 5 +++++ hw/ppc/ppc440_bamboo.c | 5 +++++ hw/ppc/prep.c | 5 +++++ hw/ppc/sam460ex.c | 5 +++++ hw/ppc/spapr.c | 5 +++++ hw/s390x/s390-virtio-ccw.c | 5 +++++ hw/xenpv/xen_machine_pv.c | 5 +++++ softmmu/vl.c | 7 +++++++ 20 files changed, 145 insertions(+), 1 deletion(-)
Signature · 1 line
2.26.2
PATCH v2 1/11 accel/kvm: Check MachineClass kvm_type() return value
MachineClass::kvm_type() can return -1 on failure. Document it, and add a check in kvm_init().
--- include/hw/boards.h | 3 ++- accel/kvm/kvm-all.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-)
include/hw/boards.h +2 -1
@@ -127,7 +127,8 @@ typedef struct {* implement and a stub device is required. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or -* computed based on other criteria such as the host kernel capabilities. +* computed based on other criteria such as the host kernel capabilities +* (which can't be negative), or -1 on error. * @numa_mem_supported: * true if '--numa node.mem' option is supported and false otherwise * @smp_parse:
accel/kvm/kvm-all.c +6 -0
@@ -2057,6 +2057,12 @@ static int kvm_init(MachineState *ms)"kvm-type" , &error_abort); type = mc->kvm_type (ms, kvm_type); +if (type <0 ) { + ret = -EINVAL ; +fprintf (stderr,"Failed to detect kvm-type for machine '%s'\n" , + mc->name); + goto err; + } } do {
Signature · 1 line
2.26.2
Re: [PATCH v2 01/11] accel/kvm: Check MachineClass kvm_type() return value
Quoted 30 lines · On Fri, 19 Feb 2021 18:38:37 +0100 Philippe Mathieu-Daudé <[email protected]>…
MachineClass::kvm_type()can return -1 on failure. Document it, and add a check inkvm_init().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/boards.h | 3 ++- accel/kvm/kvm-all.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-)include/hw/boards.h +2
-1@@ -127,7 +127,8 @@ typedef struct {* implement and a stub device is required. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or -* computed based on other criteria such as the host kernel capabilities. +* computed based on other criteria such as the host kernel capabilities +* (which can't be negative), or -1 on error. * @numa_mem_supported: * true if '--numa node.mem' option is supported and false otherwise * @smp_parse: accel/kvm/kvm-all.c +0
-0@@ -2057,6 +2057,12 @@ static int kvm_init(MachineState *ms)"kvm-type" , &error_abort);
accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2068
Quoted 10 lines
accel/kvm/kvm-all.c +6
-0type = mc->kvm_type (ms, kvm_type); +if (type <0 ) { + ret = -EINVAL ; +fprintf (stderr,"Failed to detect kvm-type for machine '%s'\n" , + mc->name); + goto err; + } } do {
No objection to this patch; but I'm wondering why some non-pseries machines implement the kvm_type callback, when I see the kvm-type property only for pseries? Am I holding my git grep wrong?
Re: [PATCH v2 01/11] accel/kvm: Check MachineClass kvm_type() return value
Quoted 42 lines · Cornelia Huck
Quoted 39 lines · On Fri, 19 Feb 2021 18:38:37 +0100 Philippe Mathieu-Daudé <[email protected]>…
MachineClass::kvm_type()can return -1 on failure. Document it, and add a check inkvm_init().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/boards.h | 3 ++- accel/kvm/kvm-all.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-)include/hw/boards.h +2
-1@@ -127,7 +127,8 @@ typedef struct {* implement and a stub device is required. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or -* computed based on other criteria such as the host kernel capabilities. +* computed based on other criteria such as the host kernel capabilities +* (which can't be negative), or -1 on error. * @numa_mem_supported: * true if '--numa node.mem' option is supported and false otherwise * @smp_parse: accel/kvm/kvm-all.c +6
-0@@ -2057,6 +2057,12 @@ static int kvm_init(MachineState *ms)"kvm-type" , &error_abort); type = mc->kvm_type (ms, kvm_type); +if (type <0 ) { + ret = -EINVAL ; +fprintf (stderr,"Failed to detect kvm-type for machine '%s'\n" , + mc->name); + goto err; + } }
Quoted 5 lines
accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2068
Quoted 1 line
accel/kvm/kvm-all.c +0
-0do {No objection to this patch; but I'm wondering why some non-pseries machines implement the
kvm_typecallback, when I see the kvm-type property only for pseries? Am I holding my git grep wrong?
Can it be what David commented here?
https://www.mail-archive.com/[email protected]/msg784508.html
Re: [PATCH v2 01/11] accel/kvm: Check MachineClass kvm_type() return value
Quoted 43 lines · On Mon, 22 Feb 2021 18:41:07 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 42 lines · Cornelia Huck
Quoted 39 lines · On Fri, 19 Feb 2021 18:38:37 +0100 Philippe Mathieu-Daudé <[email protected]>…
MachineClass::kvm_type()can return -1 on failure. Document it, and add a check inkvm_init().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/boards.h | 3 ++- accel/kvm/kvm-all.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-)include/hw/boards.h +2
-1@@ -127,7 +127,8 @@ typedef struct {* implement and a stub device is required. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or -* computed based on other criteria such as the host kernel capabilities. +* computed based on other criteria such as the host kernel capabilities +* (which can't be negative), or -1 on error. * @numa_mem_supported: * true if '--numa node.mem' option is supported and false otherwise * @smp_parse: accel/kvm/kvm-all.c +6
-0@@ -2057,6 +2057,12 @@ static int kvm_init(MachineState *ms)"kvm-type" , &error_abort); type = mc->kvm_type (ms, kvm_type); +if (type <0 ) { + ret = -EINVAL ; +fprintf (stderr,"Failed to detect kvm-type for machine '%s'\n" , + mc->name); + goto err; + } }
Quoted 9 lines
Quoted 5 lines
accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2068
Quoted 1 line
accel/kvm/kvm-all.c +0
-0do {No objection to this patch; but I'm wondering why some non-pseries machines implement the
kvm_typecallback, when I see the kvm-type property only for pseries? Am I holding my git grep wrong?Can it be what David commented here?
https://www.mail-archive.com/[email protected]/msg784508.html
Ok, I might be confused about the other ppc machines; but I'm wondering about the kvm_type callback for mips and arm/virt. Maybe I'm just confused by the whole mechanism?
Re: [PATCH v2 01/11] accel/kvm: Check MachineClass kvm_type() return value
Quoted 52 lines · Cornelia Huck
Quoted 49 lines · On Mon, 22 Feb 2021 18:41:07 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 47 lines · Cornelia Huck
Quoted 30 lines · On Fri, 19 Feb 2021 18:38:37 +0100 Philippe Mathieu-Daudé <[email protected]>…
MachineClass::kvm_type()can return -1 on failure. Document it, and add a check inkvm_init().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/boards.h | 3 ++- accel/kvm/kvm-all.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-)include/hw/boards.h +2
-1@@ -127,7 +127,8 @@ typedef struct {* implement and a stub device is required. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or -* computed based on other criteria such as the host kernel capabilities. +* computed based on other criteria such as the host kernel capabilities +* (which can't be negative), or -1 on error. * @numa_mem_supported: * true if '--numa node.mem' option is supported and false otherwise * @smp_parse: accel/kvm/kvm-all.c +0
-0@@ -2057,6 +2057,12 @@ static int kvm_init(MachineState *ms)"kvm-type" , &error_abort);accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2068
Quoted 10 lines
accel/kvm/kvm-all.c +6
-0type = mc->kvm_type (ms, kvm_type); +if (type <0 ) { + ret = -EINVAL ; +fprintf (stderr,"Failed to detect kvm-type for machine '%s'\n" , + mc->name); + goto err; + } } do {No objection to this patch; but I'm wondering why some non-pseries machines implement the
kvm_typecallback, when I see the kvm-type property only for pseries? Am I holding my git grep wrong?
Quoted 7 lines
Quoted 3 lines
Can it be what David commented here?
https://www.mail-archive.com/[email protected]/msg784508.htmlOk, I might be confused about the other ppc machines; but I'm wondering about the
kvm_typecallback for mips and arm/virt. Maybe I'm just confused by the whole mechanism?
For MIPS see https://www.linux-kvm.org/images/f/f2/01x08a-MIPS.pdf
and Jiaxun comment here:
https://lore.kernel.org/linux-mips/[email protected]/
TE KVM: Trap-and-Emul guest kernel
VZ KVM: HW Virtualized
For "the whole mechanism" I'll defer to Paolo =)
Re: [PATCH v2 01/11] accel/kvm: Check MachineClass kvm_type() return value
In reply to Cornelia HuckQuoted 52 lines · Cornelia Huck
Quoted 49 lines · On Mon, 22 Feb 2021 18:41:07 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 47 lines · Cornelia Huck
Quoted 30 lines · On Fri, 19 Feb 2021 18:38:37 +0100 Philippe Mathieu-Daudé <[email protected]>…
MachineClass::kvm_type()can return -1 on failure. Document it, and add a check inkvm_init().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/boards.h | 3 ++- accel/kvm/kvm-all.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-)include/hw/boards.h +2
-1@@ -127,7 +127,8 @@ typedef struct {* implement and a stub device is required. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or -* computed based on other criteria such as the host kernel capabilities. +* computed based on other criteria such as the host kernel capabilities +* (which can't be negative), or -1 on error. * @numa_mem_supported: * true if '--numa node.mem' option is supported and false otherwise * @smp_parse: accel/kvm/kvm-all.c +0
-0@@ -2057,6 +2057,12 @@ static int kvm_init(MachineState *ms)"kvm-type" , &error_abort);accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2068
Quoted 10 lines
accel/kvm/kvm-all.c +6
-0type = mc->kvm_type (ms, kvm_type); +if (type <0 ) { + ret = -EINVAL ; +fprintf (stderr,"Failed to detect kvm-type for machine '%s'\n" , + mc->name); + goto err; + } } do {No objection to this patch; but I'm wondering why some non-pseries machines implement the
kvm_typecallback, when I see the kvm-type property only for pseries? Am I holding my git grep wrong?
Quoted 7 lines
Quoted 3 lines
Can it be what David commented here?
https://www.mail-archive.com/[email protected]/msg784508.htmlOk, I might be confused about the other ppc machines; but I'm wondering about the
kvm_typecallback for mips and arm/virt. Maybe I'm just confused by the whole mechanism?
For ppc at least, not sure about in general, pseries is the only machine type that can possibly work under more than one KVM flavour (HV or PR). So, it's the only one where it's actually useful to be able to configure this.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH v2 01/11] accel/kvm: Check MachineClass kvm_type() return value
Quoted 57 lines · David Gibson
Quoted 56 lines · Cornelia Huck
Quoted 52 lines · On Mon, 22 Feb 2021 18:41:07 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 42 lines · Cornelia Huck
Quoted 39 lines · On Fri, 19 Feb 2021 18:38:37 +0100 Philippe Mathieu-Daudé <[email protected]>…
MachineClass::kvm_type()can return -1 on failure. Document it, and add a check inkvm_init().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/boards.h | 3 ++- accel/kvm/kvm-all.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-)include/hw/boards.h +2
-1@@ -127,7 +127,8 @@ typedef struct {* implement and a stub device is required. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or -* computed based on other criteria such as the host kernel capabilities. +* computed based on other criteria such as the host kernel capabilities +* (which can't be negative), or -1 on error. * @numa_mem_supported: * true if '--numa node.mem' option is supported and false otherwise * @smp_parse: accel/kvm/kvm-all.c +6
-0@@ -2057,6 +2057,12 @@ static int kvm_init(MachineState *ms)"kvm-type" , &error_abort); type = mc->kvm_type (ms, kvm_type); +if (type <0 ) { + ret = -EINVAL ; +fprintf (stderr,"Failed to detect kvm-type for machine '%s'\n" , + mc->name); + goto err; + } }Quoted 5 lines
accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2068
Quoted 1 line
accel/kvm/kvm-all.c +0
-0do {No objection to this patch; but I'm wondering why some non-pseries machines implement the
kvm_typecallback, when I see the kvm-type property only for pseries? Am I holding my git grep wrong?Can it be what David commented here?
https://www.mail-archive.com/[email protected]/msg784508.html
Quoted 8 lines
Quoted 3 lines
Ok, I might be confused about the other ppc machines; but I'm wondering about the
kvm_typecallback for mips and arm/virt. Maybe I'm just confused by the whole mechanism?For ppc at least, not sure about in general, pseries is the only machine type that can possibly work under more than one KVM flavour (HV or PR). So, it's the only one where it's actually useful to be able to configure this.
Wait... I'm not sure that's true. At least theoretically, some of the Book3E platforms could work with either PR or the Book3E specific KVM. Not sure if KVM PR supports all the BookE instructions it would need to in practice.
Possibly pseries is just the platform where there's been enough people interested in setting the KVM flavour so far.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH v2 01/11] accel/kvm: Check MachineClass kvm_type() return value
Quoted 67 lines · On Tue, 23 Feb 2021 10:37:01 +1100 David Gibson <[email protected]>…
Quoted 57 lines · David Gibson
Quoted 56 lines · Cornelia Huck
Quoted 52 lines · On Mon, 22 Feb 2021 18:41:07 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 42 lines · Cornelia Huck
Quoted 39 lines · On Fri, 19 Feb 2021 18:38:37 +0100 Philippe Mathieu-Daudé <[email protected]>…
MachineClass::kvm_type()can return -1 on failure. Document it, and add a check inkvm_init().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/boards.h | 3 ++- accel/kvm/kvm-all.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-)include/hw/boards.h +2
-1@@ -127,7 +127,8 @@ typedef struct {* implement and a stub device is required. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or -* computed based on other criteria such as the host kernel capabilities. +* computed based on other criteria such as the host kernel capabilities +* (which can't be negative), or -1 on error. * @numa_mem_supported: * true if '--numa node.mem' option is supported and false otherwise * @smp_parse: accel/kvm/kvm-all.c +6
-0@@ -2057,6 +2057,12 @@ static int kvm_init(MachineState *ms)"kvm-type" , &error_abort); type = mc->kvm_type (ms, kvm_type); +if (type <0 ) { + ret = -EINVAL ; +fprintf (stderr,"Failed to detect kvm-type for machine '%s'\n" , + mc->name); + goto err; + } }Quoted 5 lines
accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2068
Quoted 1 line
accel/kvm/kvm-all.c +0
-0do {No objection to this patch; but I'm wondering why some non-pseries machines implement the
kvm_typecallback, when I see the kvm-type property only for pseries? Am I holding my git grep wrong?Can it be what David commented here?
https://www.mail-archive.com/[email protected]/msg784508.htmlQuoted 8 lines
Quoted 3 lines
Ok, I might be confused about the other ppc machines; but I'm wondering about the
kvm_typecallback for mips and arm/virt. Maybe I'm just confused by the whole mechanism?For ppc at least, not sure about in general, pseries is the only machine type that can possibly work under more than one KVM flavour (HV or PR). So, it's the only one where it's actually useful to be able to configure this.
Quoted 7 lines
Wait... I'm not sure that's true. At least theoretically, some of the Book3E platforms could work with either PR or the Book3E specific KVM. Not sure if KVM PR supports all the BookE instructions it would need to in practice.
Possibly pseries is just the platform where there's been enough people interested in setting the KVM flavour so far.
If I'm not utterly confused by the code, it seems the pseries machines are the only ones where you can actually get to an invocation of ->kvm_type(): You need to have a 'kvm-type' machine property, and AFAICS only the pseries machine has that.
(Or is something hiding behind some macro magic?)
Re: [PATCH v2 01/11] accel/kvm: Check MachineClass kvm_type() return value
Quoted 75 lines · Cornelia Huck
Quoted 72 lines · On Tue, 23 Feb 2021 10:37:01 +1100 David Gibson <[email protected]>…
Quoted 57 lines · David Gibson
Quoted 56 lines · Cornelia Huck
Quoted 52 lines · On Mon, 22 Feb 2021 18:41:07 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 42 lines · Cornelia Huck
Quoted 39 lines · On Fri, 19 Feb 2021 18:38:37 +0100 Philippe Mathieu-Daudé <[email protected]>…
MachineClass::kvm_type()can return -1 on failure. Document it, and add a check inkvm_init().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/boards.h | 3 ++- accel/kvm/kvm-all.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-)include/hw/boards.h +2
-1@@ -127,7 +127,8 @@ typedef struct {* implement and a stub device is required. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or -* computed based on other criteria such as the host kernel capabilities. +* computed based on other criteria such as the host kernel capabilities +* (which can't be negative), or -1 on error. * @numa_mem_supported: * true if '--numa node.mem' option is supported and false otherwise * @smp_parse: accel/kvm/kvm-all.c +6
-0@@ -2057,6 +2057,12 @@ static int kvm_init(MachineState *ms)"kvm-type" , &error_abort); type = mc->kvm_type (ms, kvm_type); +if (type <0 ) { + ret = -EINVAL ; +fprintf (stderr,"Failed to detect kvm-type for machine '%s'\n" , + mc->name); + goto err; + } }Quoted 5 lines
accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2068
Quoted 1 line
accel/kvm/kvm-all.c +0
-0do {No objection to this patch; but I'm wondering why some non-pseries machines implement the
kvm_typecallback, when I see the kvm-type property only for pseries? Am I holding my git grep wrong?Can it be what David commented here?
https://www.mail-archive.com/[email protected]/msg784508.htmlQuoted 8 lines
Quoted 3 lines
Ok, I might be confused about the other ppc machines; but I'm wondering about the
kvm_typecallback for mips and arm/virt. Maybe I'm just confused by the whole mechanism?For ppc at least, not sure about in general, pseries is the only machine type that can possibly work under more than one KVM flavour (HV or PR). So, it's the only one where it's actually useful to be able to configure this.
Wait... I'm not sure that's true. At least theoretically, some of the Book3E platforms could work with either PR or the Book3E specific KVM. Not sure if KVM PR supports all the BookE instructions it would need to in practice.
Quoted 7 lines
Quoted 2 lines
Possibly pseries is just the platform where there's been enough people interested in setting the KVM flavour so far.
If I'm not utterly confused by the code, it seems the pseries machines are the only ones where you can actually get to an invocation of ->kvm_type(): You need to have a 'kvm-type' machine property, and AFAICS only the pseries machine has that.
OMG you are right... This changed in commit f2ce39b4f06 ("vl: make qemu_get_machine_opts static"):
@@ -2069,13 +2068,11 @@ static int kvm_init(MachineState *ms)
}
s->as = g_new0(struct KVMAs, s->nr_as);- kvm_type = qemu_opt_get(qemu_get_machine_opts(), "kvm-type");
- if (mc->kvm_type) {
+ if (object_property_find(OBJECT(current_machine), "kvm-type")) {
+ g_autofree char *kvm_type =
object_property_get_str(OBJECT(current_machine),
+ "kvm-type",
+ &error_abort);
type = mc->kvm_type(ms, kvm_type);
- } else if (kvm_type) {
- ret = -EINVAL;
- fprintf(stderr, "Invalid argument kvm-type=%s\n", kvm_type);
- goto err;
}Paolo, is that expected?
So these callbacks are dead code:hw/arm/virt.c:2585: mc->kvm_type = virt_kvm_type;hw/mips/loongson3_virt.c:625: mc->kvm_type = mips_kvm_type;hw/ppc/mac_newworld.c:598: mc->kvm_type = core99_kvm_type;hw/ppc/mac_oldworld.c:447: mc->kvm_type = heathrow_kvm_type;
Quoted 3 lines
(Or is something hiding behind some macro magic?)
PATCH v2 2/11 hw/boards: Introduce machine_class_valid_for_accelerator()
In reply to Philippe Mathieu-DaudéIntroduce the valid_accelerators[] field to express the list of valid accelators a machine can use, and add the machine_class_valid_for_current_accelerator() and machine_class_valid_for_accelerator() methods.
--- include/hw/boards.h | 24 ++++++++++++++++++++++++ hw/core/machine.c | 26 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)
include/hw/boards.h +24 -0
@@ -36,6 +36,24 @@ void machine_set_cpu_numa_node(MachineState *machine,const CpuInstanceProperties *props, Error **errp); +/** +* machine_class_valid_for_accelerator: +* @mc: the machine class +* @acc_name: accelerator name +* +* Returns %true if the accelerator is valid for the machine, %false +* otherwise. See #MachineClass.valid_accelerators. +*/ +bool machine_class_valid_for_accelerator (MachineClass *mc,const char *acc_name); +/** +* machine_class_valid_for_current_accelerator: +* @mc: the machine class +* +* Returns %true if the accelerator is valid for the current machine, +* %false otherwise. See #MachineClass.valid_accelerators. +*/ +bool machine_class_valid_for_current_accelerator (MachineClass *mc); +void machine_class_allow_dynamic_sysbus_dev (MachineClass *mc,const char *type);/* * Checks that backend isn't used, preps it for exclusive usage and
@@ -125,6 +143,11 @@ typedef struct {* should instead use "unimplemented-device" for all memory ranges where * the guest will attempt to probe for a device that QEMU doesn't * implement and a stub device is required. +* @valid_accelerators: +* If this machine supports a specific set of virtualization accelerators, +* this contains a NULL-terminated list of the accelerators that can be +* used. If this field is not set, any accelerator is valid. The QTest +* accelerator is always valid. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or * computed based on other criteria such as the host kernel capabilities
@@ -166,6 +189,7 @@ struct MachineClass {const char *alias;const char *desc;const char *deprecation_reason; +const char *const *valid_accelerators;void (*init)(MachineState *state);void (*reset)(MachineState *state);
hw/core/machine.c +26 -0
@@ -518,6 +518,32 @@ static void machine_set_nvdimm_persistence(Object *obj, const char *value, nvdimms_state->persistence_string =g_strdup (value); } +bool machine_class_valid_for_accelerator (MachineClass *mc,const char *acc_name) +{ +const char *const *name = mc->valid_accelerators; + +if (!name) { +return true; + } +if (strcmp (acc_name,"qtest" ) ==0 ) { +return true; + } + +for (unsigned i =0 ; name[i]; i++) { +if (strcasecmp (acc_name, name[i]) ==0 ) { +return true; + } + } +return false; +} + +bool machine_class_valid_for_current_accelerator (MachineClass *mc) +{ +AccelClass *ac =ACCEL_GET_CLASS (current_accel ()); + +return machine_class_valid_for_accelerator (mc, ac->name); +} +void machine_class_allow_dynamic_sysbus_dev (MachineClass *mc,const char *type) {QAPI_LIST_PREPEND (mc->allowed_dynamic_sysbus_devices,g_strdup (type));
Signature · 1 line
2.26.2
Re: [PATCH v2 02/11] hw/boards: Introduce machine_class_valid_for_accelerator()
Quoted 16 lines · On Fri, 19 Feb 2021 18:38:38 +0100 Philippe Mathieu-Daudé <[email protected]>…
Introduce the valid_accelerators[] field to express the list of valid accelators a machine can use, and add the
machine_class_valid_for_current_accelerator()andmachine_class_valid_for_accelerator()methods.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/boards.h | 24 ++++++++++++++++++++++++ hw/core/machine.c | 26 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)include/hw/boards.h +0
-0
include/hw/boards.h void machine_set_cpu_numa_node(MachineState *machine, · line 45
Quoted 10 lines
include/hw/boards.h +7
-0@@ -36,6 +36,24 @@ void machine_set_cpu_numa_node(MachineState *machine,const CpuInstanceProperties *props, Error **errp); +/** +* machine_class_valid_for_accelerator: +* @mc: the machine class +* @acc_name: accelerator name +* +* Returns %true if the accelerator is valid for the machine, %false +* otherwise. See #MachineClass.valid_accelerators.
Naming confusion: is the machine class valid for the accelerator, or the accelerator valid for the machine class? Or either? :)
include/hw/boards.h void machine_set_cpu_numa_node(MachineState *machine, · line 53
Quoted 8 lines
include/hw/boards.h +8
-0+*/ +bool machine_class_valid_for_accelerator (MachineClass *mc,const char *acc_name); +/** +* machine_class_valid_for_current_accelerator: +* @mc: the machine class +* +* Returns %true if the accelerator is valid for the current machine, +* %false otherwise. See #MachineClass.valid_accelerators.
Same here: current accelerator vs. current machine.
Quoted 49 lines
include/hw/boards.h +9
-0+*/ +bool machine_class_valid_for_current_accelerator (MachineClass *mc); +void machine_class_allow_dynamic_sysbus_dev (MachineClass *mc,const char *type);/* * Checks that backend isn't used, preps it for exclusive usage and @@ -125,6 +143,11 @@ typedef struct {* should instead use "unimplemented-device" for all memory ranges where * the guest will attempt to probe for a device that QEMU doesn't * implement and a stub device is required. +* @valid_accelerators: +* If this machine supports a specific set of virtualization accelerators, +* this contains a NULL-terminated list of the accelerators that can be +* used. If this field is not set, any accelerator is valid. The QTest +* accelerator is always valid. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or * computed based on other criteria such as the host kernel capabilities @@ -166,6 +189,7 @@ struct MachineClass {const char *alias;const char *desc;const char *deprecation_reason; +const char *const *valid_accelerators;void (*init)(MachineState *state);void (*reset)(MachineState *state);hw/core/machine.c +15
-0@@ -518,6 +518,32 @@ static void machine_set_nvdimm_persistence(Object *obj, const char *value, nvdimms_state->persistence_string =g_strdup (value); } +bool machine_class_valid_for_accelerator (MachineClass *mc,const char *acc_name) +{ +const char *const *name = mc->valid_accelerators; + +if (!name) { +return true; + } +if (strcmp (acc_name,"qtest" ) ==0 ) { +return true; + } + +for (unsigned i =0 ; name[i]; i++) { +if (strcasecmp (acc_name, name[i]) ==0 ) { +return true; + }
hw/core/machine.c static void machine_set_nvdimm_persistence(Object *obj, const char *value, · line 545
Quoted 10 lines
hw/core/machine.c +10
-0+ } +return false; +} + +bool machine_class_valid_for_current_accelerator (MachineClass *mc) +{ +AccelClass *ac =ACCEL_GET_CLASS (current_accel ()); + +return machine_class_valid_for_accelerator (mc, ac->name); +}
The implementation of the function tests for the current accelerator, so I think you need to tweak the description above?
Quoted 4 lines
hw/core/machine.c +1
-0+void machine_class_allow_dynamic_sysbus_dev (MachineClass *mc,const char *type) {QAPI_LIST_PREPEND (mc->allowed_dynamic_sysbus_devices,g_strdup (type));
Re: [PATCH v2 02/11] hw/boards: Introduce machine_class_valid_for_accelerator()
Quoted 22 lines · Cornelia Huck
Quoted 19 lines · On Fri, 19 Feb 2021 18:38:38 +0100 Philippe Mathieu-Daudé <[email protected]>…
Introduce the valid_accelerators[] field to express the list of valid accelators a machine can use, and add the
machine_class_valid_for_current_accelerator()andmachine_class_valid_for_accelerator()methods.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/boards.h | 24 ++++++++++++++++++++++++ hw/core/machine.c | 26 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)include/hw/boards.h +0
-0@@ -36,6 +36,24 @@ void machine_set_cpu_numa_node(MachineState *machine,const CpuInstanceProperties *props, Error **errp);
Quoted 10 lines
include/hw/boards.h void machine_set_cpu_numa_node(MachineState *machine, · line 45
Quoted 7 lines
include/hw/boards.h +7
-0+/** +* machine_class_valid_for_accelerator: +* @mc: the machine class +* @acc_name: accelerator name +* +* Returns %true if the accelerator is valid for the machine, %false +* otherwise. See #MachineClass.valid_accelerators. Naming confusion: is the machine class valid for the accelerator, or the accelerator valid for the machine class? Or either? :)
"the accelerator valid for the machine class".
Is this clearer?
"Returns %true if the current accelerator is valid for the
selected machine, %false otherwise.
Or...
"Returns %true if the selected accelerator is valid for the
current machine, %false otherwise.
How would look "either"?
The machine is already selected, and the accelerator too...
Quoted 80 lines
include/hw/boards.h void machine_set_cpu_numa_node(MachineState *machine, · line 53
Quoted 9 lines
include/hw/boards.h +8
-0+*/ +bool machine_class_valid_for_accelerator (MachineClass *mc,const char *acc_name); +/** +* machine_class_valid_for_current_accelerator: +* @mc: the machine class +* +* Returns %true if the accelerator is valid for the current machine, +* %false otherwise. See #MachineClass.valid_accelerators. Same here: current accelerator vs. current machine.
Quoted 49 lines
include/hw/boards.h +9
-0+*/ +bool machine_class_valid_for_current_accelerator (MachineClass *mc); +void machine_class_allow_dynamic_sysbus_dev (MachineClass *mc,const char *type);/* * Checks that backend isn't used, preps it for exclusive usage and @@ -125,6 +143,11 @@ typedef struct {* should instead use "unimplemented-device" for all memory ranges where * the guest will attempt to probe for a device that QEMU doesn't * implement and a stub device is required. +* @valid_accelerators: +* If this machine supports a specific set of virtualization accelerators, +* this contains a NULL-terminated list of the accelerators that can be +* used. If this field is not set, any accelerator is valid. The QTest +* accelerator is always valid. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or * computed based on other criteria such as the host kernel capabilities @@ -166,6 +189,7 @@ struct MachineClass {const char *alias;const char *desc;const char *deprecation_reason; +const char *const *valid_accelerators;void (*init)(MachineState *state);void (*reset)(MachineState *state);hw/core/machine.c +15
-0@@ -518,6 +518,32 @@ static void machine_set_nvdimm_persistence(Object *obj, const char *value, nvdimms_state->persistence_string =g_strdup (value); } +bool machine_class_valid_for_accelerator (MachineClass *mc,const char *acc_name) +{ +const char *const *name = mc->valid_accelerators; + +if (!name) { +return true; + } +if (strcmp (acc_name,"qtest" ) ==0 ) { +return true; + } + +for (unsigned i =0 ; name[i]; i++) { +if (strcasecmp (acc_name, name[i]) ==0 ) { +return true; + }hw/core/machine.c static void machine_set_nvdimm_persistence(Object *obj, const char *value, · line 545
Quoted 10 lines
hw/core/machine.c +10
-0+ } +return false; +} + +bool machine_class_valid_for_current_accelerator (MachineClass *mc) +{ +AccelClass *ac =ACCEL_GET_CLASS (current_accel ()); + +return machine_class_valid_for_accelerator (mc, ac->name); +}The implementation of the function tests for the current accelerator, so I think you need to tweak the description above?
Quoted 4 lines
hw/core/machine.c +1
-0+void machine_class_allow_dynamic_sysbus_dev (MachineClass *mc,const char *type) {QAPI_LIST_PREPEND (mc->allowed_dynamic_sysbus_devices,g_strdup (type));
Re: [PATCH v2 02/11] hw/boards: Introduce machine_class_valid_for_accelerator()
Quoted 38 lines · On Mon, 22 Feb 2021 18:46:15 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 22 lines · Cornelia Huck
Quoted 19 lines · On Fri, 19 Feb 2021 18:38:38 +0100 Philippe Mathieu-Daudé <[email protected]>…
Introduce the valid_accelerators[] field to express the list of valid accelators a machine can use, and add the
machine_class_valid_for_current_accelerator()andmachine_class_valid_for_accelerator()methods.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/boards.h | 24 ++++++++++++++++++++++++ hw/core/machine.c | 26 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)include/hw/boards.h +0
-0@@ -36,6 +36,24 @@ void machine_set_cpu_numa_node(MachineState *machine,const CpuInstanceProperties *props, Error **errp);Quoted 10 lines
include/hw/boards.h void machine_set_cpu_numa_node(MachineState *machine, · line 45
Quoted 7 lines
include/hw/boards.h +7
-0+/** +* machine_class_valid_for_accelerator: +* @mc: the machine class +* @acc_name: accelerator name +* +* Returns %true if the accelerator is valid for the machine, %false +* otherwise. See #MachineClass.valid_accelerators. Naming confusion: is the machine class valid for the accelerator, or the accelerator valid for the machine class? Or either? :)
"the accelerator valid for the machine class".
Is this clearer?
Quoted 7 lines
"Returns %true if the current accelerator is valid for the
selected machine, %false otherwise.Or...
"Returns %true if the selected accelerator is valid for the
current machine, %false otherwise.
Maybe that one, given how it ends up being called? Or "specified machine"?
Quoted 4 lines
How would look "either"?
The machine is already selected, and the accelerator too...
Yes, so this is basically testing the (machine,accelerator) tuple, which is what I meant with 'either'.
Quoted 12 lines
Quoted 12 lines
include/hw/boards.h void machine_set_cpu_numa_node(MachineState *machine, · line 53
Quoted 10 lines
include/hw/boards.h +8
-0+*/ +bool machine_class_valid_for_accelerator (MachineClass *mc,const char *acc_name); +/** +* machine_class_valid_for_current_accelerator: +* @mc: the machine class +* +* Returns %true if the accelerator is valid for the current machine, +* %false otherwise. See #MachineClass.valid_accelerators. Same here: current accelerator vs. current machine.
So maybe
"Returns %true if the current accelerator is valid for the specified machine class..." ?
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
include/hw/boards.h +2
-0+*/ +bool machine_class_valid_for_current_accelerator (MachineClass *mc);
PATCH v2 3/11 hw/core: Restrict 'query-machines' to those supported by current accel
In reply to Philippe Mathieu-DaudéDo not let 'query-machines' return machines not valid with the current accelerator.
--- hw/core/machine-qmp-cmds.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/core/machine-qmp-cmds.c +4 -0
@@ -204,6 +204,10 @@ MachineInfoList *qmp_query_machines(Error **errp)MachineClass *mc = el->data;MachineInfo *info; +if (!machine_class_valid_for_current_accelerator (mc)) { +continue ; + } + info =g_malloc0 (sizeof (*info));if (mc->is_default) { info->has_is_default = true;
Signature · 1 line
2.26.2
Re: [PATCH v2 03/11] hw/core: Restrict 'query-machines' to those supported by current accel
Quoted 14 lines · On Fri, 19 Feb 2021 18:38:39 +0100 Philippe Mathieu-Daudé <[email protected]>…
Do not let 'query-machines' return machines not valid with the current accelerator.
Suggested-by Daniel Berrangé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/core/machine-qmp-cmds.c | 4 ++++ 1 file changed, 4 insertions(+)hw/core/machine-qmp-cmds.c +0
-0
hw/core/machine-qmp-cmds.c MachineInfoList *qmp_query_machines(Error **errp) · line 213
Quoted 10 lines
hw/core/machine-qmp-cmds.c +4
-0@@ -204,6 +204,10 @@ MachineInfoList *qmp_query_machines(Error **errp)MachineClass *mc = el->data;MachineInfo *info; +if (!machine_class_valid_for_current_accelerator (mc)) { +continue ; + } + info =g_malloc0 (sizeof (*info));if (mc->is_default) { info->has_is_default = true;
PATCH v2 4/11 hw/arm: Restrit KVM to the virt & versal machines
In reply to Philippe Mathieu-DaudéRestrit KVM to the following ARM machines:
- virt
- xlnx-versal-virt
--- hw/arm/virt.c | 5 +++++ hw/arm/xlnx-versal-virt.c | 5 +++++ 2 files changed, 10 insertions(+)
hw/arm/virt.c +5 -0
@@ -2527,6 +2527,10 @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine,return NULL ; } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,"hvf" ,NULL +}; +/* * for arm64 kvm_type [7-0] encodes the requested number of bits * in the IPA address space
@@ -2582,6 +2586,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) mc->cpu_index_to_instance_props = virt_cpu_index_to_props; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a15" ); mc->get_default_cpu_node_id = virt_get_default_cpu_node_id; + mc->valid_accelerators = valid_accels; mc->kvm_type = virt_kvm_type;assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = virt_machine_get_hotplug_handler;
hw/arm/xlnx-versal-virt.c +5 -0
@@ -610,6 +610,10 @@ static void versal_virt_machine_instance_init(Object *obj) { } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void versal_virt_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
@@ -621,6 +625,7 @@ static void versal_virt_machine_class_init(ObjectClass *oc, void *data) mc->default_cpus =XLNX_VERSAL_NR_ACPUS ; mc->no_cdrom = true; mc->default_ram_id ="ddr" ; + mc->valid_accelerators = valid_accels; }static const TypeInfo versal_virt_machine_init_typeinfo = {
Signature · 1 line
2.26.2
Re: [PATCH v2 04/11] hw/arm: Restrit KVM to the virt & versal machines
Quoted 1 line · Philippe Mathieu-Daudé
Restrit KVM to the following ARM machines:
Typo: "Restrict" (also in patch title).
Regards,
BALATON Zoltan
Quoted 56 lines
- virt
- xlnx-versal-virtSigned-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/arm/virt.c| 5 +++++hw/arm/xlnx-versal-virt.c| 5 +++++2 files changed, 10 insertions(+)hw/arm/virt.c +5
-0@@ -2527,6 +2527,10 @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine,return NULL ; } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,"hvf" ,NULL +}; +/* * for arm64 kvm_type [7-0] encodes the requested number of bits * in the IPA address space @@ -2582,6 +2586,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) mc->cpu_index_to_instance_props = virt_cpu_index_to_props; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a15" ); mc->get_default_cpu_node_id = virt_get_default_cpu_node_id; + mc->valid_accelerators = valid_accels; mc->kvm_type = virt_kvm_type;assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = virt_machine_get_hotplug_handler;hw/arm/xlnx-versal-virt.c +5
-0@@ -610,6 +610,10 @@ static void versal_virt_machine_instance_init(Object *obj) { } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void versal_virt_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -621,6 +625,7 @@ static void versal_virt_machine_class_init(ObjectClass *oc, void *data) mc->default_cpus =XLNX_VERSAL_NR_ACPUS ; mc->no_cdrom = true; mc->default_ram_id ="ddr" ; + mc->valid_accelerators = valid_accels; }static const TypeInfo versal_virt_machine_init_typeinfo = {
PATCH v2 5/11 hw/mips: Restrict KVM to the malta & virt machines
In reply to Philippe Mathieu-DaudéRestrit KVM to the following MIPS machines:
- malta
- loongson3-virt
--- hw/mips/loongson3_virt.c | 5 +++++ hw/mips/malta.c | 5 +++++ 2 files changed, 10 insertions(+)
hw/mips/loongson3_virt.c +5 -0
@@ -612,6 +612,10 @@ static void mips_loongson3_virt_init(MachineState *machine)loongson3_virt_devices_init (machine, liointc); } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void loongson3v_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
@@ -622,6 +626,7 @@ static void loongson3v_machine_class_init(ObjectClass *oc, void *data) mc->max_cpus =LOONGSON_MAX_VCPUS ; mc->default_ram_id ="loongson3.highram" ; mc->default_ram_size =1600 * MiB; + mc->valid_accelerators = valid_accels; mc->kvm_type = mips_kvm_type; mc->minimum_page_bits =14 ; }
hw/mips/malta.c +5 -0
@@ -1443,6 +1443,10 @@ static const TypeInfo mips_malta_device = { .instance_init = mips_malta_instance_init, }; +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void mips_malta_machine_init (MachineClass *mc) { mc->desc ="MIPS Malta Core LV" ;
@@ -1456,6 +1460,7 @@ static void mips_malta_machine_init(MachineClass *mc) mc->default_cpu_type =MIPS_CPU_TYPE_NAME ("24Kf" );#endif mc->default_ram_id ="mips_malta.ram" ; + mc->valid_accelerators = valid_accels; }DEFINE_MACHINE ("malta" , mips_malta_machine_init)
Signature · 1 line
2.26.2
Re: [PATCH v2 05/11] hw/mips: Restrict KVM to the malta & virt machines
Quoted 5 lines · Philippe Mathieu-Daudé
Restrit KVM to the following MIPS machines:
- malta
- loongson3-virtSigned-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 51 lines
--- hw/mips/loongson3_virt.c | 5 +++++ hw/mips/malta.c | 5 +++++ 2 files changed, 10 insertions(+)hw/mips/loongson3_virt.c +5
-0@@ -612,6 +612,10 @@ static void mips_loongson3_virt_init(MachineState *machine)loongson3_virt_devices_init (machine, liointc); } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void loongson3v_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -622,6 +626,7 @@ static void loongson3v_machine_class_init(ObjectClass *oc, void *data) mc->max_cpus =LOONGSON_MAX_VCPUS ; mc->default_ram_id ="loongson3.highram" ; mc->default_ram_size =1600 * MiB; + mc->valid_accelerators = valid_accels; mc->kvm_type = mips_kvm_type; mc->minimum_page_bits =14 ; }hw/mips/malta.c +5
-0@@ -1443,6 +1443,10 @@ static const TypeInfo mips_malta_device = { .instance_init = mips_malta_instance_init, }; +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void mips_malta_machine_init (MachineClass *mc) { mc->desc ="MIPS Malta Core LV" ;@@ -1456,6 +1460,7 @@ static void mips_malta_machine_init(MachineClass *mc) mc->default_cpu_type =MIPS_CPU_TYPE_NAME ("24Kf" );#endif mc->default_ram_id ="mips_malta.ram" ; + mc->valid_accelerators = valid_accels; }DEFINE_MACHINE ("malta" , mips_malta_machine_init)
Huacai Chen
Reviewed-byRe: [PATCH v2 05/11] hw/mips: Restrict KVM to the malta & virt machines
Quoted 62 lines · Jiaxun Yang
Quoted 5 lines · Philippe Mathieu-Daudé
Restrit KVM to the following MIPS machines:
- malta
- loongson3-virtSigned-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Jiaxun Yang <[email protected]>Quoted 51 lines
--- hw/mips/loongson3_virt.c | 5 +++++ hw/mips/malta.c | 5 +++++ 2 files changed, 10 insertions(+)hw/mips/loongson3_virt.c +5
-0@@ -612,6 +612,10 @@ static void mips_loongson3_virt_init(MachineState *machine)loongson3_virt_devices_init (machine, liointc); } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void loongson3v_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -622,6 +626,7 @@ static void loongson3v_machine_class_init(ObjectClass *oc, void *data) mc->max_cpus =LOONGSON_MAX_VCPUS ; mc->default_ram_id ="loongson3.highram" ; mc->default_ram_size =1600 * MiB; + mc->valid_accelerators = valid_accels; mc->kvm_type = mips_kvm_type; mc->minimum_page_bits =14 ; }hw/mips/malta.c +5
-0@@ -1443,6 +1443,10 @@ static const TypeInfo mips_malta_device = { .instance_init = mips_malta_instance_init, }; +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void mips_malta_machine_init (MachineClass *mc) { mc->desc ="MIPS Malta Core LV" ;@@ -1456,6 +1460,7 @@ static void mips_malta_machine_init(MachineClass *mc) mc->default_cpu_type =MIPS_CPU_TYPE_NAME ("24Kf" );#endif mc->default_ram_id ="mips_malta.ram" ; + mc->valid_accelerators = valid_accels; }DEFINE_MACHINE ("malta" , mips_malta_machine_init)
RFC PATCH v2 6/11 hw/ppc: Restrict KVM to various PPC machines
In reply to Philippe Mathieu-DaudéRestrit KVM to the following PPC machines:
- 40p
- bamboo
- g3beige
- mac99
- mpc8544ds
- ppce500
- pseries
- sam460ex
- virtex-ml507
---
RFC: I'm surprise by this list, but this is the result of
auditing calls to kvm_enabled() checks.
hw/ppc/e500plat.c | 5 +++++ hw/ppc/mac_newworld.c | 6 ++++++ hw/ppc/mac_oldworld.c | 5 +++++ hw/ppc/mpc8544ds.c | 5 +++++ hw/ppc/ppc440_bamboo.c | 5 +++++ hw/ppc/prep.c | 5 +++++ hw/ppc/sam460ex.c | 5 +++++ hw/ppc/spapr.c | 5 +++++ 8 files changed, 41 insertions(+)
hw/ppc/e500plat.c +5 -0
@@ -67,6 +67,10 @@ HotplugHandler *e500plat_machine_get_hotpug_handler(MachineState *machine,#define TYPE_E500PLAT_MACHINE MACHINE_TYPE_NAME("ppce500") +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void e500plat_machine_class_init (ObjectClass *oc,void *data) {PPCE500MachineClass *pmc =PPCE500_MACHINE_CLASS (oc);
@@ -98,6 +102,7 @@ static void e500plat_machine_class_init(ObjectClass *oc, void *data) mc->max_cpus =32 ; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("e500v2_v30" ); mc->default_ram_id ="mpc8544ds.ram" ; + mc->valid_accelerators = valid_accels;machine_class_allow_dynamic_sysbus_dev (mc,TYPE_ETSEC_COMMON ); }
hw/ppc/mac_newworld.c +6 -0
@@ -578,6 +578,11 @@ static char *core99_fw_dev_path(FWPathProvider *p, BusState *bus,return NULL ; } + +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static int core99_kvm_type (MachineState *machine,const char *arg) {/* Always force PR KVM */
@@ -595,6 +600,7 @@ static void core99_machine_class_init(ObjectClass *oc, void *data) mc->max_cpus =MAX_CPUS ; mc->default_boot_order ="cd" ; mc->default_display ="std" ; + mc->valid_accelerators = valid_accels; mc->kvm_type = core99_kvm_type;#ifdef TARGET_PPC64 mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("970fx_v3.1" );
hw/ppc/mac_oldworld.c +5 -0
@@ -424,6 +424,10 @@ static char *heathrow_fw_dev_path(FWPathProvider *p, BusState *bus,return NULL ; } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static int heathrow_kvm_type (MachineState *machine,const char *arg) {/* Always force PR KVM */
@@ -444,6 +448,7 @@ static void heathrow_class_init(ObjectClass *oc, void *data)#endif /* TOFIX "cad" when Mac floppy is implemented */ mc->default_boot_order ="cd" ; + mc->valid_accelerators = valid_accels; mc->kvm_type = heathrow_kvm_type; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("750_v3.1" ); mc->default_display ="std" ;
hw/ppc/mpc8544ds.c +5 -0
@@ -36,6 +36,10 @@ static void mpc8544ds_init(MachineState *machine)ppce500_init (machine); } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void e500plat_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
@@ -56,6 +60,7 @@ static void e500plat_machine_class_init(ObjectClass *oc, void *data) mc->max_cpus =15 ; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("e500v2_v30" ); mc->default_ram_id ="mpc8544ds.ram" ; + mc->valid_accelerators = valid_accels; }#define TYPE_MPC8544DS_MACHINE MACHINE_TYPE_NAME("mpc8544ds")
hw/ppc/ppc440_bamboo.c +5 -0
@@ -298,12 +298,17 @@ static void bamboo_init(MachineState *machine) } } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void bamboo_machine_init (MachineClass *mc) { mc->desc ="bamboo" ; mc->init = bamboo_init; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("440epb" ); mc->default_ram_id ="ppc4xx.sdram" ; + mc->valid_accelerators = valid_accels; }DEFINE_MACHINE ("bamboo" , bamboo_machine_init)
hw/ppc/prep.c +5 -0
@@ -431,6 +431,10 @@ static void ibm_40p_init(MachineState *machine) } } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void ibm_40p_machine_init (MachineClass *mc) { mc->desc = "IBM RS/6000 7020 (40p)",
@@ -441,6 +445,7 @@ static void ibm_40p_machine_init(MachineClass *mc) mc->default_boot_order ="c" ; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("604" ); mc->default_display ="std" ; + mc->valid_accelerators = valid_accels; }DEFINE_MACHINE ("40p" , ibm_40p_machine_init)
hw/ppc/sam460ex.c +5 -0
@@ -506,6 +506,10 @@ static void sam460ex_init(MachineState *machine) boot_info->entry = entry; } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void sam460ex_machine_init (MachineClass *mc) { mc->desc ="aCube Sam460ex" ;
@@ -513,6 +517,7 @@ static void sam460ex_machine_init(MachineClass *mc) mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("460exb" ); mc->default_ram_size =512 * MiB; mc->default_ram_id ="ppc4xx.sdram" ; + mc->valid_accelerators = valid_accels; }DEFINE_MACHINE ("sam460ex" , sam460ex_machine_init)
hw/ppc/spapr.c +5 -0
@@ -4397,6 +4397,10 @@ static void spapr_cpu_exec_exit(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu) } } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void spapr_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
@@ -4426,6 +4430,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) mc->default_ram_size =512 * MiB; mc->default_ram_id ="ppc_spapr.ram" ; mc->default_display ="std" ; + mc->valid_accelerators = valid_accels; mc->kvm_type = spapr_kvm_type;machine_class_allow_dynamic_sysbus_dev (mc,TYPE_SPAPR_PCI_HOST_BRIDGE ); mc->pci_allow_0_address = true;
Signature · 1 line
2.26.2
Re: [RFC PATCH v2 06/11] hw/ppc: Restrict KVM to various PPC machines
Quoted 10 lines · Philippe Mathieu-Daudé
Restrit KVM to the following PPC machines:
- 40p
- bamboo
- g3beige
- mac99
- mpc8544ds
- ppce500
- pseries
- sam460ex
- virtex-ml507
Hrm.
The reason this list is kind of surprising is because there are 3 different "flavours" of KVM on ppc: KVM HV ("pseries" only), KVM PR (almost any combination, theoretically, but kind of buggy in practice), and the Book E specific KVM (Book-E systems with HV extensions only).
But basically, qemu explicitly managing what accelerators are available for each machine seems the wrong way around to me. The approach we've generally taken is that qemu requests the specific features it needs of KVM, and KVM tells us whether it can supply those or not (which may involve selecting between one of the several flavours).
That way we can extend KVM to cover more situations without needing corresponding changes in qemu every time.
Quoted 199 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
RFC: I'm surprise by this list, but this is the result of
auditing calls tokvm_enabled()checks.hw/ppc/e500plat.c | 5 +++++ hw/ppc/mac_newworld.c | 6 ++++++ hw/ppc/mac_oldworld.c | 5 +++++ hw/ppc/mpc8544ds.c | 5 +++++ hw/ppc/ppc440_bamboo.c | 5 +++++ hw/ppc/prep.c | 5 +++++ hw/ppc/sam460ex.c | 5 +++++ hw/ppc/spapr.c | 5 +++++ 8 files changed, 41 insertions(+)hw/ppc/e500plat.c +5
-0@@ -67,6 +67,10 @@ HotplugHandler *e500plat_machine_get_hotpug_handler(MachineState *machine,#define TYPE_E500PLAT_MACHINE MACHINE_TYPE_NAME("ppce500") +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void e500plat_machine_class_init (ObjectClass *oc,void *data) {PPCE500MachineClass *pmc =PPCE500_MACHINE_CLASS (oc);@@ -98,6 +102,7 @@ static void e500plat_machine_class_init(ObjectClass *oc, void *data) mc->max_cpus =32 ; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("e500v2_v30" ); mc->default_ram_id ="mpc8544ds.ram" ; + mc->valid_accelerators = valid_accels;machine_class_allow_dynamic_sysbus_dev (mc,TYPE_ETSEC_COMMON ); }hw/ppc/mac_newworld.c +6
-0@@ -578,6 +578,11 @@ static char *core99_fw_dev_path(FWPathProvider *p, BusState *bus,return NULL ; } + +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static int core99_kvm_type (MachineState *machine,const char *arg) {/* Always force PR KVM */ @@ -595,6 +600,7 @@ static void core99_machine_class_init(ObjectClass *oc, void *data) mc->max_cpus =MAX_CPUS ; mc->default_boot_order ="cd" ; mc->default_display ="std" ; + mc->valid_accelerators = valid_accels; mc->kvm_type = core99_kvm_type;#ifdef TARGET_PPC64 mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("970fx_v3.1" );hw/ppc/mac_oldworld.c +5
-0@@ -424,6 +424,10 @@ static char *heathrow_fw_dev_path(FWPathProvider *p, BusState *bus,return NULL ; } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static int heathrow_kvm_type (MachineState *machine,const char *arg) {/* Always force PR KVM */ @@ -444,6 +448,7 @@ static void heathrow_class_init(ObjectClass *oc, void *data)#endif /* TOFIX "cad" when Mac floppy is implemented */ mc->default_boot_order ="cd" ; + mc->valid_accelerators = valid_accels; mc->kvm_type = heathrow_kvm_type; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("750_v3.1" ); mc->default_display ="std" ;hw/ppc/mpc8544ds.c +5
-0@@ -36,6 +36,10 @@ static void mpc8544ds_init(MachineState *machine)ppce500_init (machine); } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void e500plat_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -56,6 +60,7 @@ static void e500plat_machine_class_init(ObjectClass *oc, void *data) mc->max_cpus =15 ; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("e500v2_v30" ); mc->default_ram_id ="mpc8544ds.ram" ; + mc->valid_accelerators = valid_accels; }#define TYPE_MPC8544DS_MACHINE MACHINE_TYPE_NAME("mpc8544ds")hw/ppc/ppc440_bamboo.c +5
-0@@ -298,12 +298,17 @@ static void bamboo_init(MachineState *machine) } } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void bamboo_machine_init (MachineClass *mc) { mc->desc ="bamboo" ; mc->init = bamboo_init; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("440epb" ); mc->default_ram_id ="ppc4xx.sdram" ; + mc->valid_accelerators = valid_accels; }DEFINE_MACHINE ("bamboo" , bamboo_machine_init)hw/ppc/prep.c +5
-0@@ -431,6 +431,10 @@ static void ibm_40p_init(MachineState *machine) } } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void ibm_40p_machine_init (MachineClass *mc) { mc->desc = "IBM RS/6000 7020 (40p)",@@ -441,6 +445,7 @@ static void ibm_40p_machine_init(MachineClass *mc) mc->default_boot_order ="c" ; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("604" ); mc->default_display ="std" ; + mc->valid_accelerators = valid_accels; }DEFINE_MACHINE ("40p" , ibm_40p_machine_init)hw/ppc/sam460ex.c +5
-0@@ -506,6 +506,10 @@ static void sam460ex_init(MachineState *machine) boot_info->entry = entry; } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void sam460ex_machine_init (MachineClass *mc) { mc->desc ="aCube Sam460ex" ;@@ -513,6 +517,7 @@ static void sam460ex_machine_init(MachineClass *mc) mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("460exb" ); mc->default_ram_size =512 * MiB; mc->default_ram_id ="ppc4xx.sdram" ; + mc->valid_accelerators = valid_accels; }DEFINE_MACHINE ("sam460ex" , sam460ex_machine_init)hw/ppc/spapr.c +5
-0@@ -4397,6 +4397,10 @@ static void spapr_cpu_exec_exit(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu) } } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void spapr_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -4426,6 +4430,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) mc->default_ram_size =512 * MiB; mc->default_ram_id ="ppc_spapr.ram" ; mc->default_display ="std" ; + mc->valid_accelerators = valid_accels; mc->kvm_type = spapr_kvm_type;machine_class_allow_dynamic_sysbus_dev (mc,TYPE_SPAPR_PCI_HOST_BRIDGE ); mc->pci_allow_0_address = true;
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [RFC PATCH v2 06/11] hw/ppc: Restrict KVM to various PPC machines
Quoted 27 lines · David Gibson
Quoted 10 lines · Philippe Mathieu-Daudé
Restrit KVM to the following PPC machines:
- 40p
- bamboo
- g3beige
- mac99
- mpc8544ds
- ppce500
- pseries
- sam460ex
- virtex-ml507Hrm.
The reason this list is kind of surprising is because there are 3 different "flavours" of KVM on ppc: KVM HV ("pseries" only), KVM PR (almost any combination, theoretically, but kind of buggy in practice), and the Book E specific KVM (Book-E systems with HV extensions only).
But basically, qemu explicitly managing what accelerators are available for each machine seems the wrong way around to me. The approach we've generally taken is that qemu requests the specific features it needs of KVM, and KVM tells us whether it can supply those or not (which may involve selecting between one of the several flavours).
Quoted 2 lines
That way we can extend KVM to cover more situations without needing corresponding changes in qemu every time.
OK thanks for the information. I'll wait the other patches get reviewed (in particular the most important ones, 2 and
10) before respining including this information.
Regards,
Phil.
PATCH v2 7/11 hw/s390x: Explicit the s390-ccw-virtio machines support TCG and KVM
In reply to Philippe Mathieu-DaudéAll s390-ccw-virtio machines support TCG and KVM.
--- hw/s390x/s390-virtio-ccw.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/s390x/s390-virtio-ccw.c +5 -0
@@ -586,6 +586,10 @@ static ram_addr_t s390_fixup_ram_size(ram_addr_t sz)return newsz; } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void ccw_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
@@ -612,6 +616,7 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data) mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;/* it is overridden with 'host' cpu *in kvm_arch_init* */ mc->default_cpu_type =S390_CPU_TYPE_NAME ("qemu" ); + mc->valid_accelerators = valid_accels; hc->plug = s390_machine_device_plug; hc->unplug_request = s390_machine_device_unplug_request; nc->nmi_monitor_handler = s390_nmi;
Signature · 1 line
2.26.2
Re: [PATCH v2 07/11] hw/s390x: Explicit the s390-ccw-virtio machines support TCG and KVM
On Fri, 19 Feb 2021 18:38:43 +0100
Philippe Mathieu-Daudé <[email protected]> wrote:
I'd lose the 'Explicit' in $SUBJECT.
Quoted 23 lines
All s390-ccw-virtio machines support TCG and KVM.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/s390x/s390-virtio-ccw.c | 5 +++++ 1 file changed, 5 insertions(+)hw/s390x/s390-virtio-ccw.c +4
-0@@ -586,6 +586,10 @@ static ram_addr_t s390_fixup_ram_size(ram_addr_t sz)return newsz; } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,NULL +}; +static void ccw_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
hw/s390x/s390-virtio-ccw.c static void ccw_machine_class_init(ObjectClass *oc, void *data) · line 622
Quoted 7 lines
hw/s390x/s390-virtio-ccw.c +1
-0@@ -612,6 +616,7 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data) mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;/* it is overridden with 'host' cpu *in kvm_arch_init* */ mc->default_cpu_type =S390_CPU_TYPE_NAME ("qemu" ); + mc->valid_accelerators = valid_accels; hc->plug = s390_machine_device_plug; hc->unplug_request = s390_machine_device_unplug_request; nc->nmi_monitor_handler = s390_nmi;
RFC PATCH v2 8/11 hw/i386: Explicit x86 machines support all current accelerators
In reply to Philippe Mathieu-Daudéx86 machines currently support all accelerators.
---
RFC: not sure about this, x86 is not my cup of tea
hw/i386/x86.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/i386/x86.c +5 -0
@@ -1209,6 +1209,10 @@ static void x86_machine_initfn(Object *obj) x86ms->pci_irq_mask =ACPI_BUILD_PCI_IRQS ; } +static const char *const valid_accels[] = { +"tcg" ,"kvm" ,"xen" ,"hax" ,"hvf" ,"whpx" ,NULL +}; +static void x86_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
@@ -1218,6 +1222,7 @@ static void x86_machine_class_init(ObjectClass *oc, void *data) mc->cpu_index_to_instance_props = x86_cpu_index_to_props; mc->get_default_cpu_node_id = x86_get_default_cpu_node_id; mc->possible_cpu_arch_ids = x86_possible_cpu_arch_ids; + mc->valid_accelerators = valid_accels; x86mc->compat_apic_id_mode = false; x86mc->save_tsc_khz = true; nc->nmi_monitor_handler = x86_nmi;
Signature · 1 line
2.26.2
PATCH v2 9/11 hw/xenpv: Restrict Xen Para-virtualized machine to Xen accelerator
In reply to Philippe Mathieu-DaudéWhen started with other accelerator than Xen, the XenPV machine fails with a criptic message:
$ qemu-system-x86_64 -M xenpv,accel=kvm xen be core: can't connect to xenstored qemu-system-x86_64: xen_init_pv: xen backend core setup failed
By restricting it to Xen, we display a clearer error message:
$ qemu-system-x86_64 -M xenpv,accel=kvm qemu-system-x86_64: invalid accelerator 'kvm' for machine xenpv
--- hw/xenpv/xen_machine_pv.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/xenpv/xen_machine_pv.c +5 -0
@@ -86,12 +86,17 @@ static void xen_init_pv(MachineState *machine)atexit (xen_config_cleanup); } +static const char *valid_accels[] = { +"xen" ,NULL +}; +static void xenpv_machine_init (MachineClass *mc) { mc->desc ="Xen Para-virtualized PC" ; mc->init = xen_init_pv; mc->max_cpus =1 ; mc->default_machine_opts ="accel=xen" ; + mc->valid_accelerators = valid_accels; }DEFINE_MACHINE ("xenpv" , xenpv_machine_init)
Signature · 1 line
2.26.2
Re: [PATCH v2 09/11] hw/xenpv: Restrict Xen Para-virtualized machine to Xen accelerator
Quoted 7 lines · Philippe Mathieu-Daudé
When started with other accelerator than Xen, the XenPV machine fails with a criptic message:
$ qemu-system-x86_64 -M xenpv,accel=kvm xen be core: can't connect to xenstored qemu-system-x86_64: xen_init_pv: xen backend core setup failed
Quoted 6 lines
By restricting it to Xen, we display a clearer error message:
$ qemu-system-x86_64 -M xenpv,accel=kvm qemu-system-x86_64: invalid accelerator 'kvm' for machine xenpvSigned-off-by Philippe Mathieu-Daudé <[email protected]>
PATCH v2 10/11 hw/board: Only allow TCG accelerator by default
In reply to Philippe Mathieu-DaudéBy default machines can only use the TCG and QTest accelerators.
If a machine can use another accelerator, it has to explicitly list it in its MachineClass valid_accelerators[].
--- include/hw/boards.h | 4 ++-- hw/core/machine.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)
include/hw/boards.h +2 -2
@@ -146,8 +146,8 @@ typedef struct {* @valid_accelerators: * If this machine supports a specific set of virtualization accelerators, * this contains a NULL-terminated list of the accelerators that can be -* used. If this field is not set, any accelerator is valid. The QTest -* accelerator is always valid. +* used. If this field is not set, a default list containing only the TCG +* accelerator is used. The QTest accelerator is always valid. * @kvm_type: * Return the type of KVM corresponding to the kvm-type string option or * computed based on other criteria such as the host kernel capabilities
hw/core/machine.c +4 -4
@@ -520,11 +520,11 @@ static void machine_set_nvdimm_persistence(Object *obj, const char *value,bool machine_class_valid_for_accelerator (MachineClass *mc,const char *acc_name) { -const char *const *name = mc->valid_accelerators; +static const char *const default_accels[] = { +"tcg" ,NULL + }; +const char *const *name = mc->valid_accelerators ? : default_accels; -if (!name) { -return true; - }if (strcmp (acc_name,"qtest" ) ==0 ) {return true; }
Signature · 1 line
2.26.2
PATCH v2 11/11 softmmu/vl: Exit gracefully when accelerator is not supported
In reply to Philippe Mathieu-DaudéBefore configuring an accelerator, check it is valid for the current machine. Doing so we can return a simple error message instead of criptic one.
Before:
$ qemu-system-arm -M raspi2b -enable-kvm qemu-system-arm: /build/qemu-ETIdrs/qemu-4.2/exec.c:865: cpu_address_space_init: Assertion `asidx == 0 || !kvm_enabled()' failed. Aborted
$ qemu-system-aarch64 -M xlnx-zcu102 -enable-kvm -smp 6 qemu-system-aarch64: kvm_init_vcpu: kvm_arch_init_vcpu failed (0): Invalid argument
After:
$ qemu-system-arm -M raspi2b -enable-kvm qemu-system-aarch64: invalid accelerator 'kvm' for machine raspi2b
$ qemu-system-aarch64 -M xlnx-zcu102 -enable-kvm -smp 6 qemu-system-aarch64: -accel kvm: invalid accelerator 'kvm' for machine xlnx-zcu102
--- softmmu/vl.c | 7 +++++++ 1 file changed, 7 insertions(+)
softmmu/vl.c +7 -0
@@ -2133,6 +2133,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)const char *acc =qemu_opt_get (opts,"accel" );AccelClass *ac =accel_find (acc);AccelState *accel; +MachineClass *mc;int ret;bool qtest_with_kvm;
@@ -2145,6 +2146,12 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) }return 0 ; } + mc =MACHINE_GET_CLASS (current_machine); +if (!qtest_chrdev && !machine_class_valid_for_accelerator (mc, ac->name)) { + *p_init_failed = true; +error_report ("invalid accelerator '%s' for machine %s" , acc, mc->name); +return 0 ; + } accel =ACCEL (object_new_with_class (OBJECT_CLASS (ac)));object_apply_compat_props (OBJECT (accel)); qemu_opt_foreach(opts, accelerator_set_property,
Signature · 1 line
2.26.2
Re: [PATCH v2 11/11] softmmu/vl: Exit gracefully when accelerator is not supported
Quoted 3 lines · On Fri, 19 Feb 2021 18:38:47 +0100 Philippe Mathieu-Daudé <[email protected]>…
Before configuring an accelerator, check it is valid for the current machine. Doing so we can return a simple error message instead of criptic one.
s/criptic/cryptic/
Quoted 36 lines
Before:
$ qemu-system-arm -M raspi2b -enable-kvm qemu-system-arm: /build/qemu-ETIdrs/qemu-4.2/exec.c:865: cpu_address_space_init: Assertion `asidx == 0 || !kvm_enabled()' failed. Aborted$ qemu-system-aarch64 -M xlnx-zcu102 -enable-kvm -smp 6 qemu-system-aarch64: kvm_init_vcpu: kvm_arch_init_vcpu failed (0): Invalid argumentAfter:
$ qemu-system-arm -M raspi2b -enable-kvm qemu-system-aarch64: invalid accelerator 'kvm' for machine raspi2b$ qemu-system-aarch64 -M xlnx-zcu102 -enable-kvm -smp 6 qemu-system-aarch64: -accel kvm: invalid accelerator 'kvm' for machine xlnx-zcu102Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- softmmu/vl.c | 7 +++++++ 1 file changed, 7 insertions(+)softmmu/vl.c +1
-0@@ -2133,6 +2133,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)const char *acc =qemu_opt_get (opts,"accel" );AccelClass *ac =accel_find (acc);AccelState *accel; +MachineClass *mc;int ret;bool qtest_with_kvm;
softmmu/vl.c static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) · line 2150
Quoted 5 lines
softmmu/vl.c +2
-0@@ -2145,6 +2146,12 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) }return 0 ; } + mc =MACHINE_GET_CLASS (current_machine); +if (!qtest_chrdev && !machine_class_valid_for_accelerator (mc, ac->name)) {
Shouldn't qtest be already allowed in any case in the checking function?
Quoted 7 lines
softmmu/vl.c +4
-0+ *p_init_failed = true; +error_report ("invalid accelerator '%s' for machine %s" , acc, mc->name); +return 0 ; + } accel =ACCEL (object_new_with_class (OBJECT_CLASS (ac)));object_apply_compat_props (OBJECT (accel)); qemu_opt_foreach(opts, accelerator_set_property,