From: Xiaoyao Li <xiaoyao.li@intel.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>,
Michael Roth <michael.roth@amd.com>,
Fuad Tabba <tabba@google.com>
Subject: Re: [PATCH v6 7/9] KVM: guest_memfd: Rename prepare() hook and Kconfig to make_private() / CONVERT
Date: Mon, 27 Jul 2026 17:51:59 +0800 [thread overview]
Message-ID: <627eda4b-c084-4cd8-ad3a-3b3793feae0d@intel.com> (raw)
In-Reply-To: <20260723210811.72720-8-seanjc@google.com>
On 7/24/2026 5:08 AM, Sean Christopherson wrote:
> Rework guest_memfd's prepare() hook into a more accurate make_private(),
> and rework its Kconfig from PREPARE to a more generic CONVERT.
> This will
> allow x86 to share (pun intended) a kvm_x86_ops.gmem_make_shared() hook
> between the "convert to shared" and "reclaim" flows, which are one and the
> same for SNP.
Does it mean in the future we will introduce something like below?
#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_CONVERT
int kvm_arch_gmem_make_private(struct kvm *kvm, gfn_t gfn, kvm_pfn_t
pfn, int max_order)
{
return kvm_x86_call(gmem_make_private)(kvm, pfn, gfn, max_order);
}
+int kvm_arch_gmem_make_shared(kvm_pfn_t pfn, kvm_pfn_t nr_pages)
+{
+ return kvm_x86_call(gmem_make_private)(pfn, nr_pages);
+}
#endif
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/include/asm/kvm-x86-ops.h | 4 ++--
> arch/x86/include/asm/kvm_host.h | 4 ++--
> arch/x86/kvm/Kconfig | 2 +-
> arch/x86/kvm/svm/sev.c | 2 +-
> arch/x86/kvm/svm/svm.c | 2 +-
> arch/x86/kvm/svm/svm.h | 2 +-
> arch/x86/kvm/x86.c | 6 +++---
> include/linux/kvm_host.h | 5 +++--
> virt/kvm/Kconfig | 2 +-
> virt/kvm/guest_memfd.c | 4 ++--
> 10 files changed, 17 insertions(+), 16 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h
> index 210cb95d0a0b..a4d872ddef9d 100644
> --- a/arch/x86/include/asm/kvm-x86-ops.h
> +++ b/arch/x86/include/asm/kvm-x86-ops.h
> @@ -146,8 +146,8 @@ KVM_X86_OP(vcpu_deliver_sipi_vector)
> KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons);
> KVM_X86_OP_OPTIONAL(get_untagged_addr)
> KVM_X86_OP_OPTIONAL(alloc_apic_backing_page)
> -#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_PREPARE
> -KVM_X86_OP_OPTIONAL_RET0(gmem_prepare)
> +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_CONVERT
> +KVM_X86_OP_OPTIONAL_RET0(gmem_make_private)
> #endif
> #ifdef CONFIG_HAVE_KVM_ARCH_GMEM_RECLAIM
> KVM_X86_OP_OPTIONAL(gmem_make_shared)
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 4dc8a03c829a..4be57157136b 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -1724,8 +1724,8 @@ struct kvm_x86_ops {
>
> gva_t (*get_untagged_addr)(struct kvm_vcpu *vcpu, gva_t gva, unsigned int flags);
> void *(*alloc_apic_backing_page)(struct kvm_vcpu *vcpu);
> -#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_PREPARE
> - int (*gmem_prepare)(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order);
> +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_CONVERT
> + int (*gmem_make_private)(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order);
> #endif
> #ifdef CONFIG_HAVE_KVM_ARCH_GMEM_RECLAIM
> void (*gmem_make_shared)(kvm_pfn_t pfn, kvm_pfn_t nr_pages);
> diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
> index e0e7ad015839..538ed1e80332 100644
> --- a/arch/x86/kvm/Kconfig
> +++ b/arch/x86/kvm/Kconfig
> @@ -160,7 +160,7 @@ config KVM_AMD_SEV
> depends on CRYPTO_DEV_SP_PSP && !(KVM_AMD=y && CRYPTO_DEV_CCP_DD=m)
> select ARCH_HAS_CC_PLATFORM
> select KVM_GENERIC_MEMORY_ATTRIBUTES
> - select HAVE_KVM_ARCH_GMEM_PREPARE
> + select HAVE_KVM_ARCH_GMEM_CONVERT
> select HAVE_KVM_ARCH_GMEM_RECLAIM
> select HAVE_KVM_ARCH_GMEM_INVALIDATE
> select HAVE_KVM_ARCH_GMEM_POPULATE
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 4aa8330d5b2d..0ecba768c153 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -5114,7 +5114,7 @@ static bool is_large_rmp_possible(struct kvm *kvm, kvm_pfn_t pfn, int order)
> return false;
> }
>
> -int sev_gmem_prepare(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order)
> +int sev_gmem_make_private(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order)
> {
> struct kvm_sev_info *sev = to_kvm_sev_info(kvm);
> kvm_pfn_t pfn_aligned;
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index b8c9967dd0de..d5a08f1db84b 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -5438,7 +5438,7 @@ struct kvm_x86_ops svm_x86_ops __initdata = {
> .vm_copy_enc_context_from = sev_vm_copy_enc_context_from,
> .vm_move_enc_context_from = sev_vm_move_enc_context_from,
>
> - .gmem_prepare = sev_gmem_prepare,
> + .gmem_make_private = sev_gmem_make_private,
> .gmem_make_shared = sev_gmem_make_shared,
> .gmem_invalidate_range = sev_gmem_invalidate_range,
> .gmem_max_mapping_level = sev_gmem_max_mapping_level,
> diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
> index b2acb5ab7c26..ad849edcacc7 100644
> --- a/arch/x86/kvm/svm/svm.h
> +++ b/arch/x86/kvm/svm/svm.h
> @@ -1009,7 +1009,7 @@ int sev_cpu_init(struct svm_cpu_data *sd);
> int sev_dev_get_attr(u32 group, u64 attr, u64 *val);
> extern unsigned int max_sev_asid;
> void sev_handle_rmp_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code);
> -int sev_gmem_prepare(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order);
> +int sev_gmem_make_private(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order);
> void sev_gmem_make_shared(kvm_pfn_t pfn, kvm_pfn_t nr_pages);
> void sev_gmem_invalidate_range(struct kvm *kvm, struct kvm_gfn_range *range);
> int sev_gmem_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn, bool is_private);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 249267ed2a9d..e7865b28d37b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -10619,10 +10619,10 @@ bool kvm_arch_supports_gmem_init_shared(struct kvm *kvm)
> return !kvm_arch_has_private_mem(kvm);
> }
>
> -#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_PREPARE
> -int kvm_arch_gmem_prepare(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, int max_order)
> +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_CONVERT
> +int kvm_arch_gmem_make_private(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, int max_order)
> {
> - return kvm_x86_call(gmem_prepare)(kvm, pfn, gfn, max_order);
> + return kvm_x86_call(gmem_make_private)(kvm, pfn, gfn, max_order);
> }
> #endif
>
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 0b5b9cb022ba..9cf01429281b 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -2579,8 +2579,9 @@ static inline int kvm_gmem_get_pfn(struct kvm *kvm,
> }
> #endif /* CONFIG_KVM_GUEST_MEMFD */
>
> -#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_PREPARE
> -int kvm_arch_gmem_prepare(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, int max_order);
> +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_CONVERT
> +int kvm_arch_gmem_make_private(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn,
> + int max_order);
> #endif
>
> #ifdef CONFIG_HAVE_KVM_ARCH_GMEM_POPULATE
> diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig
> index 617876993225..c3c0ee253fc7 100644
> --- a/virt/kvm/Kconfig
> +++ b/virt/kvm/Kconfig
> @@ -107,7 +107,7 @@ config KVM_GUEST_MEMFD
> select XARRAY_MULTI
> bool
>
> -config HAVE_KVM_ARCH_GMEM_PREPARE
> +config HAVE_KVM_ARCH_GMEM_CONVERT
> bool
> depends on KVM_GUEST_MEMFD
>
> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index f64cd87ec8b0..466f611ad4b7 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c
> @@ -73,11 +73,11 @@ static bool kvm_gmem_is_shared_mem(struct inode *inode, pgoff_t index)
> static int __kvm_gmem_prepare_folio(struct kvm *kvm, struct kvm_memory_slot *slot,
> pgoff_t index, struct folio *folio)
> {
> -#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_PREPARE
> +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_CONVERT
> kvm_pfn_t pfn = folio_file_pfn(folio, index);
> gfn_t gfn = slot->base_gfn + index - slot->gmem.pgoff;
>
> - return kvm_arch_gmem_prepare(kvm, gfn, pfn, folio_order(folio));
> + return kvm_arch_gmem_make_private(kvm, gfn, pfn, folio_order(folio));
> #else
> return 0;
> #endif
next prev parent reply other threads:[~2026-07-27 9:52 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 21:08 [PATCH v6 0/9] KVM: guest_memfd: RECLAIM+CONVERT cleanups Sean Christopherson
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-25 8:01 ` Fuad Tabba
2026-07-25 14:49 ` Ackerley Tng
2026-07-27 8:41 ` Xiaoyao Li
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-25 8:25 ` Fuad Tabba
2026-07-25 14:55 ` Ackerley Tng
2026-07-27 8:51 ` Xiaoyao Li
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-25 8:37 ` Fuad Tabba
2026-07-25 14:58 ` Ackerley Tng
2026-07-27 8:54 ` Xiaoyao Li
2026-07-23 21:08 ` [PATCH v6 6/9] KVM: guest_memfd: Only "prepare" folios for private pages Sean Christopherson
2026-07-27 8:56 ` Xiaoyao Li
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-25 8:47 ` Fuad Tabba
2026-07-25 15:01 ` Ackerley Tng
2026-07-27 9:51 ` Xiaoyao Li [this message]
2026-07-27 14:41 ` Sean Christopherson
2026-07-27 15:25 ` Ackerley Tng
2026-07-28 1:00 ` Xiaoyao Li
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-25 15:14 ` Ackerley Tng
2026-07-27 9:59 ` Xiaoyao Li
2026-07-23 21:08 ` [PATCH v6 9/9] KVM: guest_memfd: Make private exactly what can be mapped on page fault Sean Christopherson
2026-07-25 15:22 ` Ackerley Tng
2026-07-31 20:09 ` [PATCH v6 0/9] KVM: guest_memfd: RECLAIM+CONVERT cleanups 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=627eda4b-c084-4cd8-ad3a-3b3793feae0d@intel.com \
--to=xiaoyao.li@intel.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=seanjc@google.com \
--cc=tabba@google.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
all inboxes | Powered by JetHome®