Skip to content

Commit

Permalink
vfio: Try to enable IOPF for VFIO devices
Browse files Browse the repository at this point in the history
If IOMMU_DEV_FEAT_IOPF is set for the VFIO device, which means that
the delivering of page faults of this device from the IOMMU is enabled,
we register the VFIO page fault handler to complete the whole faulting
path (HW+SW). And add a iopf_enabled field in struct vfio_device to
record it.

Signed-off-by: Shenming Lu <lushenming@huawei.com>
  • Loading branch information
Shenming Lu authored and intel-lab-lkp committed Jan 26, 2021
1 parent bfff659 commit 275e8cc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions drivers/vfio/vfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ struct vfio_device {
struct vfio_group *group;
struct list_head group_next;
void *device_data;
bool iopf_enabled;
};

#ifdef CONFIG_VFIO_NOIOMMU
Expand Down Expand Up @@ -532,6 +533,21 @@ static struct vfio_group *vfio_group_get_from_dev(struct device *dev)
/**
* Device objects - create, release, get, put, search
*/

static void vfio_device_enable_iopf(struct vfio_device *device)
{
struct device *dev = device->dev;

if (!iommu_dev_has_feature(dev, IOMMU_DEV_FEAT_IOPF))
return;

if (WARN_ON(iommu_register_device_fault_handler(dev,
vfio_iommu_dev_fault_handler, dev)))
return;

device->iopf_enabled = true;
}

static
struct vfio_device *vfio_group_create_device(struct vfio_group *group,
struct device *dev,
Expand All @@ -549,6 +565,8 @@ struct vfio_device *vfio_group_create_device(struct vfio_group *group,
device->group = group;
device->ops = ops;
device->device_data = device_data;
/* By default try to enable IOPF */
vfio_device_enable_iopf(device);
dev_set_drvdata(dev, device);

/* No need to get group_lock, caller has group reference */
Expand All @@ -573,6 +591,8 @@ static void vfio_device_release(struct kref *kref)
mutex_unlock(&group->device_lock);

dev_set_drvdata(device->dev, NULL);
if (device->iopf_enabled)
WARN_ON(iommu_unregister_device_fault_handler(device->dev));

kfree(device);

Expand Down

0 comments on commit 275e8cc

Please sign in to comment.