[PATCH 2/2] x86 amd_gart_64: Verify we can perform the remapping requested

From: Eric W. Biederman
Date: Wed Oct 19 2011 - 17:36:17 EST



Recently I had a driver try with a peculiar 2G dma memory limit.
The driver failed in weird and strange ways because the GART remapping
apperture had been allocated above 2G where the driver cound not reach,
and no error was reported when the mappings were setup.

Implement gart_dma_supported to test for this problem case and to return
and error if we can not support the remapping.

Signed-off-by: Eric W. Biederman <ebiederm@xxxxxxxxxxxx>
---
arch/x86/kernel/amd_gart_64.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
index 8a439d3..66279cb 100644
--- a/arch/x86/kernel/amd_gart_64.c
+++ b/arch/x86/kernel/amd_gart_64.c
@@ -519,6 +519,14 @@ static int gart_mapping_error(struct device *dev, dma_addr_t dma_addr)
return (dma_addr == bad_dma_addr);
}

+static int gart_dma_supported(struct device *dev, u64 mask)
+{
+ unsigned long iommu_max_addr = iommu_bus_base + iommu_size - 1;
+
+ /* Fail if the gart window is too high to fit in the devices dma mask */
+ return iommu_max_addr <= mask;
+}
+
static int no_agp;

static __init unsigned long check_iommu_size(unsigned long aper, u64 aper_size)
@@ -703,6 +711,7 @@ static struct dma_map_ops gart_dma_ops = {
.alloc_coherent = gart_alloc_coherent,
.free_coherent = gart_free_coherent,
.mapping_error = gart_mapping_error,
+ .dma_supported = gart_dma_supported,
};

static void gart_iommu_shutdown(void)
--
1.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/