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

From: Aneesh Kumar K . V

Date: Wed Apr 29 2026 - 09:58:59 EST



Jason Gunthorpe <jgg@xxxxxxxx> writes:

> 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@xxxxxxxxxx/
>> >
>> > 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?
>

Hi Paolo,

Could you please take a look at this? I’ve tried to document the
reference count details and hope I’ve captured everything correctly, but
I’d appreciate your review to make sure I haven’t missed anything.