These are the cleanups from the SNP VMSA series. Well, that's how they started
out, now it's full into prep work for in-place conversion. Oh well.
Rework prepare()+invalidate() into make_private()+reclaim(), with direct line
of sight to adding make_shared() for in-place conversion. Have the x86 backend
use make_{private,shared} (no reclaim()) for SNP, as reclaim in SNP-land just
means "make shared".
The goals are to eliminate the misleading use of the term "invalidate", drop
the "prepare" terminology (which gets especially confusing with in-place
conversion), and in general to prepare for the future. E.g. so that KVM ends
up with something like:
if (!to_private)
kvm_gmem_make_shared(inode, start, end);
instead of a funky:
if (!to_private)
kvm_gmem_invalidate(inode, start, end);
and
#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_CONVERT
if (kvm_gmem_is_private_mem(file_inode(file), index))
r = kvm_arch_gmem_make_private(kvm, gfn, *pfn,
(kvm_pfn_t)1 << *max_order);
#endif
instead of the current bare:
r = kvm_gmem_prepare_folio(kvm, slot, gfn, folio);
We'll still need changes for things like TDX hugepage support, and obviously to
add kvm_arch_gmem_make_shared() for in-place conversion, but I think/hope this
sets the stage for SNP, TDX, and pKVM to build on the arch hooks without
needing to make non-trivial changes to the core semantics.
v6:
- Provide separate make_{private,shared}() hooks instead of a single convert(),
because forcing a single API just meant multiplexing on the front-end, and
de-multiplexing on the back-end, along with weird sanity checks to enforce
different requires for private vs. shared. [Ackerley]
- Kill off per-folio preparation entirely. [Sashiko, because Sashiko kept
finding bugs in my attemps to refactor the code, so I went scorched earth].
- Pull in "Only "prepare" folios for private pages" from the in-place series
to make it easier to kill of per-folio preparation.
- Collect some reviews (dropped many since things got reworked, at lot).
v5
- https://lore.kernel.org/all/20260714231015.3337831-1-seanjc@google.com
- Drop the VMSA fixes (already applied).
- Keep a dedicated reclaim() flow. [Fuad, Ackerley]
- Pass a gfn, not a gpa, to convert() / reclaim(). [Ackerley]
- Collect reviews. [Ackerley]
- Align the gfn when folding __kvm_gmem_prepare_folio() into its caller. [Sashiko]
v4:
- https://lore.kernel.org/all/20260709204948.1988414-1-seanjc@google.com
- Collect reviews. [Mike, Ackerley]
- Rework prepare()+invalidate() into a common convert() instead of simply
renaming invalidate() to reclaim_memory(). [Ackerley]
- Fix several (mostly benign) issues in the "prepare" flow.
v3:
- https://lore.kernel.org/all/20260630222607.497895-1-seanjc@google.com
- Ensure disabling quirks while the VM is live won't result in KVM skipping
the back-half of "zap all fast". [Sashiko]
- s/gmem_free_folio/gmem_reclaim_memory. [Ackerley]
- Use {READ,WRITE}_ONCE() when accessing the guest's VMSA GPA outside of the
per-vCPU mutex, and comment. [Sashiko]
v2:
- https://lore.kernel.org/all/20260626231416.3943216-1-seanjc@google.com
- Invalidate VMSAs if the memslot is DELETED or MOVED. [Sashiko]
- Limit stable@ patches without a Fixes to 6.12+.
v1: https://lore.kernel.org/all/20260625222229.3367197-2-seanjc@google.com
Ackerley Tng (1):
KVM: guest_memfd: Only "prepare" folios for private pages
Sean Christopherson (8):
KVM: guest_memfd: Pass the number of pages instead of the end pfn into
.invalidate()
KVM: guest_memfd: Rename invalidate() arch hook to reclaim() and
isolate it
KVM: x86: Rename kvm_x86_ops' gmem_invalidate() to gmem_make_shared()
KVM: guest_memfd: Drop the redundant printk on arch gmem_prepare()
failure
KVM: guest_memfd: Add helpers to query SHARED vs. PRIVATE for a given
page
KVM: guest_memfd: Rename prepare() hook and Kconfig to make_private()
/ CONVERT
KVM: guest_memfd: Explicitly pass number of pages to make_private()
hook
KVM: guest_memfd: Make private exactly what can be mapped on page
fault
arch/x86/include/asm/kvm-x86-ops.h | 8 ++--
arch/x86/include/asm/kvm_host.h | 9 ++--
arch/x86/kvm/Kconfig | 3 +-
arch/x86/kvm/svm/sev.c | 35 +++++++--------
arch/x86/kvm/svm/svm.c | 4 +-
arch/x86/kvm/svm/svm.h | 4 +-
arch/x86/kvm/x86.c | 18 +++++---
include/linux/kvm_host.h | 10 +++--
virt/kvm/Kconfig | 6 ++-
virt/kvm/guest_memfd.c | 68 +++++++-----------------------
10 files changed, 71 insertions(+), 94 deletions(-)
base-commit: 6bc96b971766fbbbbdd9fb2642cedacaf02da957
--
2.55.0.229.g6434b31f56-goog