Hi Matthew,

>-----Original Message-----
>From: Matthew Rosato <mjros...@linux.ibm.com>
>Sent: Wednesday, November 8, 2023 11:00 AM
>Subject: Re: [PATCH v4 28/41] vfio/iommufd: Implement the iommufd backend
>
>On 11/2/23 3:12 AM, Zhenzhong Duan wrote:
>> From: Yi Liu <yi.l....@intel.com>
>>
>> Add the iommufd backend. The IOMMUFD container class is implemented
>> based on the new /dev/iommu user API. This backend obviously depends
>> on CONFIG_IOMMUFD.
>>
>> So far, the iommufd backend doesn't support dirty page sync yet due
>> to missing support in the host kernel.
>>
>> Co-authored-by: Eric Auger <eric.au...@redhat.com>
>> Signed-off-by: Eric Auger <eric.au...@redhat.com>
>> Signed-off-by: Yi Liu <yi.l....@intel.com>
>> Signed-off-by: Zhenzhong Duan <zhenzhong.d...@intel.com>
>> ---
>
>[...]
>
>> +static int iommufd_cdev_attach_container(VFIODevice *vbasedev,
>> +                                         VFIOIOMMUFDContainer *container,
>> +                                         Error **errp)
>> +{
>> +    int ret, iommufd = vbasedev->iommufd->fd;
>> +    VFIOIOASHwpt *hwpt;
>> +    uint32_t hwpt_id;
>> +    Error *err = NULL;
>> +
>> +    /* try to attach to an existing hwpt in this container */
>> +    QLIST_FOREACH(hwpt, &container->hwpt_list, next) {
>> +        ret = iommufd_cdev_attach_hwpt(vbasedev, hwpt->hwpt_id, &err);
>> +        if (ret) {
>> +            const char *msg = error_get_pretty(err);
>> +
>> +            trace_iommufd_cdev_fail_attach_existing_hwpt(msg);
>> +            error_free(err);
>> +            err = NULL;
>> +        } else {
>> +            goto found_hwpt;
>> +        }
>> +    }
>> +
>> +    ret = iommufd_backend_alloc_hwpt(iommufd, vbasedev->devid,
>> +                                     container->ioas_id, &hwpt_id);
>> +
>> +    if (ret) {
>> +        error_setg_errno(errp, errno, "error alloc shadow hwpt");
>> +        return ret;
>> +    }
>
>The above alloc_hwpt fails for mdevs (at least, it fails for me attempting to 
>use
>iommufd backend with vfio-ccw and vfio-ap on s390).  The ioctl is failing in 
>the
>kernel because it can't find an IOMMUFD_OBJ_DEVICE.
>
>AFAIU that's because the mdevs are meant to instead use kernel access via
>vfio_iommufd_emulated_attach_ioas, not hwpt.  That's how mdevs behave when
>looking at the kernel vfio compat container.
>
>As a test, I was able to get vfio-ccw and vfio-ap working using the iommufd
>backend by just skipping this alloc_hwpt above and instead passing container-
>>ioas_id into the iommufd_cdev_attach_hwpt below.  That triggers the
>vfio_iommufd_emulated_attach_ioas call in the kernel.

Thanks for help test and investigation.
I was only focusing on real device and missed the mdev particularity, sorry.
You are right, there is no hwpt support for mdev, not even an emulated hwpt.
I'll digging into this and see how to distinguish mdev with real device in
this low level function.

BRs.
Zhenzhong

Reply via email to