Rework guest debug interface
PATCH 1/3 KVM: Rework guest debugging interface
In reply to Jan KiszkaThis rips out the support for KVM_DEBUG_GUEST and introduces a new IOCTL
instead: KVM_SET_GUEST_DEBUG. The IOCTL payload consists of a generic part, controlling the "main switch" and the single-step feature. The arch specific part adds an x86 interface for intercepting both types of debug exceptions separately and re-injecting them when the host is not interested. Moreover, it lays the ground for full hardware debug register / watchpoint support.
To signal breakpoint events properly back to userland, the current PC as well as an arch-specific data block is now returned along KVM_EXIT_DEBUG. For x86, the arch block contains the debug exception and relevant debug registers to tell possible debug events apart.
The availability of the new interface is signaled by KVM_CAP_SET_GUEST_DEBUG.
Note that both svm and vtx are supported, but only the latter was tested yet.
--- arch/ia64/kvm/kvm-ia64.c | 4 +- arch/powerpc/kvm/powerpc.c | 4 +- arch/s390/kvm/kvm-s390.c | 4 +- arch/x86/kvm/svm.c | 45 +++++++++++++++++++++++- arch/x86/kvm/vmx.c | 83 ++++++++++++++------------------------------- arch/x86/kvm/x86.c | 17 ++++----- include/asm-ia64/kvm.h | 7 +++ include/asm-powerpc/kvm.h | 7 +++ include/asm-s390/kvm.h | 7 +++ include/asm-x86/kvm.h | 17 +++++++++ include/asm-x86/kvm_host.h | 11 +---- include/linux/kvm.h | 52 +++++++++++++++++++--------- include/linux/kvm_host.h | 6 +-- virt/kvm/kvm_main.c | 6 +-- 14 files changed, 168 insertions(+), 102 deletions(-)
arch/x86/kvm/x86.c +9 -8
@@ -2730,10 +2730,6 @@ static int __vcpu_run(struct kvm_vcpu *vdown_read (&vcpu->kvm->slots_lock);vapic_enter (vcpu); -preempted: -if (vcpu->guest_debug.enabled) - kvm_x86_ops->guest_debug_pre (vcpu); - again:if (vcpu->requests)if (test_and_clear_bit (KVM_REQ_MMU_RELOAD , &vcpu->requests))
@@ -2869,7 +2865,7 @@ out:if (r >0 ) {kvm_resched (vcpu);down_read (&vcpu->kvm->slots_lock); - goto preempted; + goto again; }post_kvm_run_save (vcpu, kvm_run);
@@ -2973,7 +2969,7 @@ int kvm_arch_vcpu_ioctl_get_regs(struct/* * Don't leak debug flags in case they were set for guest debugging */ -if (vcpu->guest_debug.enabled && vcpu->guest_debug.singlestep) +if (vcpu->guest_debug &KVM_GUESTDBG_SINGLESTEP ) regs->rflags &= ~(X86_EFLAGS_TF |X86_EFLAGS_RF );vcpu_put (vcpu);
@@ -3589,8 +3585,8 @@ int kvm_arch_vcpu_ioctl_set_sregs(structreturn 0 ; } -int kvm_arch_vcpu_ioctl_debug_guest (struct kvm_vcpu *vcpu, -struct kvm_debug_guest *dbg) +int kvm_arch_vcpu_ioctl_set_guest_debug (struct kvm_vcpu *vcpu, +struct kvm_guest_debug *dbg) {int r;
@@ -3598,6 +3594,11 @@ int kvm_arch_vcpu_ioctl_debug_guest(stru r = kvm_x86_ops->set_guest_debug (vcpu, dbg); +if (dbg->control &KVM_GUESTDBG_INJECT_DB ) +kvm_queue_exception (vcpu,DB_VECTOR ); +else if (dbg->control &KVM_GUESTDBG_INJECT_BP ) +kvm_queue_exception (vcpu,BP_VECTOR ); +vcpu_put (vcpu);return r;
include/asm-x86/kvm.h +17 -0
@@ -230,4 +230,21 @@ struct kvm_pit_state {#define KVM_TRC_APIC_ACCESS (KVM_TRC_HANDLER + 0x14)#define KVM_TRC_TDP_FAULT (KVM_TRC_HANDLER + 0x15) +struct kvm_debug_exit_arch { +__u32 exception; +__u32 pad; +__u64 dr6; +__u64 dr7; +}; + +#define KVM_GUESTDBG_USE_SW_BP 0x00010000 +#define KVM_GUESTDBG_USE_HW_BP 0x00020000 +#define KVM_GUESTDBG_INJECT_DB 0x00040000 +#define KVM_GUESTDBG_INJECT_BP 0x00080000 + +/* for KVM_SET_GUEST_DEBUG */ +struct kvm_guest_debug_arch { +__u64 debugreg[8 ]; +}; +#endif
include/asm-x86/kvm_host.h +3 -8
@@ -54,6 +54,8 @@#define KVM_PAGES_PER_HPAGE (KVM_HPAGE_SIZE / PAGE_SIZE)#define DE_VECTOR 0 +#define DB_VECTOR 1 +#define BP_VECTOR 3#define UD_VECTOR 6#define NM_VECTOR 7#define DF_VECTOR 8
@@ -122,12 +124,6 @@ enum {#define KVM_NR_MEM_OBJS 40 -struct kvm_guest_debug { -int enabled; -unsigned long bp[4 ]; -int singlestep; -}; -/* * We don't want allocation failures within the mmu code, so we preallocate * enough memory for a single page fault in a cache.
@@ -383,8 +379,7 @@ struct kvm_x86_ops {void (*vcpu_put)(struct kvm_vcpu *vcpu);int (*set_guest_debug)(struct kvm_vcpu *vcpu, -struct kvm_debug_guest *dbg); -void (*guest_debug_pre)(struct kvm_vcpu *vcpu); +struct kvm_guest_debug *dbg);int (*get_msr)(struct kvm_vcpu *vcpu,u32 msr_index,u64 *pdata);int (*set_msr)(struct kvm_vcpu *vcpu,u32 msr_index,u64 data);u64 (*get_segment_base)(struct kvm_vcpu *vcpu,int seg);
include/linux/kvm.h +36 -16
87 lines not on this page · raw message
include/linux/kvm_host.h +3 -3
@@ -66,7 +66,7 @@ struct kvm_vcpu {struct kvm_run *run;int guest_mode;unsigned long requests; -struct kvm_guest_debug guest_debug; +unsigned long guest_debug;int fpu_active;int guest_fpu_loaded;wait_queue_head_t wq;
@@ -237,8 +237,8 @@ int kvm_arch_vcpu_ioctl_get_mpstate(stru struct kvm_mp_state *mp_state);int kvm_arch_vcpu_ioctl_set_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state); -int kvm_arch_vcpu_ioctl_debug_guest (struct kvm_vcpu *vcpu, -struct kvm_debug_guest *dbg); +int kvm_arch_vcpu_ioctl_set_guest_debug (struct kvm_vcpu *vcpu, +struct kvm_guest_debug *dbg);int kvm_arch_vcpu_ioctl_run (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run);int kvm_arch_init (void *opaque);
arch/x86/kvm/vmx.c +27 -56
127 lines not on this page · raw message
arch/x86/kvm/svm.c +43 -2
64 lines not on this page · raw message
virt/kvm/kvm_main.c +3 -3
@@ -1042,13 +1042,13 @@ out_free2: r =0 ;break ; } -case KVM_DEBUG_GUEST : { -struct kvm_debug_guest dbg; +case KVM_SET_GUEST_DEBUG : { +struct kvm_guest_debug dbg; r = -EFAULT ;if (copy_from_user (&dbg, argp,sizeof dbg)) goto out; - r =kvm_arch_vcpu_ioctl_debug_guest (vcpu, &dbg); + r =kvm_arch_vcpu_ioctl_set_guest_debug (vcpu, &dbg);if (r) goto out; r =0 ;
arch/ia64/kvm/kvm-ia64.c +2 -2
@@ -1299,8 +1299,8 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct kreturn -EINVAL ; } -int kvm_arch_vcpu_ioctl_debug_guest (struct kvm_vcpu *vcpu, -struct kvm_debug_guest *dbg) +int kvm_arch_vcpu_ioctl_set_guest_debug (struct kvm_vcpu *vcpu, +struct kvm_guest_debug *dbg) {return -EINVAL ; }
arch/powerpc/kvm/powerpc.c +2 -2
@@ -240,8 +240,8 @@ void kvm_arch_vcpu_put(struct kvm_vcpu * { } -int kvm_arch_vcpu_ioctl_debug_guest (struct kvm_vcpu *vcpu, -struct kvm_debug_guest *dbg) +int kvm_arch_vcpu_ioctl_set_guest_debug (struct kvm_vcpu *vcpu, +struct kvm_guest_debug *dbg) {return -ENOTSUPP ; }
arch/s390/kvm/kvm-s390.c +2 -2
@@ -401,8 +401,8 @@ int kvm_arch_vcpu_ioctl_translate(structreturn -EINVAL ;/* not implemented yet */ } -int kvm_arch_vcpu_ioctl_debug_guest (struct kvm_vcpu *vcpu, -struct kvm_debug_guest *dbg) +int kvm_arch_vcpu_ioctl_set_guest_debug (struct kvm_vcpu *vcpu, +struct kvm_guest_debug *dbg) {return -EINVAL ;/* not implemented yet */ }
include/asm-ia64/kvm.h +7 -0
@@ -208,4 +208,11 @@ struct kvm_sregs {struct kvm_fpu { }; +struct kvm_debug_exit_arch { +}; + +/* for KVM_SET_GUEST_DEBUG */ +struct kvm_guest_debug_arch { +}; +#endif
include/asm-powerpc/kvm.h +7 -0
@@ -52,4 +52,11 @@ struct kvm_fpu { __u64 fpr[32]; }; +struct kvm_debug_exit_arch { +}; + +/* for KVM_SET_GUEST_DEBUG */ +struct kvm_guest_debug_arch { +}; +#endif /* __LINUX_KVM_POWERPC_H */
include/asm-s390/kvm.h +7 -0
@@ -42,4 +42,11 @@ struct kvm_fpu { __u64 fprs[16]; }; +struct kvm_debug_exit_arch { +}; + +/* for KVM_SET_GUEST_DEBUG */ +struct kvm_guest_debug_arch { +}; +#endif
cover Rework guest debug interface
The existing guest debugging interface of kvm is limited in several ways:
- depends on hardware breakpoints, thus suffers from running out of this scarce resource.
- assumes that there are only 4 hardware breakpoints (even if some archs may once provide more)
- doesn't support watchpoint or additional arch-specific debugging features
This patch series reworks the interface, providing usable software-based breakpoint support, but also laying the ground for patches under development that will add full hardware debugging features.
Content:
Patch 1 - Replace KVM_DEBUG_GUEST with KVM_SET_GUEST_DEBUG interface,
implement kernel side support
Patch 2 - Tiny helper that allows pause and resume for a single vcpu Patch 3 - Userland changes that adopt KVM_SET_GUEST_DEBUG and switch to
software breakpoints
Depends on:
- "Fix monitor and gdbstub deadlocks v2" [1]
- "Proper vm_stop on debug events" [2]
It's late here and the series is still fresh, but everything seems to works nicely - even using gdb inside the guest while the host has active breakpoints on the guest as well.
Looking forward to feedback and review.
Jan
[1] http://permalink.gmane.org/gmane.comp.emulators.kvm.devel/17444
[2] http://permalink.gmane.org/gmane.comp.emulators.kvm.devel/17775
PATCH 2/3 qemu-kvm: Introduce single vcpu pause/resume
Small helpers that allow to pause and resume only a single vcpu thread.
--- qemu/qemu-kvm.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
qemu/qemu-kvm.c +22 -7
@@ -207,6 +207,17 @@ static int all_threads_paused(void)return 1 ; } +static void pause_vcpu_thread (int index) +{ +assert (cpu_single_env->cpu_index != index); + + vcpu_info[index].stop =1 ; +pthread_kill (vcpu_info[index].thread,SIG_IPI ); + +while (!vcpu_info[index].stopped) +qemu_cond_wait (&qemu_pause_cond); +} +static void pause_all_threads (void ) {int i;
@@ -221,17 +232,21 @@ static void pause_all_threads(void)qemu_cond_wait (&qemu_pause_cond); } +static void resume_vcpu_thread (int index) +{ +assert (!cpu_single_env); + + vcpu_info[index].stop =0 ; + vcpu_info[index].stopped =0 ; +pthread_kill (vcpu_info[index].thread,SIG_IPI ); +} +static void resume_all_threads (void ) {int i; -assert (!cpu_single_env); - -for (i =0 ; i < smp_cpus; ++i) { - vcpu_info[i].stop =0 ; - vcpu_info[i].stopped =0 ; -pthread_kill (vcpu_info[i].thread,SIG_IPI ); - } +for (i =0 ; i < smp_cpus; ++i) +resume_vcpu_thread (i); }static void kvm_vm_state_change_handler (void *context,int running)
PATCH 3/3 kvm-userspace: Switch to KVM_SET_GUEST_DEBUG
In reply to Jan KiszkaThis patch switches both libkvm as well as the qemu pieces over to the new guest debug interface. This means, instead of relying on hardware breakpoints, breakpoint traps are patched into the guest code at the required spots. Breakpoint management is done inside the qemu-kvm, transparent to gdbstub and also avoiding that the gdb frontend takes over. This allows for running debuggers inside the guest while guest debugging it active, because the host can cleanly tell apart host- and guest-originated breakpoint events.
Yet improvable are x86 corner cases when using single-step ("forgotten" debug flags on the guest's stack). And, of courese, the yet empty non-x86 helper functions have to be populated...
--- libkvm/kvm-common.h | 2 libkvm/libkvm-x86.c | 20 ++++++ libkvm/libkvm.c | 11 +-- libkvm/libkvm.h | 14 +++- qemu/exec.c | 15 ++-- qemu/qemu-kvm-ia64.c | 17 +++++ qemu/qemu-kvm-powerpc.c | 17 +++++ qemu/qemu-kvm-x86.c | 32 +++++++++ qemu/qemu-kvm.c | 154 +++++++++++++++++++++++++++++++++++++++++------- qemu/qemu-kvm.h | 27 +++++++- 10 files changed, 268 insertions(+), 41 deletions(-)
libkvm/kvm-common.h +2 -0
@@ -85,4 +85,6 @@ int handle_io_window(kvm_context_t kvm);int handle_debug (kvm_context_t kvm,int vcpu);int try_push_interrupts (kvm_context_t kvm); +int handle_debug (kvm_context_t kvm,int vcpu); +#endif
libkvm/libkvm-x86.c +20 -0
@@ -661,3 +661,23 @@ int kvm_disable_tpr_access_reporting(kvm }#endif + +int handle_debug (kvm_context_t kvm,int vcpu) +{ +#ifdef KVM_CAP_SET_GUEST_DEBUG +struct kvm_run *run = kvm->run[vcpu]; +unsigned long watchpoint =0 ; +int break_type; + +if (run->debug.arch.exception ==1 ) { +/* TODO: fully process run->debug.arch */ + break_type =KVM_GDB_BREAKPOINT_HW ; + }else + break_type =KVM_GDB_BREAKPOINT_SW ; + +return kvm->callbacks->debug (kvm->opaque, vcpu, break_type, + run->debug.pc, watchpoint); +#else +return -ENOSYS ; +#endif +}
libkvm/libkvm.c +4 -7
@@ -738,11 +738,6 @@ static int handle_io(kvm_context_t kvm,return 0 ; } -int handle_debug (kvm_context_t kvm,int vcpu) -{ -return kvm->callbacks->debug (kvm->opaque, vcpu); -} -int kvm_get_regs (kvm_context_t kvm,int vcpu,struct kvm_regs *regs) {return ioctl (kvm->vcpu_fd[vcpu],KVM_GET_REGS , regs);
@@ -945,10 +940,12 @@ int kvm_inject_irq(kvm_context_t kvm, inreturn ioctl (kvm->vcpu_fd[vcpu],KVM_INTERRUPT , &intr); } -int kvm_guest_debug (kvm_context_t kvm,int vcpu,struct kvm_debug_guest *dbg) +#ifdef KVM_CAP_SET_GUEST_DEBUG +int kvm_set_guest_debug (kvm_context_t kvm,int vcpu,struct kvm_guest_debug *dbg) { -return ioctl (kvm->vcpu_fd[vcpu],KVM_DEBUG_GUEST , dbg); +return ioctl (kvm->vcpu_fd[vcpu],KVM_SET_GUEST_DEBUG , dbg); } +#endif int kvm_set_signal_mask (kvm_context_t kvm,int vcpu,const sigset_t *sigset) {
qemu/exec.c +8 -7
@@ -1157,6 +1157,9 @@ int cpu_breakpoint_insert(CPUState *env,#if defined(TARGET_HAS_ICE )int i; +if (kvm_enabled ()) +return kvm_insert_breakpoint (env, pc, len, type); +for (i =0 ; i < env->nb_breakpoints; i++) {if (env->breakpoints[i] == pc)return 0 ;
@@ -1166,9 +1169,6 @@ int cpu_breakpoint_insert(CPUState *env,return -ENOBUFS ; env->breakpoints[env->nb_breakpoints++] = pc; -if (kvm_enabled ()) -kvm_update_debugger (env); -breakpoint_invalidate (env, pc);return 0 ;#else
@@ -1182,6 +1182,10 @@ int cpu_breakpoint_remove(CPUState *env, {#if defined(TARGET_HAS_ICE )int i; + +if (kvm_enabled ()) +return kvm_remove_breakpoint (env, pc, len, type); +for (i =0 ; i < env->nb_breakpoints; i++) {if (env->breakpoints[i] == pc) goto found;
@@ -1192,9 +1196,6 @@ int cpu_breakpoint_remove(CPUState *env,if (i < env->nb_breakpoints) env->breakpoints[i] = env->breakpoints[env->nb_breakpoints]; -if (kvm_enabled ()) -kvm_update_debugger (env); -breakpoint_invalidate (env, pc);return 0 ;#else
@@ -1214,7 +1215,7 @@ void cpu_single_step(CPUState *env, int tb_flush(env); }if (kvm_enabled ()) -kvm_update_debugger (env); +kvm_update_guest_debug (env,KVM_GDB_BREAKPOINT_NONE );#endif }
qemu/qemu-kvm.c +132 -22
179 lines not on this page · raw message
libkvm/libkvm.h +12 -2
@@ -25,6 +25,13 @@ int kvm_get_msrs(kvm_context_t, int vcpuint kvm_set_msrs (kvm_context_t ,int vcpu,struct kvm_msr_entry *msrs,int n);#endif +#define KVM_GDB_BREAKPOINT_NONE (-1) +#define KVM_GDB_BREAKPOINT_SW 0 +#define KVM_GDB_BREAKPOINT_HW 1 +#define KVM_GDB_WATCHPOINT_WRITE 2 +#define KVM_GDB_WATCHPOINT_READ 3 +#define KVM_GDB_WATCHPOINT_ACCESS 4 +/*! * \brief KVM callbacks structure *
@@ -51,7 +58,8 @@ struct kvm_callbacks {/// generic memory writes to unmapped memory (For MMIO devices) int (*mmio_write)(void *opaque,uint64_t addr,uint8_t *data,int len); -int (*debug)(void *opaque,int vcpu); +int (*debug)(void *opaque,int vcpu,int break_type,uint64_t pc, +uint64_t watchpoint);/*! * \brief Called when the VCPU issues an 'hlt' instruction. *
@@ -337,7 +345,9 @@ static inline int kvm_reset_mpstate(kvm_*/ int kvm_inject_irq (kvm_context_t kvm,int vcpu,unsigned irq); -int kvm_guest_debug (kvm_context_t ,int vcpu,struct kvm_debug_guest *dbg); +#ifdef KVM_CAP_SET_GUEST_DEBUG +int kvm_set_guest_debug (kvm_context_t ,int vcpu,struct kvm_guest_debug *dbg); +#endif #if defined(__i386__) || defined(__x86_64__)/*!
qemu/qemu-kvm.h +24 -3
@@ -12,8 +12,6 @@#include <signal.h> -#include <signal.h> -int kvm_main_loop (void );int kvm_qemu_init (void );int kvm_qemu_create_context (void );
@@ -25,7 +23,11 @@ void kvm_save_registers(CPUState *env);void kvm_load_mpstate (CPUState *env);void kvm_save_mpstate (CPUState *env);int kvm_cpu_exec (CPUState *env); -int kvm_update_debugger (CPUState *env); +int kvm_insert_breakpoint (CPUState *env,target_ulong pc, +target_ulong len,int type); +int kvm_remove_breakpoint (CPUState *env,target_ulong pc, +target_ulong len,int type); +int kvm_update_guest_debug (CPUState *env,int reinject_trap);int kvm_qemu_init_env (CPUState *env);int kvm_qemu_check_extension (int ext);void kvm_apic_init (CPUState *env);
@@ -61,6 +63,25 @@ int kvm_arch_try_push_interrupts(void *ovoid kvm_arch_update_regs_for_sipi (CPUState *env);void kvm_arch_cpu_reset (CPUState *env); +struct kvm_guest_debug ; + +struct kvm_sw_breakpoint { +target_ulong pc; +target_ulong saved_insn; +int usecount; +struct kvm_sw_breakpoint *prev; +struct kvm_sw_breakpoint *next; +}; + +extern struct kvm_sw_breakpoint *first_sw_breakpoint; + +int kvm_arch_insert_sw_breakpoint (CPUState *env, +struct kvm_sw_breakpoint *bp); +int kvm_arch_remove_sw_breakpoint (CPUState *env, +struct kvm_sw_breakpoint *bp); +void kvm_arch_update_guest_debug (CPUState *env,struct kvm_guest_debug *dbg, +int reinject_trap); +CPUState *qemu_kvm_cpu_env (int index);void qemu_kvm_aio_wait_start (void );
qemu/qemu-kvm-ia64.c +17 -0
@@ -65,3 +65,20 @@ void kvm_arch_update_regs_for_sipi(CPUStvoid kvm_arch_cpu_reset (CPUState *env) { } + +int kvm_arch_insert_sw_breakpoint (CPUState *env, +struct kvm_sw_breakpoint *bp) +{ +return -EINVAL ; +} + +int kvm_arch_remove_sw_breakpoint (CPUState *env, +struct kvm_sw_breakpoint *bp) +{ +return -EINVAL ; +} + +void kvm_arch_update_guest_debug (CPUState *env,struct kvm_guest_debug *dbg, +int reinject_type) +{ +}
qemu/qemu-kvm-powerpc.c +17 -0
@@ -217,3 +217,20 @@ int handle_powerpc_dcr_write(int vcpu, uvoid kvm_arch_cpu_reset (CPUState *env) { } + +int kvm_arch_insert_sw_breakpoint (CPUState *env, +struct kvm_sw_breakpoint *bp) +{ +return -EINVAL ; +} + +int kvm_arch_remove_sw_breakpoint (CPUState *env, +struct kvm_sw_breakpoint *bp) +{ +return -EINVAL ; +} + +void kvm_arch_update_guest_debug (CPUState *env,struct kvm_guest_debug *dbg, +int reinject_type) +{ +}
qemu/qemu-kvm-x86.c +32 -0
@@ -687,3 +687,35 @@ void kvm_arch_cpu_reset(CPUState *env) } } } + +int kvm_arch_insert_sw_breakpoint (CPUState *env, +struct kvm_sw_breakpoint *bp) +{ +uint8_t int3 =0xcc ; + +if (cpu_memory_rw_debug (env, bp->pc, (uint8_t *)&bp->saved_insn,1 ,0 ) || +cpu_memory_rw_debug (env, bp->pc, &int3,1 ,1 )) +return -EINVAL ; +return 0 ; +} + +int kvm_arch_remove_sw_breakpoint (CPUState *env, +struct kvm_sw_breakpoint *bp) +{ +if (cpu_memory_rw_debug (env, bp->pc, (uint8_t *)&bp->saved_insn,1 ,1 )) +return -EINVAL ; +return 0 ; +} + +void kvm_arch_update_guest_debug (CPUState *env,struct kvm_guest_debug *dbg, +int reinject_type) +{ +#ifdef KVM_CAP_SET_GUEST_DEBUG +if (first_sw_breakpoint) + dbg->control |=KVM_GUESTDBG_ENABLE |KVM_GUESTDBG_USE_SW_BP ; +if (reinject_type ==KVM_GDB_BREAKPOINT_HW ) + dbg->control |=KVM_GUESTDBG_INJECT_DB ; +else if (reinject_type ==KVM_GDB_BREAKPOINT_SW ) + dbg->control |=KVM_GUESTDBG_INJECT_BP ; +#endif +}
Re: [PATCH 2/3] qemu-kvm: Introduce single vcpu pause/resume
In reply to Jan KiszkaQuoted 1 line · Jan Kiszka
Small helpers that allow to pause and resume only a single vcpu thread.
Updated version with corrected assertions:
------------
Small helpers that allow to pause and resume only a single vcpu thread.
--- qemu/qemu-kvm.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
qemu/qemu-kvm.c +22 -7
@@ -207,6 +207,17 @@ static int all_threads_paused(void)return 1 ; } +static void pause_vcpu_thread (int index) +{ +assert (!cpu_single_env || cpu_single_env->cpu_index != index); + + vcpu_info[index].stop =1 ; +pthread_kill (vcpu_info[index].thread,SIG_IPI ); + +while (!vcpu_info[index].stopped) +qemu_cond_wait (&qemu_pause_cond); +} +static void pause_all_threads (void ) {int i;
@@ -221,17 +232,21 @@ static void pause_all_threads(void)qemu_cond_wait (&qemu_pause_cond); } +static void resume_vcpu_thread (int index) +{ +assert (!cpu_single_env || cpu_single_env->cpu_index != index); + + vcpu_info[index].stop =0 ; + vcpu_info[index].stopped =0 ; +pthread_kill (vcpu_info[index].thread,SIG_IPI ); +} +static void resume_all_threads (void ) {int i; -assert (!cpu_single_env); - -for (i =0 ; i < smp_cpus; ++i) { - vcpu_info[i].stop =0 ; - vcpu_info[i].stopped =0 ; -pthread_kill (vcpu_info[i].thread,SIG_IPI ); - } +for (i =0 ; i < smp_cpus; ++i) +resume_vcpu_thread (i); }static void kvm_vm_state_change_handler (void *context,int running)