Skip to contentSkip to conversation

x86: adjust GFP mask handling for coherent allocations (take 2)

PATCH In review Jan Beulich 4 participants 4 messages Nov 4, 2009 – Nov 8, 2009 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: adjust GFP mask handling for coherent allocations (take 2)

Rather than forcing GFP flags and DMA mask to be inconsistent, GFP flags should be determined even for the fallback device through dma_alloc_coherent_mask()/dma_alloc_coherent_gfp_flags(). This restores 64-bit behavior as it was prior to commits 8965eb19386fdf5ccd0ef8b02593eb8560aa3416 and 4a367f3a9dbf2e7ffcee4702203479809236ee6e (not sure why there are two of them), where GFP_DMA was forced on for 32-bit, but not for 64-bit, with the slight adjustment that afaict even 32-bit doesn't need this without CONFIG_ISA.

Cc Takashi Iwai <[email protected]>
Cc Jesse Barnes <[email protected]>
---
 arch/x86/include/asm/dma-mapping.h |   10 +++++++---
 arch/x86/kernel/pci-dma.c          |    6 ++----
 2 files changed, 9 insertions(+), 7 deletions(-)
arch/x86/include/asm/dma-mapping.h +7 -3
@@ -14,6 +14,12 @@
 #include <asm/swiotlb.h>
 #include <asm-generic/dma-coherent.h>
 
+#ifdef CONFIG_ISA
+#define ISA_DMA_BIT_MASK DMA_BIT_MASK(24)
+#else
+#define ISA_DMA_BIT_MASK DMA_BIT_MASK(32)
+#endif
+
 extern dma_addr_t bad_dma_address;
 extern int iommu_merge;
 extern struct device x86_dma_fallback_dev;
@@ -124,10 +130,8 @@ dma_alloc_coherent(struct device *dev, s
 	if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
 		return memory;
 
-	if (!dev) {
+	if (!dev)
 		dev = &x86_dma_fallback_dev;
-		gfp |= GFP_DMA;
-	}
 
 	if (!is_device_dma_capable(dev))
 		return NULL;
arch/x86/kernel/pci-dma.c +2 -4
@@ -45,12 +45,10 @@ int iommu_pass_through __read_mostly;
 dma_addr_t bad_dma_address __read_mostly = 0;
 EXPORT_SYMBOL(bad_dma_address);
 
-/* Dummy device used for NULL arguments (normally ISA). Better would
-   be probably a smaller DMA mask, but this is bug-to-bug compatible
-   to older i386. */
+/* Dummy device used for NULL arguments (normally ISA). */
 struct device x86_dma_fallback_dev = {
 	.init_name = "fallback device",
-	.coherent_dma_mask = DMA_BIT_MASK(32),
+	.coherent_dma_mask = ISA_DMA_BIT_MASK,
 	.dma_mask = &x86_dma_fallback_dev.coherent_dma_mask,
 };
 EXPORT_SYMBOL(x86_dma_fallback_dev);
Acked-by on v1 1/1
#1 lore raw

At Wed, 04 Nov 2009 12:28:39 +0000,

Quoted 11 lines · Jan Beulich

Rather than forcing GFP flags and DMA mask to be inconsistent, GFP flags should be determined even for the fallback device through dma_alloc_coherent_mask()/dma_alloc_coherent_gfp_flags(). This restores 64-bit behavior as it was prior to commits 8965eb19386fdf5ccd0ef8b02593eb8560aa3416 and 4a367f3a9dbf2e7ffcee4702203479809236ee6e (not sure why there are two of them), where GFP_DMA was forced on for 32-bit, but not for 64-bit, with the slight adjustment that afaict even 32-bit doesn't need this without CONFIG_ISA.

Quoted 2 lines

thanks,

Takashi

Quoted 54 lines
Cc Jesse Barnes <[email protected]>
---
 arch/x86/include/asm/dma-mapping.h |   10 +++++++---
 arch/x86/kernel/pci-dma.c          |    6 ++----
 2 files changed, 9 insertions(+), 7 deletions(-)
arch/x86/include/asm/dma-mapping.h +7 -3
@@ -14,6 +14,12 @@
 #include <asm/swiotlb.h>
 #include <asm-generic/dma-coherent.h>
 
+#ifdef CONFIG_ISA
+#define ISA_DMA_BIT_MASK DMA_BIT_MASK(24)
+#else
+#define ISA_DMA_BIT_MASK DMA_BIT_MASK(32)
+#endif
+
 extern dma_addr_t bad_dma_address;
 extern int iommu_merge;
 extern struct device x86_dma_fallback_dev;
@@ -124,10 +130,8 @@ dma_alloc_coherent(struct device *dev, s
 	if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
 		return memory;
 
-	if (!dev) {
+	if (!dev)
 		dev = &x86_dma_fallback_dev;
-		gfp |= GFP_DMA;
-	}
 
 	if (!is_device_dma_capable(dev))
 		return NULL;
arch/x86/kernel/pci-dma.c +2 -4
@@ -45,12 +45,10 @@ int iommu_pass_through __read_mostly;
 dma_addr_t bad_dma_address __read_mostly = 0;
 EXPORT_SYMBOL(bad_dma_address);
 
-/* Dummy device used for NULL arguments (normally ISA). Better would
-   be probably a smaller DMA mask, but this is bug-to-bug compatible
-   to older i386. */
+/* Dummy device used for NULL arguments (normally ISA). */
 struct device x86_dma_fallback_dev = {
 	.init_name = "fallback device",
-	.coherent_dma_mask = DMA_BIT_MASK(32),
+	.coherent_dma_mask = ISA_DMA_BIT_MASK,
 	.dma_mask = &x86_dma_fallback_dev.coherent_dma_mask,
 };
 EXPORT_SYMBOL(x86_dma_fallback_dev);
#2 lore raw

PATCH v3 1/1 x86: Adjust GFP mask handling for coherent allocations

Quoted 13 lines · Takashi Iwai

At Wed, 04 Nov 2009 12:28:39 +0000,

Quoted 11 lines · Jan Beulich

Rather than forcing GFP flags and DMA mask to be inconsistent, GFP flags should be determined even for the fallback device through dma_alloc_coherent_mask()/dma_alloc_coherent_gfp_flags(). This restores 64-bit behavior as it was prior to commits 8965eb19386fdf5ccd0ef8b02593eb8560aa3416 and 4a367f3a9dbf2e7ffcee4702203479809236ee6e (not sure why there are two of them), where GFP_DMA was forced on for 32-bit, but not for 64-bit, with the slight adjustment that afaict even 32-bit doesn't need this without CONFIG_ISA.

Quoted 4 lines
Quoted 2 lines

Jesse, mind picking this up for .32?

I've attached below a slightly cleaned up version of the patch, with Takashi's ack added.

Thanks,

Ingo

------------------>
Subject: x86: Adjust GFP mask handling for coherent allocations
From: "Jan Beulich" <[email protected]>
Date: Wed, 04 Nov 2009 12:28:39 +0000

Rather than forcing GFP flags and DMA mask to be inconsistent, GFP flags should be determined even for the fallback device through dma_alloc_coherent_mask()/dma_alloc_coherent_gfp_flags().

This restores 64-bit behavior as it was prior to commits 8965eb19386fdf5ccd0ef8b02593eb8560aa3416 and 4a367f3a9dbf2e7ffcee4702203479809236ee6e (not sure why there are two of them), where GFP_DMA was forced on for 32-bit, but not for 64-bit, with the slight adjustment that afaict even 32-bit doesn't need this without CONFIG_ISA.

LKML-Reference: <[email protected]>

---
 arch/x86/include/asm/dma-mapping.h |   10 +++++++---
 arch/x86/kernel/pci-dma.c          |    6 ++----
 2 files changed, 9 insertions(+), 7 deletions(-)
arch/x86/include/asm/dma-mapping.h +7 -3
Index: tip/arch/x86/include/asm/dma-mapping.h
===================================================================
@@ -14,6 +14,12 @@
 #include <asm/swiotlb.h>
 #include <asm-generic/dma-coherent.h>
 
+#ifdef CONFIG_ISA
+# define ISA_DMA_BIT_MASK DMA_BIT_MASK(24)
+#else
+# define ISA_DMA_BIT_MASK DMA_BIT_MASK(32)
+#endif
+
 extern dma_addr_t bad_dma_address;
 extern int iommu_merge;
 extern struct device x86_dma_fallback_dev;
@@ -124,10 +130,8 @@ dma_alloc_coherent(struct device *dev, s
 	if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
 		return memory;
 
-	if (!dev) {
+	if (!dev)
 		dev = &x86_dma_fallback_dev;
-		gfp |= GFP_DMA;
-	}
 
 	if (!is_device_dma_capable(dev))
 		return NULL;
arch/x86/kernel/pci-dma.c +2 -4
Index: tip/arch/x86/kernel/pci-dma.c
===================================================================
@@ -45,12 +45,10 @@ int iommu_pass_through __read_mostly;
 dma_addr_t bad_dma_address __read_mostly = 0;
 EXPORT_SYMBOL(bad_dma_address);
 
-/* Dummy device used for NULL arguments (normally ISA). Better would
-   be probably a smaller DMA mask, but this is bug-to-bug compatible
-   to older i386. */
+/* Dummy device used for NULL arguments (normally ISA). */
 struct device x86_dma_fallback_dev = {
 	.init_name = "fallback device",
-	.coherent_dma_mask = DMA_BIT_MASK(32),
+	.coherent_dma_mask = ISA_DMA_BIT_MASK,
 	.dma_mask = &x86_dma_fallback_dev.coherent_dma_mask,
 };
 EXPORT_SYMBOL(x86_dma_fallback_dev);
#3 lore raw

Re: [PATCH, v3] x86: Adjust GFP mask handling for coherent allocations

Quoted 19 lines · On Sun, 8 Nov 2009 12:12:14 +0100 Ingo Molnar <[email protected]> wrote:
Quoted 16 lines · Takashi Iwai

At Wed, 04 Nov 2009 12:28:39 +0000,

Quoted 13 lines · Jan Beulich

Rather than forcing GFP flags and DMA mask to be inconsistent, GFP flags should be determined even for the fallback device through dma_alloc_coherent_mask()/dma_alloc_coherent_gfp_flags(). This restores 64-bit behavior as it was prior to commits 8965eb19386fdf5ccd0ef8b02593eb8560aa3416 and 4a367f3a9dbf2e7ffcee4702203479809236ee6e (not sure why there are two of them), where GFP_DMA was forced on for 32-bit, but not for 64-bit, with the slight adjustment that afaict even 32-bit doesn't need this without CONFIG_ISA.

Quoted 6 lines
Quoted 1 line

Jesse, mind picking this up for .32?

I've attached below a slightly cleaned up version of the patch, with Takashi's ack added.

Sure, I just stuffed it into my for-linus tree, I'll send a pull req on Monday or Tuesday.

Thanks,

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center