lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1220454224-25985-1-git-send-email-joerg.roedel@amd.com>
Date:	Wed, 3 Sep 2008 17:03:44 +0200
From:	Joerg Roedel <joerg.roedel@....com>
To:	mingo@...hat.com, tglx@...utronix.de, hpa@...or.com
CC:	linux-kernel@...r.kernel.org, iommu@...ts.linux-foundation.org,
	Joerg Roedel <joerg.roedel@....com>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@...fujitsu.com>,
	tony.luck@...el.com
Subject: [PATCH] swiotlb: fix dma_alloc_coherent allocation failures with swiotlb

The SWIOTLB version of dma_alloc_coherent allocates all memory with
GFP_DMA unconditionally. This leads sometimes unnecessary to allocation
failures. This patch makes the allocation strategy to use the DMA32 zone
first if this is possible. The changes are boot tested on AMD64 and
compile tested for i386 and IA64.

Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@...fujitsu.com>
Cc: tony.luck@...el.com
Signed-off-by: Joerg Roedel <joerg.roedel@....com>
---
 lib/swiotlb.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 977edbd..6ba077f 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -466,13 +466,24 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size,
 	dma_addr_t dev_addr;
 	void *ret;
 	int order = get_order(size);
+	unsigned long dma_mask;
 
-	/*
-	 * XXX fix me: the DMA API should pass us an explicit DMA mask
-	 * instead, or use ZONE_DMA32 (ia64 overloads ZONE_DMA to be a ~32
-	 * bit range instead of a 16MB one).
-	 */
-	flags |= GFP_DMA;
+	if (hwdev->dma_mask == NULL)
+		return NULL;
+
+	flags &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
+	flags |= __GFP_ZERO;
+
+	dma_mask = hwdev->coherent_dma_mask;
+	if (!dma_mask)
+		dma_mask = *(hwdev->dma_mask);
+
+	if (dma_mask <= ISA_DMA_THRESHOLD)
+		flags |= GFP_DMA;
+#ifdef CONFIG_X86_64
+	else if (dma_mask <= DMA_32BIT_MASK)
+		flags |= GFP_DMA32;
+#endif
 
 	ret = (void *)__get_free_pages(flags, order);
 	if (ret && address_needs_mapping(hwdev, virt_to_bus(ret))) {
-- 
1.5.3.7


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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ