Commit 85412c04 authored by Eric Auger's avatar Eric Auger Committed by Zheng Zengkai
Browse files

iommu/smmuv3: Enforce incompatibility between nested mode and HW MSI regions

virt inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I401IF


CVE: NA

------------------------------

Nested mode currently is not compatible with HW MSI reserved regions.
Indeed MSI transactions targeting this MSI doorbells bypass the SMMU.

Let's check nested mode is not attempted in such configuration.

Signed-off-by: default avatarEric Auger <eric.auger@redhat.com>
Signed-off-by: default avatarKunkun <Jiang&lt;jiangkunkun@huawei.com>
Reviewed-by: default avatarKeqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent b4ddfa73
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -2703,6 +2703,23 @@ static bool arm_smmu_share_msi_domain(struct iommu_domain *domain,
	return share;
}

static bool arm_smmu_has_hw_msi_resv_region(struct device *dev)
{
	struct iommu_resv_region *region;
	bool has_msi_resv_region = false;
	LIST_HEAD(resv_regions);

	iommu_get_resv_regions(dev, &resv_regions);
	list_for_each_entry(region, &resv_regions, list) {
		if (region->type == IOMMU_RESV_MSI) {
			has_msi_resv_region = true;
			break;
		}
	}
	iommu_put_resv_regions(dev, &resv_regions);
	return has_msi_resv_region;
}

static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
{
	int ret = 0;
@@ -2767,10 +2784,12 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
	/*
	 * In nested mode we must check all devices belonging to the
	 * domain share the same physical MSI doorbell. Otherwise nested
	 * stage MSI binding is not supported.
	 * stage MSI binding is not supported. Also nested mode is not
	 * compatible with MSI HW reserved regions.
	 */
	if (smmu_domain->stage == ARM_SMMU_DOMAIN_NESTED &&
		!arm_smmu_share_msi_domain(domain, dev)) {
		(!arm_smmu_share_msi_domain(domain, dev) ||
		 arm_smmu_has_hw_msi_resv_region(dev))) {
		ret = -EINVAL;
		goto out_unlock;
	}
+2 −0
Original line number Diff line number Diff line
@@ -3186,6 +3186,7 @@ void iommu_get_resv_regions(struct device *dev, struct list_head *list)
	if (ops && ops->get_resv_regions)
		ops->get_resv_regions(dev, list);
}
EXPORT_SYMBOL_GPL(iommu_get_resv_regions);

void iommu_put_resv_regions(struct device *dev, struct list_head *list)
{
@@ -3194,6 +3195,7 @@ void iommu_put_resv_regions(struct device *dev, struct list_head *list)
	if (ops && ops->put_resv_regions)
		ops->put_resv_regions(dev, list);
}
EXPORT_SYMBOL_GPL(iommu_put_resv_regions);

/**
 * generic_iommu_put_resv_regions - Reserved region driver helper