target/arm: Remove TYPE_AARCH64_CPU class
cover target/arm: Remove TYPE_AARCH64_CPU class
Currently we have a class hierarchy for Arm CPUs where all the 32-bit CPUs (including M-profile) inherit directly from TYPE_ARM_CPU, but the 64-bit CPUs inherit from TYPE_AARCH64_CPU, which is a subclass of TYPE_ARM_CPU. This subclass does essentially two things:
* it sets up fields and methods for the gdbstub so that the gdbstub presents an AArch64 CPU to gdb rather than an AArch32 one
* it defines the 'aarch64' CPU property which you can use with KVM to disable AArch64 and create a 32-bit VM (with "-cpu host,aarch64=off")
This is a bit weird, because the 32-bit CPU you create with KVM and aarch64=off is still a subclass of TYPE_AARCH64_CPU. It also still presents gdb with an AArch64 CPU, so you effectively can't use the gdbstub with this kind of VM.
This patchseries removes TYPE_AARCH64_CPU so that all CPUs, both AArch32 and AArch64, directly inherit from TYPE_ARM_CPU. This lets us fix the bug with gdbstub and "aarch64=off".
Most of the gdbstub related CPUClass fields are already methods, so we can make the existing TYPE_ARM_CPU ones redirect to the AArch64 functions if ARM_FEATURE_AARCH64 is set. The odd-one-out is gdb_core_xml_file, so we have to add a new optional method gdb_get_core_xml_file to allow us to select the right XML file at runtime. (We could, like gdb_arch_name, simply replace the existing static string field with the method for all targets, but at least for this patchset I didn't want to get into that complexity.)
We make the 'aarch64' property be an object property defined if the ARM_FEATURE_AARCH64 is set rather than a class property; this brings it into line with our other CPU properties.
Once we've done that and removed a check on TYPE_AARCH64_CPU in the KVM code that hasn't been needed since we removed 32-bit Arm host KVM support, we can remove TYPE_AARCH64_CPU entirely.
(The rationale here is that I think we should be able to enable 'aarch64=off' for TCG CPUs too, so this will become less of an odd KVM-specific corner case, and this seemed worth cleaning up.)
thanks
-- PMM
Peter Maydell (9):
core/cpu.h: gdb_arch_name string should not be freed
gdbstub: Allow gdb_core_xml_file to be set at runtime target/arm: Handle AArch64 in TYPE_ARM_CPU gdb_arch_name target/arm: Handle gdb_core_xml_file in TYPE_ARM_CPU target/arm: Handle AArch64 gdb read/write regs in TYPE_ARM_CPU target/arm: Present AArch64 gdbstub based on ARM_FEATURE_AARCH64 target/arm: Move aarch64 CPU property code to TYPE_ARM_CPU target/arm/kvm: don't check TYPE_AARCH64_CPU target/arm: Remove TYPE_AARCH64_CPU
include/hw/core/cpu.h | 8 +++- target/arm/cpu-qom.h | 5 --- target/arm/cpu.h | 4 -- target/arm/internals.h | 7 ++- gdbstub/gdbstub.c | 23 ++++++++-- target/arm/cpu.c | 55 ++++++++++++++++++++++- target/arm/cpu64.c | 94 +--------------------------------------- target/arm/gdbstub.c | 12 +++++ target/arm/kvm.c | 3 +- target/arm/tcg/cpu-v7m.c | 1 - target/arm/tcg/cpu64.c | 2 +- 11 files changed, 101 insertions(+), 113 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/9 core/cpu.h: gdb_arch_name string should not be freed
The documentation for the CPUClass::gdb_arch_name method claims that the returned string should be freed with g_free(). This is not
correct: in commit a650683871ba728 we changed this method to instead return a simple constant string, but forgot to update the documentation.
Make the documentation match the new semantics.
--- include/hw/core/cpu.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/hw/core/cpu.h +2 -1
@@ -135,7 +135,8 @@ struct SysemuCPUOps;* @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop * before the insn which triggers a watchpoint rather than after it. * @gdb_arch_name: Optional callback that returns the architecture name known -* to GDB. The caller must free the returned string with g_free. +* to GDB. The returned value is expected to be a simple constant string: +* the caller will not g_free() it. * @disas_set_info: Setup architecture specific components of disassembly info * @adjust_watchpoint_address: Perform a target-specific adjustment to an * address before attempting to match it against watchpoints.
Signature · 1 line
2.43.0
Re: [PATCH for-10.1 1/9] core/cpu.h: gdb_arch_name string should not be freed
Quoted 10 lines · Peter Maydell
The documentation for the
CPUClass::gdb_arch_namemethod claims that the returned string should be freed withg_free(). This is not
correct: in commita650683871ba728we changed this method to instead return a simple constant string, but forgot to update the documentation.Make the documentation match the new semantics.
Fixes a650683871ba728 ("hw/core/cpu: Return static value with gdb_arch_name()")Signed-off-by Peter Maydell <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH for-10.0 1/9] core/cpu.h: gdb_arch_name string should not be freed
In reply to Peter MaydellQuoted 6 lines · Peter Maydell
The documentation for the
CPUClass::gdb_arch_namemethod claims that the returned string should be freed withg_free(). This is not
correct: in commita650683871ba728we changed this method to instead return a simple constant string, but forgot to update the documentation.
Quoted 7 lines
Make the documentation match the new semantics.
Fixes a650683871ba728 ("hw/core/cpu: Return static value with gdb_arch_name()")Signed-off-by Peter Maydell <[email protected]>--- include/hw/core/cpu.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
PATCH 2/9 gdbstub: Allow gdb_core_xml_file to be set at runtime
In reply to Peter MaydellCurrently the CPUClass:gdb_core_xml_file setting is a simple 'const char *' which the CPU class must set to a fixed string. Allow the CPU class to instead set a new method gdb_get_core_xml_file() which returns this string.
This will allow Arm CPUs to use different XML files for AArch32 vs AArch64 without having to have an extra AArch64-specific class type purely to give somewhere to set cc->gdb_core_xml_file differently.
--- include/hw/core/cpu.h | 5 +++++ gdbstub/gdbstub.c | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-)
include/hw/core/cpu.h +5 -0
@@ -132,6 +132,10 @@ struct SysemuCPUOps;* @gdb_num_core_regs: Number of core registers accessible to GDB or 0 to infer * from @gdb_core_xml_file. * @gdb_core_xml_file: File name for core registers GDB XML description. +* @gdb_get_core_xml_file: Optional callback that returns the file name for +* the core registers GDB XML description. The returned value is expected to +* be a simple constant string: the caller will not g_free() it. If this +* is NULL then @gdb_core_xml_file will be used instead. * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop * before the insn which triggers a watchpoint rather than after it. * @gdb_arch_name: Optional callback that returns the architecture name known
@@ -167,6 +171,7 @@ struct CPUClass {const char *gdb_core_xml_file;const gchar * (*gdb_arch_name)(CPUState *cpu); +const char * (*gdb_get_core_xml_file)(CPUState *cpu);void (*disas_set_info)(CPUState *cpu,disassemble_info *info);
gdbstub/gdbstub.c +19 -4
@@ -565,15 +565,30 @@ static void gdb_register_feature(CPUState *cpu, int base_reg,g_array_append_val (cpu->gdb_regs, s); } +static const char *gdb_get_core_xml_file (CPUState *cpu) +{ +CPUClass *cc = cpu->cc; + +/* +* The CPU class can provide the XML filename via a method, +* or as a simple fixed string field. +*/ +if (cc->gdb_get_core_xml_file) { +return cc->gdb_get_core_xml_file (cpu); + } +return cc->gdb_core_xml_file; +} +void gdb_init_cpu (CPUState *cpu) {CPUClass *cc = cpu->cc;const GDBFeature *feature; +const char *xmlfile =gdb_get_core_xml_file (cpu); cpu->gdb_regs =g_array_new (false, false,sizeof (GDBRegisterState)); -if (cc->gdb_core_xml_file) { - feature =gdb_find_static_feature (cc->gdb_core_xml_file); +if (xmlfile) { + feature =gdb_find_static_feature (xmlfile);gdb_register_feature (cpu,0 , cc->gdb_read_register, cc->gdb_write_register, feature);
@@ -1644,7 +1659,7 @@ void gdb_extend_qsupported_features(char *qflags)static void handle_query_supported (GArray *params,void *user_ctx) {g_string_printf (gdbserver_state.str_buf,"PacketSize=%x" ,MAX_PACKET_LENGTH ); -if (first_cpu->cc->gdb_core_xml_file) { +if (gdb_get_core_xml_file (first_cpu)) {g_string_append (gdbserver_state.str_buf,";qXfer:features:read+" ); }
@@ -1701,7 +1716,7 @@ static void handle_query_xfer_features(GArray *params, void *user_ctx) } process =gdb_get_cpu_process (gdbserver_state.g_cpu); -if (!gdbserver_state.g_cpu->cc->gdb_core_xml_file) { +if (!gdb_get_core_xml_file (gdbserver_state.g_cpu)) {gdb_put_packet ("" );return ; }
Signature · 1 line
2.43.0
Re: [PATCH for-10.1 2/9] gdbstub: Allow gdb_core_xml_file to be set at runtime
Quoted 10 lines · Peter Maydell
Currently the CPUClass:gdb_core_xml_file setting is a simple 'const char *' which the CPU class must set to a fixed string. Allow the CPU class to instead set a new method
gdb_get_core_xml_file()which returns this string.This will allow Arm CPUs to use different XML files for AArch32 vs AArch64 without having to have an extra AArch64-specific class type purely to give somewhere to set
cc->gdb_core_xml_filedifferently.Signed-off-by Peter Maydell <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH 3/9 target/arm: Handle AArch64 in TYPE_ARM_CPU gdb_arch_name
In reply to Peter MaydellInstead of having the TYPE_AARCH64_CPU subclass set CPUClass::gdb_arch_name to a different function, make the TYPE_ARM_CPU implementation of the method handle AArch64.
For the moment we make the "is this AArch64?" function test "is the CPU of TYPE_AARCH64_CPU?", so that this produces no behavioural change. When we've moved all the gdbstub related methods across to the base class, we will be able to change this to be "does the CPU have the ARM_FEATURE_AARCH64 feature?".
--- target/arm/internals.h | 6 ++++++ target/arm/cpu.c | 3 +++ target/arm/cpu64.c | 6 ------ 3 files changed, 9 insertions(+), 6 deletions(-)
target/arm/internals.h +6 -0
@@ -1691,6 +1691,12 @@ void aarch64_add_sve_properties(Object *obj);void aarch64_add_sme_properties (Object *obj);#endif +/* Return true if the gdbstub is presenting an AArch64 CPU */ +static inline bool arm_gdbstub_is_aarch64 (ARMCPU *cpu) +{ +return object_dynamic_cast (OBJECT (cpu),TYPE_AARCH64_CPU ); +} +/* Read the CONTROL register as the MRS instruction would. */ uint32_t arm_v7m_mrs_control (CPUARMState *env,uint32_t secure);
target/arm/cpu.c +3 -0
@@ -2647,6 +2647,9 @@ static const gchar *arm_gdb_arch_name(CPUState *cs)ARMCPU *cpu =ARM_CPU (cs);CPUARMState *env = &cpu->env; +if (arm_gdbstub_is_aarch64 (cpu)) { +return "aarch64" ; + }if (arm_feature (env,ARM_FEATURE_IWMMXT )) {return "iwmmxt" ; }
target/arm/cpu64.c +0 -6
@@ -813,11 +813,6 @@ static void aarch64_cpu_finalizefn(Object *obj) { } -static const gchar *aarch64_gdb_arch_name (CPUState *cs) -{ -return "aarch64" ; -} -static void aarch64_cpu_class_init (ObjectClass *oc,void *data) {CPUClass *cc =CPU_CLASS (oc);
@@ -825,7 +820,6 @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_read_register = aarch64_cpu_gdb_read_register; cc->gdb_write_register = aarch64_cpu_gdb_write_register; cc->gdb_core_xml_file ="aarch64-core.xml" ; - cc->gdb_arch_name = aarch64_gdb_arch_name;object_class_property_add_bool (oc,"aarch64" , aarch64_cpu_get_aarch64, aarch64_cpu_set_aarch64);
Signature · 1 line
2.43.0
Re: [PATCH for-10.1 3/9] target/arm: Handle AArch64 in TYPE_ARM_CPU gdb_arch_name
Quoted 11 lines · Peter Maydell
Instead of having the
TYPE_AARCH64_CPUsubclass setCPUClass::gdb_arch_nameto a different function, make theTYPE_ARM_CPUimplementation of the method handle AArch64.For the moment we make the "is this AArch64?" function test "is the CPU of
TYPE_AARCH64_CPU?", so that this produces no behavioural change. When we've moved all the gdbstub related methods across to the base class, we will be able to change this to be "does the CPU have theARM_FEATURE_AARCH64feature?".Signed-off-by Peter Maydell <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH for-10.1 3/9] target/arm: Handle AArch64 in TYPE_ARM_CPU gdb_arch_name
In reply to Peter MaydellQuoted 10 lines · Peter Maydell
Instead of having the
TYPE_AARCH64_CPUsubclass setCPUClass::gdb_arch_nameto a different function, make theTYPE_ARM_CPUimplementation of the method handle AArch64.For the moment we make the "is this AArch64?" function test "is the CPU of
TYPE_AARCH64_CPU?", so that this produces no behavioural change. When we've moved all the gdbstub related methods across to the base class, we will be able to change this to be "does the CPU have theARM_FEATURE_AARCH64feature?".
Quoted 6 lines
Signed-off-by Peter Maydell <[email protected]>--- target/arm/internals.h | 6 ++++++ target/arm/cpu.c | 3 +++ target/arm/cpu64.c | 6 ------ 3 files changed, 9 insertions(+), 6 deletions(-)
PATCH 4/9 target/arm: Handle gdb_core_xml_file in TYPE_ARM_CPU
In reply to Peter MaydellInstead of having the TYPE_AARCH64_CPU subclass set CPUClass:gdb_core_xml_file to a different value from that that TYPE_ARM_CPU uses, implement the gdb_get_core_xml_file method in the TYPE_ARM_CPU class to return either the AArch64 or AArch32 XML file name.
--- target/arm/cpu.c | 16 +++++++++++++++- target/arm/cpu64.c | 1 - target/arm/tcg/cpu-v7m.c | 1 - 3 files changed, 15 insertions(+), 3 deletions(-)
target/arm/cpu.c +15 -1
@@ -2656,6 +2656,20 @@ static const gchar *arm_gdb_arch_name(CPUState *cs)return "arm" ; } +static const char *arm_gdb_get_core_xml_file (CPUState *cs) +{ +ARMCPU *cpu =ARM_CPU (cs); +CPUARMState *env = &cpu->env; + +if (arm_gdbstub_is_aarch64 (cpu)) { +return "aarch64-core.xml" ; + } +if (arm_feature (env,ARM_FEATURE_M )) { +return "arm-m-profile.xml" ; + } +return "arm-core.xml" ; +} +#ifndef CONFIG_USER_ONLY #include "hw/core/sysemu-cpu-ops.h"
@@ -2721,6 +2735,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) cc->sysemu_ops = &arm_sysemu_ops;#endif cc->gdb_arch_name = arm_gdb_arch_name; + cc->gdb_get_core_xml_file = arm_gdb_get_core_xml_file; cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = arm_disas_set_info;
@@ -2743,7 +2758,6 @@ static void cpu_register_class_init(ObjectClass *oc, void *data)CPUClass *cc =CPU_CLASS (acc); acc->info = data; - cc->gdb_core_xml_file ="arm-core.xml" ;if (acc->info->deprecation_note) { cc->deprecation_note = acc->info->deprecation_note; }
target/arm/cpu64.c +0 -1
@@ -819,7 +819,6 @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_read_register = aarch64_cpu_gdb_read_register; cc->gdb_write_register = aarch64_cpu_gdb_write_register; - cc->gdb_core_xml_file ="aarch64-core.xml" ;object_class_property_add_bool (oc,"aarch64" , aarch64_cpu_get_aarch64, aarch64_cpu_set_aarch64);
target/arm/tcg/cpu-v7m.c +0 -1
@@ -261,7 +261,6 @@ static void arm_v7m_class_init(ObjectClass *oc, void *data) acc->info = data; cc->tcg_ops = &arm_v7m_tcg_ops; - cc->gdb_core_xml_file ="arm-m-profile.xml" ; }static const ARMCPUInfo arm_v7m_cpus[] = {
Signature · 1 line
2.43.0
Re: [PATCH for-10.1 4/9] target/arm: Handle gdb_core_xml_file in TYPE_ARM_CPU
Quoted 6 lines · Peter Maydell
Instead of having the
TYPE_AARCH64_CPUsubclass set CPUClass:gdb_core_xml_file to a different value from that thatTYPE_ARM_CPUuses, implement thegdb_get_core_xml_filemethod in theTYPE_ARM_CPUclass to return either the AArch64 or AArch32 XML file name.
Quoted 6 lines
Signed-off-by Peter Maydell <[email protected]>--- target/arm/cpu.c | 16 +++++++++++++++- target/arm/cpu64.c | 1 - target/arm/tcg/cpu-v7m.c | 1 - 3 files changed, 15 insertions(+), 3 deletions(-)
PATCH 5/9 target/arm: Handle AArch64 gdb read/write regs in TYPE_ARM_CPU
In reply to Peter MaydellInstead of having the TYPE_AARCH64_CPU subclass set CPUClass::gdb_read_register and ::gdb_write_register to different methods from those of the TYPE_ARM_CPU parent class, have the TYPE_ARM_CPU methods handle either AArch32 or AArch64 at runtime.
--- target/arm/cpu64.c | 5 ----- target/arm/gdbstub.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-)
target/arm/cpu64.c +0 -5
@@ -815,11 +815,6 @@ static void aarch64_cpu_finalizefn(Object *obj)static void aarch64_cpu_class_init (ObjectClass *oc,void *data) { -CPUClass *cc =CPU_CLASS (oc); - - cc->gdb_read_register = aarch64_cpu_gdb_read_register; - cc->gdb_write_register = aarch64_cpu_gdb_write_register; -object_class_property_add_bool (oc,"aarch64" , aarch64_cpu_get_aarch64, aarch64_cpu_set_aarch64); object_class_property_set_description(oc, "aarch64",
target/arm/gdbstub.c +12 -0
@@ -44,6 +44,12 @@ int arm_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)ARMCPU *cpu =ARM_CPU (cs);CPUARMState *env = &cpu->env; +#ifdef TARGET_AARCH64 +if (arm_gdbstub_is_aarch64 (cpu)) { +return aarch64_cpu_gdb_read_register (cs, mem_buf, n); + } +#endif +if (n <16 ) {/* Core integer register. */ return gdb_get_reg32 (mem_buf, env->regs[n]);
@@ -66,6 +72,12 @@ int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)CPUARMState *env = &cpu->env;uint32_t tmp; +#ifdef TARGET_AARCH64 +if (arm_gdbstub_is_aarch64 (cpu)) { +return aarch64_cpu_gdb_write_register (cs, mem_buf, n); + } +#endif + tmp =ldl_p (mem_buf);/*
Signature · 1 line
2.43.0
Re: [PATCH for-10.1 5/9] target/arm: Handle AArch64 gdb read/write regs in TYPE_ARM_CPU
Quoted 10 lines · Peter Maydell
Instead of having the
TYPE_AARCH64_CPUsubclass setCPUClass::gdb_read_registerand ::gdb_write_register to different methods from those of theTYPE_ARM_CPUparent class, have theTYPE_ARM_CPUmethods handle either AArch32 or AArch64 at runtime.Signed-off-by Peter Maydell <[email protected]>--- target/arm/cpu64.c | 5 ----- target/arm/gdbstub.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-)
PATCH 6/9 target/arm: Present AArch64 gdbstub based on ARM_FEATURE_AARCH64
In reply to Peter MaydellCurrently we provide an AArch64 gdbstub for CPUs which are TYPE_AARCH64_CPU, and an AArch32 gdbstub for those which are only TYPE_ARM_CPU. This mostly does the right thing, except in the corner case of KVM with -cpu host,aarch64=off. That produces a CPU which is TYPE_AARCH64_CPU but which has ARM_FEATURE_AARCH64 removed and which to the guest is in AArch32 mode.
Now we have moved all the handling of AArch64-vs-AArch32 gdbstub behaviour into TYPE_ARM_CPU we can change the condition we use for whether to select the AArch64 gdbstub to look at ARM_FEATURE_AARCH64. This will mean that we now correctly provide an AArch32 gdbstub for aarch64=off CPUs.
--- target/arm/internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/internals.h +1 -1
@@ -1694,7 +1694,7 @@ void aarch64_add_sme_properties(Object *obj);/* Return true if the gdbstub is presenting an AArch64 CPU */ static inline bool arm_gdbstub_is_aarch64 (ARMCPU *cpu) { -return object_dynamic_cast (OBJECT (cpu),TYPE_AARCH64_CPU ); +return arm_feature (&cpu->env,ARM_FEATURE_AARCH64 ); }/* Read the CONTROL register as the MRS instruction would. */
Signature · 1 line
2.43.0
Re: [PATCH for-10.1 6/9] target/arm: Present AArch64 gdbstub based on ARM_FEATURE_AARCH64
Quoted 13 lines · Peter Maydell
Currently we provide an AArch64 gdbstub for CPUs which are
TYPE_AARCH64_CPU, and an AArch32 gdbstub for those which are onlyTYPE_ARM_CPU. This mostly does the right thing, except in the corner case of KVM with -cpu host,aarch64=off. That produces a CPU which isTYPE_AARCH64_CPUbut which hasARM_FEATURE_AARCH64removed and which to the guest is in AArch32 mode.Now we have moved all the handling of AArch64-vs-AArch32 gdbstub behaviour into
TYPE_ARM_CPUwe can change the condition we use for whether to select the AArch64 gdbstub to look atARM_FEATURE_AARCH64. This will mean that we now correctly provide an AArch32 gdbstub for aarch64=off CPUs.
Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>--- target/arm/internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Re: [PATCH for-10.1 6/9] target/arm: Present AArch64 gdbstub based on ARM_FEATURE_AARCH64
In reply to Peter MaydellQuoted 23 lines · Peter Maydell
Currently we provide an AArch64 gdbstub for CPUs which are
TYPE_AARCH64_CPU, and an AArch32 gdbstub for those which are onlyTYPE_ARM_CPU. This mostly does the right thing, except in the corner case of KVM with -cpu host,aarch64=off. That produces a CPU which isTYPE_AARCH64_CPUbut which hasARM_FEATURE_AARCH64removed and which to the guest is in AArch32 mode.Now we have moved all the handling of AArch64-vs-AArch32 gdbstub behaviour into
TYPE_ARM_CPUwe can change the condition we use for whether to select the AArch64 gdbstub to look atARM_FEATURE_AARCH64. This will mean that we now correctly provide an AArch32 gdbstub for aarch64=off CPUs.Signed-off-by Peter Maydell <[email protected]>--- target/arm/internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/arm/internals.h +0
-0
target/arm/internals.h void aarch64_add_sme_properties(Object *obj); · line 1695
Quoted 2 lines
target/arm/internals.h +0
-0@@ -1694,7 +1694,7 @@ void aarch64_add_sme_properties(Object *obj);/* Return true if the gdbstub is presenting an AArch64 CPU */ static inline bool arm_gdbstub_is_aarch64 (ARMCPU *cpu)
4 uses, maybe worth removing (directly inlining) as a cleanup patch on top of this conversion series.
Quoted 6 lines
target/arm/internals.h +1
-1{ -return object_dynamic_cast (OBJECT (cpu),TYPE_AARCH64_CPU ); +return arm_feature (&cpu->env,ARM_FEATURE_AARCH64 ); }/* Read the CONTROL register as the MRS instruction would. */
Re: [PATCH for-10.1 6/9] target/arm: Present AArch64 gdbstub based on ARM_FEATURE_AARCH64
In reply to Peter MaydellHi Peter,
Quoted 23 lines · Peter Maydell
Currently we provide an AArch64 gdbstub for CPUs which are
TYPE_AARCH64_CPU, and an AArch32 gdbstub for those which are onlyTYPE_ARM_CPU. This mostly does the right thing, except in the corner case of KVM with -cpu host,aarch64=off. That produces a CPU which isTYPE_AARCH64_CPUbut which hasARM_FEATURE_AARCH64removed and which to the guest is in AArch32 mode.Now we have moved all the handling of AArch64-vs-AArch32 gdbstub behaviour into
TYPE_ARM_CPUwe can change the condition we use for whether to select the AArch64 gdbstub to look atARM_FEATURE_AARCH64. This will mean that we now correctly provide an AArch32 gdbstub for aarch64=off CPUs.Signed-off-by Peter Maydell <[email protected]>--- target/arm/internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/arm/internals.h +0
-0
target/arm/internals.h void aarch64_add_sme_properties(Object *obj); · line 1697
Quoted 5 lines
target/arm/internals.h +1
-1@@ -1694,7 +1694,7 @@ void aarch64_add_sme_properties(Object *obj);/* Return true if the gdbstub is presenting an AArch64 CPU */ static inline bool arm_gdbstub_is_aarch64 (ARMCPU *cpu) { -return object_dynamic_cast (OBJECT (cpu),TYPE_AARCH64_CPU ); +return arm_feature (&cpu->env,ARM_FEATURE_AARCH64 );
Unfortunately this doesn't work well: while a Aarch64 CPU is of type TYPE_AARCH64_CPU right after being instantiated (not yet QOM realized), the features are only finalized during arm_cpu_instance_init():
static void arm_cpu_instance_init(Object *obj)
{
ARMCPUClass *acc = ARM_CPU_GET_CLASS(obj);
acc->info->initfn(obj);
arm_cpu_post_init(obj);
}void arm_cpu_post_init(Object *obj)
{
ARMCPU *cpu = ARM_CPU(obj);
/*
* Some features imply others. Figure this out now, because we
* are going to look at the feature bits in deciding which
* properties to add.
*/
arm_cpu_propagate_feature_implications(cpu);
...
}The GDB feature checks are done earlier:
object_init_with_type
-> cpu_common_initfn
-> gdb_init_cpu
-> gdb_get_core_xml_file
-> arm_gdb_get_core_xml_file
-> arm_gdbstub_is_aarch64At this point the feature set is empty, triggering the assertion in gdb_find_static_feature():
$ ./build/qemu-aarch64 build/tests/tcg/aarch64-linux-user/semihosting ** ERROR:../../gdbstub/gdbstub.c:494:gdb_find_static_feature: code should not be reached Bail out! ERROR:../../gdbstub/gdbstub.c:494:gdb_find_static_feature: code should not be reached Aborted (core dumped)
I suppose gdb_init_cpu() needs more splitting work. For now I'll drop this patches 5+ from my queue.
Regards,
Phil.
Re: [PATCH for-10.1 6/9] target/arm: Present AArch64 gdbstub based on ARM_FEATURE_AARCH64
Quoted 22 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 18 lines · Peter Maydell
Currently we provide an AArch64 gdbstub for CPUs which are
TYPE_AARCH64_CPU, and an AArch32 gdbstub for those which are onlyTYPE_ARM_CPU. This mostly does the right thing, except in the corner case of KVM with -cpu host,aarch64=off. That produces a CPU which isTYPE_AARCH64_CPUbut which hasARM_FEATURE_AARCH64removed and which to the guest is in AArch32 mode.Now we have moved all the handling of AArch64-vs-AArch32 gdbstub behaviour into
TYPE_ARM_CPUwe can change the condition we use for whether to select the AArch64 gdbstub to look atARM_FEATURE_AARCH64. This will mean that we now correctly provide an AArch32 gdbstub for aarch64=off CPUs.Signed-off-by Peter Maydell <[email protected]>--- target/arm/internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
target/arm/internals.h void aarch64_add_sme_properties(Object *obj); · line 1697
Quoted 10 lines
target/arm/internals.h +1
-1@@ -1694,7 +1694,7 @@ void aarch64_add_sme_properties(Object *obj);/* Return true if the gdbstub is presenting an AArch64 CPU */ static inline bool arm_gdbstub_is_aarch64 (ARMCPU *cpu) { -return object_dynamic_cast (OBJECT (cpu),TYPE_AARCH64_CPU ); +return arm_feature (&cpu->env,ARM_FEATURE_AARCH64 );Unfortunately this doesn't work well: while a Aarch64 CPU is of type
TYPE_AARCH64_CPUright after being instantiated (not yet QOM realized), the features are only finalized duringarm_cpu_instance_init():
Thanks for finding this. The problem is that gdb_init_cpu() is being called as part of the base-class instance init, so the CPU object isn't fully instantiated yet -- it hasn't even run the aarch64_max_initfn() function yet. So gdb_init_cpu() ends up calling CPU-specific methods on a half-instantiated object, which is why it crashes.
But we do need to move things so they happen after realize, because up til realize the CPU properties might be changed (otherwise we give the wrong answer for the aarch64=off case). Except that part of the CPU subclass realize involves calling gdb_register_coprocessor(), which needs to happen after we've set up the core regs for gdb.
I think that moving the call to cpu_exec_realizefn() would work (this gets called near the start of realize, so before the subclass realize decides to add more gdb registers). But I'll have to check whether that would be wrong for some other architecture, and maybe there's a neater way to do this.
-- PMM
PATCH 7/9 target/arm: Move aarch64 CPU property code to TYPE_ARM_CPU
In reply to Peter MaydellThe only thing we have left in the TYPE_AARCH64_CPU class that makes it different to TYPE_ARM_CPU is that we register the handling of the "aarch64" property there.
Move the handling of this property to the base class, where we make it a property of the object rather than of the class, and add it to the CPU if it has the ARM_FEATURE_AARCH64 property present at init. This is in line with how we handle other Arm CPU properties, and should not change which CPUs it's visible for.
--- target/arm/cpu.c | 36 ++++++++++++++++++++++++++++++++++++ target/arm/cpu64.c | 33 --------------------------------- 2 files changed, 36 insertions(+), 33 deletions(-)
target/arm/cpu.c +36 -0
@@ -1608,6 +1608,35 @@ static void arm_set_pmu(Object *obj, bool value, Error **errp) cpu->has_pmu = value; } +static bool aarch64_cpu_get_aarch64 (Object *obj,Error **errp) +{ +ARMCPU *cpu =ARM_CPU (obj); + +return arm_feature (&cpu->env,ARM_FEATURE_AARCH64 ); +} + +static void aarch64_cpu_set_aarch64 (Object *obj,bool value,Error **errp) +{ +ARMCPU *cpu =ARM_CPU (obj); + +/* +* At this time, this property is only allowed if KVM is enabled. This +* restriction allows us to avoid fixing up functionality that assumes a +* uniform execution state like do_interrupt. +*/ +if (value == false) { +if (!kvm_enabled () || !kvm_arm_aarch32_supported ()) { +error_setg (errp,"'aarch64' feature cannot be disabled " +"unless KVM is enabled and 32-bit EL1 " +"is supported" ); +return ; + } +unset_feature (&cpu->env,ARM_FEATURE_AARCH64 ); + }else { +set_feature (&cpu->env,ARM_FEATURE_AARCH64 ); + } +} +unsigned int gt_cntfrq_period_ns (ARMCPU *cpu) {/*
@@ -1735,6 +1764,13 @@ void arm_cpu_post_init(Object *obj)*/ arm_cpu_propagate_feature_implications (cpu); +if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) { +object_property_add_bool (obj,"aarch64" , aarch64_cpu_get_aarch64, + aarch64_cpu_set_aarch64); +object_property_set_description (obj,"aarch64" , +"Set on/off to enable/disable aarch64 " +"execution state " ); + }if (arm_feature (&cpu->env,ARM_FEATURE_CBAR ) ||arm_feature (&cpu->env,ARM_FEATURE_CBAR_RO )) {qdev_property_add_static (DEVICE (obj), &arm_cpu_reset_cbar_property);
target/arm/cpu64.c +0 -33
@@ -781,45 +781,12 @@ static const ARMCPUInfo aarch64_cpus[] = {#endif }; -static bool aarch64_cpu_get_aarch64 (Object *obj,Error **errp) -{ -ARMCPU *cpu =ARM_CPU (obj); - -return arm_feature (&cpu->env,ARM_FEATURE_AARCH64 ); -} - -static void aarch64_cpu_set_aarch64 (Object *obj,bool value,Error **errp) -{ -ARMCPU *cpu =ARM_CPU (obj); - -/* At this time, this property is only allowed if KVM is enabled. This -* restriction allows us to avoid fixing up functionality that assumes a -* uniform execution state like do_interrupt. -*/ -if (value == false) { -if (!kvm_enabled () || !kvm_arm_aarch32_supported ()) { -error_setg (errp,"'aarch64' feature cannot be disabled " -"unless KVM is enabled and 32-bit EL1 " -"is supported" ); -return ; - } -unset_feature (&cpu->env,ARM_FEATURE_AARCH64 ); - }else { -set_feature (&cpu->env,ARM_FEATURE_AARCH64 ); - } -} -static void aarch64_cpu_finalizefn (Object *obj) { }static void aarch64_cpu_class_init (ObjectClass *oc,void *data) { -object_class_property_add_bool (oc,"aarch64" , aarch64_cpu_get_aarch64, - aarch64_cpu_set_aarch64); -object_class_property_set_description (oc,"aarch64" , -"Set on/off to enable/disable aarch64 " -"execution state " ); }static void aarch64_cpu_instance_init (Object *obj)
Signature · 1 line
2.43.0
Re: [PATCH for-10.1 7/9] target/arm: Move aarch64 CPU property code to TYPE_ARM_CPU
Quoted 10 lines · Peter Maydell
The only thing we have left in the
TYPE_AARCH64_CPUclass that makes it different toTYPE_ARM_CPUis that we register the handling of the "aarch64" property there.Move the handling of this property to the base class, where we make it a property of the object rather than of the class, and add it to the CPU if it has the
ARM_FEATURE_AARCH64property present at init. This is in line with how we handle other Arm CPU properties, and should not change which CPUs it's visible for.
Quoted 5 lines
Signed-off-by Peter Maydell <[email protected]>--- target/arm/cpu.c | 36 ++++++++++++++++++++++++++++++++++++ target/arm/cpu64.c | 33 --------------------------------- 2 files changed, 36 insertions(+), 33 deletions(-)
PATCH 8/9 target/arm/kvm: don't check TYPE_AARCH64_CPU
In reply to Peter MaydellWe want to merge TYPE_AARCH64_CPU with TYPE_ARM_CPU, so enforcing in kvm_arch_init_vcpu() that the CPU class is a subclass of TYPE_AARCH64_CPU will no longer be possible.
It's safe to just remove this test, because any purely-AArch32 CPU will fail the "kvm_target isn't set" check, because we no longer support the old AArch32-host KVM setup and so CPUs like the Cortex-A7 no longer set cpu->kvm_target. Only the 'host', 'max', and the odd special cases 'cortex-a53' and 'cortex-a57' set kvm_target.
--- target/arm/kvm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target/arm/kvm.c +1 -2
@@ -1882,8 +1882,7 @@ int kvm_arch_init_vcpu(CPUState *cs)CPUARMState *env = &cpu->env;uint64_t psciver; -if (cpu->kvm_target ==QEMU_KVM_ARM_TARGET_NONE || - !object_dynamic_cast (OBJECT (cpu),TYPE_AARCH64_CPU )) { +if (cpu->kvm_target ==QEMU_KVM_ARM_TARGET_NONE ) {error_report ("KVM is not supported for this guest CPU type" );return -EINVAL ; }
Signature · 1 line
2.43.0
Re: [PATCH for-10.1 8/9] target/arm/kvm: don't check TYPE_AARCH64_CPU
Quoted 10 lines · Peter Maydell
We want to merge
TYPE_AARCH64_CPUwithTYPE_ARM_CPU, so enforcing inkvm_arch_init_vcpu()that the CPU class is a subclass ofTYPE_AARCH64_CPUwill no longer be possible.It's safe to just remove this test, because any purely-AArch32 CPU will fail the "
kvm_targetisn't set" check, because we no longer support the old AArch32-host KVM setup and so CPUs like the Cortex-A7 no longer setcpu->kvm_target. Only the 'host', 'max', and the odd special cases 'cortex-a53' and 'cortex-a57' setkvm_target.
Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>--- target/arm/kvm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
PATCH 9/9 target/arm: Remove TYPE_AARCH64_CPU
In reply to Peter MaydellThe TYPE_AARCH64_CPU class is an abstract type that is the parent of all the AArch64 CPUs. It now has no special behaviour of its own, so we can eliminate it and make the AArch64 CPUs directly inherit from TYPE_ARM_CPU.
--- target/arm/cpu-qom.h | 5 ----- target/arm/cpu.h | 4 ---- target/arm/internals.h | 1 - target/arm/cpu64.c | 49 +----------------------------------------- target/arm/tcg/cpu64.c | 2 +- 5 files changed, 2 insertions(+), 59 deletions(-)
target/arm/cpu-qom.h +0 -5
@@ -28,11 +28,6 @@ OBJECT_DECLARE_CPU_TYPE(ARMCPU, ARMCPUClass, ARM_CPU)#define TYPE_ARM_MAX_CPU "max-" TYPE_ARM_CPU -#define TYPE_AARCH64_CPU "aarch64-cpu" -typedef struct AArch64CPUClass AArch64CPUClass ; -DECLARE_CLASS_CHECKERS (AArch64CPUClass,AARCH64_CPU , - TYPE_AARCH64_CPU) -#define ARM_CPU_TYPE_SUFFIX "-" TYPE_ARM_CPU#define ARM_CPU_TYPE_NAME (name) (name ARM_CPU_TYPE_SUFFIX)
target/arm/cpu.h +0 -4
@@ -1161,10 +1161,6 @@ struct ARMCPUClass {ResettablePhases parent_phases; }; -struct AArch64CPUClass { -ARMCPUClass parent_class; -}; -/* Callback functions for the generic timer's timers. */ void arm_gt_ptimer_cb (void *opaque);void arm_gt_vtimer_cb (void *opaque);
target/arm/internals.h +0 -1
@@ -350,7 +350,6 @@ static inline int r14_bank_number(int mode) }void arm_cpu_register (const ARMCPUInfo *info); -void aarch64_cpu_register (const ARMCPUInfo *info);void register_cp_regs_for_features (ARMCPU *cpu);void init_cpreg_list (ARMCPU *cpu);
target/arm/cpu64.c +1 -48
60 lines not on this page · raw message
target/arm/tcg/cpu64.c +1 -1
@@ -1316,7 +1316,7 @@ static void aarch64_cpu_register_types(void)size_t i;for (i =0 ; i <ARRAY_SIZE (aarch64_cpus); ++i) { -aarch64_cpu_register (&aarch64_cpus[i]); +arm_cpu_register (&aarch64_cpus[i]); } }
Signature · 1 line
2.43.0
Re: [PATCH for-10.1 9/9] target/arm: Remove TYPE_AARCH64_CPU
Quoted 5 lines · Peter Maydell
The
TYPE_AARCH64_CPUclass is an abstract type that is the parent of all the AArch64 CPUs. It now has no special behaviour of its own, so we can eliminate it and make the AArch64 CPUs directly inherit fromTYPE_ARM_CPU.
Quoted 8 lines
Signed-off-by Peter Maydell <[email protected]>--- target/arm/cpu-qom.h | 5 ----- target/arm/cpu.h | 4 ---- target/arm/internals.h | 1 - target/arm/cpu64.c | 49 +----------------------------------------- target/arm/tcg/cpu64.c | 2 +- 5 files changed, 2 insertions(+), 59 deletions(-)
Thanks!
Quoted 13 lines · Peter Maydell
This patchseries removes
TYPE_AARCH64_CPUso that all CPUs, both AArch32 and AArch64, directly inherit fromTYPE_ARM_CPU.Peter Maydell (9):
core/cpu.h:gdb_arch_namestring should not be freed
gdbstub: Allowgdb_core_xml_fileto be set at runtime target/arm: Handle AArch64 inTYPE_ARM_CPUgdb_arch_nametarget/arm: Handlegdb_core_xml_fileinTYPE_ARM_CPUtarget/arm: Handle AArch64 gdb read/write regs inTYPE_ARM_CPUtarget/arm: Present AArch64 gdbstub based onARM_FEATURE_AARCH64target/arm: Move aarch64 CPU property code toTYPE_ARM_CPUtarget/arm/kvm: don't checkTYPE_AARCH64_CPUtarget/arm: RemoveTYPE_AARCH64_CPU
Series queued, thanks!