From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Keith Busch <kbusch@kernel.org>
Subject: Re: [PATCH] KVM: x86/mmu: Ensure NX huge page recovery thread is alive before waking
Date: Fri, 24 Jan 2025 16:50:17 -0800 [thread overview]
Message-ID: <Z5Q1SQ-JI6PdmVbi@google.com> (raw)
In-Reply-To: <20250124234623.3609069-1-seanjc@google.com>
On Fri, Jan 24, 2025, Sean Christopherson wrote:
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index a45ae60e84ab..74c20dbb92da 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -7120,6 +7120,19 @@ static void mmu_destroy_caches(void)
> kmem_cache_destroy(mmu_page_header_cache);
> }
>
> +static void kvm_wake_nx_recovery_thread(struct kvm *kvm)
> +{
> + /*
> + * The NX recovery thread is spawned on-demand at the first KVM_RUN and
> + * may not be valid even though the VM is globally visible. Do nothing,
> + * as such a VM can't have any possible NX huge pages.
> + */
> + struct vhost_task *nx_thread = READ_ONCE(kvm->arch.nx_huge_page_recovery_thread);
> +
> + if (nx_thread)
> + vhost_task_wake(nx_thread);
As mentioned in the original thread[*], I belatedly realized there's a race with
this approach. If vhost_task_start() completes and kvm_nx_huge_page_recovery_worker()
runs before a parameter change, but the parameter change runs before the WRITE_ONCE(),
then the worker will run with stale params and could end up sleeping for far longer
than userspace wants.
I assume we could address that by taking kvm->arch.nx_once.mutex in this helper
instead of using the lockless approach. I don't think that would lead to any
deadlocks?
[*] https://lore.kernel.org/all/Z5QsBXJ7rkJFDtmK@google.com
next prev parent reply other threads:[~2025-01-25 0:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-24 23:46 [PATCH] KVM: x86/mmu: Ensure NX huge page recovery thread is alive before waking Sean Christopherson
2025-01-25 0:50 ` Sean Christopherson [this message]
2025-01-25 4:11 ` Keith Busch
2025-01-27 16:48 ` Sean Christopherson
2025-01-27 17:04 ` Keith Busch
2025-01-27 17:19 ` Sean Christopherson
2025-01-27 18:22 ` Keith Busch
2025-01-28 15:41 ` Paolo Bonzini
2025-01-28 15:44 ` Keith Busch
2025-02-04 16:28 ` Paolo Bonzini
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=Z5Q1SQ-JI6PdmVbi@google.com \
--to=seanjc@google.com \
--cc=kbusch@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.