Re: [PATCH v4 09/17] KVM: x86/mmu: Introduce hugepage_set_guest_inhibit()

From: Yan Zhao

Date: Sat Oct 10 2026 - 02:01:27 EST


On Thu, Oct 08, 2026 at 07:57:37AM +0800, Edgecombe, Rick P wrote:
> On Mon, 2026-09-28 at 17:10 +0800, Yan Zhao wrote:
> > TDX requires guests to accept S-EPT mappings created by the host KVM. Due
> > to the current implementation of the TDX module, if a guest accepts a GFN
> > at a lower level after KVM maps it at a higher level, the TDX module will
> > emulate an EPT violation VMExit to KVM instead of returning a size mismatch
> > error to the guest. If KVM fails to perform page splitting in the VMExit
> > handler, the guest's accept operation will be triggered again upon
> > re-entering the guest, causing a repeated EPT violation VMExit.
> >
> > To facilitate passing the guest's accept level information to the KVM MMU
> > core and to prevent the repeated mapping of a GFN at different levels due
> > to different accept levels specified by different vCPUs, introduce the
> > interface hugepage_set_guest_inhibit(). This interface specifies across
> > vCPUs that mapping at a certain level is inhibited from the guest.
> >
> > Intentionally don't provide an API to clear KVM_LPAGE_GUEST_INHIBIT_FLAG
> > for the time being, as detecting that it's ok to (re)install a huge page is
> > tricky (and costly if KVM wants to be 100% accurate), and KVM doesn't
> > currently support huge page promotion (only direct installation of
> > huge pages) for S-EPT.
> >
> > As a result, the only scenario where clearing the flag would likely allow
> > KVM to install a huge page is when an entire 2MB / 1GB range is converted
> > to shared or private. But if the guest is accepting at 4KB granularity,
> > odds are good the guest is using the memory for something "special" and
> > will never convert the entire range to shared (and/or back to private).
> > Punt that optimization to the future, if it's ever needed.
> >
> > Unlike hugepage_set/test_mixed(), which are placed under
> > CONFIG_KVM_VM_MEMORY_ATTRIBUTES since they are unneeded when per-VM memory
> > attributes is disabled, hugepage_set/test_guest_inhibit() are invoked when
> > per-gmem memory attributes is enabled, since TDX huge page support is
> > intentionally enabled only when per-gmem memory attributes is enabled.
>
> Not sure why we need the above paragraph. Especially the gmem part. It looks
> like it was added since v5. Was it an AI review item?
The internal Sashiko review suggested explaining why
hugepage_set/test_guest_inhibit() are not placed next to
hugepage_set/test_mixed(), given their similar naming, which seems reasonable to
me.

> With that addressed:
So what about:
"
Place hugepage_set/test_guest_inhibit() near kvm_mmu_gfn_(dis)allow_lpage(),
rather than next to hugepage_set/test_mixed(), so that they can be invoked
outside of CONFIG_KVM_VM_MEMORY_ATTRIBUTES.
"

> Reviewed-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>
Thanks!