Re: [PATCH v4 04/11] KVM: Track weak reference to vm_file in struct kvm

From: tarunsahu

Date: Tue Aug 18 2026 - 12:37:43 EST


Sean Christopherson <seanjc@xxxxxxxxxx> writes:

> On Tue, Jul 28, 2026, Tarun Sahu wrote:
>> - Add a weak reference 'vm_file' in struct kvm under
>
> "vm_file" is effectively already claimed by vm_area_struct.vm_file. *If* we go
> this route, I would very strongly prefer to take a dependency on "vfio: Use
> file-based reference counting for KVM"[*]. I'll poke that thread, we really
> should land that one particular patch long before the s390-is-arm64
> insanity.

[*] Seem interesting way to solve this. So we will also have vm_file
directly in guest_memfd instead of struct kvm and refcounting on vm_file
instead struct kvm?

struct gmem_file {
- struct kvm *kvm;
+ struct file *vm_file;
struct xarray bindings;
struct list_head entry;
};

>
> Empashish on "if" because this all feels backwards.

> It's not at all clear to
> me why liveupdate goes directly to guest_memfd, but then requires a token associated
> with the VM.

guest_memfd can be recreated without having the struct kvm, Which there
is no way to pass it on retrieval path. So the function
kvm_gmem_luo_retrieve() gets this VM token, find the vm_file (hence
struct kvm) associated with the preserved guest_memfd. Now it create a
fresh guest_memfd by calling kvm_gmem_create(..., kvm). And populate
preserved flags and folios to this guest_memfd.

>
> https://lore.kernel.org/all/20260731130902.654679-2-seiden@xxxxxxxxxxxxx