Re: [PATCH 2/2] KVM: x86/mmu: KVM: x86/mmu: Skip unsync when large pages are allowed

From: Sean Christopherson

Date: Thu Mar 12 2026 - 13:22:58 EST


On Thu, Mar 12, 2026, Sean Christopherson wrote:
> On Fri, Jan 23, 2026, Lai Jiangshan wrote:
> This is what I have locally, please holler if you object to landing the code
> after the write-tracked check.
>
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 363967a17069..3d0e0c1b5332 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -2940,6 +2940,15 @@ int mmu_try_to_unsync_pages(struct kvm *kvm, const struct kvm_memory_slot *slot,
> if (kvm_gfn_is_write_tracked(kvm, slot, gfn))
> return -EPERM;
>
> + /*
> + * Only 4KiB mappings can become unsync, and KVM disallows hugepages
> + * for unsync gfns. Upper-level gPTEs (leaf or non-leaf) are always
> + * write-protected (see above), thus if the gfn can be mapped with a
> + * hugepage and isn't write-tracked, it can't be unsync.

Gah, I swapped the ordering of who is doing what. The comment should be this:

/*
* Only 4KiB mappings can become unsync, and KVM disallows hugepages
* when accounting 4KiB shadow pages. Upper-level gPTEs are always
* write-protected (see above), thus if the gfn can be mapped with a
* hugepage and isn't write-tracked, it can't have a shadow page.
*/
if (!lpage_info_slot(gfn, slot, PG_LEVEL_2M)->disallow_lpage)
return 0;

> + */
> + if (!lpage_info_slot(gfn, slot, PG_LEVEL_2M)->disallow_lpage)
> + return 0;
> +
> /*
> * The page is not write-tracked, mark existing shadow pages unsync
> * unless KVM is synchronizing an unsync SP. In that case, KVM must
>
>
> > /*
> > * Force write-protection if the page is being tracked. Note, the page
> > * track machinery is used to write-protect upper-level shadow pages,
> > --
> > 2.19.1.6.gb485710b
> >