From: sashiko-bot@kernel.org
To: "Krzysztof Woś" <krzysztof.wos@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2] KVM: x86/mmu: Zap collapsible SPTEs on ranges with active invalidations
Date: Thu, 03 Dec 2026 14:43:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-248001@kernel.org> (raw)
In-Reply-To: <179630591906.459399.8619305795048760319@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] KVM: x86/mmu: recover_huge_pages_range() can zap TDX mirror
non-leaf SPTEs
--
commit 383a8a9cb0faf2691412211c4c44174397818320
Author: Krzysztof Woś <krzysztof.wos@gmail.com>
KVM: x86/mmu: Zap collapsible SPTEs on ranges with active invalidations
This commit factors out kvm_mmu_invalidate_range_in_progress() and uses it
in recover_huge_pages_range() to zap collapsible non-leaf SPTEs instead of
promoting them in place when an mmu_notifier invalidation overlaps the
hugepage range.
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> index 44dad106fad19..af05a91b6fa9c 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.c
> +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> @@ -1800,6 +1800,24 @@ static void recover_huge_pages_range(struct kvm *kvm,
> if (max_mapping_level < iter.level)
> continue;
>
> + /*
> + * If an in-progress mmu_notifier invalidation overlaps the
> + * hugepage range, a subset of child SPTEs may have been zapped
> + * while the host mapping is still huge, making in-place
> + * promotion unsafe. Fall back to zapping the collapsible
> + * non-leaf SPTE, which obeys host_pfn_mapping_level()'s
> + * contract and lets subsequent faults rebuild a huge SPTE once
> + * the invalidation completes.
> + */
> + if (kvm_mmu_invalidate_range_in_progress(kvm, iter.gfn,
> + iter.gfn + KVM_PAGES_PER_HPAGE(iter.level))) {
> + if (tdp_mmu_set_spte_atomic(kvm, &iter, SHADOW_NONPRESENT_VALUE))
> + goto retry;
> +
> + flush = true;
> + continue;
> + }
> +
> r = tdp_mmu_make_huge_spte(kvm, &iter, &huge_spte);
> if (r == -EAGAIN)
> goto retry;
[Severity: High]
Can this zap a lingering non-leaf SPTE in an active TDX mirror root?
kvm_tdp_mmu_recover_huge_pages() walks KVM_VALID_ROOTS, which includes mirror
roots. When a KVM_MEM_GUEST_MEMFD memslot is deleted in a TDX VM, its empty
mirror non-leaf SPTEs remain linked until TD teardown.
If userspace then clears KVM_MEMORY_ATTRIBUTE_PRIVATE on that range, adds a
regular hugepage-backed memslot with KVM_MEM_LOG_DIRTY_PAGES, and disables
dirty logging during an overlapping mmu_notifier invalidation,
kvm_mmu_max_mapping_level() returns PG_LEVEL_2M via host_pfn_mapping_level().
Before this patch, tdp_mmu_make_huge_spte() returned -ENOENT on the empty
mirror child page table and skipped the update. Now this fallback runs first
and zaps the mirror non-leaf SPTE, calling handle_removed_pt() ->
tdx_sept_free_private_spt().
Because the TD HKID is still assigned, tdx_sept_free_private_spt() hits
KVM_BUG_ON(is_hkid_assigned(to_kvm_tdx(kvm)), kvm), bugs the VM, and leaks
the encrypted S-EPT page in sp->external_spt. Should
kvm_tdp_mmu_recover_huge_pages() walk only direct roots?
--
Sashiko AI review · https://sashiko.dev/#/patchset/179630591906.459399.8619305795048760319@gmail.com?part=1
prev parent reply other threads:[~2026-12-03 14:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 13:51 [PATCH v2] KVM: x86/mmu: Zap collapsible SPTEs on ranges with active invalidations Krzysztof Woś
2026-12-03 14:43 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-248001@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=krzysztof.wos@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.