linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] x86 amd_gart_64: Verify we can perform the remapping requested
Date: Mon, 17 Oct 2011 14:20:15 -0700	[thread overview]
Message-ID: <m1fwir48og.fsf@fess.ebiederm.org> (raw)
In-Reply-To: <m1lisj48q1.fsf@fess.ebiederm.org> (Eric W. Biederman's message of "Mon, 17 Oct 2011 14:19:18 -0700")


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@xmission.com>
---
 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


  reply	other threads:[~2011-10-19 21:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-17 21:19 [PATCH 1/2] x86 swiotlb: Verify we can perform the remapping requested Eric W. Biederman
2011-10-17 21:20 ` Eric W. Biederman [this message]
2011-10-24 10:07   ` [PATCH 2/2] x86 amd_gart_64: " Joerg Roedel
2011-11-11 15:31     ` Joerg Roedel
2011-11-11 18:59       ` Eric W. Biederman
2011-11-12  9:02         ` Joerg Roedel
2011-10-21  0:40 ` [PATCH 1/2] x86 swiotlb: " Konrad Rzeszutek Wilk
2011-10-24 15:07   ` Eric W. Biederman
2011-10-27  0:01     ` FUJITA Tomonori
2011-10-27  6:10       ` Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1fwir48og.fsf@fess.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).