From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
David Matlack <dmatlack@google.com>,
Xu Yilun <yilun.xu@linux.intel.com>,
Sean Christopherson <seanjc@google.com>
Subject: Re: [PATCH 4/4] KVM: Nullify async #PF worker's "apf" pointer as soon as it might be freed
Date: Fri, 26 Jan 2024 17:30:24 +0100 [thread overview]
Message-ID: <87o7d883bz.fsf@redhat.com> (raw)
In-Reply-To: <20240110011533.503302-5-seanjc@google.com>
Sean Christopherson <seanjc@google.com> writes:
> Nullify the async #PF worker's local "apf" pointer immediately after the
> point where the structure can be freed by the vCPU. The existing comment
> is helpful, but easy to overlook as there is no associated code.
>
> Update the comment to clarify that it can be freed by as soon as the lock
> is dropped, as "after this point" isn't strictly accurate, nor does it
> help understand what prevents the structure from being freed earlier.
>
"No functional change intended." must be made a requirement, especially
for those who made it their trademark)
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> virt/kvm/async_pf.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c
> index c3f4f351a2ae..1088c6628de9 100644
> --- a/virt/kvm/async_pf.c
> +++ b/virt/kvm/async_pf.c
> @@ -83,13 +83,14 @@ static void async_pf_execute(struct work_struct *work)
> apf->vcpu = NULL;
> spin_unlock(&vcpu->async_pf.lock);
>
> - if (!IS_ENABLED(CONFIG_KVM_ASYNC_PF_SYNC) && first)
> - kvm_arch_async_page_present_queued(vcpu);
> -
> /*
> - * apf may be freed by kvm_check_async_pf_completion() after
> - * this point
> + * The apf struct may freed by kvm_check_async_pf_completion() as soon
Nit: "may be freed"/"may get freed" maybe?
> + * as the lock is dropped. Nullify it to prevent improper usage.
> */
> + apf = NULL;
> +
> + if (!IS_ENABLED(CONFIG_KVM_ASYNC_PF_SYNC) && first)
> + kvm_arch_async_page_present_queued(vcpu);
>
> trace_kvm_async_pf_completed(addr, cr2_or_gpa);
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
--
Vitaly
next prev parent reply other threads:[~2024-01-26 16:30 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-10 1:15 [PATCH 0/4] KVM: Async #PF fixes and cleanups Sean Christopherson
2024-01-10 1:15 ` [PATCH 1/4] KVM: Always flush async #PF workqueue when vCPU is being destroyed Sean Christopherson
2024-01-20 12:40 ` Xu Yilun
2024-01-24 19:04 ` Sean Christopherson
2024-01-26 7:36 ` Xu Yilun
2024-02-06 19:06 ` Sean Christopherson
2024-01-26 16:51 ` Vitaly Kuznetsov
2024-01-26 17:19 ` Sean Christopherson
2024-01-29 9:02 ` Vitaly Kuznetsov
2024-02-19 13:59 ` Xu Yilun
2024-02-19 15:51 ` Sean Christopherson
2024-02-20 3:02 ` Xu Yilun
2024-01-10 1:15 ` [PATCH 2/4] KVM: Put mm immediately after async #PF worker completes remote gup() Sean Christopherson
2024-01-20 15:24 ` Xu Yilun
2024-01-26 16:23 ` Vitaly Kuznetsov
2024-01-10 1:15 ` [PATCH 3/4] KVM: Get reference to VM's address space in the async #PF worker Sean Christopherson
2024-01-20 15:16 ` Xu Yilun
2024-01-24 18:52 ` Sean Christopherson
2024-01-26 8:06 ` Xu Yilun
2024-01-26 16:21 ` Vitaly Kuznetsov
2024-01-26 16:39 ` Sean Christopherson
2024-01-10 1:15 ` [PATCH 4/4] KVM: Nullify async #PF worker's "apf" pointer as soon as it might be freed Sean Christopherson
2024-01-20 15:24 ` Xu Yilun
2024-01-26 16:30 ` Vitaly Kuznetsov [this message]
2024-02-06 21:36 ` [PATCH 0/4] KVM: Async #PF fixes and cleanups Sean Christopherson
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=87o7d883bz.fsf@redhat.com \
--to=vkuznets@redhat.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=yilun.xu@linux.intel.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