* [PATCH v2] KVM: SEV: drop FOLL_WRITE for encrypted region registration
@ 2026-07-15 6:36 Pankaj Gupta
2026-07-15 7:35 ` Lorenzo Stoakes (ARM)
2026-07-15 9:49 ` David Hildenbrand (Arm)
0 siblings, 2 replies; 4+ messages in thread
From: Pankaj Gupta @ 2026-07-15 6:36 UTC (permalink / raw)
To: seanjc, pbonzini, tglx, bp, mingo, dave.hansen
Cc: x86, thomas.lendacky, hpa, david, yangge1116, ljs, kvm,
linux-kernel, pankaj.gupta, stable
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@vger.kernel.org
Suggested-by: "David Hildenbrand (Arm)" <david@kernel.org>
Link: https://lore.kernel.org/all/ad784f05-b36c-4e91-9f17-4c5b826735d0@kernel.org/
Signed-off-by: Pankaj Gupta <pankaj.gupta@amd.com>
---
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@amd.com/
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, ®ion->npages,
- FOLL_WRITE | FOLL_LONGTERM);
+ FOLL_LONGTERM);
if (IS_ERR(region->pages)) {
ret = PTR_ERR(region->pages);
goto e_free;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] KVM: SEV: drop FOLL_WRITE for encrypted region registration
2026-07-15 6:36 [PATCH v2] KVM: SEV: drop FOLL_WRITE for encrypted region registration Pankaj Gupta
@ 2026-07-15 7:35 ` Lorenzo Stoakes (ARM)
2026-07-15 9:49 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 4+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-07-15 7:35 UTC (permalink / raw)
To: Pankaj Gupta
Cc: seanjc, pbonzini, tglx, bp, mingo, dave.hansen, x86,
thomas.lendacky, hpa, david, yangge1116, kvm, linux-kernel,
stable
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@vger.kernel.org
> Suggested-by: "David Hildenbrand (Arm)" <david@kernel.org>
> Link: https://lore.kernel.org/all/ad784f05-b36c-4e91-9f17-4c5b826735d0@kernel.org/
> Signed-off-by: Pankaj Gupta <pankaj.gupta@amd.com>
Nice and simple, works for me :) So:
Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> ---
> 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@amd.com/
>
> 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, ®ion->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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] KVM: SEV: drop FOLL_WRITE for encrypted region registration
2026-07-15 6:36 [PATCH v2] KVM: SEV: drop FOLL_WRITE for encrypted region registration Pankaj Gupta
2026-07-15 7:35 ` Lorenzo Stoakes (ARM)
@ 2026-07-15 9:49 ` David Hildenbrand (Arm)
2026-07-15 14:09 ` Gupta, Pankaj
1 sibling, 1 reply; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-15 9:49 UTC (permalink / raw)
To: Pankaj Gupta, seanjc, pbonzini, tglx, bp, mingo, dave.hansen
Cc: x86, thomas.lendacky, hpa, yangge1116, ljs, kvm, linux-kernel,
stable
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@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] KVM: SEV: drop FOLL_WRITE for encrypted region registration
2026-07-15 9:49 ` David Hildenbrand (Arm)
@ 2026-07-15 14:09 ` Gupta, Pankaj
0 siblings, 0 replies; 4+ messages in thread
From: Gupta, Pankaj @ 2026-07-15 14:09 UTC (permalink / raw)
To: David Hildenbrand (Arm), seanjc, pbonzini, tglx, bp, mingo,
dave.hansen
Cc: x86, thomas.lendacky, hpa, yangge1116, ljs, kvm, linux-kernel,
stable
>> 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 :)
Sure :)
I will update the commit message in v3.
>
> In general, LGTM
>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
thanks
Pankaj
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-15 14:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-15 6:36 [PATCH v2] KVM: SEV: drop FOLL_WRITE for encrypted region registration Pankaj Gupta
2026-07-15 7:35 ` Lorenzo Stoakes (ARM)
2026-07-15 9:49 ` David Hildenbrand (Arm)
2026-07-15 14:09 ` Gupta, Pankaj
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.