Re: [PATCH v4 1/4] iommufd/device: Associate a kvm pointer to iommufd_device

Jason Gunthorpe
2026-04-28T12:50:21Z

On Tue, Apr 28, 2026 at 05:31:04PM +0530, Aneesh Kumar K.V wrote:
> > I thought we were trying to get away from struct kvm?
> >
> > https://lore.kernel.org/all/adf29Rn7q9Db0hxc@google.com/
> >
> > Ie this should be a 'struct file *kvm_fd'
> >
> > ?
> >
> > Though I am wondering how practical it is to do this at this moment :\
> >
>
> Should we also switch
>
> modified drivers/vfio/vfio.h
> @@ -22,8 +22,8 @@ struct vfio_device_file {
>
> u8 access_granted;
> u32 devid; /* only valid when iommufd is valid */
> - spinlock_t kvm_ref_lock; /* protect kvm field */
> - struct kvm *kvm;
> + spinlock_t kvm_ref_lock; /* protect kvm_file */
> + struct file *kvm_file;
> struct iommufd_ctx *iommufd; /* protected by struct vfio_device_set::lock */
> };
>
> @@ -88,7 +88,7 @@ struct vfio_group {
> #endif
> enum vfio_group_type type;
> struct mutex group_lock;
> - struct kvm *kvm;
> + struct file *kvm_file;
> struct file *opened_file;
> struct blocking_notifier_head notifier;
> struct iommufd_ctx *iommufd;

Ideally, yes everything outside kvm should just use the struct file
and there should be quite narrow places where you do some kvm
operation on it.

> ie,
> KVM_CREATE_DEVICE with KVM_DEV_TYPE_VFIO still use kvm->users_count,
> KVM_DEV_VFIO_FILE_ADD -> will switch to get_file(kvm->_file);
> and VFIO_DEVICE_BIND_IOMMUFD -> will switch to get_file(df->kvm_file)
>
> > Maybe ask Paolo how his series is going?

I thought the above is what Paolo's series was going after?

Jason