Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Fuad Tabba <fuad.tabba@linux.dev>,
	Ackerley Tng <ackerleytng@google.com>,
	 Xiaoyao Li <xiaoyao.li@intel.com>,
	Michael Roth <michael.roth@amd.com>,
	 Fuad Tabba <tabba@google.com>
Subject: [PATCH v6 0/9] KVM: guest_memfd: RECLAIM+CONVERT cleanups
Date: Thu, 23 Jul 2026 14:08:02 -0700	[thread overview]
Message-ID: <20260723210811.72720-1-seanjc@google.com> (raw)

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


             reply	other threads:[~2026-07-23 21:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23 21:08 Sean Christopherson [this message]
2026-07-23 21:08 ` [PATCH v6 1/9] KVM: guest_memfd: Pass the number of pages instead of the end pfn into .invalidate() Sean Christopherson
2026-07-23 21:08 ` [PATCH v6 2/9] KVM: guest_memfd: Rename invalidate() arch hook to reclaim() and isolate it Sean Christopherson
2026-07-23 21:08 ` [PATCH v6 3/9] KVM: x86: Rename kvm_x86_ops' gmem_invalidate() to gmem_make_shared() Sean Christopherson
2026-07-23 21:08 ` [PATCH v6 4/9] KVM: guest_memfd: Drop the redundant printk on arch gmem_prepare() failure Sean Christopherson
2026-07-23 21:08 ` [PATCH v6 5/9] KVM: guest_memfd: Add helpers to query SHARED vs. PRIVATE for a given page Sean Christopherson
2026-07-23 21:08 ` [PATCH v6 6/9] KVM: guest_memfd: Only "prepare" folios for private pages Sean Christopherson
2026-07-23 21:08 ` [PATCH v6 7/9] KVM: guest_memfd: Rename prepare() hook and Kconfig to make_private() / CONVERT Sean Christopherson
2026-07-23 21:08 ` [PATCH v6 8/9] KVM: guest_memfd: Explicitly pass number of pages to make_private() hook Sean Christopherson
2026-07-23 21:08 ` [PATCH v6 9/9] KVM: guest_memfd: Make private exactly what can be mapped on page fault Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260723210811.72720-1-seanjc@google.com \
    --to=seanjc@google.com \
    --cc=ackerleytng@google.com \
    --cc=fuad.tabba@linux.dev \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=tabba@google.com \
    --cc=xiaoyao.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox