From: Bharata B Rao <bharata@linux.ibm.com>
To: Paul Mackerras <paulus@ozlabs.org>
Cc: linuxram@us.ibm.com, cclaudio@linux.ibm.com,
kvm-ppc@vger.kernel.org, linux-mm@kvack.org, jglisse@redhat.com,
aneesh.kumar@linux.vnet.ibm.com, paulus@au1.ibm.com,
sukadev@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v4 1/6] kvmppc: HMM backend driver to manage pages of secure guest
Date: Tue, 9 Jul 2019 15:33:53 +0530 [thread overview]
Message-ID: <20190709100353.GA27933@in.ibm.com> (raw)
In-Reply-To: <20190617053106.lqwzibpsz4d2464z@oak.ozlabs.ibm.com>
On Mon, Jun 17, 2019 at 03:31:06PM +1000, Paul Mackerras wrote:
> On Tue, May 28, 2019 at 12:19:28PM +0530, Bharata B Rao wrote:
> > HMM driver for KVM PPC to manage page transitions of
> > secure guest via H_SVM_PAGE_IN and H_SVM_PAGE_OUT hcalls.
> >
> > H_SVM_PAGE_IN: Move the content of a normal page to secure page
> > H_SVM_PAGE_OUT: Move the content of a secure page to normal page
>
> Comments below...
>
> > @@ -4421,6 +4435,7 @@ static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *free,
> > struct kvm_memory_slot *dont)
> > {
> > if (!dont || free->arch.rmap != dont->arch.rmap) {
> > + kvmppc_hmm_release_pfns(free);
>
> I don't think this is the right place to do this. The memslot will
> have no pages mapped by this time, because higher levels of code will
> have called kvmppc_core_flush_memslot_hv() before calling this.
> Releasing the pfns should be done in that function.
In fact I can get rid of kvmppc_hmm_release_pfns() totally as we don't
have to do free the HMM pages like this explicitly. During guest shutdown
all these pages are dropped when unmap_vmas() is called.
>
> > diff --git a/arch/powerpc/kvm/book3s_hv_hmm.c b/arch/powerpc/kvm/book3s_hv_hmm.c
> > new file mode 100644
> > index 000000000000..713806003da3
>
> ...
>
> > +#define KVMPPC_PFN_HMM (0x1ULL << 61)
> > +
> > +static inline bool kvmppc_is_hmm_pfn(unsigned long pfn)
> > +{
> > + return !!(pfn & KVMPPC_PFN_HMM);
> > +}
>
> Since you are putting in these values in the rmap entries, you need to
> be careful about overlaps between these values and the other uses of
> rmap entries. The value you have chosen would be in the middle of the
> LPID field for an rmap entry for a guest that has nested guests, and
> in fact kvmhv_remove_nest_rmap_range() effectively assumes that a
> non-zero rmap entry must be a list of L2 guest mappings. (This is for
> radix guests; HPT guests use the rmap entry differently, but I am
> assuming that we will enforce that only radix guests can be secure
> guests.)
Worked out with Suraj on sharing the rmap and got a well defined
bit slot for HMM PFNs in rmap.
>
> Maybe it is true that the rmap entry will be non-zero only for those
> guest pages which are not mapped on the host side, that is,
> kvmppc_radix_flush_memslot() will see !pte_present(*ptep) for any page
> of a secure guest where the rmap entry contains a HMM pfn. If that is
> so and is a deliberate part of the design, then I would like to see it
> written down in comments and commit messages so it's clear to others
> working on the code in future.
Yes, rmap entry will be non-zero only for those guest pages which are
not mapped on the host side. However as soon as guest becomes secure
we free the HV side partition scoped page tables and hence
kvmppc_radix_flush_memslot() and other such routines which lookup
kvm->arch.pgtable will no longer touch it.
>
> Suraj is working on support for nested HPT guests, which will involve
> changing the rmap format to indicate more explicitly what sort of
> entry each rmap entry is. Please work with him to define a format for
> your rmap entries that is clearly distinguishable from the others.
>
> I think it is reasonable to say that a secure guest can't have nested
> guests, at least for now, but then we should make sure to kill all
> nested guests when a guest goes secure.
Ok. Yet to figure this part out.
>
> ...
>
> > +/*
> > + * Move page from normal memory to secure memory.
> > + */
> > +unsigned long
> > +kvmppc_h_svm_page_in(struct kvm *kvm, unsigned long gpa,
> > + unsigned long flags, unsigned long page_shift)
> > +{
> > + unsigned long addr, end;
> > + unsigned long src_pfn, dst_pfn;
> > + struct kvmppc_hmm_migrate_args args;
> > + struct vm_area_struct *vma;
> > + int srcu_idx;
> > + unsigned long gfn = gpa >> page_shift;
> > + struct kvm_memory_slot *slot;
> > + unsigned long *rmap;
> > + int ret = H_SUCCESS;
> > +
> > + if (page_shift != PAGE_SHIFT)
> > + return H_P3;
> > +
> > + srcu_idx = srcu_read_lock(&kvm->srcu);
> > + slot = gfn_to_memslot(kvm, gfn);
> > + rmap = &slot->arch.rmap[gfn - slot->base_gfn];
> > + addr = gfn_to_hva(kvm, gpa >> page_shift);
> > + srcu_read_unlock(&kvm->srcu, srcu_idx);
>
> Shouldn't we keep the srcu read lock until we have finished working on
> the page?
I wasn't sure, so keeping it locked till the end in the next version.
>
> > + if (kvm_is_error_hva(addr))
> > + return H_PARAMETER;
> > +
> > + end = addr + (1UL << page_shift);
> > +
> > + if (flags)
> > + return H_P2;
> > +
> > + args.rmap = rmap;
> > + args.lpid = kvm->arch.lpid;
> > + args.gpa = gpa;
> > + args.page_shift = page_shift;
> > +
> > + down_read(&kvm->mm->mmap_sem);
> > + vma = find_vma_intersection(kvm->mm, addr, end);
> > + if (!vma || vma->vm_start > addr || vma->vm_end < end) {
> > + ret = H_PARAMETER;
> > + goto out;
> > + }
> > + ret = migrate_vma(&kvmppc_hmm_migrate_ops, vma, addr, end,
> > + &src_pfn, &dst_pfn, &args);
> > + if (ret < 0)
> > + ret = H_PARAMETER;
> > +out:
> > + up_read(&kvm->mm->mmap_sem);
> > + return ret;
> > +}
>
> ...
>
> > +/*
> > + * Move page from secure memory to normal memory.
> > + */
> > +unsigned long
> > +kvmppc_h_svm_page_out(struct kvm *kvm, unsigned long gpa,
> > + unsigned long flags, unsigned long page_shift)
> > +{
> > + unsigned long addr, end;
> > + struct vm_area_struct *vma;
> > + unsigned long src_pfn, dst_pfn = 0;
> > + int srcu_idx;
> > + int ret = H_SUCCESS;
> > +
> > + if (page_shift != PAGE_SHIFT)
> > + return H_P3;
> > +
> > + if (flags)
> > + return H_P2;
> > +
> > + srcu_idx = srcu_read_lock(&kvm->srcu);
> > + addr = gfn_to_hva(kvm, gpa >> page_shift);
> > + srcu_read_unlock(&kvm->srcu, srcu_idx);
>
> and likewise here, shouldn't we unlock later, after the migrate_vma()
> call perhaps?
Sure.
Regards,
Bharata.
next prev parent reply other threads:[~2019-07-09 10:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-28 6:49 [PATCH v4 0/6] kvmppc: HMM driver to manage pages of secure guest Bharata B Rao
2019-05-28 6:49 ` [PATCH v4 1/6] kvmppc: HMM backend " Bharata B Rao
2019-06-17 5:31 ` Paul Mackerras
2019-07-09 10:03 ` Bharata B Rao [this message]
2019-05-28 6:49 ` [PATCH v4 2/6] kvmppc: Shared pages support for secure guests Bharata B Rao
2019-05-28 6:49 ` [PATCH v4 3/6] kvmppc: H_SVM_INIT_START and H_SVM_INIT_DONE hcalls Bharata B Rao
2019-06-17 5:37 ` Paul Mackerras
2019-07-09 10:04 ` Bharata B Rao
2019-06-18 23:05 ` Thiago Jung Bauermann
2019-07-09 10:05 ` Bharata B Rao
2019-05-28 6:49 ` [PATCH v4 4/6] kvmppc: Handle memory plug/unplug to secure VM Bharata B Rao
2019-06-17 5:38 ` Paul Mackerras
2019-05-28 6:49 ` [RFC PATCH v4 5/6] kvmppc: Radix changes for secure guest Bharata B Rao
2019-05-28 6:49 ` [RFC PATCH v4 6/6] kvmppc: Support reset of " Bharata B Rao
2019-06-17 4:06 ` Paul Mackerras
2019-07-09 10:06 ` Bharata B Rao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190709100353.GA27933@in.ibm.com \
--to=bharata@linux.ibm.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=cclaudio@linux.ibm.com \
--cc=jglisse@redhat.com \
--cc=kvm-ppc@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=linuxram@us.ibm.com \
--cc=paulus@au1.ibm.com \
--cc=paulus@ozlabs.org \
--cc=sukadev@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).