Commit 8b0cedff authored by Xiao Guangrong's avatar Xiao Guangrong Committed by Avi Kivity

KVM: use __copy_to_user/__clear_user to write guest page

Simply use __copy_to_user/__clear_user to write guest page since we have
already verified the user address when the memslot is set
Signed-off-by: default avatarXiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent 332b207d
...@@ -1388,7 +1388,7 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) ...@@ -1388,7 +1388,7 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
return 1; return 1;
kvm_x86_ops->patch_hypercall(vcpu, instructions); kvm_x86_ops->patch_hypercall(vcpu, instructions);
((unsigned char *)instructions)[3] = 0xc3; /* ret */ ((unsigned char *)instructions)[3] = 0xc3; /* ret */
if (copy_to_user((void __user *)addr, instructions, 4)) if (__copy_to_user((void __user *)addr, instructions, 4))
return 1; return 1;
kvm->arch.hv_hypercall = data; kvm->arch.hv_hypercall = data;
break; break;
...@@ -1415,7 +1415,7 @@ static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data) ...@@ -1415,7 +1415,7 @@ static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT); HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT);
if (kvm_is_error_hva(addr)) if (kvm_is_error_hva(addr))
return 1; return 1;
if (clear_user((void __user *)addr, PAGE_SIZE)) if (__clear_user((void __user *)addr, PAGE_SIZE))
return 1; return 1;
vcpu->arch.hv_vapic = data; vcpu->arch.hv_vapic = data;
break; break;
......
...@@ -1345,7 +1345,7 @@ int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data, ...@@ -1345,7 +1345,7 @@ int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
addr = gfn_to_hva(kvm, gfn); addr = gfn_to_hva(kvm, gfn);
if (kvm_is_error_hva(addr)) if (kvm_is_error_hva(addr))
return -EFAULT; return -EFAULT;
r = copy_to_user((void __user *)addr + offset, data, len); r = __copy_to_user((void __user *)addr + offset, data, len);
if (r) if (r)
return -EFAULT; return -EFAULT;
mark_page_dirty(kvm, gfn); mark_page_dirty(kvm, gfn);
...@@ -1405,7 +1405,7 @@ int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, ...@@ -1405,7 +1405,7 @@ int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
if (kvm_is_error_hva(ghc->hva)) if (kvm_is_error_hva(ghc->hva))
return -EFAULT; return -EFAULT;
r = copy_to_user((void __user *)ghc->hva, data, len); r = __copy_to_user((void __user *)ghc->hva, data, len);
if (r) if (r)
return -EFAULT; return -EFAULT;
mark_page_dirty_in_slot(kvm, ghc->memslot, ghc->gpa >> PAGE_SHIFT); mark_page_dirty_in_slot(kvm, ghc->memslot, ghc->gpa >> PAGE_SHIFT);
......
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