From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: "Cédric Le Goater" <clg@kaod.org>,
kvm-ppc@vger.kernel.org, kvm@vger.kernel.org,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Paul Mackerras" <paulus@samba.org>
Subject: Re: [RFC PATCH] KVM: PPC: Book3S HV: add support for page faults in VM_IO|VM_PFNMAP vmas
Date: Fri, 09 Feb 2018 09:19:13 +1100 [thread overview]
Message-ID: <1518128353.2312.217.camel@kernel.crashing.org> (raw)
In-Reply-To: <20180208160303.19016-1-clg@kaod.org>
On Thu, 2018-02-08 at 17:03 +0100, Cédric Le Goater wrote:
>
> +/*
> + * Stolen from virt/kvm/kvm_main.c
> + */
Just export it. It's annoying that we can't just ues hva_to_pfn() ...
> +static int hva_to_pfn_remapped(struct vm_area_struct *vma,
> + unsigned long addr, bool write_fault,
> + unsigned long *p_pfn)
> +{
> + unsigned long pfn;
> + int r;
> +
> + r = follow_pfn(vma, addr, &pfn);
> + if (r) {
> + /*
> + * get_user_pages fails for VM_IO and VM_PFNMAP vmas and does
> + * not call the fault handler, so do it here.
> + */
> + bool unlocked = false;
> +
> + r = fixup_user_fault(current, current->mm, addr,
> + (write_fault ? FAULT_FLAG_WRITE : 0),
> + &unlocked);
> + if (unlocked)
> + return -EAGAIN;
> + if (r)
> + return r;
> +
> + r = follow_pfn(vma, addr, &pfn);
> + if (r)
> + return r;
> + }
> +
> + /*
> + * Get a reference here because callers of *hva_to_pfn* and
> + * *gfn_to_pfn* ultimately call kvm_release_pfn_clean on the
> + * returned pfn. This is only needed if the VMA has VM_MIXEDMAP
> + * set, but the kvm_get_pfn/kvm_release_pfn_clean pair will
> + * simply do nothing for reserved pfns.
> + *
> + * Whoever called remap_pfn_range is also going to call e.g.
> + * unmap_mapping_range before the underlying pages are freed,
> + * causing a call to our MMU notifier.
> + */
> + kvm_get_pfn(pfn);
> +
> + *p_pfn = pfn;
> + return 0;
> +}
> +
> int kvmppc_book3s_radix_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
> unsigned long ea, unsigned long dsisr)
> {
> @@ -402,8 +450,15 @@ int kvmppc_book3s_radix_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
> vma = find_vma(current->mm, hva);
> if (vma && vma->vm_start <= hva && hva < vma->vm_end &&
> (vma->vm_flags & VM_PFNMAP)) {
> - pfn = vma->vm_pgoff +
> - ((hva - vma->vm_start) >> PAGE_SHIFT);
> + if (vma->vm_flags & (VM_IO | VM_PFNMAP)) {
> + ret = hva_to_pfn_remapped(vma, hva, writing,
> + &pfn);
> + if (ret == -EAGAIN)
> + return RESUME_GUEST;
> + } else {
> + pfn = vma->vm_pgoff +
> + ((hva - vma->vm_start) >> PAGE_SHIFT);
> + }
I don't think the else case is useful. If fact you are checking
VM_PFNMAP twice...
> pgflags = pgprot_val(vma->vm_page_prot);
> }
> up_read(¤t->mm->mmap_sem);
next prev parent reply other threads:[~2018-02-08 22:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-08 16:03 [RFC PATCH] KVM: PPC: Book3S HV: add support for page faults in VM_IO|VM_PFNMAP vmas Cédric Le Goater
2018-02-08 22:19 ` Benjamin Herrenschmidt [this message]
2018-02-09 7:14 ` Cédric Le Goater
2018-02-09 15:01 ` Paolo Bonzini
2018-02-09 21:44 ` Benjamin Herrenschmidt
2018-02-12 9:57 ` Paolo Bonzini
2018-02-12 10:33 ` Benjamin Herrenschmidt
2018-02-12 10:41 ` Paolo Bonzini
2018-02-12 10:54 ` Benjamin Herrenschmidt
2018-02-12 11:01 ` Paolo Bonzini
2018-02-12 14:38 ` Benjamin Herrenschmidt
2018-02-12 14:41 ` Paolo Bonzini
2018-02-09 21:54 ` Benjamin Herrenschmidt
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=1518128353.2312.217.camel@kernel.crashing.org \
--to=benh@kernel.crashing.org \
--cc=clg@kaod.org \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=paulus@samba.org \
--cc=pbonzini@redhat.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).