Re: [PATCH v9 07/13] KVM: guest_memfd: Add flag to remove from direct map

From: Nikita Kalyazin

Date: Fri Jan 16 2026 - 10:00:54 EST




On 16/01/2026 00:00, Edgecombe, Rick P wrote:
On Wed, 2026-01-14 at 13:46 +0000, Kalyazin, Nikita wrote:
+static void kvm_gmem_folio_restore_direct_map(struct folio *folio)
+{
+ /*
+ * Direct map restoration cannot fail, as the only error condition
+ * for direct map manipulation is failure to allocate page tables
+ * when splitting huge pages, but this split would have already
+ * happened in folio_zap_direct_map() in kvm_gmem_folio_zap_direct_map().
+ * Thus folio_restore_direct_map() here only updates prot bits.
+ */
+ if (kvm_gmem_folio_no_direct_map(folio)) {
+ WARN_ON_ONCE(folio_restore_direct_map(folio));
+ folio->private = (void *)((u64)folio->private & ~KVM_GMEM_FOLIO_NO_DIRECT_MAP);
+ }
+}
+

Does this assume the folio would not have been split after it was zapped? As in,
if it was zapped at 2MB granularity (no 4KB direct map split required) but then
restored at 4KB (split required)? Or it gets merged somehow before this?

AFAIK it can't be zapped at 2MB granularity as the zapping code will inevitably cause splitting because guest_memfd faults occur at the base page granularity as of now.