linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	alan@lxorguk.ukuu.org.uk, Soeren Moch <smoch@web.de>,
	Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Andrew Lunn <andrew@lunn.ch>
Subject: [ 01/27] mm: dmapool: use provided gfp flags for all dma_alloc_coherent() calls
Date: Fri, 14 Dec 2012 15:01:14 -0800	[thread overview]
Message-ID: <20121214222251.527615897@linuxfoundation.org> (raw)
In-Reply-To: <20121214222251.229078963@linuxfoundation.org>

3.7-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Marek Szyprowski <m.szyprowski@samsung.com>

commit 387870f2d6d679746020fa8e25ef786ff338dc98 upstream.

dmapool always calls dma_alloc_coherent() with GFP_ATOMIC flag,
regardless the flags provided by the caller. This causes excessive
pruning of emergency memory pools without any good reason. Additionaly,
on ARM architecture any driver which is using dmapools will sooner or
later  trigger the following error:
"ERROR: 256 KiB atomic DMA coherent pool is too small!
Please increase it with coherent_pool= kernel parameter!".
Increasing the coherent pool size usually doesn't help much and only
delays such error, because all GFP_ATOMIC DMA allocations are always
served from the special, very limited memory pool.

This patch changes the dmapool code to correctly use gfp flags provided
by the dmapool caller.

Reported-by: Soeren Moch <smoch@web.de>
Reported-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Andrew Lunn <andrew@lunn.ch>
Tested-by: Soeren Moch <smoch@web.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 mm/dmapool.c |   31 +++++++------------------------
 1 file changed, 7 insertions(+), 24 deletions(-)

--- a/mm/dmapool.c
+++ b/mm/dmapool.c
@@ -50,7 +50,6 @@ struct dma_pool {		/* the pool */
 	size_t allocation;
 	size_t boundary;
 	char name[32];
-	wait_queue_head_t waitq;
 	struct list_head pools;
 };
 
@@ -62,8 +61,6 @@ struct dma_page {		/* cacheable header f
 	unsigned int offset;
 };
 
-#define	POOL_TIMEOUT_JIFFIES	((100 /* msec */ * HZ) / 1000)
-
 static DEFINE_MUTEX(pools_lock);
 
 static ssize_t
@@ -172,7 +169,6 @@ struct dma_pool *dma_pool_create(const c
 	retval->size = size;
 	retval->boundary = boundary;
 	retval->allocation = allocation;
-	init_waitqueue_head(&retval->waitq);
 
 	if (dev) {
 		int ret;
@@ -227,7 +223,6 @@ static struct dma_page *pool_alloc_page(
 		memset(page->vaddr, POOL_POISON_FREED, pool->allocation);
 #endif
 		pool_initialise_page(pool, page);
-		list_add(&page->page_list, &pool->page_list);
 		page->in_use = 0;
 		page->offset = 0;
 	} else {
@@ -315,30 +310,21 @@ void *dma_pool_alloc(struct dma_pool *po
 	might_sleep_if(mem_flags & __GFP_WAIT);
 
 	spin_lock_irqsave(&pool->lock, flags);
- restart:
 	list_for_each_entry(page, &pool->page_list, page_list) {
 		if (page->offset < pool->allocation)
 			goto ready;
 	}
-	page = pool_alloc_page(pool, GFP_ATOMIC);
-	if (!page) {
-		if (mem_flags & __GFP_WAIT) {
-			DECLARE_WAITQUEUE(wait, current);
 
-			__set_current_state(TASK_UNINTERRUPTIBLE);
-			__add_wait_queue(&pool->waitq, &wait);
-			spin_unlock_irqrestore(&pool->lock, flags);
+	/* pool_alloc_page() might sleep, so temporarily drop &pool->lock */
+	spin_unlock_irqrestore(&pool->lock, flags);
 
-			schedule_timeout(POOL_TIMEOUT_JIFFIES);
+	page = pool_alloc_page(pool, mem_flags);
+	if (!page)
+		return NULL;
 
-			spin_lock_irqsave(&pool->lock, flags);
-			__remove_wait_queue(&pool->waitq, &wait);
-			goto restart;
-		}
-		retval = NULL;
-		goto done;
-	}
+	spin_lock_irqsave(&pool->lock, flags);
 
+	list_add(&page->page_list, &pool->page_list);
  ready:
 	page->in_use++;
 	offset = page->offset;
@@ -348,7 +334,6 @@ void *dma_pool_alloc(struct dma_pool *po
 #ifdef	DMAPOOL_DEBUG
 	memset(retval, POOL_POISON_ALLOCATED, pool->size);
 #endif
- done:
 	spin_unlock_irqrestore(&pool->lock, flags);
 	return retval;
 }
@@ -435,8 +420,6 @@ void dma_pool_free(struct dma_pool *pool
 	page->in_use--;
 	*(int *)vaddr = page->offset;
 	page->offset = offset;
-	if (waitqueue_active(&pool->waitq))
-		wake_up_locked(&pool->waitq);
 	/*
 	 * Resist a temptation to do
 	 *    if (!is_page_busy(page)) pool_free_page(pool, page);



  reply	other threads:[~2012-12-14 23:13 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-14 23:01 [ 00/27] 3.7.1-stable review Greg Kroah-Hartman
2012-12-14 23:01 ` Greg Kroah-Hartman [this message]
2012-12-14 23:01 ` [ 02/27] clk: ux500: fix bit error Greg Kroah-Hartman
2012-12-14 23:01 ` [ 03/27] x86,AMD: Power driver support for AMDs family 16h processors Greg Kroah-Hartman
2012-12-14 23:01 ` [ 04/27] telephony: ijx: buffer overflow in ixj_write_cid() Greg Kroah-Hartman
2012-12-14 23:01 ` [ 05/27] ezusb: add dependency to USB Greg Kroah-Hartman
2012-12-14 23:01 ` [ 06/27] x86: hpet: Fix masking of MSI interrupts Greg Kroah-Hartman
2012-12-14 23:01 ` [ 07/27] USB: add new zte 3g-dongles pid to option.c Greg Kroah-Hartman
2012-12-14 23:01 ` [ 08/27] USB: option: blacklist network interface on Huawei E173 Greg Kroah-Hartman
2012-12-14 23:01 ` [ 09/27] USB: ftdi_sio: Add support for Newport AGILIS motor drivers Greg Kroah-Hartman
2012-12-14 23:01 ` [ 10/27] usb: ftdi_sio: fixup BeagleBone A5+ quirk Greg Kroah-Hartman
2012-12-14 23:01 ` [ 11/27] USB: cp210x: add Virtenio Preon32 device id Greg Kroah-Hartman
2012-12-14 23:01 ` [ 12/27] USB: mark uas driver as BROKEN Greg Kroah-Hartman
2012-12-14 23:01 ` [ 13/27] ACPI / battery: Correct battery capacity values on Thinkpads Greg Kroah-Hartman
2012-12-14 23:01 ` [ 14/27] ACPI / PM: Add Sony Vaio VPCEB1S1E to nonvs blacklist Greg Kroah-Hartman
2012-12-14 23:01 ` [ 15/27] ACPI / PNP: Do not crash due to stale pointer use during system resume Greg Kroah-Hartman
2012-12-14 23:01 ` [ 16/27] ACPI / video: ignore BIOS initial backlight value for HP Folio 13-2000 Greg Kroah-Hartman
2012-12-14 23:01 ` [ 17/27] ACPI / video: Add "Asus UL30VT" to ACPI video detect blacklist Greg Kroah-Hartman
2012-12-14 23:01 ` [ 18/27] USB: OHCI: workaround for hardware bug: retired TDs not added to the Done Queue Greg Kroah-Hartman
2012-12-14 23:01 ` [ 19/27] xhci: Extend Fresco Logic MSI quirk Greg Kroah-Hartman
2012-12-14 23:01 ` [ 20/27] ftrace: Clear bits properly in reset_iter_read() Greg Kroah-Hartman
2012-12-14 23:01 ` [ 21/27] ring-buffer: Fix NULL pointer if rb_set_head_page() fails Greg Kroah-Hartman
2012-12-14 23:01 ` [ 22/27] ring-buffer: Fix race between integrity check and readers Greg Kroah-Hartman
2012-12-14 23:01 ` [ 23/27] cdc-acm: implement TIOCSSERIAL to avoid blocking close(2) Greg Kroah-Hartman
2012-12-14 23:01 ` [ 24/27] perf test: fix a build error on builtin-test Greg Kroah-Hartman
2012-12-14 23:01 ` [ 25/27] USB: EHCI: bugfix: urb->hcpriv should not be NULL Greg Kroah-Hartman
2012-12-14 23:01 ` [ 26/27] rcu: Fix batch-limit size problem Greg Kroah-Hartman
2012-12-14 23:01 ` [ 27/27] Staging: bcm: Add two products and remove an existing product Greg Kroah-Hartman
2012-12-15 14:22 ` [ 00/27] 3.7.1-stable review Shuah Khan
2012-12-15 20:47   ` Shuah Khan
2012-12-15 14:53 ` Satoru Takeuchi
2012-12-16 19:52 ` Nikola Ciprich
2012-12-17 22:07 ` Mariusz Kozlowski
2012-12-17 22:14   ` Greg Kroah-Hartman
2012-12-17 22:38     ` Mariusz Kozlowski

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=20121214222251.527615897@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=andrew@lunn.ch \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=smoch@web.de \
    --cc=stable@vger.kernel.org \
    --cc=thomas.petazzoni@free-electrons.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).