Re: swiotlb_alloc_coherent: allocated memory is out of range fordevice
From: FUJITA Tomonori
Date: Thu Oct 23 2008 - 07:47:39 EST
On Thu, 23 Oct 2008 12:15:57 +0200
Ingo Molnar <mingo@xxxxxxx> wrote:
> * Takashi Iwai <tiwai@xxxxxxx> wrote:
> > At Thu, 23 Oct 2008 07:22:09 +0200,
> > I wrote:
> > >
> > > > The current dma_alloc_coherent (asm-x86/dma-mapping.h) handles the gfp
> > > > flags in the exact same way as the old dma_alloc_coherent
> > > > (pci-dma.c). Neither sets GFP_DMA even if coherent_dma_mask is
> > > > 24bits. The old code is fine because of the GFP_DMA retry
> > > > mechanism. But if coherent_dma_mask is 24bits, there is no point to go
> > > > into the GFP_DMA retry mechanism. We should use GFP_DMA in the first
> > > > place.
> > > >
> > > > How about the following patch?
> > >
> > > I'll give it a try later (the machine is in my office).
> > The patch seems working fine. Thanks!
> > Tested-by: Takashi Iwai <tiwai@xxxxxxx>
> thanks guys - i've queued it up in tip/core/urgent and will send a pull
> request to Linus later today.
Thanks, I can't find the commit right now so I'm not sure if you need
the patch description but anyway, here's a sane format of the patch.
From: FUJITA Tomonori <fujita.tomonori@xxxxxxxxxxxxx>
Subject: [PATCH] x86: use GFP_DMA for 24bit coherent_dma_mask
dma_alloc_coherent (include/asm-x86/dma-mapping.h) avoids GFP_DMA
allocation first and if the allocated address is not fit for the
device's coherent_dma_mask, then dma_alloc_coherent does GFP_DMA
allocation. This is because dma_alloc_coherent avoids precious GFP_DMA
zone if possible. This is also how the old dma_alloc_coherent
However, if the coherent_dma_mask of a device is 24bit, there is no
point to go into the above GFP_DMA retry mechanism. We had better use
GFP_DMA in the first place.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxxxxxx>
Tested-by: Takashi Iwai <tiwai@xxxxxxx>
include/asm-x86/dma-mapping.h | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/include/asm-x86/dma-mapping.h b/include/asm-x86/dma-mapping.h
index 219c33d..05fcec5 100644
@@ -255,9 +255,11 @@ static inline unsigned long dma_alloc_coherent_mask(struct device *dev,
static inline gfp_t dma_alloc_coherent_gfp_flags(struct device *dev, gfp_t gfp)
unsigned long dma_mask = dma_alloc_coherent_mask(dev, gfp);
+ if (dma_mask <= DMA_24BIT_MASK)
+ gfp |= GFP_DMA;
if (dma_mask <= DMA_32BIT_MASK && !(gfp & GFP_DMA))
gfp |= GFP_DMA32;
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/