Commit ae03c377 authored by Max Gurtovoy's avatar Max Gurtovoy Committed by Alex Williamson
Browse files

vfio: Introduce a vfio_uninit_group_dev() API call



This pairs with vfio_init_group_dev() and allows undoing any state that is
stored in the vfio_device unrelated to registration. Add appropriately
placed calls to all the drivers.

The following patch will use this to add pre-registration state for the
device set.

Signed-off-by: default avatarMax Gurtovoy <mgurtovoy@nvidia.com>
Reviewed-by: default avatarCornelia Huck <cohuck@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/3-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com


Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent de5494af
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -255,11 +255,13 @@ vfio_unregister_group_dev() respectively::
	void vfio_init_group_dev(struct vfio_device *device,
				struct device *dev,
				const struct vfio_device_ops *ops);
	void vfio_uninit_group_dev(struct vfio_device *device);
	int vfio_register_group_dev(struct vfio_device *device);
	void vfio_unregister_group_dev(struct vfio_device *device);

The driver should embed the vfio_device in its own structure and call
vfio_init_group_dev() to pre-configure it before going to registration.
vfio_init_group_dev() to pre-configure it before going to registration
and call vfio_uninit_group_dev() after completing the un-registration.
vfio_register_group_dev() indicates to the core to begin tracking the
iommu_group of the specified dev and register the dev as owned by a VFIO bus
driver. Once vfio_register_group_dev() returns it is possible for userspace to
+4 −3
Original line number Diff line number Diff line
@@ -627,7 +627,7 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev)

	ret = vfio_fsl_mc_reflck_attach(vdev);
	if (ret)
		goto out_kfree;
		goto out_uninit;

	ret = vfio_fsl_mc_init_device(vdev);
	if (ret)
@@ -657,7 +657,8 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev)
	vfio_fsl_uninit_device(vdev);
out_reflck:
	vfio_fsl_mc_reflck_put(vdev->reflck);
out_kfree:
out_uninit:
	vfio_uninit_group_dev(&vdev->vdev);
	kfree(vdev);
out_group_put:
	vfio_iommu_group_put(group, dev);
@@ -675,7 +676,7 @@ static int vfio_fsl_mc_remove(struct fsl_mc_device *mc_dev)
	dprc_remove_devices(mc_dev, NULL, 0);
	vfio_fsl_uninit_device(vdev);
	vfio_fsl_mc_reflck_put(vdev->reflck);

	vfio_uninit_group_dev(&vdev->vdev);
	kfree(vdev);
	vfio_iommu_group_put(mc_dev->dev.iommu_group, dev);

+9 −4
Original line number Diff line number Diff line
@@ -120,12 +120,16 @@ static int vfio_mdev_probe(struct mdev_device *mdev)

	vfio_init_group_dev(vdev, &mdev->dev, &vfio_mdev_dev_ops);
	ret = vfio_register_group_dev(vdev);
	if (ret) {
		kfree(vdev);
		return ret;
	}
	if (ret)
		goto out_uninit;

	dev_set_drvdata(&mdev->dev, vdev);
	return 0;

out_uninit:
	vfio_uninit_group_dev(vdev);
	kfree(vdev);
	return ret;
}

static void vfio_mdev_remove(struct mdev_device *mdev)
@@ -133,6 +137,7 @@ static void vfio_mdev_remove(struct mdev_device *mdev)
	struct vfio_device *vdev = dev_get_drvdata(&mdev->dev);

	vfio_unregister_group_dev(vdev);
	vfio_uninit_group_dev(vdev);
	kfree(vdev);
}

+4 −2
Original line number Diff line number Diff line
@@ -2022,7 +2022,7 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)

	ret = vfio_pci_reflck_attach(vdev);
	if (ret)
		goto out_free;
		goto out_uninit;
	ret = vfio_pci_vf_init(vdev);
	if (ret)
		goto out_reflck;
@@ -2059,7 +2059,8 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	vfio_pci_vf_uninit(vdev);
out_reflck:
	vfio_pci_reflck_put(vdev->reflck);
out_free:
out_uninit:
	vfio_uninit_group_dev(&vdev->vdev);
	kfree(vdev->pm_save);
	kfree(vdev);
out_group_put:
@@ -2077,6 +2078,7 @@ static void vfio_pci_remove(struct pci_dev *pdev)

	vfio_pci_vf_uninit(vdev);
	vfio_pci_reflck_put(vdev->reflck);
	vfio_uninit_group_dev(&vdev->vdev);
	vfio_pci_vga_uninit(vdev);

	vfio_iommu_group_put(pdev->dev.iommu_group, &pdev->dev);
+5 −2
Original line number Diff line number Diff line
@@ -667,7 +667,7 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev,
		ret = vfio_platform_of_probe(vdev, dev);

	if (ret)
		return ret;
		goto out_uninit;

	vdev->device = dev;

@@ -675,7 +675,7 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev,
	if (ret && vdev->reset_required) {
		dev_err(dev, "No reset function found for device %s\n",
			vdev->name);
		return ret;
		goto out_uninit;
	}

	group = vfio_iommu_group_get(dev);
@@ -698,6 +698,8 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev,
	vfio_iommu_group_put(group, dev);
put_reset:
	vfio_platform_put_reset(vdev);
out_uninit:
	vfio_uninit_group_dev(&vdev->vdev);
	return ret;
}
EXPORT_SYMBOL_GPL(vfio_platform_probe_common);
@@ -708,6 +710,7 @@ void vfio_platform_remove_common(struct vfio_platform_device *vdev)

	pm_runtime_disable(vdev->device);
	vfio_platform_put_reset(vdev);
	vfio_uninit_group_dev(&vdev->vdev);
	vfio_iommu_group_put(vdev->vdev.dev->iommu_group, vdev->vdev.dev);
}
EXPORT_SYMBOL_GPL(vfio_platform_remove_common);
Loading