Commit 8aafaaf2 authored by Joerg Roedel's avatar Joerg Roedel

iommu/amd: Reserve exclusion range in iova-domain

If a device has an exclusion range specified in the IVRS
table, this region needs to be reserved in the iova-domain
of that device. This hasn't happened until now and can cause
data corruption on data transfered with these devices.

Treat exclusion ranges as reserved regions in the iommu-core
to fix the problem.

Fixes: be2a022c ('x86, AMD IOMMU: add functions to parse IOMMU memory mapping requirements for devices')
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
Reviewed-by: default avatarGary R Hook <gary.hook@amd.com>
parent 8bc32a28
...@@ -3169,21 +3169,24 @@ static void amd_iommu_get_resv_regions(struct device *dev, ...@@ -3169,21 +3169,24 @@ static void amd_iommu_get_resv_regions(struct device *dev,
return; return;
list_for_each_entry(entry, &amd_iommu_unity_map, list) { list_for_each_entry(entry, &amd_iommu_unity_map, list) {
int type, prot = 0;
size_t length; size_t length;
int prot = 0;
if (devid < entry->devid_start || devid > entry->devid_end) if (devid < entry->devid_start || devid > entry->devid_end)
continue; continue;
type = IOMMU_RESV_DIRECT;
length = entry->address_end - entry->address_start; length = entry->address_end - entry->address_start;
if (entry->prot & IOMMU_PROT_IR) if (entry->prot & IOMMU_PROT_IR)
prot |= IOMMU_READ; prot |= IOMMU_READ;
if (entry->prot & IOMMU_PROT_IW) if (entry->prot & IOMMU_PROT_IW)
prot |= IOMMU_WRITE; prot |= IOMMU_WRITE;
if (entry->prot & IOMMU_UNITY_MAP_FLAG_EXCL_RANGE)
/* Exclusion range */
type = IOMMU_RESV_RESERVED;
region = iommu_alloc_resv_region(entry->address_start, region = iommu_alloc_resv_region(entry->address_start,
length, prot, length, prot, type);
IOMMU_RESV_DIRECT);
if (!region) { if (!region) {
dev_err(dev, "Out of memory allocating dm-regions\n"); dev_err(dev, "Out of memory allocating dm-regions\n");
return; return;
......
...@@ -2013,6 +2013,9 @@ static int __init init_unity_map_range(struct ivmd_header *m) ...@@ -2013,6 +2013,9 @@ static int __init init_unity_map_range(struct ivmd_header *m)
if (e == NULL) if (e == NULL)
return -ENOMEM; return -ENOMEM;
if (m->flags & IVMD_FLAG_EXCL_RANGE)
init_exclusion_range(m);
switch (m->type) { switch (m->type) {
default: default:
kfree(e); kfree(e);
...@@ -2059,9 +2062,7 @@ static int __init init_memory_definitions(struct acpi_table_header *table) ...@@ -2059,9 +2062,7 @@ static int __init init_memory_definitions(struct acpi_table_header *table)
while (p < end) { while (p < end) {
m = (struct ivmd_header *)p; m = (struct ivmd_header *)p;
if (m->flags & IVMD_FLAG_EXCL_RANGE) if (m->flags & (IVMD_FLAG_UNITY_MAP | IVMD_FLAG_EXCL_RANGE))
init_exclusion_range(m);
else if (m->flags & IVMD_FLAG_UNITY_MAP)
init_unity_map_range(m); init_unity_map_range(m);
p += m->length; p += m->length;
......
...@@ -374,6 +374,8 @@ ...@@ -374,6 +374,8 @@
#define IOMMU_PROT_IR 0x01 #define IOMMU_PROT_IR 0x01
#define IOMMU_PROT_IW 0x02 #define IOMMU_PROT_IW 0x02
#define IOMMU_UNITY_MAP_FLAG_EXCL_RANGE (1 << 2)
/* IOMMU capabilities */ /* IOMMU capabilities */
#define IOMMU_CAP_IOTLB 24 #define IOMMU_CAP_IOTLB 24
#define IOMMU_CAP_NPCACHE 26 #define IOMMU_CAP_NPCACHE 26
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment