gdbstub: move update guest debug to accel ops
PATCH 1/1 gdbstub: move update guest debug to accel ops
From: Mads Ynddal <[email protected]>
Continuing the refactor of a48e7d9e52 (gdbstub: move guest debug support check to ops) by removing hardcoded kvm_enabled() from generic cpu.c code, and replace it with a property of AccelOpsClass.
--- accel/kvm/kvm-accel-ops.c | 1 + cpu.c | 10 +++++++--- include/sysemu/accel-ops.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-)
accel/kvm/kvm-accel-ops.c +1 -0
@@ -99,6 +99,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm;#ifdef KVM_CAP_SET_GUEST_DEBUG + ops->update_guest_debug = kvm_update_guest_debug; ops->supports_guest_debug = kvm_supports_guest_debug; ops->insert_breakpoint = kvm_insert_breakpoint; ops->remove_breakpoint = kvm_remove_breakpoint;
cpu.c +7 -3
@@ -31,8 +31,8 @@#include "hw/core/sysemu-cpu-ops.h" #include "exec/address-spaces.h" #endif +#include "sysemu/cpus.h" #include "sysemu/tcg.h" -#include "sysemu/kvm.h" #include "sysemu/replay.h" #include "exec/cpu-common.h" #include "exec/exec-all.h"
@@ -378,10 +378,14 @@ void cpu_breakpoint_remove_all(CPUState *cpu, int mask)void cpu_single_step (CPUState *cpu,int enabled) {if (cpu->singlestep_enabled != enabled) { +const AccelOpsClass *ops =cpus_get_accel (); + cpu->singlestep_enabled = enabled; -if (kvm_enabled ()) { -kvm_update_guest_debug (cpu,0 ); + +if (ops->update_guest_debug) { + ops->update_guest_debug (cpu,0 ); } +trace_breakpoint_singlestep (cpu->cpu_index, enabled); } }
include/sysemu/accel-ops.h +1 -0
@@ -48,6 +48,7 @@ struct AccelOpsClass {/* gdbstub hooks */ bool (*supports_guest_debug)(void ); +int (*update_guest_debug)(CPUState *cpu,unsigned long flags);int (*insert_breakpoint)(CPUState *cpu,int type,hwaddr addr,hwaddr len);int (*remove_breakpoint)(CPUState *cpu,int type,hwaddr addr,hwaddr len);void (*remove_all_breakpoints)(CPUState *cpu);
Signature · 1 line
2.38.1
Quoted 9 lines · Mads Ynddal
From: Mads Ynddal <[email protected]>
Continuing the refactor of
a48e7d9e52(gdbstub: move guest debug support check to ops) by removing hardcodedkvm_enabled()from genericcpu.ccode, and replace it with a property of AccelOpsClass.
Quoted 7 lines
Signed-off-by Mads Ynddal <[email protected]>---
accel/kvm/kvm-accel-ops.c | 1 + cpu.c | 10 +++++++--- include/sysemu/accel-ops.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-)
+CC Alex Bennée
Quoted 7 lines · Mads Ynddal
From: Mads Ynddal <[email protected]>
Continuing the refactor of
a48e7d9e52(gdbstub: move guest debug support check to ops) by removing hardcodedkvm_enabled()from genericcpu.ccode, and replace it with a property of AccelOpsClass.Signed-off-by Mads Ynddal <[email protected]>
Nice. Looks good to me but I'll have a proper look when I go through my gdbstub/next queue. I don't think this is critical for 7.2.
Quoted 61 lines
--- accel/kvm/kvm-accel-ops.c | 1 + cpu.c | 10 +++++++--- include/sysemu/accel-ops.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-)accel/kvm/kvm-accel-ops.c +1
-0@@ -99,6 +99,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm;#ifdef KVM_CAP_SET_GUEST_DEBUG + ops->update_guest_debug = kvm_update_guest_debug; ops->supports_guest_debug = kvm_supports_guest_debug; ops->insert_breakpoint = kvm_insert_breakpoint; ops->remove_breakpoint = kvm_remove_breakpoint;cpu.c +7
-3@@ -31,8 +31,8 @@#include "hw/core/sysemu-cpu-ops.h" #include "exec/address-spaces.h" #endif +#include "sysemu/cpus.h" #include "sysemu/tcg.h" -#include "sysemu/kvm.h" #include "sysemu/replay.h" #include "exec/cpu-common.h" #include "exec/exec-all.h" @@ -378,10 +378,14 @@ void cpu_breakpoint_remove_all(CPUState *cpu, int mask)void cpu_single_step (CPUState *cpu,int enabled) {if (cpu->singlestep_enabled != enabled) { +const AccelOpsClass *ops =cpus_get_accel (); + cpu->singlestep_enabled = enabled; -if (kvm_enabled ()) { -kvm_update_guest_debug (cpu,0 ); + +if (ops->update_guest_debug) { + ops->update_guest_debug (cpu,0 ); } +trace_breakpoint_singlestep (cpu->cpu_index, enabled); } }include/sysemu/accel-ops.h +1
-0@@ -48,6 +48,7 @@ struct AccelOpsClass {/* gdbstub hooks */ bool (*supports_guest_debug)(void ); +int (*update_guest_debug)(CPUState *cpu,unsigned long flags);int (*insert_breakpoint)(CPUState *cpu,int type,hwaddr addr,hwaddr len);int (*remove_breakpoint)(CPUState *cpu,int type,hwaddr addr,hwaddr len);void (*remove_all_breakpoints)(CPUState *cpu);
Signature · 1 line
Alex Bennée
Quoted 7 lines · Alex Bennée
Nice. Looks good to me but I'll have a proper look when I go through my gdbstub/next queue. I don't think this is critical for 7.2.
Thanks, and I agree. It can easily wait.
Hi,
Quoted 41 lines · Mads Ynddal
From: Mads Ynddal <[email protected]>
Continuing the refactor of
a48e7d9e52(gdbstub: move guest debug support check to ops) by removing hardcodedkvm_enabled()from genericcpu.ccode, and replace it with a property of AccelOpsClass.Signed-off-by Mads Ynddal <[email protected]>--- accel/kvm/kvm-accel-ops.c | 1 + cpu.c | 10 +++++++--- include/sysemu/accel-ops.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-)accel/kvm/kvm-accel-ops.c +1
-0@@ -99,6 +99,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm;#ifdef KVM_CAP_SET_GUEST_DEBUG + ops->update_guest_debug = kvm_update_guest_debug; ops->supports_guest_debug = kvm_supports_guest_debug; ops->insert_breakpoint = kvm_insert_breakpoint; ops->remove_breakpoint = kvm_remove_breakpoint;cpu.c +1
-1@@ -31,8 +31,8 @@#include "hw/core/sysemu-cpu-ops.h" #include "exec/address-spaces.h" #endif +#include "sysemu/cpus.h" #include "sysemu/tcg.h" -#include "sysemu/kvm.h" #include "sysemu/replay.h" #include "exec/cpu-common.h" #include "exec/exec-all.h" @@ -378,10 +378,14 @@ void cpu_breakpoint_remove_all(CPUState *cpu, int mask)void cpu_single_step (CPUState *cpu,int enabled)
cpu.c void cpu_breakpoint_remove_all(CPUState *cpu, int mask) · line 386
Quoted 10 lines
cpu.c +5
-2{if (cpu->singlestep_enabled != enabled) { +const AccelOpsClass *ops =cpus_get_accel (); + cpu->singlestep_enabled = enabled; -if (kvm_enabled ()) { -kvm_update_guest_debug (cpu,0 ); + +if (ops->update_guest_debug) { + ops->update_guest_debug (cpu,0 );
Isn't this '0' flag here accelerator-specific? ...
Quoted 10 lines
cpu.c +1
-0} +trace_breakpoint_singlestep (cpu->cpu_index, enabled); } }include/sysemu/accel-ops.h +0
-0
include/sysemu/accel-ops.h struct AccelOpsClass { · line 51
Quoted 4 lines
include/sysemu/accel-ops.h +1
-0@@ -48,6 +48,7 @@ struct AccelOpsClass {/* gdbstub hooks */ bool (*supports_guest_debug)(void ); +int (*update_guest_debug)(CPUState *cpu,unsigned long flags);
... if so the prototype should be:
int (*update_guest_debug)(CPUState *cpu);
and the '0' value set within kvm-accel-ops.c handler implementation.
include/sysemu/accel-ops.h struct AccelOpsClass { · line 54
Quoted 3 lines
include/sysemu/accel-ops.h +0
-0int (*insert_breakpoint)(CPUState *cpu,int type,hwaddr addr,hwaddr len);int (*remove_breakpoint)(CPUState *cpu,int type,hwaddr addr,hwaddr len);void (*remove_all_breakpoints)(CPUState *cpu);
Regards,
Phil.
Quoted 9 lines
Isn't this '0' flag here accelerator-specific? ...
... if so the prototype should be:
int (*update_guest_debug)(CPUState *cpu);and the '0' value set within
kvm-accel-ops.chandler implementation.
You're right, we can avoid the additional variable. We'll then have to wrap kvm_update_guest_debug. Would the following be ok?
accel/kvm/kvm-accel-ops.c +5 -1
@@ -86,6 +86,10 @@ static bool kvm_cpus_are_resettable(void)return !kvm_enabled () ||kvm_cpu_check_are_resettable (); } +static int kvm_update_guest_debug_ops (CPUState *cpu) { +return kvm_update_guest_debug (cpu,0 ); +} +static void kvm_accel_ops_class_init (ObjectClass *oc,void *data) {AccelOpsClass *ops =ACCEL_OPS_CLASS (oc);
@@ -99,7 +103,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm;#ifdef KVM_CAP_SET_GUEST_DEBUG - ops->update_guest_debug = kvm_update_guest_debug; + ops->update_guest_debug = kvm_update_guest_debug_ops; ops->supports_guest_debug = kvm_supports_guest_debug; ops->insert_breakpoint = kvm_insert_breakpoint; ops->remove_breakpoint = kvm_remove_breakpoint;
cpu.c +1 -1
@@ -383,7 +383,7 @@ void cpu_single_step(CPUState *cpu, int enabled) cpu->singlestep_enabled = enabled;if (ops->update_guest_debug) { - ops->update_guest_debug (cpu,0 ); + ops->update_guest_debug (cpu); }trace_breakpoint_singlestep (cpu->cpu_index, enabled);
include/sysemu/accel-ops.h +1 -1
@@ -48,7 +48,7 @@ struct AccelOpsClass {/* gdbstub hooks */ bool (*supports_guest_debug)(void ); -int (*update_guest_debug)(CPUState *cpu,unsigned long flags); +int (*update_guest_debug)(CPUState *cpu);int (*insert_breakpoint)(CPUState *cpu,int type,hwaddr addr,hwaddr len);int (*remove_breakpoint)(CPUState *cpu,int type,hwaddr addr,hwaddr len);void (*remove_all_breakpoints)(CPUState *cpu);
If you have a better name for kvm_update_guest_debug_ops, I'm open for suggestions.
On a side note. When compiling for an arch that isn't the same as the system (i.e. aarch64 on x86_64), I'm getting a linker-error for cpu.c that cpus_get_accel isn't defined. Do I need to move cpus_get_accel or somehow #ifdef its use?
Quoted 64 lines · Mads Ynddal
Quoted 8 lines
Isn't this '0' flag here accelerator-specific? ...
... if so the prototype should be:
int (*update_guest_debug)(CPUState *cpu);and the '0' value set within
kvm-accel-ops.chandler implementation.You're right, we can avoid the additional variable. We'll then have to wrap
kvm_update_guest_debug. Would the following be ok?accel/kvm/kvm-accel-ops.c +5
-1@@ -86,6 +86,10 @@ static bool kvm_cpus_are_resettable(void)return !kvm_enabled () ||kvm_cpu_check_are_resettable (); } +static int kvm_update_guest_debug_ops (CPUState *cpu) { +return kvm_update_guest_debug (cpu,0 ); +} +static void kvm_accel_ops_class_init (ObjectClass *oc,void *data) {AccelOpsClass *ops =ACCEL_OPS_CLASS (oc);@@ -99,7 +103,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm;#ifdef KVM_CAP_SET_GUEST_DEBUG - ops->update_guest_debug = kvm_update_guest_debug; + ops->update_guest_debug = kvm_update_guest_debug_ops; ops->supports_guest_debug = kvm_supports_guest_debug; ops->insert_breakpoint = kvm_insert_breakpoint; ops->remove_breakpoint = kvm_remove_breakpoint;cpu.c +1
-1@@ -383,7 +383,7 @@ void cpu_single_step(CPUState *cpu, int enabled) cpu->singlestep_enabled = enabled;if (ops->update_guest_debug) { - ops->update_guest_debug (cpu,0 ); + ops->update_guest_debug (cpu); }trace_breakpoint_singlestep (cpu->cpu_index, enabled);include/sysemu/accel-ops.h +1
-1@@ -48,7 +48,7 @@ struct AccelOpsClass {/* gdbstub hooks */ bool (*supports_guest_debug)(void ); -int (*update_guest_debug)(CPUState *cpu,unsigned long flags); +int (*update_guest_debug)(CPUState *cpu);int (*insert_breakpoint)(CPUState *cpu,int type,hwaddr addr,hwaddr len);int (*remove_breakpoint)(CPUState *cpu,int type,hwaddr addr,hwaddr len);void (*remove_all_breakpoints)(CPUState *cpu);
Quoted 2 lines
If you have a better name for
kvm_update_guest_debug_ops, I'm open for suggestions.
It will do. You could just call it update_guest_debug as it is an internal static function although I guess that makes grepping a bit of a pain.
Quoted 4 lines
On a side note. When compiling for an arch that isn't the same as the system (i.e. aarch64 on
x86_64), I'm getting a linker-error forcpu.cthatcpus_get_accelisn't defined. Do I need to movecpus_get_accelor somehow #ifdef its use?
Is something being accidentally linked with linux-user and softmmu?
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 4 lines
It will do. You could just call it
update_guest_debugas it is an internal static function although I guess that makes grepping a bit of a pain.
I agree. It should preferably be something unique, to ease grep'ing.
Quoted 1 line
Is something being accidentally linked with linux-user and softmmu?
Good question. I'm not familiar enough with the code base to know.
I experimented with enabling/disabling linux-user when configuring, and it does affect whether it compiles or not.
The following seems to fix it, and I can see the same approach is taken other places in cpu.c. Would this be an acceptable solution?
cpu.c +2 -0
@@ -386,6 +386,7 @@ void cpu_breakpoint_remove_all(CPUState *cpu, int mask)void cpu_single_step (CPUState *cpu,int enabled) {if (cpu->singlestep_enabled != enabled) { +#if !defined(CONFIG_USER_ONLY )const AccelOpsClass *ops =cpus_get_accel (); cpu->singlestep_enabled = enabled;
@@ -393,6 +394,7 @@ void cpu_single_step(CPUState *cpu, int enabled)if (ops->update_guest_debug) { ops->update_guest_debug (cpu,0 ); } +#endif trace_breakpoint_singlestep (cpu->cpu_index, enabled); }
—
Mads Ynddal
Quoted 29 lines · Mads Ynddal
Quoted 3 lines
It will do. You could just call it
update_guest_debugas it is an internal static function although I guess that makes grepping a bit of a pain.I agree. It should preferably be something unique, to ease grep'ing.
Quoted 1 line
Is something being accidentally linked with linux-user and softmmu?
Good question. I'm not familiar enough with the code base to know.
I experimented with enabling/disabling linux-user when configuring, and it does affect whether it compiles or not.
The following seems to fix it, and I can see the same approach is taken other places in
cpu.c. Would this be an acceptable solution?cpu.c +1
-0@@ -386,6 +386,7 @@ void cpu_breakpoint_remove_all(CPUState *cpu, int mask)void cpu_single_step (CPUState *cpu,int enabled) {if (cpu->singlestep_enabled != enabled) { +#if !defined(CONFIG_USER_ONLY )const AccelOpsClass *ops =cpus_get_accel (); cpu->singlestep_enabled = enabled;
cpu.c void cpu_single_step(CPUState *cpu, int enabled) · line 400
Quoted 7 lines
cpu.c +1
-0@@ -393,6 +394,7 @@ void cpu_single_step(CPUState *cpu, int enabled)if (ops->update_guest_debug) { ops->update_guest_debug (cpu,0 ); } +#endif trace_breakpoint_singlestep (cpu->cpu_index, enabled); }
Sorry this dropped of my radar. Yes I think the ifdef will do. Are you going to post a v2 with all the various updates?
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 5 lines
Sorry this dropped of my radar. Yes I think the ifdef will do. Are you going to post a v2 with all the various updates?
No worries, I'll make a v2 with the changes.
—
Mads Ynddal