From patchwork Tue Apr 20 10:59:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 93650 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 o3KAtZUl007660 for ; Tue, 20 Apr 2010 10:55:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754495Ab0DTKzd (ORCPT ); Tue, 20 Apr 2010 06:55:33 -0400 Received: from serv2.oss.ntt.co.jp ([222.151.198.100]:46859 "EHLO serv2.oss.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754374Ab0DTKzc (ORCPT ); Tue, 20 Apr 2010 06:55:32 -0400 Received: from serv2.oss.ntt.co.jp (localhost [127.0.0.1]) by serv2.oss.ntt.co.jp (Postfix) with ESMTP id 157A124820B; Tue, 20 Apr 2010 19:55:31 +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 03DF62481F9; Tue, 20 Apr 2010 19:55:31 +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 E181B11C11D; Tue, 20 Apr 2010 19:55:30 +0900 (JST) Date: Tue, 20 Apr 2010 19:59:13 +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, fernando@oss.ntt.co.jp Subject: [PATCH RFC v2 3/6] KVM: introduce a wrapper function to copy dirty bitmaps to user space Message-Id: <20100420195913.ac44281c.yoshikawa.takuya@oss.ntt.co.jp> In-Reply-To: <20100420195349.dab60b1d.yoshikawa.takuya@oss.ntt.co.jp> References: <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:55:37 +0000 (UTC) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 76b23ed..6f0b706 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2771,9 +2771,7 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, kfree(old_slots); } - r = 0; - if (copy_to_user(log->dirty_bitmap, dirty_bitmap, n)) - r = -EFAULT; + r = kvm_copy_dirty_bitmap(log->dirty_bitmap, dirty_bitmap, n); out_free: vfree(dirty_bitmap); out: diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 4446622..42b7161 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -330,6 +330,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp, int kvm_dev_ioctl_check_extension(long ext); +int kvm_copy_dirty_bitmap(unsigned long __user *to, + const unsigned long *from, + unsigned long bytes); int kvm_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log); 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 40a6888..6908304 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -777,6 +777,16 @@ int kvm_vm_ioctl_set_memory_region(struct kvm *kvm, return kvm_set_memory_region(kvm, mem, user_alloc); } +int kvm_copy_dirty_bitmap(unsigned long __user *to, + const unsigned long *from, + unsigned long bytes) +{ + if (copy_to_user(to, from, bytes)) + return -EFAULT; + + return 0; +} + int kvm_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) { struct kvm_memory_slot *memslot; @@ -795,7 +805,7 @@ int kvm_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) n = kvm_dirty_bitmap_bytes(memslot); r = -EFAULT; - if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) + if (kvm_copy_dirty_bitmap(log->dirty_bitmap, memslot->dirty_bitmap, n)) goto out; r = 0;