From patchwork Thu Apr 1 19:35:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenhao Xu X-Patchwork-Id: 90251 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o31JZvIf001641 for ; Thu, 1 Apr 2010 19:35:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756502Ab0DATfs (ORCPT ); Thu, 1 Apr 2010 15:35:48 -0400 Received: from mail-pw0-f46.google.com ([209.85.160.46]:56559 "EHLO mail-pw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755055Ab0DATfr convert rfc822-to-8bit (ORCPT ); Thu, 1 Apr 2010 15:35:47 -0400 Received: by pwi5 with SMTP id 5so1348038pwi.19 for ; Thu, 01 Apr 2010 12:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:received:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=7TELJPibGzIT0mEs/sG68yknZC0NFMbd7x09kvB54vs=; b=lhj3N3wRJDI1mPQuCKrTkY6+37pl8T3tvjVsHur7yCKS9cBsiv1oadJyDZnZeoKQp6 QejVZDDtj6rsYp/pw9TOEeruBlJaGMru0IYnY+/HjewdDC3HCdrvGrWcPrhv03FHJOUA Sv/7x/SlsIC15Yl1TUvtSCbdrUzovzUanTmkQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=Mg4k8zsaaI6HAsnOh1qhNjrFZKIwHQZgrK2OyWShh+pOjY7q835FYsk2Iy3zBbJPb6 6Jq4m44OZ8AxJwowy11VU64KvH7Ckc8fQSg/uaHNCTVvYrpttiHXFwJWsGUA7tAkc5+P e/Nw1VZpCGezAwk9HllTB+fs9fr6qQghixDVg= MIME-Version: 1.0 Received: by 10.141.34.14 with HTTP; Thu, 1 Apr 2010 12:35:27 -0700 (PDT) In-Reply-To: <4BB45C63.3070401@redhat.com> References: <4BB45C63.3070401@redhat.com> From: Wenhao Xu Date: Thu, 1 Apr 2010 12:35:27 -0700 Received: by 10.141.13.5 with SMTP id q5mr969173rvi.280.1270150547069; Thu, 01 Apr 2010 12:35:47 -0700 (PDT) Message-ID: Subject: Re: [questions] savevm|loadvm To: Avi Kivity Cc: Juan Quintela , qemu-devel@nongnu.org, kvm@vger.kernel.org, aliguori@us.ibm.com, paul@codesourcery.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 01 Apr 2010 19:35:57 +0000 (UTC) --- qemu-0.12.3/kvm-all.c 2010-02-23 12:54:38.000000000 -0800 +++ de-0.12.3/kvm-all.c 2010-04-01 12:23:07.000000000 -0700 @@ -577,7 +577,6 @@ { struct kvm_run *run = env->kvm_run; int ret; - dprintf("kvm_cpu_exec()\n"); do { @@ -641,7 +640,8 @@ dprintf("kvm_exit_unknown\n"); break; case KVM_EXIT_FAIL_ENTRY: - dprintf("kvm_exit_fail_entry\n"); + printf("kvm_exit_fail_entry\n"); + exit(1); break; case KVM_EXIT_EXCEPTION: dprintf("kvm_exit_exception\n"); @@ -670,7 +670,31 @@ env->exit_request = 0; env->exception_index = EXCP_INTERRUPT; } - + + /* de, start emulation */ + if(env->ask_for_emulation){ + //if( (env->eflags & IF_MASK) && (run->ready_for_interrupt_injection)){ + if(run->exit_reason == KVM_EXIT_IRQ_WINDOW_OPEN ){ + int saved_vm_running = vm_running; + vm_stop(0); + if (kvm_arch_get_registers(env)) { + printf("Fatal: kvm vcpu get registers failed\n"); + abort(); + } + env->kvm_state->regs_modified = 1; + env->is_in_emulation = 1; + target_ulong pc_start = env->segs[R_CS].base + env->eip; + /* int flags = env->hflags |(env->eflags & (IOPL_MASK | TF_MASK | RF_MASK | VM_MASK)); */ + /* int code32 = !((flags >> HF_CS32_SHIFT) & 1); */ + printf("start emulation at pc: 0x%x, eip:0x%x\n", pc_start, env->eip); + /* target_disas(stderr, pc_start, 10, code32); */ + /* env->interrupt_request = 0; */ + printf("tr type:%d\n", (env->tr.flags >> DESC_TYPE_SHIFT) & 0xf); + + if(saved_vm_running) + vm_start(); + } + } return ret; } ask_for_emulation is in the CPU_COMMON --- qemu-0.12.3/cpu-defs.h 2010-02-23 12:54:38.000000000 -0800 +++ de-0.12.3/cpu-defs.h 2010-03-28 15:17:14.000000000 -0700 @@ -197,6 +197,8 @@ const char *cpu_model_str; \ struct KVMState *kvm_state; \ struct kvm_run *kvm_run; \ - int kvm_fd; + int kvm_fd; \ + int ask_for_emulation; /* ask for emulation if 1 */ \ + int is_in_emulation; /* is in emulation */ when is_in_emulation, don't enter kvm again in cpu_exec --- qemu-0.12.3/cpu-exec.c 2010-02-23 12:54:38.000000000 -0800 +++ de-0.12.3/cpu-exec.c 2010-03-30 00:38:01.000000000 -0700 #if defined(TARGET_I386) - if (!kvm_enabled()) { - /* put eflags in CPU temporary format */ - CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); - DF = 1 - (2 * ((env->eflags >> 10) & 1)); - CC_OP = CC_OP_EFLAGS; - env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); - } + if (!kvm_enabled() || env->is_in_emulation) { + /* put eflags in CPU temporary format */ + CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); + DF = 1 - (2 * ((env->eflags >> 10) & 1)); + CC_OP = CC_OP_EFLAGS; + env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); + } - if (kvm_enabled()) { - kvm_cpu_exec(env); - longjmp(env->jmp_env, 1); - } + if (kvm_enabled() && !env->is_in_emulation) { + kvm_cpu_exec(env); + longjmp(env->jmp_env, 1); + } command "start_emulation", "stop_emulation" support in the monitor --- qemu-0.12.3/monitor.c 2010-02-23 12:54:38.000000000 -0800 +++ de-0.12.3/monitor.c 2010-03-28 15:16:18.000000000 -0700 @@ -56,6 +56,9 @@ #include "json-streamer.h" #include "json-parser.h" #include "osdep.h" +/* de */ +static void do_start_emulation(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + CPUState *env = mon_get_cpu(); + env->ask_for_emulation = 1; + monitor_printf(mon, "Starting emulation...\n"); +} + +static void do_stop_emulation(Monitor *mon, const QDict *qdict, QObject **ret_data)