Re: [PATCH] KVM: x86/mmu: Ensure NX huge page recovery thread is alive before waking

From: Keith Busch
Date: Mon Jan 27 2025 - 13:22:39 EST


On Mon, Jan 27, 2025 at 08:48:03AM -0800, Sean Christopherson wrote:
> > > - vhost_task_start(kvm->arch.nx_huge_page_recovery_thread);
> > > + if (!nx_thread)
> > > + return;
> > > +
> > > + vhost_task_start(nx_thread);
> > > +
> > > + /* Make the task visible only once it is fully started. */
> > > + WRITE_ONCE(kvm->arch.nx_huge_page_recovery_thread, nx_thread);
> >
> > I believe the WRITE_ONCE needs to happen before the vhost_task_start to
> > ensure the parameter update callback can see it before it's started.
>
> It's not clear to me that calling vhost_task_wake() before vhost_task_start() is
> allowed, which is why I deliberately waited until the task was started to make it
> visible. Though FWIW, doing "vhost_task_wake(nx_thread)" before vhost_task_start()
> doesn't explode.

Hm, it does look questionable to try to wake a process that hadn't been
started yet, but I think it may be okay: task state will be TASK_NEW
before vhost_task_start(), which looks like will cause wake_up_process()
to do nothing.