[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200526215622.r455gfohtufr45vj@box>
Date: Wed, 27 May 2020 00:56:22 +0300
From: "Kirill A. Shutemov" <kirill@...temov.name>
To: Mike Rapoport <rppt@...nel.org>
Cc: Dave Hansen <dave.hansen@...ux.intel.com>,
Andy Lutomirski <luto@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Paolo Bonzini <pbonzini@...hat.com>,
Sean Christopherson <sean.j.christopherson@...el.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>,
David Rientjes <rientjes@...gle.com>,
Andrea Arcangeli <aarcange@...hat.com>,
Kees Cook <keescook@...omium.org>,
Will Drewry <wad@...omium.org>,
"Edgecombe, Rick P" <rick.p.edgecombe@...el.com>,
"Kleen, Andi" <andi.kleen@...el.com>, x86@...nel.org,
kvm@...r.kernel.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org,
"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
Subject: Re: [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@...ux.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
Powered by blists - more mailing lists