public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch 2.6.27-rc3] at91_mci: don't use coherent dma buffers
@ 2008-08-18 23:07 David Brownell
  2008-08-21 13:50 ` Pierre Ossman
  2008-08-22  7:40 ` Nicolas Ferre
  0 siblings, 2 replies; 6+ messages in thread
From: David Brownell @ 2008-08-18 23:07 UTC (permalink / raw)
  To: Pierre Ossman; +Cc: lkml, Andrew Victor, Nicolas Ferre, Russell King

From: David Brownell <dbrownell@users.sourceforge.net>

At91_mci is abusing dma_free_coherent(), which may not be called
with IRQs disabled.  I saw "mkfs.ext3" on an MMC card objecting
voluminously as each write completed:

 WARNING: at arch/arm/mm/consistent.c:368 dma_free_coherent+0x2c/0x224()
 [<c002726c>] (dump_stack+0x0/0x14) from [<c00387d4>] (warn_on_slowpath+0x4c/0x68)
 [<c0038788>] (warn_on_slowpath+0x0/0x68) from [<c0028768>] (dma_free_coherent+0x2c/0x224)
  r6:00008008 r5:ffc06000 r4:00000000
 [<c002873c>] (dma_free_coherent+0x0/0x224) from [<c01918ac>] (at91_mci_irq+0x374/0x420)
 [<c0191538>] (at91_mci_irq+0x0/0x420) from [<c0065d9c>] (handle_IRQ_event+0x2c/0x6c)
 ...

This bug has been around for a LONG time.  The MM warning is
from late 2005, but the driver merged a year later ... so I'm
puzzled why nobody noticed this before now.

The fix involves noting that this buffer shouldn't be DMA-coherent;
it's just used for normal DMA writes.  So replace it with standard
kmalloc() buffering and DMA mapping calls.

This is the quickie fix.  A better one would not rely on allocating
large bounce buffers.  (Note that dma_alloc_coherent could have failed
too, but that case was ignored... kmalloc is a bit more likely to
fail though.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>

---
 drivers/mmc/host/at91_mci.c |   20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

--- a/drivers/mmc/host/at91_mci.c
+++ b/drivers/mmc/host/at91_mci.c
@@ -621,12 +621,21 @@ static void at91_mci_send_command(struct
 				if (cpu_is_at91sam9260 () || cpu_is_at91sam9263())
 					if (host->total_length < 12)
 						host->total_length = 12;
-				host->buffer = dma_alloc_coherent(NULL,
-						host->total_length,
-						&host->physical_address, GFP_KERNEL);
+
+				host->buffer = kmalloc(host->total_length, GFP_KERNEL);
+				if (!host->buffer) {
+					pr_debug("Can't alloc tx buffer\n");
+					cmd->error = -ENOMEM;
+					mmc_request_done(host->mmc, host->request);
+					return;
+				}
 
 				at91_mci_sg_to_dma(host, data);
 
+				host->physical_address = dma_map_single(NULL,
+						host->buffer, host->total_length,
+						DMA_TO_DEVICE);
+
 				pr_debug("Transmitting %d bytes\n", host->total_length);
 
 				at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address);
@@ -694,7 +703,10 @@ static void at91_mci_completed_command(s
 	cmd->resp[3] = at91_mci_read(host, AT91_MCI_RSPR(3));
 
 	if (host->buffer) {
-		dma_free_coherent(NULL, host->total_length, host->buffer, host->physical_address);
+		dma_unmap_single(NULL,
+				host->physical_address, host->total_length,
+				DMA_TO_DEVICE);
+		kfree(host->buffer);
 		host->buffer = NULL;
 	}
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2.6.27-rc3] at91_mci: don't use coherent dma buffers
  2008-08-18 23:07 [patch 2.6.27-rc3] at91_mci: don't use coherent dma buffers David Brownell
@ 2008-08-21 13:50 ` Pierre Ossman
  2008-08-22  7:40 ` Nicolas Ferre
  1 sibling, 0 replies; 6+ messages in thread
From: Pierre Ossman @ 2008-08-21 13:50 UTC (permalink / raw)
  To: David Brownell; +Cc: lkml, Andrew Victor, Nicolas Ferre, Russell King

Ok with you nicolas?

On Mon, 18 Aug 2008 16:07:21 -0700
David Brownell <david-b@pacbell.net> wrote:

> From: David Brownell <dbrownell@users.sourceforge.net>
> 
> At91_mci is abusing dma_free_coherent(), which may not be called
> with IRQs disabled.  I saw "mkfs.ext3" on an MMC card objecting
> voluminously as each write completed:
> 
>  WARNING: at arch/arm/mm/consistent.c:368 dma_free_coherent+0x2c/0x224()
>  [<c002726c>] (dump_stack+0x0/0x14) from [<c00387d4>] (warn_on_slowpath+0x4c/0x68)
>  [<c0038788>] (warn_on_slowpath+0x0/0x68) from [<c0028768>] (dma_free_coherent+0x2c/0x224)
>   r6:00008008 r5:ffc06000 r4:00000000
>  [<c002873c>] (dma_free_coherent+0x0/0x224) from [<c01918ac>] (at91_mci_irq+0x374/0x420)
>  [<c0191538>] (at91_mci_irq+0x0/0x420) from [<c0065d9c>] (handle_IRQ_event+0x2c/0x6c)
>  ...
> 
> This bug has been around for a LONG time.  The MM warning is
> from late 2005, but the driver merged a year later ... so I'm
> puzzled why nobody noticed this before now.
> 
> The fix involves noting that this buffer shouldn't be DMA-coherent;
> it's just used for normal DMA writes.  So replace it with standard
> kmalloc() buffering and DMA mapping calls.
> 
> This is the quickie fix.  A better one would not rely on allocating
> large bounce buffers.  (Note that dma_alloc_coherent could have failed
> too, but that case was ignored... kmalloc is a bit more likely to
> fail though.)
> 
> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
> 
> ---
>  drivers/mmc/host/at91_mci.c |   20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> --- a/drivers/mmc/host/at91_mci.c
> +++ b/drivers/mmc/host/at91_mci.c
> @@ -621,12 +621,21 @@ static void at91_mci_send_command(struct
>  				if (cpu_is_at91sam9260 () || cpu_is_at91sam9263())
>  					if (host->total_length < 12)
>  						host->total_length = 12;
> -				host->buffer = dma_alloc_coherent(NULL,
> -						host->total_length,
> -						&host->physical_address, GFP_KERNEL);
> +
> +				host->buffer = kmalloc(host->total_length, GFP_KERNEL);
> +				if (!host->buffer) {
> +					pr_debug("Can't alloc tx buffer\n");
> +					cmd->error = -ENOMEM;
> +					mmc_request_done(host->mmc, host->request);
> +					return;
> +				}
>  
>  				at91_mci_sg_to_dma(host, data);
>  
> +				host->physical_address = dma_map_single(NULL,
> +						host->buffer, host->total_length,
> +						DMA_TO_DEVICE);
> +
>  				pr_debug("Transmitting %d bytes\n", host->total_length);
>  
>  				at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address);
> @@ -694,7 +703,10 @@ static void at91_mci_completed_command(s
>  	cmd->resp[3] = at91_mci_read(host, AT91_MCI_RSPR(3));
>  
>  	if (host->buffer) {
> -		dma_free_coherent(NULL, host->total_length, host->buffer, host->physical_address);
> +		dma_unmap_single(NULL,
> +				host->physical_address, host->total_length,
> +				DMA_TO_DEVICE);
> +		kfree(host->buffer);
>  		host->buffer = NULL;
>  	}
>  


-- 
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  rdesktop, core developer          http://www.rdesktop.org

  WARNING: This correspondence is being monitored by the
  Swedish government. Make sure your server uses encryption
  for SMTP traffic and consider using PGP for end-to-end
  encryption.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2.6.27-rc3] at91_mci: don't use coherent dma buffers
  2008-08-18 23:07 [patch 2.6.27-rc3] at91_mci: don't use coherent dma buffers David Brownell
  2008-08-21 13:50 ` Pierre Ossman
@ 2008-08-22  7:40 ` Nicolas Ferre
  2008-08-22  8:40   ` Nicolas Ferre
  1 sibling, 1 reply; 6+ messages in thread
From: Nicolas Ferre @ 2008-08-22  7:40 UTC (permalink / raw)
  To: David Brownell, Pierre Ossman, Andrew Morton
  Cc: lkml, Andrew Victor, Russell King

Pierre, Andrew,

You can add my...

David Brownell :
> From: David Brownell <dbrownell@users.sourceforge.net>
> 
> At91_mci is abusing dma_free_coherent(), which may not be called
> with IRQs disabled.  I saw "mkfs.ext3" on an MMC card objecting
> voluminously as each write completed:
> 
>  WARNING: at arch/arm/mm/consistent.c:368 dma_free_coherent+0x2c/0x224()
>  [<c002726c>] (dump_stack+0x0/0x14) from [<c00387d4>] (warn_on_slowpath+0x4c/0x68)
>  [<c0038788>] (warn_on_slowpath+0x0/0x68) from [<c0028768>] (dma_free_coherent+0x2c/0x224)
>   r6:00008008 r5:ffc06000 r4:00000000
>  [<c002873c>] (dma_free_coherent+0x0/0x224) from [<c01918ac>] (at91_mci_irq+0x374/0x420)
>  [<c0191538>] (at91_mci_irq+0x0/0x420) from [<c0065d9c>] (handle_IRQ_event+0x2c/0x6c)
>  ...
> 
> This bug has been around for a LONG time.  The MM warning is
> from late 2005, but the driver merged a year later ... so I'm
> puzzled why nobody noticed this before now.
> 
> The fix involves noting that this buffer shouldn't be DMA-coherent;
> it's just used for normal DMA writes.  So replace it with standard
> kmalloc() buffering and DMA mapping calls.
> 
> This is the quickie fix.  A better one would not rely on allocating
> large bounce buffers.  (Note that dma_alloc_coherent could have failed
> too, but that case was ignored... kmalloc is a bit more likely to
> fail though.)
> 
> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>

...

Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>


-- 
Nicolas Ferre


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2.6.27-rc3] at91_mci: don't use coherent dma buffers
  2008-08-22  7:40 ` Nicolas Ferre
@ 2008-08-22  8:40   ` Nicolas Ferre
  2008-08-27 19:01     ` Pierre Ossman
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Ferre @ 2008-08-22  8:40 UTC (permalink / raw)
  To: David Brownell, Pierre Ossman, Andrew Morton
  Cc: Nicolas Ferre, lkml, Andrew Victor, Russell King

Pierre, Andrew,

Based on Andrew comments, I rewrite this email..

You can add my...

> David Brownell :
>> From: David Brownell <dbrownell@users.sourceforge.net>
>>
>> At91_mci is abusing dma_free_coherent(), which may not be called
>> with IRQs disabled.  I saw "mkfs.ext3" on an MMC card objecting
>> voluminously as each write completed:
>>
>>  WARNING: at arch/arm/mm/consistent.c:368 dma_free_coherent+0x2c/0x224()
>>  [<c002726c>] (dump_stack+0x0/0x14) from [<c00387d4>] 
>> (warn_on_slowpath+0x4c/0x68)
>>  [<c0038788>] (warn_on_slowpath+0x0/0x68) from [<c0028768>] 
>> (dma_free_coherent+0x2c/0x224)
>>   r6:00008008 r5:ffc06000 r4:00000000
>>  [<c002873c>] (dma_free_coherent+0x0/0x224) from [<c01918ac>] 
>> (at91_mci_irq+0x374/0x420)
>>  [<c0191538>] (at91_mci_irq+0x0/0x420) from [<c0065d9c>] 
>> (handle_IRQ_event+0x2c/0x6c)
>>  ...
>>
>> This bug has been around for a LONG time.  The MM warning is
>> from late 2005, but the driver merged a year later ... so I'm
>> puzzled why nobody noticed this before now.
>>
>> The fix involves noting that this buffer shouldn't be DMA-coherent;
>> it's just used for normal DMA writes.  So replace it with standard
>> kmalloc() buffering and DMA mapping calls.
>>
>> This is the quickie fix.  A better one would not rely on allocating
>> large bounce buffers.  (Note that dma_alloc_coherent could have failed
>> too, but that case was ignored... kmalloc is a bit more likely to
>> fail though.)
>>
>> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
> 
> ...

Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>


Kind regards,
-- 
Nicolas Ferre


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2.6.27-rc3] at91_mci: don't use coherent dma buffers
  2008-08-22  8:40   ` Nicolas Ferre
@ 2008-08-27 19:01     ` Pierre Ossman
  2008-08-27 19:11       ` Andrew Morton
  0 siblings, 1 reply; 6+ messages in thread
From: Pierre Ossman @ 2008-08-27 19:01 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Nicolas Ferre, David Brownell, Nicolas Ferre, lkml, Andrew Victor,
	Russell King

On Fri, 22 Aug 2008 10:40:30 +0200
Nicolas Ferre <nicolas.ferre@atmel.com> wrote:

> >>
> >> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
> > 
> > ...
> 
> Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
> 

I have nothing else in my queue, so Andrew, as I suspect you have other
things going to Linus, if you could please include this one as well. :)

Acked-by: Pierre Ossman <drzeus@drzeus.cx>

Rgds
-- 
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  rdesktop, core developer          http://www.rdesktop.org

  WARNING: This correspondence is being monitored by the
  Swedish government. Make sure your server uses encryption
  for SMTP traffic and consider using PGP for end-to-end
  encryption.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2.6.27-rc3] at91_mci: don't use coherent dma buffers
  2008-08-27 19:01     ` Pierre Ossman
@ 2008-08-27 19:11       ` Andrew Morton
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2008-08-27 19:11 UTC (permalink / raw)
  To: Pierre Ossman; +Cc: nicolas.ferre, david-b, linux-kernel, linux, rmk

On Wed, 27 Aug 2008 21:01:05 +0200
Pierre Ossman <drzeus-mmc@drzeus.cx> wrote:

> On Fri, 22 Aug 2008 10:40:30 +0200
> Nicolas Ferre <nicolas.ferre@atmel.com> wrote:
> 
> > >>
> > >> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
> > > 
> > > ...
> > 
> > Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
> > 
> 
> I have nothing else in my queue, so Andrew, as I suspect you have other
> things going to Linus, if you could please include this one as well. :)

No probs, thanks.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-08-27 19:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-18 23:07 [patch 2.6.27-rc3] at91_mci: don't use coherent dma buffers David Brownell
2008-08-21 13:50 ` Pierre Ossman
2008-08-22  7:40 ` Nicolas Ferre
2008-08-22  8:40   ` Nicolas Ferre
2008-08-27 19:01     ` Pierre Ossman
2008-08-27 19:11       ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox