KVM: guest_memfd: RECLAIM+CONVERT cleanups
Status from this message: Applied to kvm-x86 coco, thanks!
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v6 Latest9 patches 20 repliesApplied
- v57 patches 28 repliesSuperseded
Changes in v6 from the cover letter
- 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).
Patches in v6 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/9 | KVM: guest_memfd: Pass the number of pages instead of the end pfn into .invalidate()arch/ arch/ arch/ +3 more | +10 | 3 replies | |
| 2/9 | KVM: guest_memfd: Rename invalidate() arch hook to reclaim() and isolate itarch/ arch/ include/ +2 more | +17 | 0 replies | |
| 3/9 | KVM: x86: Rename kvm_x86_ops' gmem_invalidate() to gmem_make_shared()arch/ arch/ arch/ +3 more | +10 | 3 replies | |
| 4/9 | KVM: guest_memfd: Drop the redundant printk on arch gmem_prepare() failurevirt/ | +3 | 0 replies | |
| 5/9 | KVM: guest_memfd: Add helpers to query SHARED vs. PRIVATE for a given pagevirt/ | +11 | 3 replies | |
| 6/9 | KVM: guest_memfd: Only "prepare" folios for private pagesvirt/ | +2 | 1 reply | |
| 7/9 | KVM: guest_memfd: Rename prepare() hook and Kconfig to make_private() / CONVERTarch/ arch/ arch/ +7 more | +17 | 6 replies | |
| 8/9 | KVM: guest_memfd: Explicitly pass number of pages to make_private() hookarch/ arch/ arch/ +3 more | +19 | 2 replies | |
| 9/9 | KVM: guest_memfd: Make private exactly what can be mapped on page faultvirt/ | +7 | 1 reply |
Reviews trailers per patch
All 9 patches have a Reviewed-by or Acked-by.
| Patch | Xiaoyao Li | Fuad Tabba | Ackerley Tng |
|---|---|---|---|
| 1/9 | R-b | R-b | R-b |
| 2/9 | R-b | R-b | R-b |
| 3/9 | R-b | R-b | R-b |
| 4/9 | R-b | R-b | R-b |
| 5/9 | R-b | R-b | R-b |
| 6/9 | R-b | R-b | |
| 7/9 | R-b | R-b | R-b |
| 8/9 | R-b | R-b | |
| 9/9 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.
Cover letter [PATCH v6 0/9] KVM: guest_memfd: RECLAIM+CONVERT cleanups
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/[email protected]
- 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/[email protected]
- 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/[email protected]
- 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/[email protected]
- 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/[email protected]
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
Signature · 1 line
2.55.0.229.g6434b31f56-goog