Skip to content

KVM: guest_memfd: RECLAIM+CONVERT cleanups

Sean Christopherson kvm lkml 2 versions – Applied

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

  1. v6 Latest9 patches 20 repliesApplied
  2. 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 filesSizeRepliesApplied
1/9KVM: guest_memfd: Pass the number of pages instead of the end pfn into .invalidate()arch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/sev.c arch/x86/kvm/svm/svm.h +3 more+10 -143 replies
2/9KVM: guest_memfd: Rename invalidate() arch hook to reclaim() and isolate itarch/x86/kvm/Kconfig arch/x86/kvm/x86.c include/linux/kvm_host.h +2 more+17 -60 replies
3/9KVM: x86: Rename kvm_x86_ops' gmem_invalidate() to gmem_make_shared()arch/x86/include/asm/kvm-x86-ops.h arch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/sev.c +3 more+10 -63 replies
4/9KVM: guest_memfd: Drop the redundant printk on arch gmem_prepare() failurevirt/kvm/guest_memfd.c+3 -70 replies
5/9KVM: guest_memfd: Add helpers to query SHARED vs. PRIVATE for a given pagevirt/kvm/guest_memfd.c+11 -13 replies
6/9KVM: guest_memfd: Only "prepare" folios for private pagesvirt/kvm/guest_memfd.c+2 -11 reply
7/9KVM: guest_memfd: Rename prepare() hook and Kconfig to make_private() / CONVERTarch/x86/include/asm/kvm-x86-ops.h arch/x86/include/asm/kvm_host.h arch/x86/kvm/Kconfig +7 more+17 -166 replies
8/9KVM: guest_memfd: Explicitly pass number of pages to make_private() hookarch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/sev.c arch/x86/kvm/svm/svm.h +3 more+19 -222 replies
9/9KVM: guest_memfd: Make private exactly what can be mapped on page faultvirt/kvm/guest_memfd.c+7 -461 reply

Reviews trailers per patch

All 9 patches have a Reviewed-by or Acked-by.

PatchXiaoyao LiFuad TabbaAckerley Tng
1/9R-b R-b R-b
2/9R-b R-b R-b
3/9R-b R-b R-b
4/9R-b R-b R-b
5/9R-b R-b R-b
6/9R-b R-b
7/9R-b R-b R-b
8/9R-b R-b
9/9R-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.

Read the v6 thread

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