* [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III
@ 2011-05-20 17:12 Jan Kiszka
2011-05-20 17:12 ` [PATCH 01/10] qemu-kvm: Remove obsolete inclusions Jan Kiszka
` (11 more replies)
0 siblings, 12 replies; 16+ messages in thread
From: Jan Kiszka @ 2011-05-20 17:12 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, Alexander Graf
This is a rather short round as the next and final one cannot be split
up very well.
We start with three code cleanup patches, then work towards using
upstream kvm_cpu_exec, and finally rework the core's PIO access
management used for device assignment.
Please review/merge.
CC: Alexander Graf <agraf@suse.de>
Jan Kiszka (10):
qemu-kvm: Remove obsolete inclusions
qemu-kvm: Remove remaining s390 fragments
qemu-kvm: ppc: Drop diff to upstream
qemu-kvm: Refactor vm exit in kvm_run
qemu-kvm: Use thread_kicked instead of KVMCPUState::signalled
qemu-kvm: Activate iothread version of qemu_cpu_kick_self
qemu-kvm: Refactor exit_request processing in kvm_run
qemu-kvm: Use upstream kvm_arch_process_async_events
qemu-kvm: Use upstream kvm_cpu_exec
qemu-kvm: Rework ioport access management
cpu-defs.h | 1 -
cpu-exec.c | 2 -
cpus.c | 6 +
exec.c | 1 -
gdbstub.c | 1 -
hw/acpi.c | 3 -
hw/device-assignment.c | 20 +--
hw/ppc440.c | 1 -
hw/ppc440_bamboo.c | 1 -
hw/ppce500_mpc8544ds.c | 1 -
hw/virtio-balloon.c | 1 -
kvm-all.c | 3 -
qemu-kvm-x86.c | 158 +--------------------
qemu-kvm.c | 359 ++++++++++++-----------------------------------
qemu-kvm.h | 77 +----------
target-i386/helper.c | 1 -
target-i386/kvm.c | 4 -
target-ppc/cpu.h | 10 +--
target-ppc/fake-exec.c | 104 --------------
target-ppc/helper.c | 1 -
target-ppc/machine.c | 1 -
21 files changed, 121 insertions(+), 635 deletions(-)
delete mode 100644 target-ppc/fake-exec.c
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 01/10] qemu-kvm: Remove obsolete inclusions
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
@ 2011-05-20 17:12 ` Jan Kiszka
2011-05-20 17:12 ` [PATCH 02/10] qemu-kvm: Remove remaining s390 fragments Jan Kiszka
` (10 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Jan Kiszka @ 2011-05-20 17:12 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm
Reduces the diff to upstream.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
cpu-exec.c | 2 --
exec.c | 1 -
gdbstub.c | 1 -
hw/acpi.c | 3 ---
hw/ppc440.c | 1 -
hw/ppc440_bamboo.c | 1 -
hw/ppce500_mpc8544ds.c | 1 -
hw/virtio-balloon.c | 1 -
target-i386/helper.c | 1 -
9 files changed, 0 insertions(+), 12 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index 583d7d6..6ec519d 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -41,8 +41,6 @@
#endif
#endif
-#include "qemu-kvm.h"
-
#if defined(__sparc__) && !defined(CONFIG_SOLARIS)
// Work around ugly bugs in glibc that mangle global register contents
#undef env
diff --git a/exec.c b/exec.c
index 1dc970f..9a493d0 100644
--- a/exec.c
+++ b/exec.c
@@ -32,7 +32,6 @@
#if !defined(TARGET_IA64)
#include "tcg.h"
#endif
-#include "qemu-kvm.h"
#include "hw/hw.h"
#include "hw/qdev.h"
diff --git a/gdbstub.c b/gdbstub.c
index df93691..0838948 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -34,7 +34,6 @@
#include "sysemu.h"
#include "gdbstub.h"
#endif
-#include "qemu-kvm.h"
#define MAX_PACKET_LENGTH 4096
diff --git a/hw/acpi.c b/hw/acpi.c
index 3d78d5f..ad40fb4 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -19,9 +19,6 @@
#include "hw.h"
#include "pc.h"
#include "acpi.h"
-#include "kvm.h"
-#include "qemu-kvm.h"
-#include "string.h"
struct acpi_table_header
{
diff --git a/hw/ppc440.c b/hw/ppc440.c
index 7d651e9..1ed001a 100644
--- a/hw/ppc440.c
+++ b/hw/ppc440.c
@@ -20,7 +20,6 @@
#include "ppc405.h"
#include "sysemu.h"
#include "kvm.h"
-#include "qemu-kvm.h"
#define PPC440EP_PCI_CONFIG 0xeec00000
#define PPC440EP_PCI_INTACK 0xeed00000
diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index 6627cd8..20b8629 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -23,7 +23,6 @@
#include "device_tree.h"
#include "loader.h"
#include "elf.h"
-#include "qemu-kvm.h"
#define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
index 13153dd..17b0165 100644
--- a/hw/ppce500_mpc8544ds.c
+++ b/hw/ppce500_mpc8544ds.c
@@ -32,7 +32,6 @@
#include "loader.h"
#include "elf.h"
#include "sysbus.h"
-#include "qemu-kvm.h"
#define BINARY_DEVICE_TREE_FILE "mpc8544ds.dtb"
#define UIMAGE_LOAD_BASE 0
diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 447b337..70a8710 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -20,7 +20,6 @@
#include "balloon.h"
#include "virtio-balloon.h"
#include "kvm.h"
-#include "qemu-kvm.h"
#include "qlist.h"
#include "qint.h"
#include "qstring.h"
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 4ab5241..2315c84 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -32,7 +32,6 @@
#include "monitor.h"
#endif
-#include "qemu-kvm.h"
#ifndef OBSOLETE_KVM_IMPL
#define run_on_cpu on_vcpu
#endif /* !OBSOLETE_KVM_IMPL */
--
1.7.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 02/10] qemu-kvm: Remove remaining s390 fragments
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
2011-05-20 17:12 ` [PATCH 01/10] qemu-kvm: Remove obsolete inclusions Jan Kiszka
@ 2011-05-20 17:12 ` Jan Kiszka
2011-05-20 17:12 ` [PATCH 03/10] qemu-kvm: ppc: Drop diff to upstream Jan Kiszka
` (9 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Jan Kiszka @ 2011-05-20 17:12 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm
qemu-kvm is not used with s390, only upstream works theses days. So
remove any conditionals related to this arch.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
qemu-kvm.c | 12 ------------
qemu-kvm.h | 10 +---------
2 files changed, 1 insertions(+), 21 deletions(-)
diff --git a/qemu-kvm.c b/qemu-kvm.c
index c9ff5fe..19ede6e 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -307,11 +307,9 @@ static int kvm_run(CPUState *env)
env->kvm_vcpu_dirty = 0;
}
push_nmi();
-#if !defined(__s390__)
if (!kvm_state->irqchip_in_kernel) {
run->request_interrupt_window = kvm_arch_try_push_interrupts(env);
}
-#endif
r = pre_kvm_run(env);
if (r) {
@@ -334,11 +332,9 @@ static int kvm_run(CPUState *env)
kvm_flush_coalesced_mmio_buffer();
-#if !defined(__s390__)
if (r == -1) {
return 1;
}
-#endif
if (1) {
switch (run->exit_reason) {
case KVM_EXIT_UNKNOWN:
@@ -372,14 +368,6 @@ static int kvm_run(CPUState *env)
case KVM_EXIT_SHUTDOWN:
r = handle_shutdown(env);
break;
-#if defined(__s390__)
- case KVM_EXIT_S390_SIEIC:
- r = kvm_s390_handle_intercept(kvm, env, run);
- break;
- case KVM_EXIT_S390_RESET:
- r = kvm_s390_handle_reset(kvm, env, run);
- break;
-#endif
case KVM_EXIT_INTERNAL_ERROR:
r = kvm_handle_internal_error(env, run);
break;
diff --git a/qemu-kvm.h b/qemu-kvm.h
index b552e1e..8ff773a 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -15,10 +15,6 @@
#ifdef CONFIG_KVM
-#if defined(__s390__)
-#include <asm/ptrace.h>
-#endif
-
#include <stdint.h>
#ifndef __user
@@ -31,11 +27,7 @@
/* FIXME: share this number with kvm */
/* FIXME: or dynamically alloc/realloc regions */
-#ifdef __s390__
-#define KVM_MAX_NUM_MEM_REGIONS 1u
-#define MAX_VCPUS 64
-#define LIBKVM_S390_ORIGIN (0UL)
-#elif defined(__ia64__)
+#if defined(__ia64__)
#define KVM_MAX_NUM_MEM_REGIONS 32u
#define MAX_VCPUS 256
#else
--
1.7.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 03/10] qemu-kvm: ppc: Drop diff to upstream
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
2011-05-20 17:12 ` [PATCH 01/10] qemu-kvm: Remove obsolete inclusions Jan Kiszka
2011-05-20 17:12 ` [PATCH 02/10] qemu-kvm: Remove remaining s390 fragments Jan Kiszka
@ 2011-05-20 17:12 ` Jan Kiszka
2011-05-20 17:12 ` [PATCH 04/10] qemu-kvm: Refactor vm exit in kvm_run Jan Kiszka
` (8 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Jan Kiszka @ 2011-05-20 17:12 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, Alexander Graf
qemu-kvm is x86-only today. Remove the remaining delta of the former ppc
support to avoid needless conflicts when sync'ing with upstream.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
CC: Alexander Graf <agraf@suse.de>
---
target-ppc/cpu.h | 10 +----
target-ppc/fake-exec.c | 104 ------------------------------------------------
target-ppc/helper.c | 1 -
target-ppc/machine.c | 1 -
4 files changed, 1 insertions(+), 115 deletions(-)
delete mode 100644 target-ppc/fake-exec.c
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index 133df95..7a6a7df 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -52,10 +52,9 @@
#if defined(TARGET_PPCEMB)
/* Specific definitions for PowerPC embedded */
/* BookE have 36 bits physical address space */
-#if defined(CONFIG_USER_ONLY) || defined(USE_KVM)
+#if defined(CONFIG_USER_ONLY)
/* It looks like a lot of Linux programs assume page size
* is 4kB long. This is evil, but we have to deal with it...
- * Also kvm for embedded powerpc needs (atm) 4kB aligned pages
*/
#define TARGET_PAGE_BITS 12
#else /* defined(CONFIG_USER_ONLY) */
@@ -1927,13 +1926,6 @@ static inline void cpu_set_tls(CPUState *env, target_ulong newtls)
#endif
}
-/* hidden flags (hflags) - used internally by qemu to represent additional
- * cpu states.
- */
-#define HF_HALTED_SHIFT 1
-
-#define HF_HALTED_MASK 1<<HF_HALTED_SHIFT
-
#if !defined(CONFIG_USER_ONLY)
static inline int booke206_tlbe_id(CPUState *env, ppcemb_tlb_t *tlbe)
{
diff --git a/target-ppc/fake-exec.c b/target-ppc/fake-exec.c
deleted file mode 100644
index 259e06d..0000000
--- a/target-ppc/fake-exec.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * fake-exec.c
- *
- * This is a file for stub functions so that compilation is possible
- * when TCG CPU emulation is disabled during compilation.
- *
- * Copyright 2007 IBM Corporation.
- * Added by & Authors:
- * Jerone Young <jyoung5@us.ibm.com>
- * This work is licensed under the GNU GPL licence version 2 or later.
- *
- */
-
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <inttypes.h>
-
-#include "cpu.h"
-#include "exec-all.h"
-
-
-struct ppc_def_t {
- const unsigned char *name;
- uint32_t pvr;
- uint32_t svr;
- uint64_t insns_flags;
- uint64_t msr_mask;
- powerpc_mmu_t mmu_model;
- powerpc_excp_t excp_model;
- powerpc_input_t bus_model;
- uint32_t flags;
- int bfd_mach;
- void (*init_proc)(CPUPPCState *env);
- int (*check_pow)(CPUPPCState *env);
-};
-
-int code_copy_enabled = 0;
-
-void cpu_dump_state (CPUState *env, FILE *f,
- int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
- int flags)
-{
-}
-
-void ppc_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
-{
-}
-
-void cpu_dump_statistics (CPUState *env, FILE*f,
- int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
- int flags)
-{
-}
-
-unsigned long code_gen_max_block_size(void)
-{
- return 32;
-}
-
-void cpu_gen_init(void)
-{
-}
-
-int cpu_restore_state(TranslationBlock *tb,
- CPUState *env, unsigned long searched_pc,
- void *puc)
-
-{
- return 0;
-}
-
-int cpu_ppc_gen_code(CPUState *env, TranslationBlock *tb, int *gen_code_size_ptr)
-{
- return 0;
-}
-
-void init_proc_ppc440ep_kvm(CPUPPCState *env)
-{
- ppc40x_irq_init(env);
-}
-
-static ppc_def_t ppc440ep_kvm = {
- .name = "440EP KVM",
- .mmu_model = POWERPC_MMU_SOFT_4xx, /*XXX needed for GDB stub */
- .init_proc = init_proc_ppc440ep_kvm,
-};
-
-const ppc_def_t *cpu_ppc_find_by_name (const unsigned char *name)
-{
- return &ppc440ep_kvm;
-}
-
-int cpu_ppc_register_internal (CPUPPCState *env, const ppc_def_t *def)
-{
- env->mmu_model = def->mmu_model;
- (*def->init_proc)(env);
- return 0;
-}
-
-void flush_icache_range(unsigned long start, unsigned long stop)
-{
-}
diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index 95f81ec..4238be6 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -28,7 +28,6 @@
#include "helper_regs.h"
#include "qemu-common.h"
#include "kvm.h"
-#include "qemu-kvm.h"
//#define DEBUG_MMU
//#define DEBUG_BATS
diff --git a/target-ppc/machine.c b/target-ppc/machine.c
index 4b98113..0c1986e 100644
--- a/target-ppc/machine.c
+++ b/target-ppc/machine.c
@@ -1,7 +1,6 @@
#include "hw/hw.h"
#include "hw/boards.h"
#include "kvm.h"
-#include "qemu-kvm.h"
void cpu_save(QEMUFile *f, void *opaque)
{
--
1.7.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 04/10] qemu-kvm: Refactor vm exit in kvm_run
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
` (2 preceding siblings ...)
2011-05-20 17:12 ` [PATCH 03/10] qemu-kvm: ppc: Drop diff to upstream Jan Kiszka
@ 2011-05-20 17:12 ` Jan Kiszka
2011-05-20 17:12 ` [PATCH 05/10] qemu-kvm: Use thread_kicked instead of KVMCPUState::signalled Jan Kiszka
` (7 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Jan Kiszka @ 2011-05-20 17:12 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm
Use kvm_vcpu_ioctl to simplify the vm exit code a bit. This increases
the similarity to upstream.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
qemu-kvm.c | 17 +++++++----------
1 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/qemu-kvm.c b/qemu-kvm.c
index 19ede6e..e5b8e42 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -299,7 +299,6 @@ static int kvm_run(CPUState *env)
{
int r;
struct kvm_run *run = env->kvm_run;
- int fd = env->kvm_fd;
again:
if (env->kvm_vcpu_dirty) {
@@ -319,22 +318,20 @@ static int kvm_run(CPUState *env)
env->exit_request = 0;
pthread_kill(env->thread->thread, SIG_IPI);
}
- r = ioctl(fd, KVM_RUN, 0);
-
- if (r == -1 && errno != EINTR && errno != EAGAIN) {
- r = -errno;
- post_kvm_run(env);
- fprintf(stderr, "kvm_run: %s\n", strerror(-r));
- return r;
- }
+ r = kvm_vcpu_ioctl(env, KVM_RUN, 0);
post_kvm_run(env);
kvm_flush_coalesced_mmio_buffer();
- if (r == -1) {
+ if (r == -EINTR || r == -EAGAIN) {
return 1;
}
+ if (r < 0) {
+ fprintf(stderr, "kvm_run: %s\n", strerror(-r));
+ return r;
+ }
+
if (1) {
switch (run->exit_reason) {
case KVM_EXIT_UNKNOWN:
--
1.7.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 05/10] qemu-kvm: Use thread_kicked instead of KVMCPUState::signalled
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
` (3 preceding siblings ...)
2011-05-20 17:12 ` [PATCH 04/10] qemu-kvm: Refactor vm exit in kvm_run Jan Kiszka
@ 2011-05-20 17:12 ` Jan Kiszka
2011-05-20 17:12 ` [PATCH 06/10] qemu-kvm: Activate iothread version of qemu_cpu_kick_self Jan Kiszka
` (6 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Jan Kiszka @ 2011-05-20 17:12 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm
Another step forward to use signaling services from cpus.c.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
cpu-defs.h | 1 -
qemu-kvm.c | 6 +++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/cpu-defs.h b/cpu-defs.h
index 624fd1a..5a0f11d 100644
--- a/cpu-defs.h
+++ b/cpu-defs.h
@@ -158,7 +158,6 @@ typedef struct CPUWatchpoint {
struct qemu_work_item;
struct KVMCPUState {
- int signalled;
struct qemu_work_item *queued_work_first, *queued_work_last;
};
diff --git a/qemu-kvm.c b/qemu-kvm.c
index e5b8e42..843c973 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -840,12 +840,12 @@ void kvm_update_interrupt_request(CPUState *env)
* Testing for created here is really redundant
*/
if (current_env && current_env->created &&
- env != current_env && !env->kvm_cpu_state.signalled) {
+ env != current_env && !env->thread_kicked) {
signal = 1;
}
if (signal) {
- env->kvm_cpu_state.signalled = 1;
+ env->thread_kicked = true;
if (env->thread) {
pthread_kill(env->thread->thread, SIG_IPI);
}
@@ -941,7 +941,7 @@ static void kvm_main_loop_wait(CPUState *env, int timeout)
pthread_cond_signal(&qemu_pause_cond);
}
- env->kvm_cpu_state.signalled = 0;
+ env->thread_kicked = false;
}
static int all_threads_paused(void)
--
1.7.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 06/10] qemu-kvm: Activate iothread version of qemu_cpu_kick_self
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
` (4 preceding siblings ...)
2011-05-20 17:12 ` [PATCH 05/10] qemu-kvm: Use thread_kicked instead of KVMCPUState::signalled Jan Kiszka
@ 2011-05-20 17:12 ` Jan Kiszka
2011-05-20 17:12 ` [PATCH 07/10] qemu-kvm: Refactor exit_request processing in kvm_run Jan Kiszka
` (5 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Jan Kiszka @ 2011-05-20 17:12 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm
This is a temporary hack: We will soon use this service for kvm which is
running in iothread mode - but with CONFIG_IOTHREAD disabled.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
cpus.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/cpus.c b/cpus.c
index 5d1c396..b64c29f 100644
--- a/cpus.c
+++ b/cpus.c
@@ -590,6 +590,7 @@ void qemu_cpu_kick(void *env)
{
}
+#ifdef UNUSED_IMPL
void qemu_cpu_kick_self(void)
{
#ifndef _WIN32
@@ -600,6 +601,7 @@ void qemu_cpu_kick_self(void)
abort();
#endif
}
+#endif
void qemu_notify_event(void)
{
@@ -848,6 +850,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
return NULL;
}
+#endif
static void qemu_cpu_kick_thread(CPUState *env)
{
#ifndef _WIN32
@@ -866,6 +869,7 @@ static void qemu_cpu_kick_thread(CPUState *env)
}
#endif
}
+#ifdef CONFIG_IOTHREAD
void qemu_cpu_kick(void *_env)
{
@@ -878,6 +882,7 @@ void qemu_cpu_kick(void *_env)
}
}
+#endif
void qemu_cpu_kick_self(void)
{
#ifndef _WIN32
@@ -891,6 +896,7 @@ void qemu_cpu_kick_self(void)
abort();
#endif
}
+#ifdef CONFIG_IOTHREAD
int qemu_cpu_is_self(void *_env)
{
--
1.7.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 07/10] qemu-kvm: Refactor exit_request processing in kvm_run
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
` (5 preceding siblings ...)
2011-05-20 17:12 ` [PATCH 06/10] qemu-kvm: Activate iothread version of qemu_cpu_kick_self Jan Kiszka
@ 2011-05-20 17:12 ` Jan Kiszka
2011-05-20 17:12 ` [PATCH 08/10] qemu-kvm: Use upstream kvm_arch_process_async_events Jan Kiszka
` (4 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Jan Kiszka @ 2011-05-20 17:12 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm
Move closer to upstream by reusing its self-signaling service in
kvm_run, maintain cpu_single_env the same way, push this under
qemu_mutex, and clear exit_request unconditionally when leaving kvm_run.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
qemu-kvm.c | 25 ++++++++++++++-----------
1 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/qemu-kvm.c b/qemu-kvm.c
index 843c973..24c667c 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -278,16 +278,21 @@ static inline void push_nmi(void)
static void post_kvm_run(CPUState *env)
{
pthread_mutex_lock(&qemu_mutex);
- kvm_arch_post_run(env, env->kvm_run);
cpu_single_env = env;
+
+ kvm_arch_post_run(env, env->kvm_run);
}
-static int pre_kvm_run(CPUState *env)
+static void pre_kvm_run(CPUState *env)
{
kvm_arch_pre_run(env, env->kvm_run);
+ if (env->exit_request) {
+ qemu_cpu_kick_self();
+ }
+
+ cpu_single_env = NULL;
pthread_mutex_unlock(&qemu_mutex);
- return 0;
}
int kvm_is_ready_for_interrupt_injection(CPUState *env)
@@ -300,6 +305,8 @@ static int kvm_run(CPUState *env)
int r;
struct kvm_run *run = env->kvm_run;
+ cpu_single_env = env;
+
again:
if (env->kvm_vcpu_dirty) {
kvm_arch_put_registers(env, KVM_PUT_RUNTIME_STATE);
@@ -310,14 +317,8 @@ static int kvm_run(CPUState *env)
run->request_interrupt_window = kvm_arch_try_push_interrupts(env);
}
- r = pre_kvm_run(env);
- if (r) {
- return r;
- }
- if (env->exit_request) {
- env->exit_request = 0;
- pthread_kill(env->thread->thread, SIG_IPI);
- }
+ pre_kvm_run(env);
+
r = kvm_vcpu_ioctl(env, KVM_RUN, 0);
post_kvm_run(env);
@@ -325,6 +326,7 @@ static int kvm_run(CPUState *env)
kvm_flush_coalesced_mmio_buffer();
if (r == -EINTR || r == -EAGAIN) {
+ env->exit_request = 0;
return 1;
}
if (r < 0) {
@@ -384,6 +386,7 @@ static int kvm_run(CPUState *env)
if (!r) {
goto again;
}
+ env->exit_request = 0;
return r;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 08/10] qemu-kvm: Use upstream kvm_arch_process_async_events
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
` (6 preceding siblings ...)
2011-05-20 17:12 ` [PATCH 07/10] qemu-kvm: Refactor exit_request processing in kvm_run Jan Kiszka
@ 2011-05-20 17:12 ` Jan Kiszka
2011-05-20 17:12 ` [PATCH 09/10] qemu-kvm: Use upstream kvm_cpu_exec Jan Kiszka
` (3 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Jan Kiszka @ 2011-05-20 17:12 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm
Upstream's kvm_arch_process_async_events is now identical to qemu-kvm's
combination of kvm_arch_process_async_events and process_irqchip_events.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
qemu-kvm-x86.c | 49 -------------------------------------------------
qemu-kvm.c | 13 +------------
qemu-kvm.h | 2 --
target-i386/kvm.c | 2 --
4 files changed, 1 insertions(+), 65 deletions(-)
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index b009251..18f7c3a 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -225,16 +225,6 @@ void kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
}
}
-int kvm_arch_has_work(CPUState *env)
-{
- if (((env->interrupt_request & CPU_INTERRUPT_HARD) &&
- (env->eflags & IF_MASK)) ||
- (env->interrupt_request & CPU_INTERRUPT_NMI)) {
- return 1;
- }
- return 0;
-}
-
int kvm_arch_try_push_interrupts(void *opaque)
{
CPUState *env = cpu_single_env;
@@ -331,42 +321,3 @@ int kvm_arch_init_irq_routing(void)
return 0;
}
-
-void kvm_arch_process_irqchip_events(CPUState *env)
-{
- if (env->interrupt_request & CPU_INTERRUPT_INIT) {
- kvm_cpu_synchronize_state(env);
- do_cpu_init(env);
- }
- if (env->interrupt_request & CPU_INTERRUPT_SIPI) {
- kvm_cpu_synchronize_state(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;
-}
diff --git a/qemu-kvm.c b/qemu-kvm.c
index 24c667c..41c4219 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -1032,23 +1032,12 @@ static void qemu_kvm_system_reset(void)
resume_all_threads();
}
-static void process_irqchip_events(CPUState *env)
-{
- kvm_arch_process_irqchip_events(env);
- if (kvm_arch_has_work(env))
- env->halted = 0;
-}
-
static int kvm_main_loop_cpu(CPUState *env)
{
while (1) {
int run_cpu = !kvm_cpu_is_stopped(env);
if (run_cpu) {
- kvm_arch_process_async_events(env);
- if (!kvm_irqchip_in_kernel()) {
- process_irqchip_events(env);
- run_cpu = !env->halted;
- }
+ run_cpu = !kvm_arch_process_async_events(env);
}
if (run_cpu) {
kvm_cpu_exec(env);
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 8ff773a..5621cfa 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -314,8 +314,6 @@ void kvm_hpet_disable_kpit(void);
void on_vcpu(CPUState *env, void (*func)(void *data), void *data);
void kvm_update_interrupt_request(CPUState *env);
-int kvm_arch_has_work(CPUState *env);
-void kvm_arch_process_irqchip_events(CPUState *env);
int kvm_arch_try_push_interrupts(void *opaque);
void kvm_arch_push_nmi(void);
int kvm_set_boot_cpu_id(KVMState *s, uint32_t id);
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index a4365bf..e98eccf 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1636,7 +1636,6 @@ void kvm_arch_post_run(CPUState *env, struct kvm_run *run)
cpu_set_apic_base(env->apic_state, run->apic_base);
}
-#ifdef OBSOLETE_KVM_IMPL
int kvm_arch_process_async_events(CPUState *env)
{
if (env->interrupt_request & CPU_INTERRUPT_MCE) {
@@ -1682,7 +1681,6 @@ int kvm_arch_process_async_events(CPUState *env)
return env->halted;
}
-#endif
static int kvm_handle_halt(CPUState *env)
{
--
1.7.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 09/10] qemu-kvm: Use upstream kvm_cpu_exec
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
` (7 preceding siblings ...)
2011-05-20 17:12 ` [PATCH 08/10] qemu-kvm: Use upstream kvm_arch_process_async_events Jan Kiszka
@ 2011-05-20 17:12 ` Jan Kiszka
2011-05-20 17:17 ` Christoph Hellwig
2011-05-20 17:12 ` [PATCH 10/10] qemu-kvm: Rework ioport access management Jan Kiszka
` (2 subsequent siblings)
11 siblings, 1 reply; 16+ messages in thread
From: Jan Kiszka @ 2011-05-20 17:12 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm
Upstream's and qemu-kvm's kvm_cpu_exec are not logically equivalent so
that we can safely switch the implementations.
A bit refactoring of kvm_main_loop_cpu is required as upstream's cpu
loop already contains the asynchronous event processing which ran
outside so far.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
kvm-all.c | 3 -
qemu-kvm-x86.c | 101 +-----------------------
qemu-kvm.c | 225 ++++-------------------------------------------------
qemu-kvm.h | 44 +----------
target-i386/kvm.c | 2 -
5 files changed, 17 insertions(+), 358 deletions(-)
diff --git a/kvm-all.c b/kvm-all.c
index 5ac177f..88d0785 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -958,8 +958,6 @@ void kvm_cpu_synchronize_post_init(CPUState *env)
env->kvm_vcpu_dirty = 0;
}
-#ifdef OBSOLETE_KVM_IMPL
-
int kvm_cpu_exec(CPUState *env)
{
struct kvm_run *run = env->kvm_run;
@@ -1065,7 +1063,6 @@ int kvm_cpu_exec(CPUState *env)
return ret;
}
-#endif
int kvm_ioctl(KVMState *s, int type, ...)
{
int ret;
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index 18f7c3a..89bb692 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -49,13 +49,13 @@ static int kvm_create_pit(KVMState *s)
#ifdef KVM_EXIT_TPR_ACCESS
-static int kvm_handle_tpr_access(CPUState *env)
+int kvm_handle_tpr_access(CPUState *env)
{
struct kvm_run *run = env->kvm_run;
kvm_tpr_access_report(env,
run->tpr_access.rip,
run->tpr_access.is_write);
- return 0;
+ return 1;
}
@@ -70,41 +70,6 @@ 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;
- struct kvm_run *run = env->kvm_run;
-
- switch (run->exit_reason) {
-#ifdef KVM_EXIT_SET_TPR
- case KVM_EXIT_SET_TPR:
- break;
-#endif
-#ifdef KVM_EXIT_TPR_ACCESS
- case KVM_EXIT_TPR_ACCESS:
- 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;
- break;
- }
-
- return r;
-}
-
#ifdef KVM_CAP_IRQCHIP
int kvm_get_lapic(CPUState *env, struct kvm_lapic_state *s)
@@ -178,11 +143,6 @@ int kvm_set_pit2(KVMState *s, struct kvm_pit_state2 *ps2)
#endif
#endif
-static void kvm_set_cr8(CPUState *env, uint64_t cr8)
-{
- env->kvm_run->cr8 = cr8;
-}
-
#ifdef KVM_CAP_VAPIC
static int kvm_enable_tpr_access_reporting(CPUState *env)
{
@@ -207,63 +167,6 @@ static int _kvm_arch_init_vcpu(CPUState *env)
return 0;
}
-int kvm_arch_halt(CPUState *env)
-{
-
- if (!((env->interrupt_request & CPU_INTERRUPT_HARD) &&
- (env->eflags & IF_MASK)) &&
- !(env->interrupt_request & CPU_INTERRUPT_NMI)) {
- env->halted = 1;
- }
- return 1;
-}
-
-void kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
-{
- if (!kvm_irqchip_in_kernel()) {
- kvm_set_cr8(env, cpu_get_apic_tpr(env->apic_state));
- }
-}
-
-int kvm_arch_try_push_interrupts(void *opaque)
-{
- CPUState *env = cpu_single_env;
- int r, irq;
-
- if (kvm_is_ready_for_interrupt_injection(env) &&
- (env->interrupt_request & CPU_INTERRUPT_HARD) &&
- (env->eflags & IF_MASK)) {
- env->interrupt_request &= ~CPU_INTERRUPT_HARD;
- irq = cpu_get_pic_interrupt(env);
- if (irq >= 0) {
- r = kvm_inject_irq(env, irq);
- if (r < 0) {
- printf("cpu %d fail inject %x\n", env->cpu_index, irq);
- }
- }
- }
-
- return (env->interrupt_request & CPU_INTERRUPT_HARD) != 0;
-}
-
-#ifdef KVM_CAP_USER_NMI
-void kvm_arch_push_nmi(void)
-{
- CPUState *env = cpu_single_env;
- int r;
-
- if (likely(!(env->interrupt_request & CPU_INTERRUPT_NMI))) {
- return;
- }
-
- env->interrupt_request &= ~CPU_INTERRUPT_NMI;
- r = kvm_inject_nmi(env);
- if (r < 0) {
- printf("cpu %d fail inject NMI\n", env->cpu_index);
- }
-}
-#endif /* KVM_CAP_USER_NMI */
-
#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
void kvm_arch_do_ioperm(void *_data)
{
diff --git a/qemu-kvm.c b/qemu-kvm.c
index 41c4219..b2387df 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -73,31 +73,6 @@ static QLIST_HEAD(, ioperm_data) ioperm_head;
#define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1))
-static int handle_unhandled(uint64_t reason)
-{
- fprintf(stderr, "kvm: unhandled exit %" PRIx64 "\n", reason);
- return -EINVAL;
-}
-
-#define VMX_INVALID_GUEST_STATE 0x80000021
-
-static int handle_failed_vmentry(uint64_t reason)
-{
- fprintf(stderr, "kvm: vm entry failed with error 0x%" PRIx64 "\n\n", reason);
-
- /* Perhaps we will need to check if this machine is intel since exit reason 0x21
- has a different interpretation on SVM */
- if (reason == VMX_INVALID_GUEST_STATE) {
- fprintf(stderr, "If you're runnning a guest on an Intel machine without\n");
- fprintf(stderr, "unrestricted mode support, the failure can be most likely\n");
- fprintf(stderr, "due to the guest entering an invalid state for Intel VT.\n");
- fprintf(stderr, "For example, the guest maybe running in big real mode\n");
- fprintf(stderr, "which is not supported on less recent Intel processors.\n\n");
- }
-
- return -EINVAL;
-}
-
static inline void set_gsi(KVMState *s, unsigned int gsi)
{
uint32_t *bitmap = s->used_gsi_bitmap;
@@ -244,169 +219,6 @@ int kvm_set_irqchip(KVMState *s, struct kvm_irqchip *chip)
#endif
-static int handle_mmio(CPUState *env)
-{
- unsigned long addr = env->kvm_run->mmio.phys_addr;
- struct kvm_run *kvm_run = env->kvm_run;
- void *data = kvm_run->mmio.data;
-
- /* hack: Red Hat 7.1 generates these weird accesses. */
- if ((addr > 0xa0000 - 4 && addr <= 0xa0000) && kvm_run->mmio.len == 3) {
- return 0;
- }
-
- cpu_physical_memory_rw(addr, data, kvm_run->mmio.len, kvm_run->mmio.is_write);
- return 0;
-}
-
-static int handle_shutdown(CPUState *env)
-{
- /* stop the current vcpu from going back to guest mode */
- env->stopped = 1;
-
- qemu_system_reset_request();
- return 1;
-}
-
-static inline void push_nmi(void)
-{
-#ifdef KVM_CAP_USER_NMI
- kvm_arch_push_nmi();
-#endif /* KVM_CAP_USER_NMI */
-}
-
-static void post_kvm_run(CPUState *env)
-{
- pthread_mutex_lock(&qemu_mutex);
- cpu_single_env = env;
-
- kvm_arch_post_run(env, env->kvm_run);
-}
-
-static void pre_kvm_run(CPUState *env)
-{
- kvm_arch_pre_run(env, env->kvm_run);
-
- if (env->exit_request) {
- qemu_cpu_kick_self();
- }
-
- cpu_single_env = NULL;
- pthread_mutex_unlock(&qemu_mutex);
-}
-
-int kvm_is_ready_for_interrupt_injection(CPUState *env)
-{
- return env->kvm_run->ready_for_interrupt_injection;
-}
-
-static int kvm_run(CPUState *env)
-{
- int r;
- struct kvm_run *run = env->kvm_run;
-
- cpu_single_env = env;
-
- again:
- if (env->kvm_vcpu_dirty) {
- kvm_arch_put_registers(env, KVM_PUT_RUNTIME_STATE);
- env->kvm_vcpu_dirty = 0;
- }
- push_nmi();
- if (!kvm_state->irqchip_in_kernel) {
- run->request_interrupt_window = kvm_arch_try_push_interrupts(env);
- }
-
- pre_kvm_run(env);
-
- r = kvm_vcpu_ioctl(env, KVM_RUN, 0);
-
- post_kvm_run(env);
-
- kvm_flush_coalesced_mmio_buffer();
-
- if (r == -EINTR || r == -EAGAIN) {
- env->exit_request = 0;
- return 1;
- }
- if (r < 0) {
- fprintf(stderr, "kvm_run: %s\n", strerror(-r));
- return r;
- }
-
- if (1) {
- switch (run->exit_reason) {
- case KVM_EXIT_UNKNOWN:
- r = handle_unhandled(run->hw.hardware_exit_reason);
- break;
- case KVM_EXIT_FAIL_ENTRY:
- r = handle_failed_vmentry(run->fail_entry.hardware_entry_failure_reason);
- break;
- case KVM_EXIT_EXCEPTION:
- fprintf(stderr, "exception %d (%x)\n", run->ex.exception,
- run->ex.error_code);
- cpu_dump_state(env, stderr, fprintf, CPU_DUMP_CODE);
- abort();
- break;
- case KVM_EXIT_IO:
- kvm_handle_io(run->io.port,
- (uint8_t *)run + run->io.data_offset,
- run->io.direction,
- run->io.size,
- run->io.count);
- r = 0;
- break;
- case KVM_EXIT_MMIO:
- r = handle_mmio(env);
- break;
- case KVM_EXIT_HLT:
- r = kvm_arch_halt(env);
- break;
- case KVM_EXIT_IRQ_WINDOW_OPEN:
- break;
- case KVM_EXIT_SHUTDOWN:
- r = handle_shutdown(env);
- break;
- case KVM_EXIT_INTERNAL_ERROR:
- r = kvm_handle_internal_error(env, run);
- break;
- default:
- r = kvm_arch_run(env);
- if (r < 0) {
- fprintf(stderr, "unhandled vm exit: 0x%x\n", run->exit_reason);
- cpu_dump_state(env, stderr, fprintf, CPU_DUMP_CODE);
- abort();
- }
- if (r > 0) {
- return r;
- }
- break;
- }
- }
- if (!r) {
- goto again;
- }
- env->exit_request = 0;
- return r;
-}
-
-int kvm_inject_irq(CPUState *env, unsigned irq)
-{
- struct kvm_interrupt intr;
-
- intr.irq = irq;
- return kvm_vcpu_ioctl(env, KVM_INTERRUPT, &intr);
-}
-
-int kvm_inject_nmi(CPUState *env)
-{
-#ifdef KVM_CAP_USER_NMI
- return kvm_vcpu_ioctl(env, KVM_NMI);
-#else
- return -ENOSYS;
-#endif
-}
-
#ifdef KVM_CAP_DEVICE_ASSIGNMENT
int kvm_assign_pci_device(KVMState *s,
struct kvm_assigned_pci_dev *assigned_dev)
@@ -856,20 +668,6 @@ void kvm_update_interrupt_request(CPUState *env)
}
}
-int kvm_cpu_exec(CPUState *env)
-{
- int r;
-
- r = kvm_run(env);
- if (r < 0) {
- printf("kvm_run returned %d\n", r);
- cpu_dump_state(env, stderr, fprintf, CPU_DUMP_CODE);
- vm_stop(VMSTOP_PANIC);
- }
-
- return 0;
-}
-
static int kvm_cpu_is_stopped(CPUState *env)
{
return !vm_running || env->stopped;
@@ -1035,16 +833,21 @@ static void qemu_kvm_system_reset(void)
static int kvm_main_loop_cpu(CPUState *env)
{
while (1) {
- int run_cpu = !kvm_cpu_is_stopped(env);
- if (run_cpu) {
- run_cpu = !kvm_arch_process_async_events(env);
- }
- if (run_cpu) {
- kvm_cpu_exec(env);
- kvm_main_loop_wait(env, 0);
- } else {
- kvm_main_loop_wait(env, 1000);
+ int timeout = 1000;
+ if (!kvm_cpu_is_stopped(env)) {
+ switch (kvm_cpu_exec(env)) {
+ case EXCP_HLT:
+ break;
+ case EXCP_DEBUG:
+ kvm_debug_cpu_requested = env;
+ env->stopped = 1;
+ break;
+ default:
+ timeout = 0;
+ break;
+ }
}
+ kvm_main_loop_wait(env, timeout);
}
pthread_mutex_unlock(&qemu_mutex);
return 0;
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 5621cfa..57dc6aa 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -37,35 +37,8 @@
#include "kvm.h"
-int kvm_arch_run(CPUState *env);
-
int kvm_create_irqchip(KVMState *s);
-/*!
- * \brief Check if a vcpu is ready for interrupt injection
- *
- * This checks if vcpu interrupts are not masked by mov ss or sti.
- *
- * \param kvm Pointer to the current kvm_context
- * \param vcpu Which virtual CPU should get dumped
- * \return boolean indicating interrupt injection readiness
- */
-int kvm_is_ready_for_interrupt_injection(CPUState *env);
-
-#if defined(__i386__) || defined(__x86_64__)
-/*!
- * \brief Simulate an external vectored interrupt
- *
- * This allows you to simulate an external vectored interrupt.
- *
- * \param kvm Pointer to the current kvm_context
- * \param vcpu Which virtual CPU should get dumped
- * \param irq Vector number
- * \return 0 on success
- */
-int kvm_inject_irq(CPUState *env, unsigned irq);
-#endif
-
#ifdef KVM_CAP_IRQCHIP
/*!
* \brief Dump in kernel IRQCHIP contents
@@ -115,17 +88,6 @@ int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s);
#endif
-/*!
- * \brief Simulate an NMI
- *
- * This allows you to simulate a non-maskable interrupt.
- *
- * \param kvm Pointer to the current kvm_context
- * \param vcpu Which virtual CPU should get dumped
- * \return 0 on success
- */
-int kvm_inject_nmi(CPUState *env);
-
#endif
#ifdef KVM_CAP_PIT
@@ -314,8 +276,6 @@ void kvm_hpet_disable_kpit(void);
void on_vcpu(CPUState *env, void (*func)(void *data), void *data);
void kvm_update_interrupt_request(CPUState *env);
-int kvm_arch_try_push_interrupts(void *opaque);
-void kvm_arch_push_nmi(void);
int kvm_set_boot_cpu_id(KVMState *s, uint32_t id);
void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write);
@@ -347,9 +307,7 @@ struct ioperm_data {
QLIST_ENTRY(ioperm_data) entries;
};
-int kvm_arch_halt(CPUState *env);
-int handle_tpr_access(void *opaque, CPUState *env, uint64_t rip,
- int is_write);
+int kvm_handle_tpr_access(CPUState *env);
#else
#define kvm_nested 0
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index e98eccf..bccd87c 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1565,7 +1565,6 @@ int kvm_arch_get_registers(CPUState *env)
return 0;
}
-#ifdef OBSOLETE_KVM_IMPL
void kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
{
int ret;
@@ -1623,7 +1622,6 @@ void kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
run->cr8 = cpu_get_apic_tpr(env->apic_state);
}
}
-#endif
void kvm_arch_post_run(CPUState *env, struct kvm_run *run)
{
--
1.7.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 10/10] qemu-kvm: Rework ioport access management
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
` (8 preceding siblings ...)
2011-05-20 17:12 ` [PATCH 09/10] qemu-kvm: Use upstream kvm_cpu_exec Jan Kiszka
@ 2011-05-20 17:12 ` Jan Kiszka
2011-05-20 17:14 ` [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Alexander Graf
2011-05-26 8:29 ` Avi Kivity
11 siblings, 0 replies; 16+ messages in thread
From: Jan Kiszka @ 2011-05-20 17:12 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm
Clean up the interface for enabling/disabling direct ioport access for
assigned devices. There is now only a register and a deregister service.
Both are automatically updating the access on all vcpus. Besides that,
there is an update service for newly created VCPUs that applies all
currently registered regions.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
hw/device-assignment.c | 20 +++------
qemu-kvm-x86.c | 12 ++++--
qemu-kvm.c | 107 ++++++++++++++++++++++++++++++++++--------------
qemu-kvm.h | 21 ++-------
4 files changed, 96 insertions(+), 64 deletions(-)
diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index abc38f8..57d8dc0 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -298,7 +298,7 @@ static void assigned_dev_ioport_map(PCIDevice *pci_dev, int region_num,
AssignedDevice *r_dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
AssignedDevRegion *region = &r_dev->v_addrs[region_num];
int first_map = (region->e_size == 0);
- CPUState *env;
+ int r;
region->e_physbase = addr;
region->e_size = size;
@@ -307,17 +307,11 @@ static void assigned_dev_ioport_map(PCIDevice *pci_dev, int region_num,
addr, region->u.r_baseport, type, size, region_num);
if (first_map && region->region->resource_fd < 0) {
- struct ioperm_data *data;
-
- data = qemu_mallocz(sizeof(struct ioperm_data));
- data->start_port = region->u.r_baseport;
- data->num = region->r_size;
- data->turn_on = 1;
-
- kvm_add_ioperm_data(data);
-
- for (env = first_cpu; env; env = env->next_cpu)
- kvm_ioperm(env, data);
+ r = kvm_add_ioport_region(region->u.r_baseport, region->r_size);
+ if (r < 0) {
+ fprintf(stderr, "%s: failed to enable ioport access (%m)\n",
+ __func__);
+ }
}
register_ioport_read(addr, size, 1, assigned_dev_ioport_readb,
@@ -832,7 +826,7 @@ static void free_assigned_device(AssignedDevice *dev)
}
if (pci_region->type & IORESOURCE_IO) {
if (pci_region->resource_fd < 0) {
- kvm_remove_ioperm_data(region->u.r_baseport, region->r_size);
+ kvm_remove_ioport_region(region->u.r_baseport, region->r_size);
}
} else if (pci_region->type & IORESOURCE_MEM) {
if (region->u.r_virtbase) {
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index 89bb692..2a01ccc 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -164,14 +164,18 @@ static int _kvm_arch_init_vcpu(CPUState *env)
#ifdef KVM_EXIT_TPR_ACCESS
kvm_enable_tpr_access_reporting(env);
#endif
- return 0;
+
+ return kvm_update_ioport_access(env);
}
#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
-void kvm_arch_do_ioperm(void *_data)
+int kvm_arch_set_ioport_access(unsigned long start, unsigned long size,
+ bool enable)
{
- struct ioperm_data *data = _data;
- ioperm(data->start_port, data->num, data->turn_on);
+ if (ioperm(start, size, enable) < 0) {
+ return -errno;
+ }
+ return 0;
}
#endif
diff --git a/qemu-kvm.c b/qemu-kvm.c
index b2387df..94e12f3 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -66,11 +66,6 @@ static int qemu_system_ready;
CPUState *kvm_debug_cpu_requested;
-#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
-/* The list of ioperm_data */
-static QLIST_HEAD(, ioperm_data) ioperm_head;
-#endif
-
#define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1))
static inline void set_gsi(KVMState *s, unsigned int gsi)
@@ -856,19 +851,10 @@ static int kvm_main_loop_cpu(CPUState *env)
static void *ap_main_loop(void *_env)
{
CPUState *env = _env;
-#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
- struct ioperm_data *data = NULL;
-#endif
current_env = env;
env->thread_id = kvm_get_thread_id();
-#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
- /* do ioperm for io ports of assigned devices */
- QLIST_FOREACH(data, &ioperm_head, entries)
- on_vcpu(env, kvm_arch_do_ioperm, data);
-#endif
-
pthread_mutex_lock(&qemu_mutex);
cpu_single_env = env;
@@ -1069,36 +1055,95 @@ void qemu_mutex_lock_iothread(void)
}
#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
-void kvm_add_ioperm_data(struct ioperm_data *data)
+typedef struct KVMIOPortRegion {
+ unsigned long start;
+ unsigned long size;
+ int status;
+ QLIST_ENTRY(KVMIOPortRegion) entry;
+} KVMIOPortRegion;
+
+static QLIST_HEAD(, KVMIOPortRegion) ioport_regions;
+
+static void do_set_ioport_access(void *data)
{
- QLIST_INSERT_HEAD(&ioperm_head, data, entries);
+ KVMIOPortRegion *region = data;
+ bool enable = region->status > 0;
+ int r;
+
+ r = kvm_arch_set_ioport_access(region->start, region->size, enable);
+ if (r < 0) {
+ region->status = r;
+ } else {
+ region->status = 1;
+ }
}
-void kvm_remove_ioperm_data(unsigned long start_port, unsigned long num)
+int kvm_add_ioport_region(unsigned long start, unsigned long size)
{
- struct ioperm_data *data;
-
- data = QLIST_FIRST(&ioperm_head);
- while (data) {
- struct ioperm_data *next = QLIST_NEXT(data, entries);
+ KVMIOPortRegion *region = qemu_mallocz(sizeof(KVMIOPortRegion));
+ CPUState *env;
+ int r = 0;
- if (data->start_port == start_port && data->num == num) {
- QLIST_REMOVE(data, entries);
- qemu_free(data);
+ region->start = start;
+ region->size = size;
+ region->status = 1;
+ QLIST_INSERT_HEAD(&ioport_regions, region, entry);
+
+ if (qemu_system_ready) {
+ for (env = first_cpu; env != NULL; env = env->next_cpu) {
+ on_vcpu(env, do_set_ioport_access, region);
+ if (region->status < 0) {
+ r = region->status;
+ kvm_remove_ioport_region(start, size);
+ break;
+ }
}
-
- data = next;
}
+ return r;
}
-void kvm_ioperm(CPUState *env, void *data)
+int kvm_remove_ioport_region(unsigned long start, unsigned long size)
{
- if (kvm_enabled() && qemu_system_ready) {
- on_vcpu(env, kvm_arch_do_ioperm, data);
+ KVMIOPortRegion *region, *tmp;
+ CPUState *env;
+ int r = -ENOENT;
+
+ QLIST_FOREACH_SAFE(region, &ioport_regions, entry, tmp) {
+ if (region->start == start && region->size == size) {
+ region->status = 0;
+ }
+ if (qemu_system_ready) {
+ for (env = first_cpu; env != NULL; env = env->next_cpu) {
+ on_vcpu(env, do_set_ioport_access, region);
+ }
+ }
+ QLIST_REMOVE(region, entry);
+ qemu_free(region);
+ r = 0;
}
+ return r;
}
+#endif /* CONFIG_KVM_DEVICE_ASSIGNMENT */
-#endif
+int kvm_update_ioport_access(CPUState *env)
+{
+#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
+ KVMIOPortRegion *region;
+ int r;
+
+ assert(qemu_cpu_is_self(env));
+
+ QLIST_FOREACH(region, &ioport_regions, entry) {
+ bool enable = region->status > 0;
+
+ r = kvm_arch_set_ioport_access(region->start, region->size, enable);
+ if (r < 0) {
+ return r;
+ }
+ }
+#endif /* CONFIG_KVM_DEVICE_ASSIGNMENT */
+ return 0;
+}
int kvm_set_boot_cpu_id(KVMState *s, uint32_t id)
{
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 57dc6aa..094aef2 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -282,31 +282,20 @@ void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write);
int kvm_arch_init_irq_routing(void);
-#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
-struct ioperm_data;
+int kvm_add_ioport_region(unsigned long start, unsigned long size);
+int kvm_remove_ioport_region(unsigned long start, unsigned long size);
-void kvm_ioperm(CPUState *env, void *data);
-void kvm_add_ioperm_data(struct ioperm_data *data);
-void kvm_remove_ioperm_data(unsigned long start_port, unsigned long num);
-void kvm_arch_do_ioperm(void *_data);
-#endif
+int kvm_update_ioport_access(CPUState *env);
+int kvm_arch_set_ioport_access(unsigned long start, unsigned long size,
+ bool enable);
#ifdef CONFIG_KVM
-#include "qemu-queue.h"
-
extern int kvm_irqchip;
extern int kvm_pit;
extern int kvm_pit_reinject;
extern int kvm_nested;
extern unsigned int kvm_shadow_memory;
-struct ioperm_data {
- unsigned long start_port;
- unsigned long num;
- int turn_on;
- QLIST_ENTRY(ioperm_data) entries;
-};
-
int kvm_handle_tpr_access(CPUState *env);
#else
--
1.7.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
` (9 preceding siblings ...)
2011-05-20 17:12 ` [PATCH 10/10] qemu-kvm: Rework ioport access management Jan Kiszka
@ 2011-05-20 17:14 ` Alexander Graf
2011-05-20 17:16 ` Jan Kiszka
2011-05-26 8:29 ` Avi Kivity
11 siblings, 1 reply; 16+ messages in thread
From: Alexander Graf @ 2011-05-20 17:14 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Avi Kivity, Marcelo Tosatti, kvm
On 20.05.2011, at 19:12, Jan Kiszka wrote:
> This is a rather short round as the next and final one cannot be split
> up very well.
>
> We start with three code cleanup patches, then work towards using
> upstream kvm_cpu_exec, and finally rework the core's PIO access
> management used for device assignment.
>
> Please review/merge.
So with this set applied, s390 and ppc targets should work in qemu-kvm.git?
Alex
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III
2011-05-20 17:14 ` [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Alexander Graf
@ 2011-05-20 17:16 ` Jan Kiszka
0 siblings, 0 replies; 16+ messages in thread
From: Jan Kiszka @ 2011-05-20 17:16 UTC (permalink / raw)
To: Alexander Graf; +Cc: Avi Kivity, Marcelo Tosatti, kvm
On 2011-05-20 19:14, Alexander Graf wrote:
>
> On 20.05.2011, at 19:12, Jan Kiszka wrote:
>
>> This is a rather short round as the next and final one cannot be split
>> up very well.
>>
>> We start with three code cleanup patches, then work towards using
>> upstream kvm_cpu_exec, and finally rework the core's PIO access
>> management used for device assignment.
>>
>> Please review/merge.
>
> So with this set applied, s390 and ppc targets should work in qemu-kvm.git?
I bet not yet. Part IV will finally switch over to upstream vcpu loop,
and that should make them work.
Jan
--
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 09/10] qemu-kvm: Use upstream kvm_cpu_exec
2011-05-20 17:12 ` [PATCH 09/10] qemu-kvm: Use upstream kvm_cpu_exec Jan Kiszka
@ 2011-05-20 17:17 ` Christoph Hellwig
2011-05-22 10:55 ` Jan Kiszka
0 siblings, 1 reply; 16+ messages in thread
From: Christoph Hellwig @ 2011-05-20 17:17 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Avi Kivity, Marcelo Tosatti, kvm
On Fri, May 20, 2011 at 07:12:39PM +0200, Jan Kiszka wrote:
> Upstream's and qemu-kvm's kvm_cpu_exec are not logically equivalent so
s/not/now/?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 09/10] qemu-kvm: Use upstream kvm_cpu_exec
2011-05-20 17:17 ` Christoph Hellwig
@ 2011-05-22 10:55 ` Jan Kiszka
0 siblings, 0 replies; 16+ messages in thread
From: Jan Kiszka @ 2011-05-22 10:55 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Avi Kivity, Marcelo Tosatti, kvm
[-- Attachment #1: Type: text/plain, Size: 313 bytes --]
On 2011-05-20 19:17, Christoph Hellwig wrote:
> On Fri, May 20, 2011 at 07:12:39PM +0200, Jan Kiszka wrote:
>> Upstream's and qemu-kvm's kvm_cpu_exec are not logically equivalent so
>
> s/not/now/?
Oops, of course.
If there is no other need to repost, this should be fixed on merge.
Thanks,
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
` (10 preceding siblings ...)
2011-05-20 17:14 ` [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Alexander Graf
@ 2011-05-26 8:29 ` Avi Kivity
11 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2011-05-26 8:29 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Marcelo Tosatti, kvm, Alexander Graf
On 05/20/2011 08:12 PM, Jan Kiszka wrote:
> This is a rather short round as the next and final one cannot be split
> up very well.
>
> We start with three code cleanup patches, then work towards using
> upstream kvm_cpu_exec, and finally rework the core's PIO access
> management used for device assignment.
>
> Please review/merge.
>
Thanks, applied.
--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2011-05-26 8:29 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-20 17:12 [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Jan Kiszka
2011-05-20 17:12 ` [PATCH 01/10] qemu-kvm: Remove obsolete inclusions Jan Kiszka
2011-05-20 17:12 ` [PATCH 02/10] qemu-kvm: Remove remaining s390 fragments Jan Kiszka
2011-05-20 17:12 ` [PATCH 03/10] qemu-kvm: ppc: Drop diff to upstream Jan Kiszka
2011-05-20 17:12 ` [PATCH 04/10] qemu-kvm: Refactor vm exit in kvm_run Jan Kiszka
2011-05-20 17:12 ` [PATCH 05/10] qemu-kvm: Use thread_kicked instead of KVMCPUState::signalled Jan Kiszka
2011-05-20 17:12 ` [PATCH 06/10] qemu-kvm: Activate iothread version of qemu_cpu_kick_self Jan Kiszka
2011-05-20 17:12 ` [PATCH 07/10] qemu-kvm: Refactor exit_request processing in kvm_run Jan Kiszka
2011-05-20 17:12 ` [PATCH 08/10] qemu-kvm: Use upstream kvm_arch_process_async_events Jan Kiszka
2011-05-20 17:12 ` [PATCH 09/10] qemu-kvm: Use upstream kvm_cpu_exec Jan Kiszka
2011-05-20 17:17 ` Christoph Hellwig
2011-05-22 10:55 ` Jan Kiszka
2011-05-20 17:12 ` [PATCH 10/10] qemu-kvm: Rework ioport access management Jan Kiszka
2011-05-20 17:14 ` [PATCH 00/10] qemu-kvm: Cleanup and switch to upstream - Part III Alexander Graf
2011-05-20 17:16 ` Jan Kiszka
2011-05-26 8:29 ` Avi Kivity
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.