From patchwork Tue Jun 22 09:13:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 107359 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o5M9DKfZ002259 for ; Tue, 22 Jun 2010 09:13:20 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932167Ab0FVJNS (ORCPT ); Tue, 22 Jun 2010 05:13:18 -0400 Received: from serv2.oss.ntt.co.jp ([222.151.198.100]:41862 "EHLO serv2.oss.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932077Ab0FVJNR (ORCPT ); Tue, 22 Jun 2010 05:13:17 -0400 Received: from serv2.oss.ntt.co.jp (localhost [127.0.0.1]) by serv2.oss.ntt.co.jp (Postfix) with ESMTP id A08A024822D; Tue, 22 Jun 2010 18:13:16 +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 8E93224822A; Tue, 22 Jun 2010 18:13:16 +0900 (JST) Received: from yshtky3.kern.oss.ntt.co.jp (unknown [172.17.1.73]) by serv1.oss.ntt.co.jp (Postfix) with SMTP id 7479413C2FF; Tue, 22 Jun 2010 18:13:16 +0900 (JST) Date: Tue, 22 Jun 2010 18:13:56 +0900 From: Takuya Yoshikawa To: avi@redhat.com, mtosatti@redhat.com, agraf@suse.de Cc: kvm@vger.kernel.org, kvm-ia64@vger.kernel.org, kvm-ppc@vger.kernel.org, takuya.yoshikawa@gmail.com Subject: [PATCH 3/4] KVM: cleanup: remove kvm_get_dirty_log() Message-Id: <20100622181356.b592b264.yoshikawa.takuya@oss.ntt.co.jp> In-Reply-To: <20100622180358.be8fd912.yoshikawa.takuya@oss.ntt.co.jp> References: <20100622180358.be8fd912.yoshikawa.takuya@oss.ntt.co.jp> X-Mailer: Sylpheed 3.0.2 (GTK+ 2.20.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, 22 Jun 2010 09:13:20 +0000 (UTC) diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c index 25ef888..78fc171 100644 --- a/arch/ia64/kvm/kvm-ia64.c +++ b/arch/ia64/kvm/kvm-ia64.c @@ -1818,10 +1818,10 @@ static void kvm_ia64_sync_dirty_log(struct kvm *kvm, int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) { - int r; + int r, i; unsigned long n; struct kvm_memory_slot *memslot; - int is_dirty = 0; + unsigned long is_dirty = 0; mutex_lock(&kvm->slots_lock); @@ -1835,15 +1835,23 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, goto out; kvm_ia64_sync_dirty_log(kvm, memslot); - r = kvm_get_dirty_log(kvm, log, &is_dirty); - if (r) - goto out; + + n = kvm_dirty_bitmap_bytes(memslot); + + 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) { kvm_flush_remote_tlbs(kvm); - n = kvm_dirty_bitmap_bytes(memslot); + r = -EFAULT; + if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) + goto out; memset(memslot->dirty_bitmap, 0, n); + } else { + r = -EFAULT; + if (clear_user(log->dirty_bitmap, n)) + goto out; } r = 0; out: diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index 801d9f3..bea6f7c 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -1185,28 +1185,43 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot; struct kvm_vcpu *vcpu; ulong ga, ga_end; - int is_dirty = 0; - int r; + unsigned long is_dirty = 0; + int r, i; unsigned long n; mutex_lock(&kvm->slots_lock); - r = kvm_get_dirty_log(kvm, log, &is_dirty); - if (r) + r = -EINVAL; + if (log->slot >= KVM_MEMORY_SLOTS) + goto out; + + memslot = &kvm->memslots->memslots[log->slot]; + r = -ENOENT; + if (!memslot->dirty_bitmap) goto out; + n = kvm_dirty_bitmap_bytes(memslot); + + 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) { - memslot = &kvm->memslots->memslots[log->slot]; - ga = memslot->base_gfn << PAGE_SHIFT; ga_end = ga + (memslot->npages << PAGE_SHIFT); kvm_for_each_vcpu(n, vcpu, kvm) kvmppc_mmu_pte_pflush(vcpu, ga, ga_end); - n = kvm_dirty_bitmap_bytes(memslot); + r = -EFAULT; + if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) + goto out; + memset(memslot->dirty_bitmap, 0, n); + } else { + r = -EFAULT; + if (clear_user(log->dirty_bitmap, n)) + goto out; } r = 0; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 2d96555..c2f81de 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -337,8 +337,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp, int kvm_dev_ioctl_check_extension(long ext); -int kvm_get_dirty_log(struct kvm *kvm, - struct kvm_dirty_log *log, int *is_dirty); int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 84a0906..1dc86ef 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -772,40 +772,6 @@ int kvm_vm_ioctl_set_memory_region(struct kvm *kvm, return kvm_set_memory_region(kvm, mem, user_alloc); } -int kvm_get_dirty_log(struct kvm *kvm, - struct kvm_dirty_log *log, int *is_dirty) -{ - struct kvm_memory_slot *memslot; - int r, i; - unsigned long n; - unsigned long any = 0; - - r = -EINVAL; - if (log->slot >= KVM_MEMORY_SLOTS) - goto out; - - memslot = &kvm->memslots->memslots[log->slot]; - r = -ENOENT; - if (!memslot->dirty_bitmap) - goto out; - - n = kvm_dirty_bitmap_bytes(memslot); - - for (i = 0; !any && i < n/sizeof(long); ++i) - any = memslot->dirty_bitmap[i]; - - r = -EFAULT; - if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) - goto out; - - if (any) - *is_dirty = 1; - - r = 0; -out: - return r; -} - void kvm_disable_largepages(void) { largepages_enabled = false;