From: Marc Zyngier <maz@kernel.org>
To: <kvm@vger.kernel.org>, <kvmarm@lists.cs.columbia.edu>,
<linux-arm-kernel@lists.infradead.org>, <james.morse@arm.com>
Subject: Re: [PATCH 2/3] KVM: arm/arm64: Re-check VMA on detecting a poisoned page
Date: Thu, 12 Dec 2019 11:33:30 +0000 [thread overview]
Message-ID: <88f65ab4ac87f53534fbbfd2410d1cc5@www.loen.fr> (raw)
In-Reply-To: <20191211165651.7889-3-maz@kernel.org>
On 2019-12-11 16:56, Marc Zyngier wrote:
> When we check for a poisoned page, we use the VMA to tell userspace
> about the looming disaster. But we pass a pointer to this VMA
> after having released the mmap_sem, which isn't a good idea.
>
> Instead, re-check that we have still have a VMA, and that this
> VMA still points to a poisoned page. If the VMA isn't there,
> userspace is playing with our nerves, so lety's give it a -EFAULT
> (it deserves it). If the PFN isn't poisoned anymore, let's restart
> from the top and handle the fault again.
>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
> virt/kvm/arm/mmu.c | 25 +++++++++++++++++++++++--
> 1 file changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c
> index 0b32a904a1bb..f73393f5ddb7 100644
> --- a/virt/kvm/arm/mmu.c
> +++ b/virt/kvm/arm/mmu.c
> @@ -1741,9 +1741,30 @@ static int user_mem_abort(struct kvm_vcpu
> *vcpu, phys_addr_t fault_ipa,
>
> pfn = gfn_to_pfn_prot(kvm, gfn, write_fault, &writable);
> if (pfn == KVM_PFN_ERR_HWPOISON) {
> - kvm_send_hwpoison_signal(hva, vma);
> - return 0;
> + /*
> + * Search for the VMA again, as it may have been
> + * removed in the interval...
> + */
> + down_read(¤t->mm->mmap_sem);
> + vma = find_vma_intersection(current->mm, hva, hva + 1);
> + if (vma) {
> + /*
> + * Recheck for a poisoned page. If something changed
> + * behind our back, don't do a thing and take the
> + * fault again.
> + */
> + pfn = gfn_to_pfn_prot(kvm, gfn, write_fault, &writable);
> + if (pfn == KVM_PFN_ERR_HWPOISON)
> + kvm_send_hwpoison_signal(hva, vma);
> +
> + ret = 0;
> + } else {
> + ret = -EFAULT;
> + }
> + up_read(¤t->mm->mmap_sem);
> + return ret;
> }
> +
> if (is_error_noslot_pfn(pfn))
> return -EFAULT;
Revisiting this, I wonder if we're not better off just holding the
mmap_sem
for a bit longer. Something like:
diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c
index 0b32a904a1bb..87d416d000c6 100644
--- a/virt/kvm/arm/mmu.c
+++ b/virt/kvm/arm/mmu.c
@@ -1719,13 +1719,13 @@ static int user_mem_abort(struct kvm_vcpu
*vcpu, phys_addr_t fault_ipa,
if (vma_pagesize == PMD_SIZE ||
(vma_pagesize == PUD_SIZE && kvm_stage2_has_pmd(kvm)))
gfn = (fault_ipa & huge_page_mask(hstate_vma(vma))) >> PAGE_SHIFT;
- up_read(¤t->mm->mmap_sem);
-
/* We need minimum second+third level pages */
ret = mmu_topup_memory_cache(memcache, kvm_mmu_cache_min_pages(kvm),
KVM_NR_MEM_OBJS);
- if (ret)
+ if (ret) {
+ up_read(¤t->mm->mmap_sem);
return ret;
+ }
mmu_seq = vcpu->kvm->mmu_notifier_seq;
/*
@@ -1742,8 +1742,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu,
phys_addr_t fault_ipa,
pfn = gfn_to_pfn_prot(kvm, gfn, write_fault, &writable);
if (pfn == KVM_PFN_ERR_HWPOISON) {
kvm_send_hwpoison_signal(hva, vma);
+ up_read(¤t->mm->mmap_sem);
return 0;
}
+
+ up_read(¤t->mm->mmap_sem);
+
if (is_error_noslot_pfn(pfn))
return -EFAULT;
James, what do you think?
M.
--
Jazz is not dead. It just smells funny...
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-12-12 11:33 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-11 16:56 [PATCH 0/3] KVM: arm/arm64: user_mem_abort() assorted fixes Marc Zyngier
2019-12-11 16:56 ` [PATCH 1/3] KVM: arm/arm64: Properly handle faulting of device mappings Marc Zyngier
2019-12-11 17:53 ` Alexandru Elisei
2019-12-11 18:01 ` Marc Zyngier
2019-12-12 15:35 ` James Morse
2019-12-13 8:29 ` Christoffer Dall
2019-12-13 9:28 ` Marc Zyngier
2019-12-13 11:14 ` Christoffer Dall
2019-12-16 10:31 ` Marc Zyngier
2019-12-18 15:13 ` Christoffer Dall
2019-12-11 16:56 ` [PATCH 2/3] KVM: arm/arm64: Re-check VMA on detecting a poisoned page Marc Zyngier
2019-12-12 11:33 ` Marc Zyngier [this message]
2019-12-12 15:34 ` James Morse
2019-12-12 15:40 ` Marc Zyngier
2019-12-13 9:25 ` Christoffer Dall
2019-12-13 9:22 ` Christoffer Dall
2019-12-16 18:29 ` James Morse
2019-12-11 16:56 ` [PATCH 3/3] KVM: arm/arm64: Drop spurious message when faulting on a non-existent mapping Marc Zyngier
2019-12-13 9:26 ` Christoffer Dall
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=88f65ab4ac87f53534fbbfd2410d1cc5@www.loen.fr \
--to=maz@kernel.org \
--cc=james.morse@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
/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).