From f282a75bf3ed393e9eed57c0aa34a93097022e76 Mon Sep 17 00:00:00 2001 From: James Sewart Date: Sat, 9 Mar 2019 18:05:53 +0000 Subject: [PATCH 4/9] iommu/vt-d: Create an IOMMU group for devices that require an idenity map Devices that require an identity map because of quirks or other reasons should be put in their own IOMMU group so as to not end up with multiple different domains per group. Signed-off-by: James Sewart diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 1075a7c74507..1db0ceb33020 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -5424,6 +5424,22 @@ struct intel_iommu *intel_svm_device_to_iommu(struct device *dev) } #endif /* CONFIG_INTEL_IOMMU_SVM */ +static struct iommu_group *intel_identity_group; + +struct iommu_group *intel_iommu_pci_device_group(struct device *dev) +{ + if (iommu_no_mapping(dev)) { + if (!intel_identity_group) { + intel_identity_group = iommu_group_alloc(); + if (IS_ERR(intel_identity_group)) + return NULL; + } + return intel_identity_group; + } + + return pci_device_group(dev); +} + const struct iommu_ops intel_iommu_ops = { .capable = intel_iommu_capable, .domain_alloc = intel_iommu_domain_alloc, @@ -5438,7 +5454,7 @@ const struct iommu_ops intel_iommu_ops = { .get_resv_regions = intel_iommu_get_resv_regions, .put_resv_regions = intel_iommu_put_resv_regions, .apply_resv_region = intel_iommu_apply_resv_region, - .device_group = pci_device_group, + .device_group = intel_iommu_pci_device_group, .pgsize_bitmap = INTEL_IOMMU_PGSIZES, }; -- 2.17.1