Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: at91_mci: don't use coherent dma buffers

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: Pierre Ossman <drzeus-mmc@drzeus.cx>
Cc: Andrew Victor <linux@maxim.org.za>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

David Brownell and committed by
Linus Torvalds
e385ea63 363f66fe

+16 -4
+16 -4
drivers/mmc/host/at91_mci.c
··· 621 621 if (cpu_is_at91sam9260 () || cpu_is_at91sam9263()) 622 622 if (host->total_length < 12) 623 623 host->total_length = 12; 624 - host->buffer = dma_alloc_coherent(NULL, 625 - host->total_length, 626 - &host->physical_address, GFP_KERNEL); 624 + 625 + host->buffer = kmalloc(host->total_length, GFP_KERNEL); 626 + if (!host->buffer) { 627 + pr_debug("Can't alloc tx buffer\n"); 628 + cmd->error = -ENOMEM; 629 + mmc_request_done(host->mmc, host->request); 630 + return; 631 + } 627 632 628 633 at91_mci_sg_to_dma(host, data); 634 + 635 + host->physical_address = dma_map_single(NULL, 636 + host->buffer, host->total_length, 637 + DMA_TO_DEVICE); 629 638 630 639 pr_debug("Transmitting %d bytes\n", host->total_length); 631 640 ··· 703 694 cmd->resp[3] = at91_mci_read(host, AT91_MCI_RSPR(3)); 704 695 705 696 if (host->buffer) { 706 - dma_free_coherent(NULL, host->total_length, host->buffer, host->physical_address); 697 + dma_unmap_single(NULL, 698 + host->physical_address, host->total_length, 699 + DMA_TO_DEVICE); 700 + kfree(host->buffer); 707 701 host->buffer = NULL; 708 702 } 709 703