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: 96747 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 o44D1t7f003423 for ; Tue, 4 May 2010 13:01:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759603Ab0EDNB0 (ORCPT ); Tue, 4 May 2010 09:01:26 -0400 Received: from mail-px0-f174.google.com ([209.85.212.174]:43236 "EHLO mail-px0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758726Ab0EDNBZ (ORCPT ); Tue, 4 May 2010 09:01:25 -0400 Received: by pxi5 with SMTP id 5so811798pxi.19 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 Cc: avi@redhat.com, mtosatti@redhat.com, agraf@suse.de, yoshikawa.takuya@oss.ntt.co.jp, fernando@oss.ntt.co.jp, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-ia64@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, benh@kernel.crashing.org, paulus@samba.org, linuxppc-dev@ozlabs.org, arnd@arndb.de, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org 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 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, 04 May 2010 13:01:55 +0000 (UTC) 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;