Patchwork [v2,4/7] iommu/vt-d: Ignore domain parameter in attach_device if device requires identity map

login
register
mail settings
Submitter Benjamin Serebrin via iommu
Date March 14, 2019, 11:58 a.m.
Message ID <D8A19A7A-91CB-4297-9445-47DB248B7817@arista.com>
Download mbox | patch
Permalink /patch/748709/
State New
Headers show

Comments

Benjamin Serebrin via iommu - March 14, 2019, 11:58 a.m.
If a device requires an identity map then it is not safe to attach a
domain that can remap addresses. Warn the user if this occurs.

Signed-off-by: James Sewart <jamessewart@arista.com>
---
 drivers/iommu/intel-iommu.c | 5 +++++
 1 file changed, 5 insertions(+)
Lu Baolu - March 15, 2019, 2:30 a.m.
Hi,

On 3/14/19 7:58 PM, James Sewart wrote:
> If a device requires an identity map then it is not safe to attach a
> domain that can remap addresses. Warn the user if this occurs.
> 
> Signed-off-by: James Sewart <jamessewart@arista.com>
> ---
>   drivers/iommu/intel-iommu.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
> index 2e00e8708f06..104d36f225a7 100644
> --- a/drivers/iommu/intel-iommu.c
> +++ b/drivers/iommu/intel-iommu.c
> @@ -5101,6 +5101,11 @@ static int intel_iommu_attach_device(struct iommu_domain *domain,
>   		}
>   	}
>   
> +	if (iommu_no_mapping(dev)) {
> +		dmar_domain = si_domain;
> +		dev_warn(dev, "VT-d: Device is required to use identity IOMMU mapping, ignoring domain attached\n");
> +	}

This is awful. :-)

IOMMU generic layer allocated a @domain and tries to bind the @domain
with a device. This code replaces @domain with si_domain without
notifying the upper layer.

Best regards,
Lu Baolu

Patch

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 2e00e8708f06..104d36f225a7 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -5101,6 +5101,11 @@  static int intel_iommu_attach_device(struct iommu_domain *domain,
 		}
 	}
 
+	if (iommu_no_mapping(dev)) {
+		dmar_domain = si_domain;
+		dev_warn(dev, "VT-d: Device is required to use identity IOMMU mapping, ignoring domain attached\n");
+	}
+
 	iommu = device_to_iommu(dev, &bus, &devfn);
 	if (!iommu)
 		return -ENODEV;