From patchwork Tue May 4 13:01:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 51619 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 4879BB8A48 for ; Wed, 5 May 2010 01:28:36 +1000 (EST) Received: by ozlabs.org (Postfix) id 249D6B7D1A; Tue, 4 May 2010 23:01:26 +1000 (EST) Delivered-To: linuxppc-dev@ozlabs.org Received: from mail-pw0-f42.google.com (mail-pw0-f42.google.com [209.85.160.42]) by ozlabs.org (Postfix) with ESMTP id A6A78B7D21 for ; Tue, 4 May 2010 23:01:25 +1000 (EST) Received: by pwi8 with SMTP id 8so1803064pwi.15 for ; Tue, 04 May 2010 06:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:in-reply-to:references:x-mailer:mime-version :content-type:content-transfer-encoding; bh=qoRa2i67CGCZwqxBtKPKzNXrVtY6BephVE+O8IM1jKk=; b=xSmBXM1WQSMkBsFOY6idxCgTvUiWtzNdHVX4G36MWsxHtPY6y3plYdfeBfB/wURpr7 Aml0MV6t+SkXnx0k/vOXrt2+tjBeTw71zzoZqFDCU7hdyZhN31jKIKeiJqCSZaMIILgE DLo9FeTsW6c1/WLUyGS8wih42mjdkKhkCx1Ko= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type:content-transfer-encoding; b=RGc4uaNeQnxjm7bcr9/UFvq3cIJpLurrjTO4It4ptWEvO/xPSIpdwfxZqAh45Qzs36 69av8NQbG0kTfwRqME06Un6brM2cmbd0VwO4cVwjOsRsfpiIVdWIbwJXXBhGM/EuFJPj whKx89wMyYPdek04jn5e7YxNG0IqWbYu409bc= Received: by 10.141.91.2 with SMTP id t2mr4530693rvl.111.1272978084241; Tue, 04 May 2010 06:01:24 -0700 (PDT) Received: from stein (v079161.dynamic.ppp.asahi-net.or.jp [124.155.79.161]) by mx.google.com with ESMTPS id b2sm1187434rvn.19.2010.05.04.06.01.21 (version=SSLv3 cipher=RC4-MD5); Tue, 04 May 2010 06:01:23 -0700 (PDT) Date: Tue, 4 May 2010 22:01:22 +0900 From: Takuya Yoshikawa To: Takuya Yoshikawa Subject: [RFC][PATCH 3/12] KVM: introduce wrapper functions to create and destroy dirty bitmaps Message-Id: <20100504220122.0706ea6b.takuya.yoshikawa@gmail.com> In-Reply-To: <20100504215645.6448af8f.takuya.yoshikawa@gmail.com> References: <20100504215645.6448af8f.takuya.yoshikawa@gmail.com> X-Mailer: Sylpheed 3.0.2 (GTK+ 2.20.0; i486-pc-linux-gnu) Mime-Version: 1.0 X-Mailman-Approved-At: Wed, 05 May 2010 01:27:55 +1000 Cc: linux-arch@vger.kernel.org, x86@kernel.org, arnd@arndb.de, kvm@vger.kernel.org, kvm-ia64@vger.kernel.org, fernando@oss.ntt.co.jp, mtosatti@redhat.com, agraf@suse.de, kvm-ppc@vger.kernel.org, linux-kernel@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp, linuxppc-dev@ozlabs.org, mingo@redhat.com, paulus@samba.org, avi@redhat.com, hpa@zytor.com, tglx@linutronix.de X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org We will change the vmalloc() and vfree() to do_mmap() and do_munmap() later. This patch makes it easy and cleanup the code. Signed-off-by: Takuya Yoshikawa Signed-off-by: Fernando Luis Vazquez Cao --- virt/kvm/kvm_main.c | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 7ab6312..3e3acad 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -435,6 +435,12 @@ out_err_nodisable: return ERR_PTR(r); } +static void kvm_destroy_dirty_bitmap(struct kvm_memory_slot *memslot) +{ + vfree(memslot->dirty_bitmap); + memslot->dirty_bitmap = NULL; +} + /* * Free any memory in @free but not in @dont. */ @@ -447,7 +453,7 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free, vfree(free->rmap); if (!dont || free->dirty_bitmap != dont->dirty_bitmap) - vfree(free->dirty_bitmap); + kvm_destroy_dirty_bitmap(free); for (i = 0; i < KVM_NR_PAGE_SIZES - 1; ++i) { @@ -458,7 +464,6 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free, } free->npages = 0; - free->dirty_bitmap = NULL; free->rmap = NULL; } @@ -520,6 +525,18 @@ static int kvm_vm_release(struct inode *inode, struct file *filp) return 0; } +static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot) +{ + unsigned long dirty_bytes = kvm_dirty_bitmap_bytes(memslot); + + memslot->dirty_bitmap = vmalloc(dirty_bytes); + if (!memslot->dirty_bitmap) + return -ENOMEM; + + memset(memslot->dirty_bitmap, 0, dirty_bytes); + return 0; +} + /* * Allocate some memory and give it an address in the guest physical address * space. @@ -653,12 +670,8 @@ skip_lpage: /* Allocate page dirty bitmap if needed */ if ((new.flags & KVM_MEM_LOG_DIRTY_PAGES) && !new.dirty_bitmap) { - unsigned long dirty_bytes = kvm_dirty_bitmap_bytes(&new); - - new.dirty_bitmap = vmalloc(dirty_bytes); - if (!new.dirty_bitmap) + if (kvm_create_dirty_bitmap(&new) < 0) goto out_free; - memset(new.dirty_bitmap, 0, dirty_bytes); /* destroy any largepage mappings for dirty tracking */ if (old.npages) flush_shadow = 1;