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

From: Aneesh Kumar K . V
Date: Tue Jul 29 2025 - 04:30:39 EST


Jason Gunthorpe <jgg@xxxxxxxx> 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