Re: [PATCH 03/12] KVM: x86: do not deliver asynchronous page faults if CR0.PG=0

From: Paolo Bonzini
Date: Fri Feb 11 2022 - 06:16:38 EST


On 2/11/22 00:16, Sean Christopherson wrote:
Third time's a charm...

if (kvm_pv_async_pf_enabled(vcpu))
return false;

if (vcpu->arch.apf.send_user_only &&
static_call(kvm_x86_get_cpl)(vcpu) == 0)
return false;

/* L1 CR0.PG=1 is guaranteed if the vCPU is in guest mode (L2). */
if (is_guest_mode(vcpu))
return !vcpu->arch.apf.delivery_as_pf_vmexit;

return is_paging(vcpu);



Went for this, but with slightly different final "if":

if (is_guest_mode(vcpu)) {
/*
* L1 needs to opt into the special #PF vmexits that are
* used to deliver async page faults.
*/
return vcpu->arch.apf.delivery_as_pf_vmexit;
} else {
/*
* Play it safe in case the guest does a quick real mode
* foray. The real mode IDT is unlikely to have a #PF
* exception setup.
*/
return is_paging(vcpu);
}

Paolo