Re: [PATCH v5 5/9] iommufd: Add iommufd fault object

Baolu Lu
2024-05-20T01:26:04Z

On 5/15/24 4:37 PM, Tian, Kevin wrote:
>> +static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user
>> *buf,
>> + size_t count, loff_t *ppos)
>> +{
>> + size_t response_size = sizeof(struct iommu_hwpt_page_response);
>> + struct iommufd_fault *fault = filep->private_data;
>> + struct iommu_hwpt_page_response response;
>> + struct iommufd_device *idev = NULL;
>> + struct iopf_group *group;
>> + size_t done = 0;
>> + int rc;
>> +
>> + if (*ppos || count % response_size)
>> + return -ESPIPE;
>> +
>> + mutex_lock(&fault->mutex);
>> + while (count > done) {
>> + rc = copy_from_user(&response, buf + done, response_size);
>> + if (rc)
>> + break;
>> +
>> + if (!idev || idev->obj.id != response.dev_id)
>> + idev = container_of(iommufd_get_object(fault->ictx,
>> + response.dev_id,
>> +
>> IOMMUFD_OBJ_DEVICE),
>> + struct iommufd_device, obj);
>> + if (IS_ERR(idev))
>> + break;
>> +
>> + group = xa_erase(&idev->faults, response.cookie);
>> + if (!group)
>> + break;
> is 'continue' better?

If we can't find a matched iopf group here, it means userspace provided
something wrong. The current logic is that we stop here and tell
userspace that only part of the faults have been responded to and it
should retry the remaining responses with the right message.

Best regards,
baolu