[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201020125504.xadmnhpf3pu4uva7@black.fi.intel.com>
Date: Tue, 20 Oct 2020 15:55:04 +0300
From: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: "Kirill A. Shutemov" <kirill@...temov.name>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Andy Lutomirski <luto@...nel.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>,
Liran Alon <liran.alon@...cle.com>,
Mike Rapoport <rppt@...nel.org>, x86@...nel.org,
kvm@...r.kernel.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: Re: [RFCv2 11/16] KVM: Protected memory extension
On Tue, Oct 20, 2020 at 09:17:01AM +0200, Peter Zijlstra wrote:
> On Tue, Oct 20, 2020 at 09:18:54AM +0300, Kirill A. Shutemov wrote:
> > +int __kvm_protect_memory(unsigned long start, unsigned long end, bool protect)
> > +{
> > + struct mm_struct *mm = current->mm;
> > + struct vm_area_struct *vma, *prev;
> > + int ret;
> > +
> > + if (mmap_write_lock_killable(mm))
> > + return -EINTR;
> > +
> > + ret = -ENOMEM;
> > + vma = find_vma(current->mm, start);
> > + if (!vma)
> > + goto out;
> > +
> > + ret = -EINVAL;
> > + if (vma->vm_start > start)
> > + goto out;
> > +
> > + if (start > vma->vm_start)
> > + prev = vma;
> > + else
> > + prev = vma->vm_prev;
> > +
> > + ret = 0;
> > + while (true) {
> > + unsigned long newflags, tmp;
> > +
> > + tmp = vma->vm_end;
> > + if (tmp > end)
> > + tmp = end;
> > +
> > + newflags = vma->vm_flags;
> > + if (protect)
> > + newflags |= VM_KVM_PROTECTED;
> > + else
> > + newflags &= ~VM_KVM_PROTECTED;
> > +
> > + /* The VMA has been handled as part of other memslot */
> > + if (newflags == vma->vm_flags)
> > + goto next;
> > +
> > + ret = mprotect_fixup(vma, &prev, start, tmp, newflags);
> > + if (ret)
> > + goto out;
> > +
> > +next:
> > + start = tmp;
> > + if (start < prev->vm_end)
> > + start = prev->vm_end;
> > +
> > + if (start >= end)
> > + goto out;
> > +
> > + vma = prev->vm_next;
> > + if (!vma || vma->vm_start != start) {
> > + ret = -ENOMEM;
> > + goto out;
> > + }
> > + }
> > +out:
> > + mmap_write_unlock(mm);
> > + return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(__kvm_protect_memory);
>
> Since migration will be disabled after this; should the above not (at
> the very least) force compaction before proceeding to lock the pages in?
Migration has to be implemented instead, before we hit upstream.
BTW, VMs with direct device assignment pins all guest memory today. So
it's not something new in the virtualization world.
--
Kirill A. Shutemov
Powered by blists - more mailing lists