From mboxrd@z Thu Jan 1 00:00:00 1970 From: Juan Quintela Subject: Re: [questions] savevm|loadvm Date: Wed, 31 Mar 2010 13:31:38 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org To: Wenhao Xu Return-path: Received: from mx1.redhat.com ([209.132.183.28]:50047 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757154Ab0CaLbo (ORCPT ); Wed, 31 Mar 2010 07:31:44 -0400 In-Reply-To: (Wenhao Xu's message of "Tue, 30 Mar 2010 10:03:29 -0700") Sender: kvm-owner@vger.kernel.org List-ID: Wenhao Xu wrote: > Hi, Juan, > I am fresh to both QEMU and KVM. But so far, I notice that QEMU > uses "KVM_SET_USER_MEMORY_REGION" to set memory region that KVM can > use and uses cpu_register_physical_memory_offset to register the same > memory to QEMU emulator, which means QEMU and KVM use the same host > virtual memory. And therefore the memory KVM modified could be > directly reflected to QEMU. I don't quite understand the different > memory layout problem between the two. So I don't know exactly what > you mean to "fix" it? 1st. qemu-kvm.git and qemu.git memory layouts are different, indeed with qemu.git kvm mode. (yes it is complex and weird). kvm vs qemu initialization is different. Expecting to stop kvm, and run tcg from there is not going to work. I guess it would need a lot of changes, but I haven't looked at it myself. > For why switching is useful? Actually, I am a master student now > and doing a course project. What am I arguing is that QEMU could be > potentially useful to do many instrumentation analysis, but it is a > bit slow. So by combing with KVM, when the os runs to some place where > we are interested in, switch it to QEMU emulator mode and do the > analysis and then switch back. idea is good, but I don't think that it is _so_ easy at this point. tcg and kvm basically live in a different world. Not sure of what needs to be done to make them back on sync. > FYI, there is a paper doing so in Xen, "Practical taint-based > protection using demand emulation". I want to do the same "demand > emulation" for KVM. > > I am trying to patch some code. When kvm_run returns, I tried to > synchronize the CPU state and memory dirty map, and then run into QEMU > emulator mode. However, I got an error, "qemu: fatal: invalid tss > type". I don't know exactly where is the problem. I guess you need to look at tcg startup, and see how it initializes vcpus, and hack something around that when you try to run tcg at kvm_run exit. Have Fun :) Later, Juan. From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nww9L-0000iM-0t for qemu-devel@nongnu.org; Wed, 31 Mar 2010 07:31:55 -0400 Received: from [140.186.70.92] (port=57730 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nww9I-0000gg-Ec for qemu-devel@nongnu.org; Wed, 31 Mar 2010 07:31:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Nww9A-0006bl-Kx for qemu-devel@nongnu.org; Wed, 31 Mar 2010 07:31:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51412) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Nww9A-0006bf-3I for qemu-devel@nongnu.org; Wed, 31 Mar 2010 07:31:44 -0400 From: Juan Quintela In-Reply-To: (Wenhao Xu's message of "Tue, 30 Mar 2010 10:03:29 -0700") References: Date: Wed, 31 Mar 2010 13:31:38 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Qemu-devel] Re: [questions] savevm|loadvm List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenhao Xu Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org Wenhao Xu wrote: > Hi, Juan, > I am fresh to both QEMU and KVM. But so far, I notice that QEMU > uses "KVM_SET_USER_MEMORY_REGION" to set memory region that KVM can > use and uses cpu_register_physical_memory_offset to register the same > memory to QEMU emulator, which means QEMU and KVM use the same host > virtual memory. And therefore the memory KVM modified could be > directly reflected to QEMU. I don't quite understand the different > memory layout problem between the two. So I don't know exactly what > you mean to "fix" it? 1st. qemu-kvm.git and qemu.git memory layouts are different, indeed with qemu.git kvm mode. (yes it is complex and weird). kvm vs qemu initialization is different. Expecting to stop kvm, and run tcg from there is not going to work. I guess it would need a lot of changes, but I haven't looked at it myself. > For why switching is useful? Actually, I am a master student now > and doing a course project. What am I arguing is that QEMU could be > potentially useful to do many instrumentation analysis, but it is a > bit slow. So by combing with KVM, when the os runs to some place where > we are interested in, switch it to QEMU emulator mode and do the > analysis and then switch back. idea is good, but I don't think that it is _so_ easy at this point. tcg and kvm basically live in a different world. Not sure of what needs to be done to make them back on sync. > FYI, there is a paper doing so in Xen, "Practical taint-based > protection using demand emulation". I want to do the same "demand > emulation" for KVM. > > I am trying to patch some code. When kvm_run returns, I tried to > synchronize the CPU state and memory dirty map, and then run into QEMU > emulator mode. However, I got an error, "qemu: fatal: invalid tss > type". I don't know exactly where is the problem. I guess you need to look at tcg startup, and see how it initializes vcpus, and hack something around that when you try to run tcg at kvm_run exit. Have Fun :) Later, Juan.