提交 74cf87f1 编写于 作者: L lingmingqiang 提交者: Xie XiuQi

Revert Update vfio-type1-iommu driver to support Warpdrive with IOMMU.

driver inclusion
category: bugfix
bugzilla: NA
CVE: NA

This reverts commit a6d418ceb33231c14280688797ca5b9b5b85e72a.

Feature or Bugfix: Bugfix
Signed-off-by: Nlingmingqiang <lingmingqiang@huawei.com>
Reviewed-by: Nhucheng.hu <hucheng.hu@huawei.com>
Reviewed-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 bfed4439
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/dma-iommu.h> #include <linux/dma-iommu.h>
#include <linux/irqdomain.h> #include <linux/irqdomain.h>
#include <linux/vfio_spimdev.h>
#define DRIVER_VERSION "0.2" #define DRIVER_VERSION "0.2"
#define DRIVER_AUTHOR "Alex Williamson <alex.williamson@redhat.com>" #define DRIVER_AUTHOR "Alex Williamson <alex.williamson@redhat.com>"
...@@ -96,8 +95,6 @@ struct vfio_dma { ...@@ -96,8 +95,6 @@ struct vfio_dma {
}; };
struct vfio_group { struct vfio_group {
/* iommu_group of mdev's parent device */
struct iommu_group *parent_group;
struct iommu_group *iommu_group; struct iommu_group *iommu_group;
struct list_head next; struct list_head next;
}; };
...@@ -1343,109 +1340,6 @@ static bool vfio_iommu_has_sw_msi(struct iommu_group *group, phys_addr_t *base) ...@@ -1343,109 +1340,6 @@ static bool vfio_iommu_has_sw_msi(struct iommu_group *group, phys_addr_t *base)
return ret; return ret;
} }
/* return 0 if the device is not spimdev.
* return 1 if the device is spimdev, the data will be updated with parent
* device's group.
* return -errno if other error.
*/
static int vfio_spimdev_type(struct device *dev, void *data)
{
struct iommu_group **group = data;
struct iommu_group *pgroup;
int (*spimdev_mdev)(struct device *dev);
struct device *pdev;
int ret = 1;
/* vfio_spimdev module is not configurated */
spimdev_mdev = symbol_get(vfio_spimdev_is_spimdev);
if (!spimdev_mdev)
return 0;
/* check if it belongs to vfio_spimdev device */
if (!spimdev_mdev(dev)) {
ret = 0;
goto get_exit;
}
pdev = dev->parent;
pgroup = iommu_group_get(pdev);
if (!pgroup) {
ret = -ENODEV;
goto get_exit;
}
if (group) {
/* check if all parent devices is the same */
if (*group && *group != pgroup)
ret = -ENODEV;
else
*group = pgroup;
}
iommu_group_put(pgroup);
get_exit:
symbol_put(vfio_spimdev_is_spimdev);
return ret;
}
/* return 0 or -errno */
static int vfio_spimdev_bus(struct device *dev, void *data)
{
struct bus_type **bus = data;
if (!dev->bus)
return -ENODEV;
/* ensure all devices has the same bus_type */
if (*bus && *bus != dev->bus)
return -EINVAL;
*bus = dev->bus;
return 0;
}
/* return 0 means it is not spi group, 1 means it is, or -EXXX for error */
static int vfio_iommu_type1_attach_spigroup(struct vfio_domain *domain,
struct vfio_group *group,
struct iommu_group *iommu_group)
{
int ret;
struct bus_type *pbus = NULL;
struct iommu_group *pgroup = NULL;
ret = iommu_group_for_each_dev(iommu_group, &pgroup,
vfio_spimdev_type);
if (ret < 0)
goto out;
else if (ret > 0) {
domain->domain = iommu_group_share_domain(pgroup);
if (IS_ERR(domain->domain))
goto out;
ret = iommu_group_for_each_dev(pgroup, &pbus,
vfio_spimdev_bus);
if (ret < 0)
goto err_with_share_domain;
if (pbus && iommu_capable(pbus, IOMMU_CAP_CACHE_COHERENCY))
domain->prot |= IOMMU_CACHE;
group->parent_group = pgroup;
INIT_LIST_HEAD(&domain->group_list);
list_add(&group->next, &domain->group_list);
return 1;
}
return 0;
err_with_share_domain:
iommu_group_unshare_domain(pgroup);
out:
return ret;
}
static int vfio_iommu_type1_attach_group(void *iommu_data, static int vfio_iommu_type1_attach_group(void *iommu_data,
struct iommu_group *iommu_group) struct iommu_group *iommu_group)
{ {
...@@ -1454,8 +1348,8 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, ...@@ -1454,8 +1348,8 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
struct vfio_domain *domain, *d; struct vfio_domain *domain, *d;
struct bus_type *bus = NULL, *mdev_bus; struct bus_type *bus = NULL, *mdev_bus;
int ret; int ret;
bool resv_msi = false, msi_remap; bool resv_msi, msi_remap;
phys_addr_t resv_msi_base = 0; phys_addr_t resv_msi_base;
mutex_lock(&iommu->lock); mutex_lock(&iommu->lock);
...@@ -1492,14 +1386,6 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, ...@@ -1492,14 +1386,6 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
if (mdev_bus) { if (mdev_bus) {
if ((bus == mdev_bus) && !iommu_present(bus)) { if ((bus == mdev_bus) && !iommu_present(bus)) {
symbol_put(mdev_bus_type); symbol_put(mdev_bus_type);
ret = vfio_iommu_type1_attach_spigroup(domain, group,
iommu_group);
if (ret < 0)
goto out_free;
else if (ret > 0)
goto replay_check;
if (!iommu->external_domain) { if (!iommu->external_domain) {
INIT_LIST_HEAD(&domain->group_list); INIT_LIST_HEAD(&domain->group_list);
iommu->external_domain = domain; iommu->external_domain = domain;
...@@ -1578,13 +1464,12 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, ...@@ -1578,13 +1464,12 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
vfio_test_domain_fgsp(domain); vfio_test_domain_fgsp(domain);
replay_check:
/* replay mappings on new domains */ /* replay mappings on new domains */
ret = vfio_iommu_replay(iommu, domain); ret = vfio_iommu_replay(iommu, domain);
if (ret) if (ret)
goto out_detach; goto out_detach;
if (!group->parent_group && resv_msi) { if (resv_msi) {
ret = iommu_get_msi_cookie(domain->domain, resv_msi_base); ret = iommu_get_msi_cookie(domain->domain, resv_msi_base);
if (ret) if (ret)
goto out_detach; goto out_detach;
...@@ -1597,13 +1482,9 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, ...@@ -1597,13 +1482,9 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
return 0; return 0;
out_detach: out_detach:
if (!group->parent_group) iommu_detach_group(domain->domain, iommu_group);
iommu_detach_group(domain->domain, iommu_group);
out_domain: out_domain:
if (group->parent_group) iommu_domain_free(domain->domain);
iommu_group_unshare_domain(group->parent_group);
else
iommu_domain_free(domain->domain);
out_free: out_free:
kfree(domain); kfree(domain);
kfree(group); kfree(group);
...@@ -1659,25 +1540,12 @@ static void vfio_sanity_check_pfn_list(struct vfio_iommu *iommu) ...@@ -1659,25 +1540,12 @@ static void vfio_sanity_check_pfn_list(struct vfio_iommu *iommu)
WARN_ON(iommu->notifier.head); WARN_ON(iommu->notifier.head);
} }
static void vfio_iommu_undo(struct vfio_iommu *iommu,
struct iommu_domain *domain)
{
struct rb_node *n = rb_first(&iommu->dma_list);
struct vfio_dma *dma;
for (; n; n = rb_next(n)) {
dma = rb_entry(n, struct vfio_dma, node);
iommu_unmap(domain, dma->iova, dma->size);
}
}
static void vfio_iommu_type1_detach_group(void *iommu_data, static void vfio_iommu_type1_detach_group(void *iommu_data,
struct iommu_group *iommu_group) struct iommu_group *iommu_group)
{ {
struct vfio_iommu *iommu = iommu_data; struct vfio_iommu *iommu = iommu_data;
struct vfio_domain *domain; struct vfio_domain *domain;
struct vfio_group *group; struct vfio_group *group;
struct iommu_domain *sdomain = NULL;
mutex_lock(&iommu->lock); mutex_lock(&iommu->lock);
...@@ -1705,12 +1573,7 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, ...@@ -1705,12 +1573,7 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,
if (!group) if (!group)
continue; continue;
if (group->parent_group) iommu_detach_group(domain->domain, iommu_group);
sdomain = iommu_group_unshare_domain(
group->parent_group);
else
iommu_detach_group(domain->domain, iommu_group);
list_del(&group->next); list_del(&group->next);
kfree(group); kfree(group);
/* /*
...@@ -1727,10 +1590,7 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, ...@@ -1727,10 +1590,7 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,
else else
vfio_iommu_unmap_unpin_reaccount(iommu); vfio_iommu_unmap_unpin_reaccount(iommu);
} }
if (domain->domain != sdomain) iommu_domain_free(domain->domain);
iommu_domain_free(domain->domain);
else
vfio_iommu_undo(iommu, sdomain);
list_del(&domain->next); list_del(&domain->next);
kfree(domain); kfree(domain);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册