Re: [PATCH v2] KVM: x86: Avoid guest page table walk when gpa_available is set

From: Brijesh Singh
Date: Tue Aug 08 2017 - 15:25:18 EST


Hi Radim,


On 07/20/2017 02:43 AM, Radim KrÄmÃÅ wrote:
2017-07-19 08:35-0500, Brijesh Singh:
On 07/19/2017 06:19 AM, Radim KrÄmÃÅ wrote:
2017-07-17 16:32-0500, Brijesh Singh:
Hi Paolo and Radim

Any comments on this patch, I could not find it in 4.13-2 branch.

Please let me know if you want to fix something, or want me to
refresh and resend the patch.

Sorry, I tried it during the merge window, but it didn't pass tests on
VMX and I got distracted by other bugs before looking into the cause.

Can you reproduce the fail?


No worries, thanks.

I can try to reproduce it, are you running kvm-unittest or something different?

I noticed that a linux guest hung in early boot, but at least (io)apic
kvm-unit-tests failed as well, IIRC.

IIRC, VMX does not set the gpa_available flag hence I am wondering what did I miss
in the patch to trigger the failure. I will debug it and let you know.

It does now, in ept_violation and ept_misconfig,


I am able to reproduce the issue on VMX, Sorry it took a bit longer to verify
it.

I was not aware that VMX is also making use of gpa_available flag hence I missed
updating the vmx.c to set the gpa_val. After applying the below small patch I am
able to boot the guest on Intel Xeon E5-2665.

Additionally, there was one issue in current patch pointed by Paolo [1]. If patch
was using vcpu->arch.gpa_val check as pointed by Paolo then on VMX we will silently
fallback to guest page table walk (even when gpa_available is set). I guess since I
have testing my code on SVM platform hence never caught the error. I will soon send
updated patch.

[1] http://marc.info/?l=kvm&m=150116338725964&w=2

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index b5e0b02..9309fbb 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -6309,6 +6309,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu)
? PFERR_PRESENT_MASK : 0;
vcpu->arch.gpa_available = true;
+ vcpu->arch.gpa_val = gpa;
vcpu->arch.exit_qualification = exit_qualification;
return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0);
@@ -6326,6 +6327,7 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu)
}
ret = handle_mmio_page_fault(vcpu, gpa, true);
+ vcpu->arch.gpa_val = gpa;
vcpu->arch.gpa_available = true;
if (likely(ret == RET_MMIO_PF_EMULATE))
return x86_emulate_instruction(vcpu, gpa, 0, NULL, 0) ==