Re: [PATCH v4 0/9] KVM: x86: Apply NX mitigation more precisely

From: Mingwei Zhang
Date: Tue Sep 06 2022 - 14:38:49 EST


On Tue, Aug 30, 2022, Sean Christopherson wrote:
> Note, this applies on Yosry's stats series (there's a trivial-but-subtle
> conflict in the TDP MMU shadow page accounting).
> https://lore.kernel.org/all/20220823004639.2387269-1-yosryahmed@xxxxxxxxxx
>
> Precisely track (via kvm_mmu_page) if a non-huge page is being forced
> and use that info to avoid unnecessarily forcing smaller page sizes in
> disallowed_hugepage_adjust().
>
> KVM incorrectly assumes that the NX huge page mitigation is the only
> scenario where KVM will create a non-leaf page instead of a huge page.
> As a result, if the original source of huge page incompatibility goes
> away, the NX mitigation is enabled, and KVM encounters an present shadow
> page when attempting to install a huge page, KVM will force a smaller page
> regardless of whether or not a smaller page is actually necessary to
> satisfy the NX huge page mitigation.
>
> Unnecessarily forcing small pages can result in degraded guest performance,
> especially on larger VMs. The bug was originally discovered when testing
> dirty log performance, as KVM would leave small pages lying around when
> zapping collapsible SPTEs. That case was indadvertantly fixed by commit
> 5ba7c4c6d1c7 ("KVM: x86/MMU: Zap non-leaf SPTEs when disabling dirty
> logging"), but other scenarios are still affected, e.g. KVM will not
> rebuild a huge page if the mmu_notifier zaps a range of PTEs because the
> primary MMU is creating a huge page.
>
> v4:
> - Collect reviews. [Mingwei]
> - Add comment to document possible_nx_huge_pages. [Mingwei]
> - Drop extra memory barriers. [Paolo]
> - Document ordering providing by TDP SPTE helpers. [Paolo]

Hi Paolo and folks,

Just a gentle ping. Are we good on this version? It seems the ordering
concern in TDP MMU has been addressed.

Thanks.
-Mingwei