Re: [PATCH v2 5/5] KVM: SNP: Mark source page dirty in sev_gmem_post_populate

From: Ackerley Tng

Date: Wed May 27 2026 - 15:14:40 EST


Sean Christopherson <seanjc@xxxxxxxxxx> writes:

> On Fri, May 22, 2026, Ackerley Tng wrote:
>> Mark the folio as dirty after copying data into the source page in
>> sev_gmem_post_populate. After the memcpy, failing to mark the page dirty
>> can lead to the memory management subsystem discarding the changes if the
>> page is reclaimed or otherwise processed by the swap subsystem.
>>
>> Fixes: 2a62345b3052 ("KVM: guest_memfd: GUP source pages prior to populating guest memory")
>> Signed-off-by: Ackerley Tng <ackerleytng@xxxxxxxxxx>
>> ---
>> arch/x86/kvm/svm/sev.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
>> index dbf75326a40f4..1a361f08c7a3d 100644
>> --- a/arch/x86/kvm/svm/sev.c
>> +++ b/arch/x86/kvm/svm/sev.c
>> @@ -2395,6 +2395,7 @@ static int sev_gmem_post_populate(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn,
>> void *dst_vaddr = kmap_local_pfn(pfn);
>>
>> memcpy(src_vaddr, dst_vaddr, PAGE_SIZE);
>> + folio_mark_dirty(page_folio(src_page));
>
> I'd rather use set_page_dirty(). I'll fixup when applying, unless someon objects.
>

I was looking for page, dirty but set_page_dirty() somehow escaped my
search. This works, thanks!

>> kunmap_local(dst_vaddr);
>> kunmap_local(src_vaddr);
>>
>> --
>> 2.54.0.794.g4f17f83d09-goog
>>