Commit d9a0cd51 authored by Alex Williamson's avatar Alex Williamson
Browse files

Merge branch 'v5.16/vfio/hch-cleanup-vfio-iommu_group-creation-v6' into v5.16/vfio/next

parents 02d5e016 3f901389
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -351,7 +351,7 @@ static int vfio_ap_mdev_probe(struct mdev_device *mdev)
	list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
	mutex_unlock(&matrix_dev->lock);

	ret = vfio_register_group_dev(&matrix_mdev->vdev);
	ret = vfio_register_emulated_iommu_dev(&matrix_mdev->vdev);
	if (ret)
		goto err_list;
	dev_set_drvdata(&mdev->dev, matrix_mdev);
+2 −15
Original line number Diff line number Diff line
@@ -505,22 +505,13 @@ static void vfio_fsl_uninit_device(struct vfio_fsl_mc_device *vdev)

static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev)
{
	struct iommu_group *group;
	struct vfio_fsl_mc_device *vdev;
	struct device *dev = &mc_dev->dev;
	int ret;

	group = vfio_iommu_group_get(dev);
	if (!group) {
		dev_err(dev, "VFIO_FSL_MC: No IOMMU group\n");
		return -EINVAL;
	}

	vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
	if (!vdev) {
		ret = -ENOMEM;
		goto out_group_put;
	}
	if (!vdev)
		return -ENOMEM;

	vfio_init_group_dev(&vdev->vdev, dev, &vfio_fsl_mc_ops);
	vdev->mc_dev = mc_dev;
@@ -556,8 +547,6 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev)
out_uninit:
	vfio_uninit_group_dev(&vdev->vdev);
	kfree(vdev);
out_group_put:
	vfio_iommu_group_put(group, dev);
	return ret;
}

@@ -574,8 +563,6 @@ static int vfio_fsl_mc_remove(struct fsl_mc_device *mc_dev)

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

	return 0;
}

+4 −41
Original line number Diff line number Diff line
@@ -13,60 +13,23 @@

#include "mdev_private.h"

static int mdev_attach_iommu(struct mdev_device *mdev)
{
	int ret;
	struct iommu_group *group;

	group = iommu_group_alloc();
	if (IS_ERR(group))
		return PTR_ERR(group);

	ret = iommu_group_add_device(group, &mdev->dev);
	if (!ret)
		dev_info(&mdev->dev, "MDEV: group_id = %d\n",
			 iommu_group_id(group));

	iommu_group_put(group);
	return ret;
}

static void mdev_detach_iommu(struct mdev_device *mdev)
{
	iommu_group_remove_device(&mdev->dev);
	dev_info(&mdev->dev, "MDEV: detaching iommu\n");
}

static int mdev_probe(struct device *dev)
{
	struct mdev_driver *drv =
		container_of(dev->driver, struct mdev_driver, driver);
	struct mdev_device *mdev = to_mdev_device(dev);
	int ret;

	ret = mdev_attach_iommu(mdev);
	if (ret)
		return ret;

	if (drv->probe) {
		ret = drv->probe(mdev);
		if (ret)
			mdev_detach_iommu(mdev);
	}

	return ret;
	if (!drv->probe)
		return 0;
	return drv->probe(to_mdev_device(dev));
}

static void mdev_remove(struct device *dev)
{
	struct mdev_driver *drv =
		container_of(dev->driver, struct mdev_driver, driver);
	struct mdev_device *mdev = to_mdev_device(dev);

	if (drv->remove)
		drv->remove(mdev);

	mdev_detach_iommu(mdev);
		drv->remove(to_mdev_device(dev));
}

static int mdev_match(struct device *dev, struct device_driver *drv)
+1 −1
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ static int vfio_mdev_probe(struct mdev_device *mdev)
		return -ENOMEM;

	vfio_init_group_dev(vdev, &mdev->dev, &vfio_mdev_dev_ops);
	ret = vfio_register_group_dev(vdev);
	ret = vfio_register_emulated_iommu_dev(vdev);
	if (ret)
		goto out_uninit;

+2 −11
Original line number Diff line number Diff line
@@ -1806,7 +1806,6 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_uninit_device);
int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev)
{
	struct pci_dev *pdev = vdev->pdev;
	struct iommu_group *group;
	int ret;

	if (pdev->hdr_type != PCI_HEADER_TYPE_NORMAL)
@@ -1825,10 +1824,6 @@ int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev)
		return -EBUSY;
	}

	group = vfio_iommu_group_get(&pdev->dev);
	if (!group)
		return -EINVAL;

	if (pci_is_root_bus(pdev->bus)) {
		ret = vfio_assign_device_set(&vdev->vdev, vdev);
	} else if (!pci_probe_reset_slot(pdev->slot)) {
@@ -1842,10 +1837,10 @@ int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev)
	}

	if (ret)
		goto out_group_put;
		return ret;
	ret = vfio_pci_vf_init(vdev);
	if (ret)
		goto out_group_put;
		return ret;
	ret = vfio_pci_vga_init(vdev);
	if (ret)
		goto out_vf;
@@ -1876,8 +1871,6 @@ int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev)
		vfio_pci_set_power_state(vdev, PCI_D0);
out_vf:
	vfio_pci_vf_uninit(vdev);
out_group_put:
	vfio_iommu_group_put(group, &pdev->dev);
	return ret;
}
EXPORT_SYMBOL_GPL(vfio_pci_core_register_device);
@@ -1893,8 +1886,6 @@ void vfio_pci_core_unregister_device(struct vfio_pci_core_device *vdev)
	vfio_pci_vf_uninit(vdev);
	vfio_pci_vga_uninit(vdev);

	vfio_iommu_group_put(pdev->dev.iommu_group, &pdev->dev);

	if (!disable_idle_d3)
		vfio_pci_set_power_state(vdev, PCI_D0);
}
Loading