From patchwork Wed Mar 17 07:49:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 86272 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 o2H7plV2003368 for ; Wed, 17 Mar 2010 07:51:47 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752732Ab0CQHvU (ORCPT ); Wed, 17 Mar 2010 03:51:20 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:50963 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752557Ab0CQHvT (ORCPT ); Wed, 17 Mar 2010 03:51:19 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id BB01C1700BD; Wed, 17 Mar 2010 15:51:17 +0800 (CST) Received: from fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id o2H7o5aT004513; Wed, 17 Mar 2010 15:50:05 +0800 Received: from [10.167.141.99] (unknown [10.167.141.99]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 75B80D490B; Wed, 17 Mar 2010 15:53:34 +0800 (CST) Message-ID: <4BA0897F.3050906@cn.fujitsu.com> Date: Wed, 17 Mar 2010 15:49:19 +0800 From: Xiao Guangrong User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: Avi Kivity CC: Takuya Yoshikawa , KVM list , LKML Subject: [PATCH v2] KVM: cleanup {kvm_vm_ioctl, kvm}_get_dirty_log() 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]); Wed, 17 Mar 2010 07:51:48 +0000 (UTC) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index bcf52d1..e6cbbd4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2644,22 +2644,17 @@ static int kvm_vm_ioctl_reinject(struct kvm *kvm, int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) { - int r, n, i; + int r, n, is_dirty = 0; struct kvm_memory_slot *memslot; - unsigned long is_dirty = 0; unsigned long *dirty_bitmap = NULL; mutex_lock(&kvm->slots_lock); - r = -EINVAL; - if (log->slot >= KVM_MEMORY_SLOTS) + r = kvm_get_dirty_log(kvm, log, &is_dirty); + if (r) goto out; memslot = &kvm->memslots->memslots[log->slot]; - r = -ENOENT; - if (!memslot->dirty_bitmap) - goto out; - n = ALIGN(memslot->npages, BITS_PER_LONG) / 8; r = -ENOMEM; @@ -2668,9 +2663,6 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, goto out; memset(dirty_bitmap, 0, n); - for (i = 0; !is_dirty && i < n/sizeof(long); i++) - is_dirty = memslot->dirty_bitmap[i]; - /* If nothing is dirty, don't bother messing with page tables. */ if (is_dirty) { struct kvm_memslots *slots, *old_slots; @@ -2694,8 +2686,7 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, } r = 0; - if (copy_to_user(log->dirty_bitmap, dirty_bitmap, n)) - r = -EFAULT; + out_free: vfree(dirty_bitmap); out: diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index bcd08b8..b08a7de 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -767,9 +767,7 @@ int kvm_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log, int *is_dirty) { struct kvm_memory_slot *memslot; - int r, i; - int n; - unsigned long any = 0; + int r, n, any = 0; r = -EINVAL; if (log->slot >= KVM_MEMORY_SLOTS) @@ -782,8 +780,7 @@ int kvm_get_dirty_log(struct kvm *kvm, n = ALIGN(memslot->npages, BITS_PER_LONG) / 8; - for (i = 0; !any && i < n/sizeof(long); ++i) - any = memslot->dirty_bitmap[i]; + any = !bitmap_empty(memslot->dirty_bitmap, memslot->npages); r = -EFAULT; if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n))