On Wed, Aug 14, 2024 at 4:35 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote: > > vfio/iommufd will reassemble the contiguous range from the 4k PFNs to > > setup the IOMMU, but KVM is not able to do it so reliably. > > Heh, KVM should very reliably do the exact opposite, i.e. KVM should never create > a huge page unless the mapping is huge in the primary MMU. And that's very much > by design, as KVM has no knowledge of what actually resides at a given PFN, and > thus can't determine whether or not its safe to create a huge page if KVM happens > to realize the VM has access to a contiguous range of memory. Indeed: the EPT is managed as a secondary MMU. It replays the contents of the primary MMU, apart from A/D bits (which are independent) and permissions possibly being more restrictive, and that includes the page size. Which in turn explains why the VA has to be aligned for KVM to pick up the hint: aligning the VA allows the primary MMU to use a hugepage, which is a prerequisite for using it in EPT. Paolo