All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: Linux Kernel list <linux-kernel@vger.kernel.org>
Cc: Russell King <rmk@arm.linux.org.uk>, David Miller <davem@davemloft.net>
Subject: [patch 2.6.23-rc1] dma_free_coherent() needs irqs enabled (sigh)
Date: Tue, 24 Jul 2007 14:29:05 -0700	[thread overview]
Message-ID: <200707241429.05615.david-b@pacbell.net> (raw)

On at least ARM (and I'm told MIPS too) dma_free_coherent() has a newish
call context requirement:  unlike its dma_alloc_coherent() sibling, it
may not be called with IRQs disabled.  (This was new behavior on ARM as
of late 2006, caused by ARM SMP updates.)  This little surprise can be
annoyingly driver-visible.

Since it looks like that restriction won't be removed, this patch changes
the definition of the API to include that requirement.  Also, to help
catch nonportable drivers, it updates the x86 and swiotlb versions to
include the relevant warnings.  (I already observed that it trips on the
bus_reset_tasklet of the new firewire_ohci driver.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: David Miller <davem@davemloft.net>
Cc: Russell King <rmk@arm.linux.org.uk>
---
 Documentation/DMA-API.txt    |    3 +++
 arch/i386/kernel/pci-dma.c   |    3 ++-
 arch/x86_64/kernel/pci-dma.c |    1 +
 lib/swiotlb.c                |    1 +
 4 files changed, 7 insertions(+), 1 deletion(-)

--- g26.orig/Documentation/DMA-API.txt	2007-07-22 05:06:57.000000000 -0700
+++ g26/Documentation/DMA-API.txt	2007-07-22 14:48:45.000000000 -0700
@@ -68,6 +68,9 @@ size and dma_handle must all be the same
 consistent allocate.  cpu_addr must be the virtual address returned by
 the consistent allocate
 
+Note that unlike their sibling allocation calls, these routines
+may only be called with IRQs enabled.
+
 
 Part Ib - Using small dma-coherent buffers
 ------------------------------------------
--- g26.orig/arch/x86_64/kernel/pci-dma.c	2007-07-22 05:13:10.000000000 -0700
+++ g26/arch/x86_64/kernel/pci-dma.c	2007-07-22 14:48:45.000000000 -0700
@@ -163,6 +163,7 @@ EXPORT_SYMBOL(dma_alloc_coherent);
 void dma_free_coherent(struct device *dev, size_t size,
 			 void *vaddr, dma_addr_t bus)
 {
+	WARN_ON(irqs_disabled());	/* for portability */
 	if (dma_ops->unmap_single)
 		dma_ops->unmap_single(dev, bus, size, 0);
 	free_pages((unsigned long)vaddr, get_order(size));
--- g26.orig/arch/i386/kernel/pci-dma.c	2007-07-22 05:06:57.000000000 -0700
+++ g26/arch/i386/kernel/pci-dma.c	2007-07-22 14:48:46.000000000 -0700
@@ -63,7 +63,8 @@ void dma_free_coherent(struct device *de
 {
 	struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL;
 	int order = get_order(size);
-	
+
+	WARN_ON(irqs_disabled());	/* for portability */
 	if (mem && vaddr >= mem->virt_base && vaddr < (mem->virt_base + (mem->size << PAGE_SHIFT))) {
 		int page = (vaddr - mem->virt_base) >> PAGE_SHIFT;
 
--- g26.orig/lib/swiotlb.c	2007-07-22 05:13:15.000000000 -0700
+++ g26/lib/swiotlb.c	2007-07-22 14:48:46.000000000 -0700
@@ -497,6 +497,7 @@ void
 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
 		      dma_addr_t dma_handle)
 {
+	WARN_ON(irqs_disabled());
 	if (!(vaddr >= (void *)io_tlb_start
                     && vaddr < (void *)io_tlb_end))
 		free_pages((unsigned long) vaddr, get_order(size));

             reply	other threads:[~2007-07-24 21:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-24 21:29 David Brownell [this message]
2007-07-24 22:07 ` [patch 2.6.23-rc1] dma_free_coherent() needs irqs enabled (sigh) Russell King
2007-07-24 23:08   ` David Brownell
2007-07-24 23:11     ` Russell King
2007-07-25  0:35       ` David Brownell
2007-07-25 10:46 ` Stefan Richter
2007-07-25 17:18   ` [PATCH] firewire: fw-ohci: dma_free_coherent needs IRQs enabled Stefan Richter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200707241429.05615.david-b@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmk@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.