Re: [RFC PATCH 1/1] KVM: x86: Skip empty TDP leaf page tables

Sean Christopherson <[email protected]>
Newsgroups org.kernel.vger.kvm
Message-ID <[email protected]>
On Fri, Aug 14, 2026, Hao Zhang wrote:
> From: Hao Zhang <[email protected]>
> 
> When KVM zaps only leaf SPTEs, the TDP page table hierarchy is
> intentionally retained so that subsequent faults can reuse it.  However,
> a later zap of the same range still descends through retained 4K leaf
> page tables whose leaf SPTEs are all non-present.
> 
> Track whether a retained 4K leaf page table contains any present leaf
> SPTEs.  If a zap fully covers the corresponding 2MiB range and the page
> table is known to be empty, skip descending into it.
> 
> Keep the page table hierarchy linked so that it can still be reused by
> future page faults.  Installing a new leaf SPTE clears the empty hint.
> The hint checks are skipped for ranges smaller than a complete 2MiB leaf
> page table.
> 
> The iterator restarts its walk from the root after yielding.  Allow the
> restarted walk to mark an empty leaf page table again instead of
> permanently excluding the page table that contained the yield.
> 
> Tested on a 4-vCPU, 1GB guest with five repetitions on the same host.
> The main improvement is seen for repeated same-range invalidation; rolling
> sweep workloads are mostly neutral.
> 
> Signed-off-by: Hao Zhang <[email protected]>
> ---

Does the generic iterator solution I provided a (long) while back work for your
use case?  I would still strongly prefer a generic solution that doesn't rely on
storing metadata in the MMU page.

https://lore.kernel.org/all/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.