Re: [RFC PATCH v1 07/38] iommufd/viommu: Add support to associate viommu with kvm instance

Aneesh Kumar K.V
2025-07-29T08:30:29Z

Jason Gunthorpe <jgg@ziepe.ca> writes:

> On Mon, Jul 28, 2025 at 07:21:44PM +0530, Aneesh Kumar K.V (Arm) wrote:
>
>> +#if IS_ENABLED(CONFIG_KVM)
>> +#include <linux/kvm_host.h>
>> +
>> +static int viommu_get_kvm(struct iommufd_viommu *viommu, int kvm_vm_fd)
>> +{
>> + int rc = -EBADF;
>> + struct file *filp;
>> +
>> + filp = fget(kvm_vm_fd);
>> +
>> + if (!file_is_kvm(filp))
>> + goto err_out;
>> +
>> + /* hold the kvm reference via file descriptor */
>> + viommu->kvm_filp = filp;
>> + return 0;
>> +err_out:
>> + viommu->kvm_filp = NULL;
>> + fput(filp);
>> + return rc;
>> +}
>> +
>> +static void viommu_put_kvm(struct iommufd_viommu *viommu)
>> +{
>> + fput(viommu->kvm_filp);
>> + viommu->kvm_filp = NULL;
>> +}
>> +#endif
>
> Missing stub functions for !CONFIG_KVM?
>
> Looks like an OK design otherwise
>
>> @@ -1057,6 +1068,7 @@ struct iommu_viommu_alloc {
>> __u32 data_len;
>> __u32 __reserved;
>> __aligned_u64 data_uptr;
>> + __u32 kvm_vm_fd;
>
> fds are __s32, they are signed numbers.
>

Thanks for the review comments. I’ll update the patch with the suggested changes.

-aneesh