Re: [PATCH v3 11/12] KVM: x86: Guard .gmem_prepare() declarations with HAVE_KVM_GMEM_PREPARE=y
From: Michael Roth
Date: Wed Jul 01 2026 - 18:49:57 EST
On Tue, Jun 30, 2026 at 03:26:06PM -0700, Sean Christopherson wrote:
> Wrap the .gmem_prepare() declarations with HAVE_KVM_GMEM_PREPARE so that
> non-SEV code doesn't try to wire up a callback without doing the necessary
> enabling.
>
> No functional change intended.
>
> Fixes: 3bb2531e20bf ("KVM: guest_memfd: Add hook for initializing memory")
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Reviewed-by: Michael Roth <michael.roth@xxxxxxx>
Not sure about the need for the Fixes tag, but it certainly guards against
some future problems.
> ---
> arch/x86/include/asm/kvm-x86-ops.h | 4 +++-
> arch/x86/include/asm/kvm_host.h | 2 ++
> 2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h
> index deb3ded5796e..39247d2f29d6 100644
> --- a/arch/x86/include/asm/kvm-x86-ops.h
> +++ b/arch/x86/include/asm/kvm-x86-ops.h
> @@ -146,12 +146,14 @@ 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)
> -KVM_X86_OP_OPTIONAL_RET0(gmem_max_mapping_level)
> +#endif
> #ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE
> KVM_X86_OP_OPTIONAL(gmem_invalidate_range)
> KVM_X86_OP_OPTIONAL(gmem_reclaim_memory)
> #endif
> +KVM_X86_OP_OPTIONAL_RET0(gmem_max_mapping_level)
> #endif
>
> #undef KVM_X86_OP
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 93af3bb82869..cf2ec19212ad 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -1903,7 +1903,9 @@ 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);
> +#endif
> #ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE
> void (*gmem_invalidate_range)(struct kvm *kvm, struct kvm_gfn_range *range);
> void (*gmem_reclaim_memory)(kvm_pfn_t start, kvm_pfn_t end);
> --
> 2.55.0.rc0.799.gd6f94ed593-goog
>