Re: [PATCH v2] KVM: SEV: drop FOLL_WRITE for encrypted region registration

From: Lorenzo Stoakes (ARM)

Date: Wed Jul 15 2026 - 03:38:14 EST


On Wed, Jul 15, 2026 at 01:36:26AM -0500, 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.
>
> Fixes: 7e066cb9b71a ("KVM: SEV: Use long-term pin when registering encrypted memory regions")
> Cc: stable@xxxxxxxxxxxxxxx
> Suggested-by: "David Hildenbrand (Arm)" <david@xxxxxxxxxx>
> Link: https://lore.kernel.org/all/ad784f05-b36c-4e91-9f17-4c5b826735d0@xxxxxxxxxx/
> Signed-off-by: Pankaj Gupta <pankaj.gupta@xxxxxxx>

Nice and simple, works for me :) So:

Acked-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>

> ---
> v1 -> v2
> - Remove FOLL_WRITE when the pin is not used for host writes
>
> v1: https://lore.kernel.org/all/20260701144543.39582-1-pankaj.gupta@xxxxxxx/
>
> arch/x86/kvm/svm/sev.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 427229347876..5f2998761462 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2752,7 +2752,7 @@ int sev_mem_enc_register_region(struct kvm *kvm,
> return -ENOMEM;
>
> region->pages = sev_pin_memory(kvm, range->addr, range->size, &region->npages,
> - FOLL_WRITE | FOLL_LONGTERM);
> + FOLL_LONGTERM);
> if (IS_ERR(region->pages)) {
> ret = PTR_ERR(region->pages);
> goto e_free;
> --
> 2.34.1
>

Cheers, Lorenzo