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

Edgecombe, Rick P rick.p.edgecombe at intel.com
Thu Jan 15 16:00:03 PST 2026


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?


More information about the linux-riscv mailing list