* [PATCH] KVM: SVM: limit kvm_handle_page_fault to #PF handling
@ 2017-10-10 8:49 Paolo Bonzini
2017-10-10 19:01 ` Radim Krčmář
2017-10-11 15:30 ` Brijesh Singh
0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2017-10-10 8:49 UTC (permalink / raw)
To: linux-kernel, kvm; +Cc: Brijesh Singh
It has always annoyed me a bit how SVM_EXIT_NPF is handled by
pf_interception. This is also the only reason behind the
under-documented need_unprotect argument to kvm_handle_page_fault.
Let NPF go straight to kvm_mmu_page_fault, just like VMX
does in handle_ept_violation and handle_ept_misconfig.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/mmu.c | 5 ++---
arch/x86/kvm/mmu.h | 3 +--
arch/x86/kvm/svm.c | 15 +++++++++++++--
arch/x86/kvm/vmx.c | 3 +--
4 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index d6fba5684ca8..1706683d5fd7 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -3820,8 +3820,7 @@ static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn,
}
int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,
- u64 fault_address, char *insn, int insn_len,
- bool need_unprotect)
+ u64 fault_address, char *insn, int insn_len)
{
int r = 1;
@@ -3829,7 +3828,7 @@ int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,
default:
trace_kvm_page_fault(fault_address, error_code);
- if (need_unprotect && kvm_event_needs_reinjection(vcpu))
+ if (kvm_event_needs_reinjection(vcpu))
kvm_mmu_unprotect_page_virt(vcpu, fault_address);
r = kvm_mmu_page_fault(vcpu, fault_address, error_code, insn,
insn_len);
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index 64a2dbd2b1af..1092302aa16a 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -65,8 +65,7 @@ void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly,
bool accessed_dirty);
bool kvm_can_do_async_pf(struct kvm_vcpu *vcpu);
int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,
- u64 fault_address, char *insn, int insn_len,
- bool need_unprotect);
+ u64 fault_address, char *insn, int insn_len);
static inline unsigned int kvm_mmu_available_pages(struct kvm *kvm)
{
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 0e68f0b3cbf7..01e6e8fab5d6 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -2144,7 +2144,18 @@ static int pf_interception(struct vcpu_svm *svm)
return kvm_handle_page_fault(&svm->vcpu, error_code, fault_address,
svm->vmcb->control.insn_bytes,
- svm->vmcb->control.insn_len, !npt_enabled);
+ svm->vmcb->control.insn_len);
+}
+
+static int npf_interception(struct vcpu_svm *svm)
+{
+ u64 fault_address = svm->vmcb->control.exit_info_2;
+ u64 error_code = svm->vmcb->control.exit_info_1;
+
+ trace_kvm_page_fault(fault_address, error_code);
+ return kvm_mmu_page_fault(&svm->vcpu, error_code, fault_address,
+ svm->vmcb->control.insn_bytes,
+ svm->vmcb->control.insn_len);
}
static int db_interception(struct vcpu_svm *svm)
@@ -4131,7 +4142,7 @@ static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = {
[SVM_EXIT_MONITOR] = monitor_interception,
[SVM_EXIT_MWAIT] = mwait_interception,
[SVM_EXIT_XSETBV] = xsetbv_interception,
- [SVM_EXIT_NPF] = pf_interception,
+ [SVM_EXIT_NPF] = npf_interception,
[SVM_EXIT_RSM] = emulate_on_interception,
[SVM_EXIT_AVIC_INCOMPLETE_IPI] = avic_incomplete_ipi_interception,
[SVM_EXIT_AVIC_UNACCELERATED_ACCESS] = avic_unaccelerated_access_interception,
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 74582375e0be..c9214e3a01df 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -5894,8 +5894,7 @@ static int handle_exception(struct kvm_vcpu *vcpu)
cr2 = vmcs_readl(EXIT_QUALIFICATION);
/* EPT won't cause page fault directly */
WARN_ON_ONCE(!vcpu->arch.apf.host_apf_reason && enable_ept);
- return kvm_handle_page_fault(vcpu, error_code, cr2, NULL, 0,
- true);
+ return kvm_handle_page_fault(vcpu, error_code, cr2, NULL, 0);
}
ex_no = intr_info & INTR_INFO_VECTOR_MASK;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: SVM: limit kvm_handle_page_fault to #PF handling
2017-10-10 8:49 [PATCH] KVM: SVM: limit kvm_handle_page_fault to #PF handling Paolo Bonzini
@ 2017-10-10 19:01 ` Radim Krčmář
2017-10-11 15:30 ` Brijesh Singh
1 sibling, 0 replies; 3+ messages in thread
From: Radim Krčmář @ 2017-10-10 19:01 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: linux-kernel, kvm, Brijesh Singh
2017-10-10 10:49+0200, Paolo Bonzini:
> It has always annoyed me a bit how SVM_EXIT_NPF is handled by
> pf_interception. This is also the only reason behind the
> under-documented need_unprotect argument to kvm_handle_page_fault.
> Let NPF go straight to kvm_mmu_page_fault, just like VMX
> does in handle_ept_violation and handle_ept_misconfig.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
And we also drop the unneeded pv async_pf switch,
Reviewed-by: Radim Krčmář <rkrcmar@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: SVM: limit kvm_handle_page_fault to #PF handling
2017-10-10 8:49 [PATCH] KVM: SVM: limit kvm_handle_page_fault to #PF handling Paolo Bonzini
2017-10-10 19:01 ` Radim Krčmář
@ 2017-10-11 15:30 ` Brijesh Singh
1 sibling, 0 replies; 3+ messages in thread
From: Brijesh Singh @ 2017-10-11 15:30 UTC (permalink / raw)
To: Paolo Bonzini, linux-kernel, kvm; +Cc: brijesh.singh
Hi Paolo,
On 10/10/2017 03:49 AM, Paolo Bonzini wrote:
...
> +
> +static int npf_interception(struct vcpu_svm *svm)
> +{
> + u64 fault_address = svm->vmcb->control.exit_info_2;
> + u64 error_code = svm->vmcb->control.exit_info_1;
> +
> + trace_kvm_page_fault(fault_address, error_code);
> + return kvm_mmu_page_fault(&svm->vcpu, error_code, fault_address,
^^^^^^^ ^^^^^
The argument order need to be swapped, second argument should be
'fault_address' and third 'error_code'
return kvm_mmu_page_fault(&svm->vcpu, fault_address, error_code,
svm->vmcb->control.insn_bytes,
svm->vmcb->control.insn_len);
With that fixed.
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-11 15:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-10 8:49 [PATCH] KVM: SVM: limit kvm_handle_page_fault to #PF handling Paolo Bonzini
2017-10-10 19:01 ` Radim Krčmář
2017-10-11 15:30 ` Brijesh Singh
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).