Commit e0506bcb authored by Izik Eidus's avatar Izik Eidus Committed by Avi Kivity

KVM: Change kvm_{read,write}_guest() to use copy_{from,to}_user()

This changes kvm_write_guest_page/kvm_read_guest_page to use
copy_to_user/read_from_user, as a result we get better speed
and better dirty bit tracking.
Signed-off-by: default avatarIzik Eidus <izike@qumranet.com>
Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
parent 539cb660
...@@ -630,20 +630,15 @@ static int next_segment(unsigned long len, int offset) ...@@ -630,20 +630,15 @@ static int next_segment(unsigned long len, int offset)
int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset, int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
int len) int len)
{ {
void *page_virt; int r;
struct page *page; unsigned long addr;
page = gfn_to_page(kvm, gfn); addr = gfn_to_hva(kvm, gfn);
if (is_error_page(page)) { if (kvm_is_error_hva(addr))
kvm_release_page(page); return -EFAULT;
r = copy_from_user(data, (void __user *)addr + offset, len);
if (r)
return -EFAULT; return -EFAULT;
}
page_virt = kmap_atomic(page, KM_USER0);
memcpy(data, page_virt + offset, len);
kunmap_atomic(page_virt, KM_USER0);
kvm_release_page(page);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(kvm_read_guest_page); EXPORT_SYMBOL_GPL(kvm_read_guest_page);
...@@ -671,21 +666,16 @@ EXPORT_SYMBOL_GPL(kvm_read_guest); ...@@ -671,21 +666,16 @@ EXPORT_SYMBOL_GPL(kvm_read_guest);
int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data, int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
int offset, int len) int offset, int len)
{ {
void *page_virt; int r;
struct page *page; unsigned long addr;
page = gfn_to_page(kvm, gfn); addr = gfn_to_hva(kvm, gfn);
if (is_error_page(page)) { if (kvm_is_error_hva(addr))
kvm_release_page(page); return -EFAULT;
r = copy_to_user((void __user *)addr + offset, data, len);
if (r)
return -EFAULT; return -EFAULT;
}
page_virt = kmap_atomic(page, KM_USER0);
memcpy(page_virt + offset, data, len);
kunmap_atomic(page_virt, KM_USER0);
mark_page_dirty(kvm, gfn); mark_page_dirty(kvm, gfn);
kvm_release_page(page);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(kvm_write_guest_page); EXPORT_SYMBOL_GPL(kvm_write_guest_page);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment