On Mon, May 25, 2020 at 04:41:20PM +0200, Vitaly Kuznetsov wrote:
[..]
>  void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
>                                struct kvm_async_pf *work)
>  {
> -     struct x86_exception fault;
> +     struct kvm_lapic_irq irq = {
> +             .delivery_mode = APIC_DM_FIXED,
> +             .vector = vcpu->arch.apf.vec
> +     };
>  
>       if (work->wakeup_all)
>               work->arch.token = ~0; /* broadcast wakeup */
> @@ -10444,26 +10491,20 @@ void kvm_arch_async_page_present(struct kvm_vcpu 
> *vcpu,
>               kvm_del_async_pf_gfn(vcpu, work->arch.gfn);
>       trace_kvm_async_pf_ready(work->arch.token, work->cr2_or_gpa);
>  
> -     if (vcpu->arch.apf.msr_val & KVM_ASYNC_PF_ENABLED &&
> -         !apf_put_user_ready(vcpu, work->arch.token)) {
> -                     fault.vector = PF_VECTOR;
> -                     fault.error_code_valid = true;
> -                     fault.error_code = 0;
> -                     fault.nested_page_fault = false;
> -                     fault.address = work->arch.token;
> -                     fault.async_page_fault = true;
> -                     kvm_inject_page_fault(vcpu, &fault);
> -     }
> +     if (kvm_pv_async_pf_enabled(vcpu) &&
> +         !apf_put_user_ready(vcpu, work->arch.token))
> +             kvm_apic_set_irq(vcpu, &irq, NULL);
> +

Hi Vitaly,

Have a question about page ready events. 

Now we deliver PAGE_NOT_PRESENT page faults only if guest is not in
kernel mode. So say kernel tried to access a page and we halted cpu.
When page is available, we will inject page_ready interrupt. At
that time we don't seem to check whether page_not_present was injected
or not. 

IOW, we seem to deliver page_ready irrespective of the fact whether
PAGE_NOT_PRESENT was delivered or not. And that means we will be
sending page present tokens to guest. Guest will not have a state
associated with that token and think that page_not_present has
not been delivered yet and allocate an element in hash table for
future page_not_present event. And that will lead to memory leak
and token conflict etc.

While setting up async pf, should we keep track whether associated
page_not_present was delivered to guest or not and deliver page_ready
accordingly.

Thanks
Vivek

Reply via email to