Re: [PATCH] KVM: x86: switch hugepage recovery thread to vhost_task

Sean Christopherson
2024-11-14T15:38:17Z

On Thu, Nov 14, 2024, Paolo Bonzini wrote:
> On 11/14/24 00:56, Sean Christopherson wrote:
> > > +static bool kvm_nx_huge_page_recovery_worker(void *data)
> > > +{
> > > + struct kvm *kvm = data;
> > > long remaining_time;
> > > - while (true) {
> > > - start_time = get_jiffies_64();
> > > - remaining_time = get_nx_huge_page_recovery_timeout(start_time);
> > > + if (kvm->arch.nx_huge_page_next == NX_HUGE_PAGE_DISABLED)
> > > + return false;
> >
> > The "next" concept is broken. Once KVM sees NX_HUGE_PAGE_DISABLED for a given VM,
> > KVM will never re-evaluate nx_huge_page_next. Similarly, if the recovery period
> > and/or ratio changes, KVM won't recompute the "next" time until the current timeout
> > has expired.
> >
> > I fiddled around with various ideas, but I don't see a better solution that something
> > along the lines of KVM's request system, e.g. set a bool to indicate the params
> > changed, and sprinkle smp_{r,w}mb() barriers to ensure the vhost task sees the
> > new params.
>
> "next" is broken, but there is a much better way to fix it. You just
> track the *last* time that the recovery ran. This is also better
> behaved when you flip recovery back and forth to disabled and back
> to enabled: if your recovery period is 1 minute, it will run the
> next recovery after 1 minute independent of how many times you flipped
> the parameter.

Heh, I my brain was trying to get there last night, but I couldn't quite piece
things together.

Reviewed-by: Sean Christopherson <seanjc@google.com>