lkml.org 
[lkml]   [2020]   [May]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC 06/16] KVM: Use GUP instead of copy_from/to_user() to access guest memory
On Tue, May 26, 2020 at 09:14:59AM +0300, Mike Rapoport wrote:
> On Fri, May 22, 2020 at 03:52:04PM +0300, Kirill A. Shutemov wrote:
> > New helpers copy_from_guest()/copy_to_guest() to be used if KVM memory
> > protection feature is enabled.
> >
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > ---
> > include/linux/kvm_host.h | 4 +++
> > virt/kvm/kvm_main.c | 78 ++++++++++++++++++++++++++++++++++------
> > 2 files changed, 72 insertions(+), 10 deletions(-)
> >
> > static int __kvm_read_guest_page(struct kvm_memory_slot *slot, gfn_t gfn,
> > - void *data, int offset, int len)
> > + void *data, int offset, int len,
> > + bool protected)
> > {
> > int r;
> > unsigned long addr;
> > @@ -2257,7 +2297,10 @@ static int __kvm_read_guest_page(struct kvm_memory_slot *slot, gfn_t gfn,
> > addr = gfn_to_hva_memslot_prot(slot, gfn, NULL);
> > if (kvm_is_error_hva(addr))
> > return -EFAULT;
> > - r = __copy_from_user(data, (void __user *)addr + offset, len);
> > + if (protected)
> > + r = copy_from_guest(data, addr + offset, len);
> > + else
> > + r = __copy_from_user(data, (void __user *)addr + offset, len);
>
> Maybe always use copy_{from,to}_guest() and move the 'if (protected)'
> there?
> If kvm is added to memory slot, it cab be the passed to copy_{to,from}_guest.

Right, Vitaly has pointed me to this already.

--
Kirill A. Shutemov

\
 
 \ /
  Last update: 2020-05-26 23:57    [W:0.147 / U:2.820 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site