From: Nikita Kalyazin <kalyazin@amazon.com>
To: <pbonzini@redhat.com>, <seanjc@google.com>, <corbet@lwn.net>,
<tglx@linutronix.de>, <mingo@redhat.com>, <bp@alien8.de>,
<dave.hansen@linux.intel.com>, <hpa@zytor.com>,
<rostedt@goodmis.org>, <mhiramat@kernel.org>,
<mathieu.desnoyers@efficios.com>, <kvm@vger.kernel.org>,
<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-trace-kernel@vger.kernel.org>
Cc: <jthoughton@google.com>, <david@redhat.com>, <peterx@redhat.com>,
<oleg@redhat.com>, <vkuznets@redhat.com>, <gshan@redhat.com>,
<graf@amazon.de>, <jgowans@amazon.com>, <roypat@amazon.co.uk>,
<derekmn@amazon.com>, <nsaenz@amazon.es>, <xmarcalx@amazon.com>,
<kalyazin@amazon.com>
Subject: [RFC PATCH 0/6] KVM: x86: async PF user
Date: Mon, 18 Nov 2024 12:39:42 +0000 [thread overview]
Message-ID: <20241118123948.4796-1-kalyazin@amazon.com> (raw)
Async PF [1] allows to run other processes on a vCPU while the host
handles a stage-2 fault caused by a process on that vCPU. When using
VM-exit-based stage-2 fault handling [2], async PF functionality is lost
because KVM does not run the vCPU while a fault is being handled so no
other process can execute on the vCPU. This patch series extends
VM-exit-based stage-2 fault handling with async PF support by letting
userspace handle faults instead of the kernel, hence the "async PF user"
name.
I circulated the idea with Paolo, Sean, David H, and James H at the LPC,
and the only concern I heard was about injecting the "page not present"
event via #PF exception in the CoCo case, where it may not work. In my
implementation, I reused the existing code for doing that, so the async
PF user implementation is on par with the present async PF
implementation in this regard, and support for the CoCo case can be
added separately.
Please note that this series is applied on top of the VM-exit-based
stage-2 fault handling RFC [2].
Implementation
The following workflow is implemented:
- A process in the guest causes a stage-2 fault.
- KVM checks whether the fault can be handled asynchronously. If it
can, KVM prepares the VM exit info that contains a newly added "async
PF flag" raised and an async PF token value corresponding to the
fault.
- Userspace reads the VM exit info and resumes the vCPU immediately.
Meanwhile it processes the fault.
- When the fault is resolved, userspace calls a new async ioctl using
the token to notify KVM.
- KVM communicates to the guest that the process can be resumed.
Notes:
- No changes to the x86 async PF PV interface are required
- The series does not introduce new dependencies on x86 compared to the
existing async PF
Testing
Inspired by [3], I built a Firecracker-based setup, where Firecracker
implemented the VM-exit-based fault handling. I observed that a workload
consisting of a CPU-bound and memory-bound threads running concurrently
was executing faster with async PF user enabled: with 10 ms-long fault
processing, it was 26% faster.
It is difficult to provide an objective performance comparison between
async PF kernel and async PF user, because async PF user can only work
with VM-exit-based fault handling, which has its own performance
characteristics compared to in-kernel fault handling or UserfaultFD.
The patch series is built on top of the VM-exit-based stage-2 fault
handling RFC [2].
Patch 1 updates documentation to reflect [2] changes.
Patches 2-6 add the implementation of async PF user.
Questions:
- Are there any general concerns about the approach?
- Can we leave the CoCo use case aside for now, or do we need to
support it straight away?
- What is the desired level of coupling between async PF and async PF
user? For now, I kept the coupling to the bare minimum (only the
PV-related data structure is shared between the two).
[1] https://kvm-forum.qemu.org/2021/sdei_apf_for_arm64_gavin.pdf
[2] https://lore.kernel.org/kvm/CADrL8HUHRMwUPhr7jLLBgD9YLFAnVHc=N-C=8er-x6GUtV97pQ@mail.gmail.com/T/
[3] https://lore.kernel.org/all/20200508032919.52147-1-gshan@redhat.com/
Nikita
Nikita Kalyazin (6):
Documentation: KVM: add userfault KVM exit flag
Documentation: KVM: add async pf user doc
KVM: x86: add async ioctl support
KVM: trace events: add type argument to async pf
KVM: x86: async_pf_user: add infrastructure
KVM: x86: async_pf_user: hook to fault handling and add ioctl
Documentation/virt/kvm/api.rst | 35 ++++++
arch/x86/include/asm/kvm_host.h | 12 +-
arch/x86/kvm/Kconfig | 7 ++
arch/x86/kvm/lapic.c | 2 +
arch/x86/kvm/mmu/mmu.c | 68 ++++++++++-
arch/x86/kvm/x86.c | 101 +++++++++++++++-
arch/x86/kvm/x86.h | 2 +
include/linux/kvm_host.h | 30 +++++
include/linux/kvm_types.h | 1 +
include/trace/events/kvm.h | 50 +++++---
include/uapi/linux/kvm.h | 12 +-
virt/kvm/Kconfig | 3 +
virt/kvm/Makefile.kvm | 1 +
virt/kvm/async_pf.c | 2 +-
virt/kvm/async_pf_user.c | 197 ++++++++++++++++++++++++++++++++
virt/kvm/async_pf_user.h | 24 ++++
virt/kvm/kvm_main.c | 14 +++
17 files changed, 535 insertions(+), 26 deletions(-)
create mode 100644 virt/kvm/async_pf_user.c
create mode 100644 virt/kvm/async_pf_user.h
base-commit: 15f01813426bf9672e2b24a5bac7b861c25de53b
--
2.40.1
next reply other threads:[~2024-11-18 12:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-18 12:39 Nikita Kalyazin [this message]
2024-11-18 12:39 ` [RFC PATCH 1/6] Documentation: KVM: add userfault KVM exit flag Nikita Kalyazin
2024-11-18 12:39 ` [RFC PATCH 2/6] Documentation: KVM: add async pf user doc Nikita Kalyazin
2024-11-18 12:39 ` [RFC PATCH 3/6] KVM: x86: add async ioctl support Nikita Kalyazin
2024-11-18 12:39 ` [RFC PATCH 4/6] KVM: trace events: add type argument to async pf Nikita Kalyazin
2024-11-18 12:39 ` [RFC PATCH 5/6] KVM: x86: async_pf_user: add infrastructure Nikita Kalyazin
2024-11-18 12:39 ` [RFC PATCH 6/6] KVM: x86: async_pf_user: hook to fault handling and add ioctl Nikita Kalyazin
2024-11-19 1:26 ` [RFC PATCH 0/6] KVM: x86: async PF user James Houghton
2024-11-19 16:19 ` Nikita Kalyazin
2025-02-11 21:17 ` Sean Christopherson
2025-02-12 18:14 ` Nikita Kalyazin
2025-02-19 15:17 ` Sean Christopherson
2025-02-20 18:29 ` Nikita Kalyazin
2025-02-20 18:49 ` Sean Christopherson
2025-02-21 11:02 ` Nikita Kalyazin
2025-02-26 0:58 ` Sean Christopherson
2025-02-26 17:07 ` Nikita Kalyazin
2025-02-27 16:44 ` Sean Christopherson
2025-02-27 18:24 ` Nikita Kalyazin
2025-02-27 23:47 ` Sean Christopherson
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=20241118123948.4796-1-kalyazin@amazon.com \
--to=kalyazin@amazon.com \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=david@redhat.com \
--cc=derekmn@amazon.com \
--cc=graf@amazon.de \
--cc=gshan@redhat.com \
--cc=hpa@zytor.com \
--cc=jgowans@amazon.com \
--cc=jthoughton@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=nsaenz@amazon.es \
--cc=oleg@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=rostedt@goodmis.org \
--cc=roypat@amazon.co.uk \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=xmarcalx@amazon.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