Re: [PATCH v2 1/5] KVM: guest_memfd: Use write permissions when GUP-ing source pages
From: Sean Christopherson
Date: Tue May 26 2026 - 12:26:11 EST
The shortlog is misleading, bordering on outright wrong. I think most people
would read it as "ALWAYS Use write permissions when GUP-ing source pages". I
also think it should be scoped to:
KVM: SEV:
because this only affects SNP, and IMO is an SNP bug, not a guest_memfd bug. E.g.
KVM: SEV: Pin source page for write when adding CPUID data for SNP guest
On Fri, May 22, 2026, Ackerley Tng wrote:
> From: Sean Christopherson <seanjc@xxxxxxxxxx>
>
> sev_gmem_post_populate() may write to the source page if there was an error
Avoid referencing function names in changelogs when possible. Unless the reader
is already familiar with the code, the name is meaningless. The purpose of the
changelog is to complement the literal patch, not to provide a play-by-play
description.
> while performing SNP_LAUNCH_UPDATE.
>
> Since GUP requested only reads, there is a chance sev_gmem_post_populate()
> could be writing to some read-only page.
>
> sev_gmem_post_populate() will only ever write the source page if the type
> of page being LAUNCH_UPDATEd is a CPUID page. Hence, request a writable
> page only when loading the CPUID page.
>
> Since TDX never writes to the source page, always pass false to
> kvm_gmem_populate().
Describe changes in human-friendly, conversational language. And in a way that
doesn't require looking at the patch to understand the changelog: "pass false"
is meaningless without looking at the code to see what flag was added (or exists).
> With this, even if a read-only mapping or the global zero page was provided
> as the source page, GUP will do a copy-on-write, making it writable before
> the write happens in gvm_post_populate.
Objection, speculation. If the mapping is truly read-only, i.e. doesn't allow
writes at all, then GUP will fail. This is all superfluous information though;
"read-only" is a pretty ubiquitous concept, there's no need to explain it in
gory detail.
I'll rewrite to this when applying:
---
When populating a guest_memfd instance with the initial CPUID data for an
SNP guest, acquire a writable pin on the source page as KVM will write back
the "correct" CPUID information if the userspace provided data is rejected
by trusted firmware. Because KVM writes to the source page using a kernel
mapping, pinning for read could result in KVM clobbering read-only memory.
Note, well-behaved VMMs are unlikely to be affected, as CPUID information
is almost always dynamically generated by userspace, i.e. it's unlikely for
the CPUID information to be backed by a read-only mapping.
---
> Fixes: 2a62345b30529 ("KVM: guest_memfd: GUP source pages prior to populating guest memory")
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Ackerley Tng <ackerleytng@xxxxxxxxxx>
> ---