From: Anish Moorthy <amoorthy@google.com>
To: seanjc@google.com, kvm@vger.kernel.org, kvmarm@lists.linux.dev
Cc: oliver.upton@linux.dev, pbonzini@redhat.com, maz@kernel.org,
robert.hoo.linux@gmail.com, jthoughton@google.com,
amoorthy@google.com, dmatlack@google.com,
axelrasmussen@google.com, peterx@redhat.com,
nadav.amit@gmail.com, isaku.yamahata@gmail.com,
kconsul@linux.vnet.ibm.com
Subject: [PATCH v6 09/14] KVM: arm64: Enable KVM_CAP_EXIT_ON_MISSING and annotate an EFAULT from stage-2 fault-handler
Date: Thu, 9 Nov 2023 21:03:20 +0000 [thread overview]
Message-ID: <20231109210325.3806151-10-amoorthy@google.com> (raw)
In-Reply-To: <20231109210325.3806151-1-amoorthy@google.com>
Prevent the stage-2 fault handler from faulting in pages when
KVM_MEM_EXIT_ON_MISSING is set by allowing its __gfn_to_pfn_memslot()
calls to check the memslot flag.
To actually make that behavior useful, prepare a KVM_EXIT_MEMORY_FAULT
when the stage-2 handler cannot resolve the pfn for a fault. With
KVM_MEM_EXIT_ON_MISSING enabled this effects the delivery of stage-2
faults as vCPU exits, which userspace can attempt to resolve without
terminating the guest.
Delivering stage-2 faults to userspace in this way sidesteps the
significant scalabiliy issues associated with using userfaultfd for the
same purpose.
Signed-off-by: Anish Moorthy <amoorthy@google.com>
---
Documentation/virt/kvm/api.rst | 2 +-
arch/arm64/kvm/Kconfig | 1 +
arch/arm64/kvm/mmu.c | 7 +++++--
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index fd87bbfbfdf2..67fcb9dbe855 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -8068,7 +8068,7 @@ See KVM_EXIT_MEMORY_FAULT for more information.
7.35 KVM_CAP_EXIT_ON_MISSING
----------------------------
-:Architectures: x86
+:Architectures: x86, arm64
:Returns: Informational only, -EINVAL on direct KVM_ENABLE_CAP.
The presence of this capability indicates that userspace may set the
diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig
index 1a777715199f..d6fae31f7e1a 100644
--- a/arch/arm64/kvm/Kconfig
+++ b/arch/arm64/kvm/Kconfig
@@ -43,6 +43,7 @@ menuconfig KVM
select GUEST_PERF_EVENTS if PERF_EVENTS
select INTERVAL_TREE
select XARRAY_MULTI
+ select HAVE_KVM_EXIT_ON_MISSING
help
Support hosting virtualized guest machines.
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 13066a6fdfff..3b9fb80672ac 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1486,13 +1486,16 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
mmap_read_unlock(current->mm);
pfn = __gfn_to_pfn_memslot(memslot, gfn, false, false, NULL,
- write_fault, &writable, false, NULL);
+ write_fault, &writable, true, NULL);
if (pfn == KVM_PFN_ERR_HWPOISON) {
kvm_send_hwpoison_signal(hva, vma_shift);
return 0;
}
- if (is_error_noslot_pfn(pfn))
+ if (is_error_noslot_pfn(pfn)) {
+ kvm_prepare_memory_fault_exit(vcpu, gfn * PAGE_SIZE, PAGE_SIZE,
+ write_fault, exec_fault, false);
return -EFAULT;
+ }
if (kvm_is_device_pfn(pfn)) {
/*
--
2.42.0.869.gea05f2083d-goog
next prev parent reply other threads:[~2023-11-09 21:03 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-09 21:03 [PATCH v6 00/14] Improve KVM + userfaultfd performance via KVM_MEMORY_FAULT_EXITs on stage-2 faults Anish Moorthy
2023-11-09 21:03 ` [PATCH v6 01/14] KVM: Documentation: Clarify meaning of hva_to_pfn()'s 'atomic' parameter Anish Moorthy
2024-02-07 15:26 ` Sean Christopherson
2024-02-07 18:44 ` Anish Moorthy
2023-11-09 21:03 ` [PATCH v6 02/14] KVM: Documentation: Add docstrings for __kvm_read/write_guest_page() Anish Moorthy
2024-02-07 15:30 ` Sean Christopherson
2023-11-09 21:03 ` [PATCH v6 03/14] KVM: Simplify error handling in __gfn_to_pfn_memslot() Anish Moorthy
2023-11-09 21:03 ` [PATCH v6 04/14] KVM: Define and communicate KVM_EXIT_MEMORY_FAULT RWX flags to userspace Anish Moorthy
2024-02-07 15:30 ` Sean Christopherson
2024-02-07 18:57 ` Anish Moorthy
2023-11-09 21:03 ` [PATCH v6 05/14] KVM: Try using fast GUP to resolve read faults Anish Moorthy
2024-02-05 21:55 ` Anish Moorthy
2023-11-09 21:03 ` [PATCH v6 06/14] KVM: Add memslot flag to let userspace force an exit on missing hva mappings Anish Moorthy
2024-01-31 0:25 ` James Houghton
2024-01-31 21:59 ` Anish Moorthy
2024-02-01 0:26 ` James Houghton
2024-02-01 1:19 ` Oliver Upton
2024-02-01 16:28 ` Sean Christopherson
2024-02-01 19:24 ` Anish Moorthy
2024-02-02 1:03 ` Oliver Upton
2024-02-02 1:01 ` Oliver Upton
2024-02-01 16:09 ` Sean Christopherson
2024-02-01 19:53 ` Anish Moorthy
2024-02-07 15:35 ` Sean Christopherson
2023-11-09 21:03 ` [PATCH v6 07/14] KVM: x86: Enable KVM_CAP_EXIT_ON_MISSING and annotate EFAULTs from stage-2 fault handler Anish Moorthy
2023-11-09 21:03 ` [PATCH v6 08/14] KVM: arm64: Enable KVM_CAP_MEMORY_FAULT_INFO Anish Moorthy
2023-11-09 21:07 ` Anish Moorthy
2024-02-07 15:39 ` Sean Christopherson
2024-02-07 16:41 ` Oliver Upton
2024-02-07 21:21 ` Anish Moorthy
2024-02-07 21:41 ` Sean Christopherson
2024-02-07 22:07 ` Oliver Upton
2024-02-09 1:13 ` Anish Moorthy
2023-11-09 21:03 ` Anish Moorthy [this message]
2024-01-30 23:58 ` [PATCH v6 09/14] KVM: arm64: Enable KVM_CAP_EXIT_ON_MISSING and annotate an EFAULT from stage-2 fault-handler James Houghton
2024-01-31 22:38 ` Anish Moorthy
2024-02-09 1:21 ` Anish Moorthy
2023-11-09 21:03 ` [PATCH v6 10/14] KVM: selftests: Report per-vcpu demand paging rate from demand paging test Anish Moorthy
2023-11-09 21:03 ` [PATCH v6 11/14] KVM: selftests: Allow many vCPUs and reader threads per UFFD in " Anish Moorthy
2023-11-09 21:03 ` [PATCH v6 12/14] KVM: selftests: Use EPOLL in userfaultfd_util reader threads and signal errors via TEST_ASSERT Anish Moorthy
2023-11-09 21:03 ` [PATCH v6 13/14] KVM: selftests: Add memslot_flags parameter to memstress_create_vm() Anish Moorthy
2023-11-09 21:03 ` [PATCH v6 14/14] KVM: selftests: Handle memory fault exits in demand_paging_test Anish Moorthy
2024-02-07 15:46 ` [PATCH v6 00/14] Improve KVM + userfaultfd performance via KVM_MEMORY_FAULT_EXITs on stage-2 faults Sean Christopherson
2024-02-09 16:00 ` Anish Moorthy
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=20231109210325.3806151-10-amoorthy@google.com \
--to=amoorthy@google.com \
--cc=axelrasmussen@google.com \
--cc=dmatlack@google.com \
--cc=isaku.yamahata@gmail.com \
--cc=jthoughton@google.com \
--cc=kconsul@linux.vnet.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=nadav.amit@gmail.com \
--cc=oliver.upton@linux.dev \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=robert.hoo.linux@gmail.com \
--cc=seanjc@google.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).