From patchwork Tue Apr 20 10:53:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 93646 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 o3KAoKwj006046 for ; Tue, 20 Apr 2010 10:50:20 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754435Ab0DTKuK (ORCPT ); Tue, 20 Apr 2010 06:50:10 -0400 Received: from serv2.oss.ntt.co.jp ([222.151.198.100]:46701 "EHLO serv2.oss.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754401Ab0DTKuI (ORCPT ); Tue, 20 Apr 2010 06:50:08 -0400 Received: from serv2.oss.ntt.co.jp (localhost [127.0.0.1]) by serv2.oss.ntt.co.jp (Postfix) with ESMTP id 6F18324820B; Tue, 20 Apr 2010 19:50:07 +0900 (JST) Received: from serv1.oss.ntt.co.jp (serv1.oss.ntt.co.jp [172.19.0.2]) by serv2.oss.ntt.co.jp (Postfix) with ESMTP id 50F882481F9; Tue, 20 Apr 2010 19:50:07 +0900 (JST) Received: from yshtky3.kern.oss.ntt.co.jp (unknown [172.17.1.144]) by serv1.oss.ntt.co.jp (Postfix) with SMTP id 2B33411C11D; Tue, 20 Apr 2010 19:50:07 +0900 (JST) Date: Tue, 20 Apr 2010 19:53:49 +0900 From: Takuya Yoshikawa To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org, kvm-ia64@vger.kernel.org, kvm-ppc@vger.kernel.org Subject: [PATCH RFC v2 0/6] KVM: moving dirty gitmaps to user space! Message-Id: <20100420195349.dab60b1d.yoshikawa.takuya@oss.ntt.co.jp> X-Mailer: Sylpheed 2.6.0 (GTK+ 2.16.1; i486-pc-linux-gnu) Mime-Version: 1.0 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]); Tue, 20 Apr 2010 10:50:20 +0000 (UTC) === Appendix: To test the patch 6, we are using the following patch for qemu-kvm. --- configure | 2 +- qemu-kvm.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/configure b/configure index be8dac4..0b2d017 100755 --- a/configure +++ b/configure @@ -1498,7 +1498,7 @@ fi if test "$kvm" != "no" ; then cat > $TMPC < -#if !defined(KVM_API_VERSION) || KVM_API_VERSION < 12 || KVM_API_VERSION > 12 +#if !defined(KVM_API_VERSION) || KVM_API_VERSION < 13 || KVM_API_VERSION > 13 #error Invalid KVM version #endif #if !defined(KVM_CAP_USER_MEMORY) diff --git a/qemu-kvm.c b/qemu-kvm.c index cc5b352..087adea 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -44,7 +44,7 @@ #define BUS_MCEERR_AO 5 #endif -#define EXPECTED_KVM_API_VERSION 12 +#define EXPECTED_KVM_API_VERSION 13 #if EXPECTED_KVM_API_VERSION != KVM_API_VERSION #error libkvm: userspace and kernel version mismatch @@ -684,6 +684,21 @@ static int kvm_get_map(kvm_context_t kvm, int ioctl_num, int slot, void *buf) return 0; } +static int kvm_switch_map(kvm_context_t kvm, int slot, void **buf) +{ + int r; + struct kvm_dirty_log log = { + .slot = slot, + }; + + r = kvm_vm_ioctl(kvm_state, KVM_SWITCH_DIRTY_LOG, &log); + if (r < 0) + return r; + + *buf = (void *)log.addr; + return 0; +} + int kvm_get_dirty_pages(kvm_context_t kvm, unsigned long phys_addr, void *buf) { int slot; @@ -706,14 +721,11 @@ int kvm_get_dirty_pages_range(kvm_context_t kvm, unsigned long phys_addr, for (i = 0; i < KVM_MAX_NUM_MEM_REGIONS; ++i) { if ((slots[i].len && (uint64_t) slots[i].phys_addr >= phys_addr) && ((uint64_t) slots[i].phys_addr + slots[i].len <= end_addr)) { - buf = qemu_malloc(BITMAP_SIZE(slots[i].len)); - r = kvm_get_map(kvm, KVM_GET_DIRTY_LOG, i, buf); + r = kvm_switch_map(kvm, i, &buf); if (r) { - qemu_free(buf); return r; } r = cb(slots[i].phys_addr, slots[i].len, buf, opaque); - qemu_free(buf); if (r) return r; }