Re: [PATCH RFC v1 03/11] iommu/virtio: Handle incoming page faults

From: Vivek Kumar Gautam
Date: Mon Oct 11 2021 - 05:20:30 EST


Hi Jean,


On 10/11/21 2:46 PM, Jean-Philippe Brucker wrote:
Hi Vivek,

On Mon, Oct 11, 2021 at 01:41:15PM +0530, Vivek Gautam wrote:
+ list_for_each_entry(ep, &viommu->endpoints, list) {
+ if (ep->eid == endpoint) {
+ vdev = ep->vdev;

I have a question here though -
Is endpoint-ID unique across all the endpoints available per 'viommu_dev' or
per 'viommu_domain'?
If it is per 'viommu_domain' then the above list is also incorrect.
As you pointed to in the patch [1] -
[PATCH RFC v1 02/11] iommu/virtio: Maintain a list of endpoints served
by viommu_dev
I am planning to add endpoint ID into a static global xarray in
viommu_probe_device() as below:

vdev_for_each_id(i, eid, vdev) {
ret = xa_insert(&viommu_ep_ids, eid, vdev, GFP_KERNEL);
if (ret)
goto err_free_dev;
}

and replace the above list traversal as below:

xa_lock_irqsave(&viommu_ep_ids, flags);
xa_for_each(&viommu_ep_ids, eid, vdev) {
if (eid == endpoint) {
ret =
iommu_report_device_fault(vdev->dev, &fault_evt);
if (ret)
dev_err(vdev->dev, "Couldn't
handle page request\n");
}
}
xa_unlock_irqrestore(&viommu_ep_ids, flags);

But using a global xarray would also be incorrect if the endpointsID are global
across 'viommu_domain'.

I need to find the correct 'viommu_endpoint' to call iommu_report_device_fault()
with the correct device.

The endpoint IDs are only unique across viommu_dev, so a global xarray
wouldn't work but one in viommu_dev would. In vdomain it doesn't work
either because we can't get to the domain from the fault handler without
first finding the endpoint

Thanks. That's easy then. Will have a xarray in viommu_dev and iterate over it from the fault handler.

Best regards
Vivek