qemu-kvm: Sort out upstream merge regressions
cover qemu-kvm: Sort out upstream merge regressions
Recent merge with upstream left some corners of qemu-kvm broken behind. This series addresses those I've spotted based on my merge experiments in the past months.
Jan Kiszka (4):
qemu-kvm: Map run_on_cpu on qemu-kvm variant
qemu-kvm: Synchronize states before reset
qemu-kvm: Process async MCE events in main loop
qemu-kvm: Unbreak guest debugging
kvm.h | 4 ---- qemu-kvm-x86.c | 41 ++++++++++++++++++++++++++++++++++++++++- qemu-kvm.c | 47 ++++++++++++++--------------------------------- target-i386/helper.c | 3 +++ target-i386/kvm.c | 2 +- 5 files changed, 58 insertions(+), 39 deletions(-)
PATCH 1/4 qemu-kvm: Map run_on_cpu on qemu-kvm variant
--- target-i386/helper.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
target-i386/helper.c +3 -0
@@ -33,6 +33,9 @@#endif #include "qemu-kvm.h" +#ifndef OBSOLETE_KVM_IMPL +#define run_on_cpu on_vcpu +#endif /* !OBSOLETE_KVM_IMPL */ //#define DEBUG_MMU
Signature · 1 line
1.7.1
PATCH 2/4 qemu-kvm: Synchronize states before reset
In reply to Jan KiszkaThis aligns qemu-kvm with upstream commit a7ada1510c.
--- qemu-kvm.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
qemu-kvm.c +2 -0
@@ -18,6 +18,7 @@#include "compatfd.h" #include "gdbstub.h" #include "monitor.h" +#include "cpus.h" #include "qemu-kvm.h" #include "libkvm.h"
@@ -1396,6 +1397,7 @@ static void qemu_kvm_system_reset(void) {pause_all_threads (); +cpu_synchronize_all_states ();qemu_system_reset ();resume_all_threads ();
Signature · 1 line
1.7.1
PATCH 3/4 qemu-kvm: Process async MCE events in main loop
In reply to Jan KiszkaThis aligns qemu-kvm with upstream commit ab443475c9. Namely, we were missing a call to an equivalent of kvm_arch_process_async_events from the main loop. This adds a stripped down version of upstream's process_async_events until we switch over.
--- kvm.h | 2 -- qemu-kvm-x86.c | 27 +++++++++++++++++++++++++++ qemu-kvm.c | 9 ++++++--- 3 files changed, 33 insertions(+), 5 deletions(-)
kvm.h +0 -2
@@ -110,9 +110,7 @@ void kvm_arch_post_run(CPUState *env, struct kvm_run *run);int kvm_arch_handle_exit (CPUState *env,struct kvm_run *run); -#ifdef OBSOLETE_KVM_IMPL int kvm_arch_process_async_events (CPUState *env); -#endif int kvm_arch_get_registers (CPUState *env);
qemu-kvm-x86.c +27 -0
@@ -811,3 +811,30 @@ void kvm_arch_process_irqchip_events(CPUState *env)do_cpu_sipi (env); } } + +int kvm_arch_process_async_events (CPUState *env) +{ +if (env->interrupt_request &CPU_INTERRUPT_MCE ) { +/* We must not raise CPU_INTERRUPT_MCE if it's not supported. */ +assert (env->mcg_cap); + + env->interrupt_request &= ~CPU_INTERRUPT_MCE ; + +kvm_cpu_synchronize_state (env); + +if (env->exception_injected ==EXCP08_DBLE ) { +/* this means triple fault */ +qemu_system_reset_request (); + env->exit_request =1 ; +return 0 ; + } + env->exception_injected =EXCP12_MCHK ; + env->has_error_code =0 ; + + env->halted =0 ; +if (kvm_irqchip_in_kernel () && env->mp_state ==KVM_MP_STATE_HALTED ) { + env->mp_state =KVM_MP_STATE_RUNNABLE ; + } + } +return 0 ; +}
qemu-kvm.c +6 -3
@@ -1414,9 +1414,12 @@ static int kvm_main_loop_cpu(CPUState *env) {while (1 ) {int run_cpu = !kvm_cpu_is_stopped (env); -if (run_cpu && !kvm_irqchip_in_kernel ()) { -process_irqchip_events (env); - run_cpu = !env->halted; +if (run_cpu) { +kvm_arch_process_async_events (env); +if (!kvm_irqchip_in_kernel ()) { +process_irqchip_events (env); + run_cpu = !env->halted; + } }if (run_cpu) {kvm_cpu_exec (env);
Signature · 1 line
1.7.1
PATCH 4/4 qemu-kvm: Unbreak guest debugging
In reply to Jan KiszkaAlign handling of guest debug exits to upstream by moving it completely to the arch section. This patch accounts for changed return codes in the exit handling code.
--- kvm.h | 2 -- qemu-kvm-x86.c | 14 +++++++++++++- qemu-kvm.c | 36 ++++++------------------------------ target-i386/kvm.c | 2 +- 4 files changed, 20 insertions(+), 34 deletions(-)
kvm.h +0 -2
@@ -147,8 +147,6 @@ QTAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint);struct kvm_sw_breakpoint *kvm_find_sw_breakpoint (CPUState *env,target_ulong pc); -int kvm_handle_debug (struct kvm_debug_exit_arch *arch_info); -int kvm_sw_breakpoints_active (CPUState *env); int kvm_arch_insert_sw_breakpoint(CPUState *current_env,
qemu-kvm-x86.c +13 -1
@@ -183,6 +183,8 @@ int kvm_enable_vapic(CPUState *env, uint64_t vapic)#endif +extern CPUState *kvm_debug_cpu_requested; +int kvm_arch_run (CPUState *env) {int r =0 ;
@@ -198,8 +200,18 @@ int kvm_arch_run(CPUState *env) r =kvm_handle_tpr_access (env);break ;#endif +#ifdef KVM_CAP_SET_GUEST_DEBUG +case KVM_EXIT_DEBUG : +DPRINTF ("kvm_exit_debug\n" ); + r =kvm_handle_debug (&run->debug.arch); +if (r ==EXCP_DEBUG ) { + kvm_debug_cpu_requested = env; + env->stopped =1 ; + } +break ; +#endif /* KVM_CAP_SET_GUEST_DEBUG */ default : - r =1 ; + r =-1 ;break ; }
qemu-kvm.c +6 -30
@@ -74,7 +74,7 @@ static int qemu_system_ready;pthread_t io_thread;static int io_thread_sigfd =-1 ; -static CPUState *kvm_debug_cpu_requested; +CPUState *kvm_debug_cpu_requested;#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT /* The list of ioperm_data */
@@ -86,20 +86,6 @@ static QLIST_HEAD(, ioperm_data) ioperm_head;int kvm_abi =EXPECTED_KVM_API_VERSION ;int kvm_page_size; -#ifdef KVM_CAP_SET_GUEST_DEBUG -static int kvm_debug (CPUState *env, -struct kvm_debug_exit_arch *arch_info) -{ -int handle =kvm_handle_debug (arch_info); - -if (handle) { - kvm_debug_cpu_requested = env; - env->stopped =1 ; - } -return handle; -} -#endif -static int handle_unhandled (uint64_t reason) {fprintf (stderr,"kvm: unhandled exit %" PRIx64"\n" , reason);
@@ -453,17 +439,6 @@ int kvm_set_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip)#endif -static int handle_debug (CPUState *env) -{ -#ifdef KVM_CAP_SET_GUEST_DEBUG -struct kvm_run *run = env->kvm_run; - -return kvm_debug (env, &run->debug.arch); -#else -return 0 ; -#endif -} -int kvm_get_regs (CPUState *env,struct kvm_regs *regs) {return kvm_vcpu_ioctl (env,KVM_GET_REGS , regs);
@@ -623,9 +598,6 @@ int kvm_run(CPUState *env) run->io.count); r =0 ;break ; -case KVM_EXIT_DEBUG : - r =handle_debug (env); -break ;case KVM_EXIT_MMIO : r =handle_mmio (env);break ;
@@ -649,11 +621,15 @@ int kvm_run(CPUState *env) r =kvm_handle_internal_error (env, run);break ;default : -if (kvm_arch_run (env)) { + r =kvm_arch_run (env); +if (r <0 ) {fprintf (stderr,"unhandled vm exit: 0x%x\n" , run->exit_reason);kvm_show_regs (env);abort (); } +if (r >0 ) { +return r; + }break ; } }
target-i386/kvm.c +1 -1
@@ -1768,7 +1768,7 @@ void kvm_arch_remove_all_hw_breakpoints(void)static CPUWatchpoint hw_watchpoint; -int kvm_handle_debug (struct kvm_debug_exit_arch *arch_info) +static int kvm_handle_debug (struct kvm_debug_exit_arch *arch_info) {int ret =0 ;int n;
Signature · 1 line
1.7.1
Avi Kivity
AppliedQuoted 3 lines · Jan Kiszka
Recent merge with upstream left some corners of qemu-kvm broken behind. This series addresses those I've spotted based on my merge experiments in the past months.
Applied all, thanks.
Signature · 1 line
error compiling committee.c: too many arguments to function