Re: [PATCH RFC] KVM: TDX: Defer guest memory removal to decrease shutdown time

From: Kirill A. Shutemov
Date: Mon Mar 17 2025 - 04:14:04 EST


On Thu, Mar 13, 2025 at 08:16:29PM +0200, Adrian Hunter wrote:
> @@ -3221,6 +3241,19 @@ int tdx_gmem_private_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn)
> return PG_LEVEL_4K;
> }
>
> +int tdx_gmem_defer_removal(struct kvm *kvm, struct inode *inode)
> +{
> + struct kvm_tdx *kvm_tdx = to_kvm_tdx(kvm);
> +
> + if (kvm_tdx->nr_gmem_inodes >= TDX_MAX_GMEM_INODES)
> + return 0;

We have graceful way to handle this, but should we pr_warn_once() or
something if we ever hit this limit?

Hm. It is also a bit odd that we need to wait until removal to add a link
to guest_memfd inode from struct kvm/kvm_tdx. Can we do it right away in
__kvm_gmem_create()?

Do I read correctly that inode->i_mapping->i_private_list only ever has
single entry of the gmem? Seems wasteful.

Maybe move it to i_private (I don't see flags being used anywhere) and
re-use the list_head to link all inodes of the struct kvm?

No need in the gmem_inodes array.
>

--
Kiryl Shutsemau / Kirill A. Shutemov