From 1ab3c6c07382c4249854f811cd6182a0a88e25fb Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Tue, 15 Mar 2011 12:26:12 +0100 Subject: Implement qemu_kvm_eat_signals only for CONFIG_LINUX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qemu_kvm_eat_signals requires POSIX support with realtime extensions for sigtimedwait. Not all our target platforms provide this. Moreover, undefined sigbus_reraise was referenced on non-Linux as well. Signed-off-by: Jan Kiszka CC: Andreas Färber Signed-off-by: Marcelo Tosatti --- cpus.c | 94 +++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) (limited to 'cpus.c') diff --git a/cpus.c b/cpus.c index 077729c507..26e5bbaeff 100644 --- a/cpus.c +++ b/cpus.c @@ -245,11 +245,58 @@ static void qemu_init_sigbus(void) prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0, 0); } +static void qemu_kvm_eat_signals(CPUState *env) +{ + struct timespec ts = { 0, 0 }; + siginfo_t siginfo; + sigset_t waitset; + sigset_t chkset; + int r; + + sigemptyset(&waitset); + sigaddset(&waitset, SIG_IPI); + sigaddset(&waitset, SIGBUS); + + do { + r = sigtimedwait(&waitset, &siginfo, &ts); + if (r == -1 && !(errno == EAGAIN || errno == EINTR)) { + perror("sigtimedwait"); + exit(1); + } + + switch (r) { + case SIGBUS: + if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) { + sigbus_reraise(); + } + break; + default: + break; + } + + r = sigpending(&chkset); + if (r == -1) { + perror("sigpending"); + exit(1); + } + } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS)); + +#ifndef CONFIG_IOTHREAD + if (sigismember(&chkset, SIGIO) || sigismember(&chkset, SIGALRM)) { + qemu_notify_event(); + } +#endif +} + #else /* !CONFIG_LINUX */ static void qemu_init_sigbus(void) { } + +static void qemu_kvm_eat_signals(CPUState *env) +{ +} #endif /* !CONFIG_LINUX */ #ifndef _WIN32 @@ -455,49 +502,6 @@ static void qemu_tcg_init_cpu_signals(void) #endif } -static void qemu_kvm_eat_signals(CPUState *env) -{ - struct timespec ts = { 0, 0 }; - siginfo_t siginfo; - sigset_t waitset; - sigset_t chkset; - int r; - - sigemptyset(&waitset); - sigaddset(&waitset, SIG_IPI); - sigaddset(&waitset, SIGBUS); - - do { - r = sigtimedwait(&waitset, &siginfo, &ts); - if (r == -1 && !(errno == EAGAIN || errno == EINTR)) { - perror("sigtimedwait"); - exit(1); - } - - switch (r) { - case SIGBUS: - if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) { - sigbus_reraise(); - } - break; - default: - break; - } - - r = sigpending(&chkset); - if (r == -1) { - perror("sigpending"); - exit(1); - } - } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS)); - -#ifndef CONFIG_IOTHREAD - if (sigismember(&chkset, SIGIO) || sigismember(&chkset, SIGALRM)) { - qemu_notify_event(); - } -#endif -} - #else /* _WIN32 */ HANDLE qemu_event_handle; @@ -526,10 +530,6 @@ static void qemu_event_increment(void) } } -static void qemu_kvm_eat_signals(CPUState *env) -{ -} - static int qemu_signal_init(void) { return 0; -- cgit v1.2.1 From 1009d2edea4acd5b683ab1572ad7f4d4583e1860 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Tue, 15 Mar 2011 12:26:13 +0100 Subject: x86: Unbreak TCG support for hardware breakpoints Commit 83f338f73e broke x86 hardware breakpoint emulation by moving the debug exception handling out of cpu_exec. Fix this by moving all TCG related bits back, only leaving the generic guest debugging parts in cpus.c. Signed-off-by: Jan Kiszka CC: TeLeMan Signed-off-by: Marcelo Tosatti --- cpus.c | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'cpus.c') diff --git a/cpus.c b/cpus.c index 26e5bbaeff..975a6ce949 100644 --- a/cpus.c +++ b/cpus.c @@ -166,29 +166,8 @@ static bool all_cpu_threads_idle(void) return true; } -static CPUDebugExcpHandler *debug_excp_handler; - -CPUDebugExcpHandler *cpu_set_debug_excp_handler(CPUDebugExcpHandler *handler) -{ - CPUDebugExcpHandler *old_handler = debug_excp_handler; - - debug_excp_handler = handler; - return old_handler; -} - -static void cpu_handle_debug_exception(CPUState *env) +static void cpu_handle_guest_debug(CPUState *env) { - CPUWatchpoint *wp; - - if (!env->watchpoint_hit) { - QTAILQ_FOREACH(wp, &env->watchpoints, entry) { - wp->flags &= ~BP_WATCHPOINT_HIT; - } - } - if (debug_excp_handler) { - debug_excp_handler(env); - } - gdb_set_stop_cpu(env); qemu_system_debug_request(); #ifdef CONFIG_IOTHREAD @@ -818,7 +797,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) if (cpu_can_run(env)) { r = kvm_cpu_exec(env); if (r == EXCP_DEBUG) { - cpu_handle_debug_exception(env); + cpu_handle_guest_debug(env); } } qemu_kvm_wait_io_event(env); @@ -1110,7 +1089,7 @@ bool cpu_exec_all(void) r = tcg_cpu_exec(env); } if (r == EXCP_DEBUG) { - cpu_handle_debug_exception(env); + cpu_handle_guest_debug(env); break; } } else if (env->stop || env->stopped) { -- cgit v1.2.1 From f2c1cc81c8229e8c1e26aae517d32aa534936a0c Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Tue, 15 Mar 2011 12:26:18 +0100 Subject: kvm: Add in-kernel irqchip awareness to cpu_thread_is_idle With in-kernel irqchip support enabled, the vcpu threads sleep in kernel space while halted. Account for this difference in cpu_thread_is_idle. Signed-off-by: Jan Kiszka Signed-off-by: Marcelo Tosatti --- cpus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cpus.c') diff --git a/cpus.c b/cpus.c index 975a6ce949..d310b7e3bd 100644 --- a/cpus.c +++ b/cpus.c @@ -148,7 +148,8 @@ static bool cpu_thread_is_idle(CPUState *env) if (env->stopped || !vm_running) { return true; } - if (!env->halted || qemu_cpu_has_work(env)) { + if (!env->halted || qemu_cpu_has_work(env) || + (kvm_enabled() && kvm_irqchip_in_kernel())) { return false; } return true; -- cgit v1.2.1 From dc7a09cfe47679d89289101cc9eb387c45e48fe7 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Tue, 15 Mar 2011 12:26:31 +0100 Subject: Expose thread_id in info cpus Based on patch by Glauber Costa: To allow management applications like libvirt to apply CPU affinities to the VCPU threads, expose their ID via info cpus. This patch provides the pre-existing and used interface from qemu-kvm. Signed-off-by: Jan Kiszka Signed-off-by: Marcelo Tosatti --- cpus.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cpus.c') diff --git a/cpus.c b/cpus.c index d310b7e3bd..28c2da2aec 100644 --- a/cpus.c +++ b/cpus.c @@ -776,6 +776,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) qemu_mutex_lock(&qemu_global_mutex); qemu_thread_get_self(env->thread); + env->thread_id = qemu_get_thread_id(); r = kvm_init_vcpu(env); if (r < 0) { @@ -817,6 +818,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) /* signal CPU creation */ qemu_mutex_lock(&qemu_global_mutex); for (env = first_cpu; env != NULL; env = env->next_cpu) { + env->thread_id = qemu_get_thread_id(); env->created = 1; } qemu_cond_signal(&qemu_cpu_cond); -- cgit v1.2.1