<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/mm/dmapool.c, branch v4.3</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v4.3</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v4.3'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2015-10-02T01:42:35Z</updated>
<entry>
<title>dmapool: fix overflow condition in pool_find_page()</title>
<updated>2015-10-02T01:42:35Z</updated>
<author>
<name>Robin Murphy</name>
<email>robin.murphy@arm.com</email>
</author>
<published>2015-10-01T22:37:19Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=676bd99178cd962ed24ffdad222b7069d330a969'/>
<id>urn:sha1:676bd99178cd962ed24ffdad222b7069d330a969</id>
<content type='text'>
If a DMA pool lies at the very top of the dma_addr_t range (as may
happen with an IOMMU involved), the calculated end address of the pool
wraps around to zero, and page lookup always fails.

Tweak the relevant calculation to be overflow-proof.

Signed-off-by: Robin Murphy &lt;robin.murphy@arm.com&gt;
Cc: Arnd Bergmann &lt;arnd@arndb.de&gt;
Cc: Marek Szyprowski &lt;m.szyprowski@samsung.com&gt;
Cc: Sumit Semwal &lt;sumit.semwal@linaro.org&gt;
Cc: Sakari Ailus &lt;sakari.ailus@iki.fi&gt;
Cc: Russell King &lt;rmk+kernel@arm.linux.org.uk&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>mm: add support for __GFP_ZERO flag to dma_pool_alloc()</title>
<updated>2015-09-08T22:35:28Z</updated>
<author>
<name>Sean O. Stalley</name>
<email>sean.stalley@intel.com</email>
</author>
<published>2015-09-08T22:02:24Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=fa23f56d90ed7bd760ae2aea6dfb2f501a099e90'/>
<id>urn:sha1:fa23f56d90ed7bd760ae2aea6dfb2f501a099e90</id>
<content type='text'>
Currently a call to dma_pool_alloc() with a ___GFP_ZERO flag returns a
non-zeroed memory region.

This patchset adds support for the __GFP_ZERO flag to dma_pool_alloc(),
adds 2 wrapper functions for allocing zeroed memory from a pool, and
provides a coccinelle script for finding &amp; replacing instances of
dma_pool_alloc() followed by memset(0) with a single dma_pool_zalloc()
call.

There was some concern that this always calls memset() to zero, instead
of passing __GFP_ZERO into the page allocator.
[https://lkml.org/lkml/2015/7/15/881]

I ran a test on my system to get an idea of how often dma_pool_alloc()
calls into pool_alloc_page().

After Boot:	[   30.119863] alloc_calls:541, page_allocs:7
After an hour:	[ 3600.951031] alloc_calls:9566, page_allocs:12
After copying 1GB file onto a USB drive:
		[ 4260.657148] alloc_calls:17225, page_allocs:12

It doesn't look like dma_pool_alloc() calls down to the page allocator
very often (at least on my system).

This patch (of 4):

Currently the __GFP_ZERO flag is ignored by dma_pool_alloc().
Make dma_pool_alloc() zero the memory if this flag is set.

Signed-off-by: Sean O. Stalley &lt;sean.stalley@intel.com&gt;
Acked-by: David Rientjes &lt;rientjes@google.com&gt;
Cc: Vinod Koul &lt;vinod.koul@intel.com&gt;
Cc: Bjorn Helgaas &lt;bhelgaas@google.com&gt;
Cc: Gilles Muller &lt;Gilles.Muller@lip6.fr&gt;
Cc: Nicolas Palix &lt;nicolas.palix@imag.fr&gt;
Cc: Michal Marek &lt;mmarek@suse.cz&gt;
Cc: Sebastian Andrzej Siewior &lt;bigeasy@linutronix.de&gt;
Cc: Jonathan Corbet &lt;corbet@lwn.net&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>mm/dmapool: allow NULL `pool' pointer in dma_pool_destroy()</title>
<updated>2015-09-08T22:35:28Z</updated>
<author>
<name>Sergey Senozhatsky</name>
<email>sergey.senozhatsky@gmail.com</email>
</author>
<published>2015-09-08T22:00:56Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=44d7175da6ea10e353e69b586bb68bbfef89e403'/>
<id>urn:sha1:44d7175da6ea10e353e69b586bb68bbfef89e403</id>
<content type='text'>
dma_pool_destroy() does not tolerate a NULL dma_pool pointer argument and
performs a NULL-pointer dereference.  This requires additional attention
and effort from developers/reviewers and forces all dma_pool_destroy()
callers to do a NULL check

    if (pool)
        dma_pool_destroy(pool);

Or, otherwise, be invalid dma_pool_destroy() users.

Tweak dma_pool_destroy() and NULL-check the pointer there.

Proposed by Andrew Morton.

Link: https://lkml.org/lkml/2015/6/8/583
Signed-off-by: Sergey Senozhatsky &lt;sergey.senozhatsky@gmail.com&gt;
Acked-by: David Rientjes &lt;rientjes@google.com&gt;
Cc: Julia Lawall &lt;julia.lawall@lip6.fr&gt;
Cc: Joe Perches &lt;joe@perches.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>mm/dmapool.c: change is_page_busy() return from int to bool</title>
<updated>2015-09-04T23:54:41Z</updated>
<author>
<name>Nicholas Krause</name>
<email>xerofoify@gmail.com</email>
</author>
<published>2015-09-04T22:48:19Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=d9e7e37b4d83371d08650612e0bb0b80a1240289'/>
<id>urn:sha1:d9e7e37b4d83371d08650612e0bb0b80a1240289</id>
<content type='text'>
This makes the function is_page_busy() return bool rather then an int now
due to this particular function's single return statement only ever
evaulating to either one or zero.

Signed-off-by: Nicholas Krause &lt;xerofoify@gmail.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>mm/dmapool.c: fixed a brace coding style issue</title>
<updated>2014-10-10T02:26:00Z</updated>
<author>
<name>Paul McQuade</name>
<email>paulmcquad@gmail.com</email>
</author>
<published>2014-10-09T22:29:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=baa2ef83981c71ceb00f68fbdac323253c2c3e42'/>
<id>urn:sha1:baa2ef83981c71ceb00f68fbdac323253c2c3e42</id>
<content type='text'>
Remove 3 brace coding style for any arm of this statement

Signed-off-by: Paul McQuade &lt;paulmcquad@gmail.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>mm: dmapool: add/remove sysfs file outside of the pool lock lock</title>
<updated>2014-10-10T02:25:59Z</updated>
<author>
<name>Sebastian Andrzej Siewior</name>
<email>bigeasy@linutronix.de</email>
</author>
<published>2014-10-09T22:28:50Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=01c2965f0723a25209d5cf4cac630ed0f6d0edf4'/>
<id>urn:sha1:01c2965f0723a25209d5cf4cac630ed0f6d0edf4</id>
<content type='text'>
cat /sys/.../pools followed by removal the device leads to:

|======================================================
|[ INFO: possible circular locking dependency detected ]
|3.17.0-rc4+ #1498 Not tainted
|-------------------------------------------------------
|rmmod/2505 is trying to acquire lock:
| (s_active#28){++++.+}, at: [&lt;c017f754&gt;] kernfs_remove_by_name_ns+0x3c/0x88
|
|but task is already holding lock:
| (pools_lock){+.+.+.}, at: [&lt;c011494c&gt;] dma_pool_destroy+0x18/0x17c
|
|which lock already depends on the new lock.
|the existing dependency chain (in reverse order) is:
|
|-&gt; #1 (pools_lock){+.+.+.}:
|   [&lt;c0114ae8&gt;] show_pools+0x30/0xf8
|   [&lt;c0313210&gt;] dev_attr_show+0x1c/0x48
|   [&lt;c0180e84&gt;] sysfs_kf_seq_show+0x88/0x10c
|   [&lt;c017f960&gt;] kernfs_seq_show+0x24/0x28
|   [&lt;c013efc4&gt;] seq_read+0x1b8/0x480
|   [&lt;c011e820&gt;] vfs_read+0x8c/0x148
|   [&lt;c011ea10&gt;] SyS_read+0x40/0x8c
|   [&lt;c000e960&gt;] ret_fast_syscall+0x0/0x48
|
|-&gt; #0 (s_active#28){++++.+}:
|   [&lt;c017e9ac&gt;] __kernfs_remove+0x258/0x2ec
|   [&lt;c017f754&gt;] kernfs_remove_by_name_ns+0x3c/0x88
|   [&lt;c0114a7c&gt;] dma_pool_destroy+0x148/0x17c
|   [&lt;c03ad288&gt;] hcd_buffer_destroy+0x20/0x34
|   [&lt;c03a4780&gt;] usb_remove_hcd+0x110/0x1a4

The problem is the lock order of pools_lock and kernfs_mutex in
dma_pool_destroy() vs show_pools() call path.

This patch breaks out the creation of the sysfs file outside of the
pools_lock mutex.  The newly added pools_reg_lock ensures that there is no
race of create vs destroy code path in terms whether or not the sysfs file
has to be deleted (and was it deleted before we try to create a new one)
and what to do if device_create_file() failed.

Signed-off-by: Sebastian Andrzej Siewior &lt;bigeasy@linutronix.de&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>Fix unbalanced mutex in dma_pool_create().</title>
<updated>2014-09-18T17:39:16Z</updated>
<author>
<name>Krzysztof Hałasa</name>
<email>khalasa@piap.pl</email>
</author>
<published>2014-09-18T13:12:02Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=153a9f131f50420b7ce008c94f1c6374cbc460d7'/>
<id>urn:sha1:153a9f131f50420b7ce008c94f1c6374cbc460d7</id>
<content type='text'>
dma_pool_create() needs to unlock the mutex in error case.  The bug was
introduced in the 3.16 by commit cc6b664aa26d ("mm/dmapool.c: remove
redundant NULL check for dev in dma_pool_create()")/

Signed-off-by: Krzysztof Hałasa &lt;khc@piap.pl&gt;
Cc: stable@vger.kernel.org  # v3.16
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>mm/dmapool.c: reuse devres_release() to free resources</title>
<updated>2014-06-04T23:54:08Z</updated>
<author>
<name>Andy Shevchenko</name>
<email>andriy.shevchenko@linux.intel.com</email>
</author>
<published>2014-06-04T23:10:02Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=172cb4b3d49a1339dd67ee05e3f47972a70f556f'/>
<id>urn:sha1:172cb4b3d49a1339dd67ee05e3f47972a70f556f</id>
<content type='text'>
Instead of calling an additional routine in dmam_pool_destroy() rely on
what dmam_pool_release() is doing.

Signed-off-by: Andy Shevchenko &lt;andriy.shevchenko@linux.intel.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>mm/dmapool.c: remove redundant NULL check for dev in dma_pool_create()</title>
<updated>2014-06-04T23:54:04Z</updated>
<author>
<name>Daeseok Youn</name>
<email>daeseok.youn@gmail.com</email>
</author>
<published>2014-06-04T23:08:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=cc6b664aa26de93d9a3f99d4021a8d88b434ed06'/>
<id>urn:sha1:cc6b664aa26de93d9a3f99d4021a8d88b434ed06</id>
<content type='text'>
"dev" cannot be NULL because it is already checked before calling
dma_pool_create().

If dev ever was NULL, the code would oops in dev_to_node() after enabling
CONFIG_NUMA.

It is possible that some driver is using dev==NULL and has never been run
on a NUMA machine.  Such a driver is probably outdated, possibly buggy and
will need some attention if it starts triggering NULL derefs.

Signed-off-by: Daeseok Youn &lt;daeseok.youn@gmail.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>mm: Fix printk typo in dmapool.c</title>
<updated>2014-05-05T13:44:47Z</updated>
<author>
<name>Hiroshige Sato</name>
<email>sato.vintage@gmail.com</email>
</author>
<published>2014-04-16T12:28:34Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5835f25117ef6a56144bfc6be98b5a3cb188bf7a'/>
<id>urn:sha1:5835f25117ef6a56144bfc6be98b5a3cb188bf7a</id>
<content type='text'>
Fix printk typo in dmapool.c

Signed-off-by: Hiroshige Sato &lt;sato.vintage@gmail.com&gt;
Signed-off-by: Jiri Kosina &lt;jkosina@suse.cz&gt;
</content>
</entry>
</feed>
