Re: [PATCH 09/10] qemu-kvm: Use upstream kvm_cpu_exec

2011-05-22 Thread Jan Kiszka
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



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 09/10] qemu-kvm: Use upstream kvm_cpu_exec

2011-05-20 Thread Christoph Hellwig
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/?

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 09/10] qemu-kvm: Use upstream kvm_cpu_exec

2011-05-20 Thread Jan Kiszka
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 
---
 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 0x8021
-
-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 0