Re: [PATCH v2] KVM: SEV: drop FOLL_WRITE for encrypted region registration
From: David Hildenbrand (Arm)
Date: Wed Jul 15 2026 - 05:50:45 EST
On 7/15/26 08:36, Pankaj Gupta wrote:
> Commit 7e066cb9b71a ("KVM: SEV: Use long-term pin when registering
> encrypted memory regions") added FOLL_LONGTERM to
> sev_mem_enc_register_region() so anonymous guest RAM is migrated out of
> MIGRATE_CMA/ZONE_MOVABLE before a long term pin. It also kept
> FOLL_WRITE on the pin.
>
> Combining FOLL_WRITE with FOLL_LONGTERM breaks registration of file-backed
> guest memory, such as virtio-pmem host memory-backend-file mappings
> (MAP_SHARED). GUP rejects long-term writable pins on dirty tracked file
> mappings since:
>
> commit 8ac268436e6d ("mm/gup: disallow FOLL_LONGTERM GUP-nonfast writing to file-backed mappings")
> commit a6e79df92e4a ("mm/gup: disallow FOLL_LONGTERM GUP-fast writing to file-backed mappings").
>
> Region registration only requires long-term pin to prevent page migration and
> does not write through this GUP pin.
>
> Drop FOLL_WRITE and pin guest memory only with FOLL_LONGTERM.
Worth mentioning here something like
"In the past, FOLL_WRITE was required to trigger CoW unsharing, making sure that
we don't end up replacing the page in the page tables during a later write fault
after already having pinned a (shared) page in MAP_PRIVATE mappings.
FOLL_LONGTERM does that nowadays (see gup_must_unshare()) even without FOLL_WRITE.
Given that SEV only pins RAM for XYZ and doesn't actually write to the pinned
pages, we can just drop the FOLL_WRITE"
Fill out XYZ :)
In general, LGTM
Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
--
Cheers,
David