Re: [PATCH] KVM: SVM: Connect 'npt' module param to KVM's internal 'npt_enabled'

From: Sean Christopherson
Date: Mon Mar 08 2021 - 12:19:42 EST


On Mon, Mar 08, 2021, Maxim Levitsky wrote:
> On Thu, 2021-03-04 at 18:16 -0800, Sean Christopherson wrote:
> > Directly connect the 'npt' param to the 'npt_enabled' variable so that
> > runtime adjustments to npt_enabled are reflected in sysfs. Move the
> > !PAE restriction to a runtime check to ensure NPT is forced off if the
> > host is using 2-level paging, and add a comment explicitly stating why
> > NPT requires a 64-bit kernel or a kernel with PAE enabled.
>
> Let me ask a small question for a personal itch.
>
> Do you think it is feasable to allow the user to enable npt/ept per guest?
> (the default should still of course come from npt module parameter)

Feasible, yes. Worth the extra maintenance, probably not. It's a niche use
case, and only viable if you have a priori knowledge of the guest being run.
I doubt there are more than a few people in the world that meet those criteria,
and want to run multiple VMs, and also care deeply about the performance
degregation of the other VMs.

> This weekend I checked it a bit and I think that it shouldn't be hard
> to do.
>
> There are some old and broken OSes which can't work with npt=1
> https://blog.stuffedcow.net/2015/08/win9x-tlb-invalidation-bug/
> https://blog.stuffedcow.net/2015/08/pagewalk-coherence/
>
> I won't be surprised if some other old OSes
> are affected by this as well knowing from the above
> that on Intel the MMU speculates less and doesn't
> break their assumptions up to today.
> (This is tested to be true on my Kabylake laptop)

Heh, I would be quite surprised if Intel CPUs speculate less. I wouldn't be
surprised if the old Windows behavior got grandfathered into Intel CPUs because
the buggy behavior worked on old CPUs and so must continue to work on new CPUs.

> In addition to that, on semi-unrelated note,
> our shadowing MMU also shows up the exact same issue since it
> also caches translations in form of unsync MMU pages.
>
> But I can (and did disable) this using a hack (see below)
> and this finally made my win98 "hobby" guest actually work fine
> on AMD for me.
>
> I am also thinking to make this "sync" mmu mode to be
> another module param (this can also be useful for debug,
> see below)
> What do you think?
>
> On yet another semi-unrelated note,
> A "sync" mmu mode affects another bug I am tracking,
> but I don't yet understand why:
>
> I found out that while windows 10 doesn't boot at all with
> disabled tdp on the host (npt/ept - I tested both)
> the "sync" mmu mode does make it work.

Intel and AMD? Or just AMD? If both architectures fail, this definitely needs
to be debugged and fixed. Given the lack of bug reports, most KVM users
obviously don't care about TDP=0, but any bug in the unsync code likely affects
nested TDP as well, which far more people do care about.

> I was also able to reproduce a crash on Linux
> (but only with nested migration loop)

With or without TDP enabled?