From: Wanpeng Li <kernellwp@gmail.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>,
"Wanpeng Li" <wanpeng.li@hotmail.com>
Subject: [PATCH v5 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler
Date: Mon, 26 Jun 2017 18:46:59 -0700 [thread overview]
Message-ID: <1498528021-5115-3-git-send-email-wanpeng.li@hotmail.com> (raw)
In-Reply-To: <1498528021-5115-1-git-send-email-wanpeng.li@hotmail.com>
From: Wanpeng Li <wanpeng.li@hotmail.com>
This patch adds the L1 guest async page fault #PF vmexit handler, such
#PF is converted into vmexit from L2 to L1 on #PF which is then handled
by L1 similar to ordinary async page fault.
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
arch/x86/kvm/vmx.c | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index df825bb..f533cc1 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -616,6 +616,7 @@ struct vcpu_vmx {
bool emulation_required;
u32 exit_reason;
+ u32 apf_reason;
/* Posted interrupt descriptor */
struct pi_desc pi_desc;
@@ -5648,14 +5649,31 @@ static int handle_exception(struct kvm_vcpu *vcpu)
}
if (is_page_fault(intr_info)) {
- /* EPT won't cause page fault directly */
- BUG_ON(enable_ept);
cr2 = vmcs_readl(EXIT_QUALIFICATION);
- trace_kvm_page_fault(cr2, error_code);
+ switch (vmx->apf_reason) {
+ default:
+ /* EPT won't cause page fault directly */
+ BUG_ON(enable_ept);
+ trace_kvm_page_fault(cr2, error_code);
- if (kvm_event_needs_reinjection(vcpu))
- kvm_mmu_unprotect_page_virt(vcpu, cr2);
- return kvm_mmu_page_fault(vcpu, cr2, error_code, NULL, 0);
+ if (kvm_event_needs_reinjection(vcpu))
+ kvm_mmu_unprotect_page_virt(vcpu, cr2);
+ return kvm_mmu_page_fault(vcpu, cr2, error_code, NULL, 0);
+ break;
+ case KVM_PV_REASON_PAGE_NOT_PRESENT:
+ vmx->apf_reason = 0;
+ local_irq_disable();
+ kvm_async_pf_task_wait(cr2);
+ local_irq_enable();
+ break;
+ case KVM_PV_REASON_PAGE_READY:
+ vmx->apf_reason = 0;
+ local_irq_disable();
+ kvm_async_pf_task_wake(cr2);
+ local_irq_enable();
+ break;
+ }
+ return 0;
}
ex_no = intr_info & INTR_INFO_VECTOR_MASK;
@@ -8602,6 +8620,10 @@ static void vmx_complete_atomic_exit(struct vcpu_vmx *vmx)
vmx->exit_intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
exit_intr_info = vmx->exit_intr_info;
+ /* if exit due to PF check for async PF */
+ if (is_page_fault(exit_intr_info))
+ vmx->apf_reason = kvm_read_and_reset_pf_reason();
+
/* Handle machine checks before interrupts are enabled */
if (is_machine_check(exit_intr_info))
kvm_machine_check();
--
2.7.4
next prev parent reply other threads:[~2017-06-27 1:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-27 1:46 [PATCH v5 0/4] KVM: async_pf: Fix async pf exception injection Wanpeng Li
2017-06-27 1:46 ` [PATCH v5 1/4] KVM: x86: Simple kvm_x86_ops->queue_exception parameter Wanpeng Li
2017-06-27 1:46 ` Wanpeng Li [this message]
2017-06-27 13:30 ` [PATCH v5 2/4] KVM: async_pf: Add L1 guest async_pf #PF vmexit handler Paolo Bonzini
2017-06-27 22:40 ` Wanpeng Li
2017-06-27 1:47 ` [PATCH v5 3/4] KVM: async_pf: Force a nested vmexit if the injected #PF is async_pf Wanpeng Li
2017-06-27 13:40 ` Paolo Bonzini
2017-06-27 1:47 ` [PATCH v5 4/4] KVM: async_pf: Let host know whether the guest support delivery async_pf as #PF vmexit Wanpeng Li
2017-06-27 13:19 ` Paolo Bonzini
2017-06-27 22:49 ` Wanpeng Li
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=1498528021-5115-3-git-send-email-wanpeng.li@hotmail.com \
--to=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=wanpeng.li@hotmail.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).