Re: [PATCH v5 01/31] vfio: Use file-based reference counting for KVM
From: Steffen Eiden
Date: Fri Jul 31 2026 - 11:06:29 EST
On Fri, Jul 31, 2026 at 03:08:29PM +0200, Steffen Eiden wrote:
> Replace manual module reference counting with file-based reference
> counting for KVM integration. Previously, VFIO used symbol_get() to
> obtain function pointers for kvm_get_kvm_safe() and kvm_put_kvm(),
> then manually tracked module references through these symbols. This
> approach required storing the put_kvm function pointer in each device
> and carefully managing symbol references.
>
> Pass struct file pointers instead of struct kvm pointers throughout the
> VFIO-KVM interface. This leverages the kernel's existing file reference
> counting mechanism via get_file_active() and fput(), eliminating the
> need for manual module reference tracking. The file->private_data field
> provides access to the underlying struct kvm when needed.
>
> This simplifies the code and removes all remaining externally exported
> symbols for KVM, paving the path for a second concurrent KVM module.
>
> Suggested-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
> Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> Signed-off-by: Steffen Eiden <seiden@xxxxxxxxxxxxx>
> ---
> arch/x86/include/asm/kvm_page_track.h | 8 ++---
> arch/x86/kvm/Makefile | 3 --
> arch/x86/kvm/mmu/page_track.c | 16 +++++----
> drivers/s390/crypto/vfio_ap_ops.c | 24 ++++++++++---
> drivers/vfio/group.c | 2 +-
> drivers/vfio/pci/vfio_pci_zdev.c | 7 +++-
> drivers/vfio/vfio.h | 10 +++---
> drivers/vfio/vfio_main.c | 49 ++++++---------------------
> include/linux/kvm_host.h | 2 ++
> include/linux/vfio.h | 4 +--
> virt/kvm/kvm_main.c | 23 ++++++++++---
> virt/kvm/vfio.c | 8 ++---
> 12 files changed, 81 insertions(+), 75 deletions(-)
@sean: This is based on your draft in https://lore.kernel.org/all/adkFk3ZN4HJtpLA3@xxxxxxxxxx/
do you want another/more attribution? If yes which?
Steffen