<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/drivers/mtd/mtd_blkdevs.c, branch v4.4.8</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v4.4.8</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v4.4.8'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2015-10-31T00:24:43+00:00</updated>
<entry>
<title>mtd: blkdevs: fix potential deadlock + lockdep warnings</title>
<updated>2015-10-31T00:24:43+00:00</updated>
<author>
<name>Brian Norris</name>
<email>computersforpeace@gmail.com</email>
</author>
<published>2015-10-26T17:20:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f3c63795e90f0c6238306883b6c72f14d5355721'/>
<id>urn:sha1:f3c63795e90f0c6238306883b6c72f14d5355721</id>
<content type='text'>
Commit 073db4a51ee4 ("mtd: fix: avoid race condition when accessing
mtd-&gt;usecount") fixed a race condition but due to poor ordering of the
mutex acquisition, introduced a potential deadlock.

The deadlock can occur, for example, when rmmod'ing the m25p80 module, which
will delete one or more MTDs, along with any corresponding mtdblock
devices. This could potentially race with an acquisition of the block
device as follows.

 -&gt; blktrans_open()
    -&gt;  mutex_lock(&amp;dev-&gt;lock);
    -&gt;  mutex_lock(&amp;mtd_table_mutex);

 -&gt; del_mtd_device()
    -&gt;  mutex_lock(&amp;mtd_table_mutex);
    -&gt;  blktrans_notify_remove() -&gt; del_mtd_blktrans_dev()
       -&gt;  mutex_lock(&amp;dev-&gt;lock);

This is a classic (potential) ABBA deadlock, which can be fixed by
making the A-&gt;B ordering consistent everywhere. There was no real
purpose to the ordering in the original patch, AFAIR, so this shouldn't
be a problem. This ordering was actually already present in
del_mtd_blktrans_dev(), for one, where the function tried to ensure that
its caller already held mtd_table_mutex before it acquired &amp;dev-&gt;lock:

        if (mutex_trylock(&amp;mtd_table_mutex)) {
                mutex_unlock(&amp;mtd_table_mutex);
                BUG();
        }

So, reverse the ordering of acquisition of &amp;dev-&gt;lock and &amp;mtd_table_mutex so
we always acquire mtd_table_mutex first.

Snippets of the lockdep output follow:

  # modprobe -r m25p80
  [   53.419251]
  [   53.420838] ======================================================
  [   53.427300] [ INFO: possible circular locking dependency detected ]
  [   53.433865] 4.3.0-rc6 #96 Not tainted
  [   53.437686] -------------------------------------------------------
  [   53.444220] modprobe/372 is trying to acquire lock:
  [   53.449320]  (&amp;new-&gt;lock){+.+...}, at: [&lt;c043fe4c&gt;] del_mtd_blktrans_dev+0x80/0xdc
  [   53.457271]
  [   53.457271] but task is already holding lock:
  [   53.463372]  (mtd_table_mutex){+.+.+.}, at: [&lt;c0439994&gt;] del_mtd_device+0x18/0x100
  [   53.471321]
  [   53.471321] which lock already depends on the new lock.
  [   53.471321]
  [   53.479856]
  [   53.479856] the existing dependency chain (in reverse order) is:
  [   53.487660]
  -&gt; #1 (mtd_table_mutex){+.+.+.}:
  [   53.492331]        [&lt;c043fc5c&gt;] blktrans_open+0x34/0x1a4
  [   53.497879]        [&lt;c01afce0&gt;] __blkdev_get+0xc4/0x3b0
  [   53.503364]        [&lt;c01b0bb8&gt;] blkdev_get+0x108/0x320
  [   53.508743]        [&lt;c01713c0&gt;] do_dentry_open+0x218/0x314
  [   53.514496]        [&lt;c0180454&gt;] path_openat+0x4c0/0xf9c
  [   53.519959]        [&lt;c0182044&gt;] do_filp_open+0x5c/0xc0
  [   53.525336]        [&lt;c0172758&gt;] do_sys_open+0xfc/0x1cc
  [   53.530716]        [&lt;c000f740&gt;] ret_fast_syscall+0x0/0x1c
  [   53.536375]
  -&gt; #0 (&amp;new-&gt;lock){+.+...}:
  [   53.540587]        [&lt;c063f124&gt;] mutex_lock_nested+0x38/0x3cc
  [   53.546504]        [&lt;c043fe4c&gt;] del_mtd_blktrans_dev+0x80/0xdc
  [   53.552606]        [&lt;c043f164&gt;] blktrans_notify_remove+0x7c/0x84
  [   53.558891]        [&lt;c04399f0&gt;] del_mtd_device+0x74/0x100
  [   53.564544]        [&lt;c043c670&gt;] del_mtd_partitions+0x80/0xc8
  [   53.570451]        [&lt;c0439aa0&gt;] mtd_device_unregister+0x24/0x48
  [   53.576637]        [&lt;c046ce6c&gt;] spi_drv_remove+0x1c/0x34
  [   53.582207]        [&lt;c03de0f0&gt;] __device_release_driver+0x88/0x114
  [   53.588663]        [&lt;c03de19c&gt;] device_release_driver+0x20/0x2c
  [   53.594843]        [&lt;c03dd9e8&gt;] bus_remove_device+0xd8/0x108
  [   53.600748]        [&lt;c03dacc0&gt;] device_del+0x10c/0x210
  [   53.606127]        [&lt;c03dadd0&gt;] device_unregister+0xc/0x20
  [   53.611849]        [&lt;c046d878&gt;] __unregister+0x10/0x20
  [   53.617211]        [&lt;c03da868&gt;] device_for_each_child+0x50/0x7c
  [   53.623387]        [&lt;c046eae8&gt;] spi_unregister_master+0x58/0x8c
  [   53.629578]        [&lt;c03e12f0&gt;] release_nodes+0x15c/0x1c8
  [   53.635223]        [&lt;c03de0f8&gt;] __device_release_driver+0x90/0x114
  [   53.641689]        [&lt;c03de900&gt;] driver_detach+0xb4/0xb8
  [   53.647147]        [&lt;c03ddc78&gt;] bus_remove_driver+0x4c/0xa0
  [   53.652970]        [&lt;c00cab50&gt;] SyS_delete_module+0x11c/0x1e4
  [   53.658976]        [&lt;c000f740&gt;] ret_fast_syscall+0x0/0x1c
  [   53.664621]
  [   53.664621] other info that might help us debug this:
  [   53.664621]
  [   53.672979]  Possible unsafe locking scenario:
  [   53.672979]
  [   53.679169]        CPU0                    CPU1
  [   53.683900]        ----                    ----
  [   53.688633]   lock(mtd_table_mutex);
  [   53.692383]                                lock(&amp;new-&gt;lock);
  [   53.698306]                                lock(mtd_table_mutex);
  [   53.704658]   lock(&amp;new-&gt;lock);
  [   53.707946]
  [   53.707946]  *** DEADLOCK ***

Fixes: 073db4a51ee4 ("mtd: fix: avoid race condition when accessing mtd-&gt;usecount")
Reported-by: Felipe Balbi &lt;balbi@ti.com&gt;
Tested-by: Felipe Balbi &lt;balbi@ti.com&gt;
Signed-off-by: Brian Norris &lt;computersforpeace@gmail.com&gt;
Cc: &lt;stable@vger.kernel.org&gt;
</content>
</entry>
<entry>
<title>mtd: blktrans: fix multiplication overflow</title>
<updated>2015-09-29T00:23:21+00:00</updated>
<author>
<name>Peng Fan</name>
<email>van.freenix@gmail.com</email>
</author>
<published>2015-09-11T13:41:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=2ce401d56b36a7492b26646b94d1fe9194880a1a'/>
<id>urn:sha1:2ce401d56b36a7492b26646b94d1fe9194880a1a</id>
<content type='text'>
In drivers/mtd/mtd_blkdevs.c:
406	set_capacity(gd, (new-&gt;size * tr-&gt;blksize) &gt;&gt; 9);
The type of new-&gt;size is unsigned long and the type of tr-&gt;blksize is int,
the result of 'new-&gt;size * tr-&gt;blksize' may exceed ULONG_MAX on 32bit
machines.

I use nand chip MT29F32G08CBADBWP which is 4GB and the parameters passed
to kernel is 'mtdparts=gpmi-nand:-(user)', the whole nand chip will be
treated as a 4GB mtd partition. new-&gt;size is 0x800000 and tr-&gt;blksize is
0x200, 'new-&gt;size * tr-&gt;blksize' however is 0. This is what we do not want
to see.

Using type cast u64 to fix the multiplication overflow issue.

Signed-off-by: Peng Fan &lt;van.freenix@gmail.com&gt;
Cc: David Woodhouse &lt;dwmw2@infradead.org&gt;
Signed-off-by: Brian Norris &lt;computersforpeace@gmail.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'for-4.3/core' of git://git.kernel.dk/linux-block</title>
<updated>2015-09-02T20:10:25+00:00</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2015-09-02T20:10:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=1081230b748de8f03f37f80c53dfa89feda9b8de'/>
<id>urn:sha1:1081230b748de8f03f37f80c53dfa89feda9b8de</id>
<content type='text'>
Pull core block updates from Jens Axboe:
 "This first core part of the block IO changes contains:

   - Cleanup of the bio IO error signaling from Christoph.  We used to
     rely on the uptodate bit and passing around of an error, now we
     store the error in the bio itself.

   - Improvement of the above from myself, by shrinking the bio size
     down again to fit in two cachelines on x86-64.

   - Revert of the max_hw_sectors cap removal from a revision again,
     from Jeff Moyer.  This caused performance regressions in various
     tests.  Reinstate the limit, bump it to a more reasonable size
     instead.

   - Make /sys/block/&lt;dev&gt;/queue/discard_max_bytes writeable, by me.
     Most devices have huge trim limits, which can cause nasty latencies
     when deleting files.  Enable the admin to configure the size down.
     We will look into having a more sane default instead of UINT_MAX
     sectors.

   - Improvement of the SGP gaps logic from Keith Busch.

   - Enable the block core to handle arbitrarily sized bios, which
     enables a nice simplification of bio_add_page() (which is an IO hot
     path).  From Kent.

   - Improvements to the partition io stats accounting, making it
     faster.  From Ming Lei.

   - Also from Ming Lei, a basic fixup for overflow of the sysfs pending
     file in blk-mq, as well as a fix for a blk-mq timeout race
     condition.

   - Ming Lin has been carrying Kents above mentioned patches forward
     for a while, and testing them.  Ming also did a few fixes around
     that.

   - Sasha Levin found and fixed a use-after-free problem introduced by
     the bio-&gt;bi_error changes from Christoph.

   - Small blk cgroup cleanup from Viresh Kumar"

* 'for-4.3/core' of git://git.kernel.dk/linux-block: (26 commits)
  blk: Fix bio_io_vec index when checking bvec gaps
  block: Replace SG_GAPS with new queue limits mask
  block: bump BLK_DEF_MAX_SECTORS to 2560
  Revert "block: remove artifical max_hw_sectors cap"
  blk-mq: fix race between timeout and freeing request
  blk-mq: fix buffer overflow when reading sysfs file of 'pending'
  Documentation: update notes in biovecs about arbitrarily sized bios
  block: remove bio_get_nr_vecs()
  fs: use helper bio_add_page() instead of open coding on bi_io_vec
  block: kill merge_bvec_fn() completely
  md/raid5: get rid of bio_fits_rdev()
  md/raid5: split bio for chunk_aligned_read
  block: remove split code in blkdev_issue_{discard,write_same}
  btrfs: remove bio splitting and merge_bvec_fn() calls
  bcache: remove driver private bio splitting code
  block: simplify bio_add_page()
  block: make generic_make_request handle arbitrarily sized bios
  blk-cgroup: Drop unlikely before IS_ERR(_OR_NULL)
  block: don't access bio-&gt;bi_error after bio_put()
  block: shrink struct bio down to 2 cache lines again
  ...
</content>
</entry>
<entry>
<title>mtd: blkdevs: fix switch-bool compilation warning</title>
<updated>2015-08-25T20:58:10+00:00</updated>
<author>
<name>Tomer Barletz</name>
<email>barletz@gmail.com</email>
</author>
<published>2015-08-05T04:00:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=cc7fce80229067890365c1ee196be5d304d36dea'/>
<id>urn:sha1:cc7fce80229067890365c1ee196be5d304d36dea</id>
<content type='text'>
With gcc 5.1 I get:
warning: switch condition has boolean value [-Wswitch-bool]

Signed-off-by: Tomer Barletz &lt;barletz@gmail.com&gt;
Signed-off-by: Brian Norris &lt;computersforpeace@gmail.com&gt;
</content>
</entry>
<entry>
<title>block: have drivers use blk_queue_max_discard_sectors()</title>
<updated>2015-07-17T14:41:53+00:00</updated>
<author>
<name>Jens Axboe</name>
<email>axboe@fb.com</email>
</author>
<published>2015-07-14T14:15:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=2bb4cd5cc472b191a46938becb7dafdd44644329'/>
<id>urn:sha1:2bb4cd5cc472b191a46938becb7dafdd44644329</id>
<content type='text'>
Some drivers use it now, others just set the limits field manually.
But in preparation for splitting this into a hard and soft limit,
ensure that they all call the proper function for setting the hw
limit for discards.

Reviewed-by: Jeff Moyer &lt;jmoyer@redhat.com&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</content>
</entry>
<entry>
<title>mtd: blktrans: use better error code for unimplemented ioctl()</title>
<updated>2015-05-21T17:44:32+00:00</updated>
<author>
<name>Brian Norris</name>
<email>computersforpeace@gmail.com</email>
</author>
<published>2015-05-21T17:44:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=c4a3f13c2ab997617eaf7020af33b057a68285fd'/>
<id>urn:sha1:c4a3f13c2ab997617eaf7020af33b057a68285fd</id>
<content type='text'>
In commit 50183936254b ("mtd: blktrans: change blktrans_getgeo return
value") we fixed the problem that ioctl(HDIO_GETGEO) might return 0
(success) for mtdblock devices which did not implement the feature and
would leave a blank (zero) result.

But now, let's get the error code right. Other code paths on this ioctl
tend to use -ENOTTY to notify the user that the ioctl() is not supported
for the device, so let's use that instead of -EOPNOTSUPP.

Suggested-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Brian Norris &lt;computersforpeace@gmail.com&gt;
</content>
</entry>
<entry>
<title>mtd: blktrans: change blktrans_getgeo return value</title>
<updated>2015-05-21T07:26:41+00:00</updated>
<author>
<name>Wenlin Kang</name>
<email>wenlin.kang@windriver.com</email>
</author>
<published>2015-05-21T06:49:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=50183936254b76997d222cd36bac997ebf8115de'/>
<id>urn:sha1:50183936254b76997d222cd36bac997ebf8115de</id>
<content type='text'>
Modify function blktrans_getgeo()'s return value to -EOPNOTSUPP when
dev-&gt;tr-&gt;getgeo == NULL.

We shouldn't make the return value to 0 when dev-&gt;tr-&gt;getgeo == NULL,
because the function blktrans_getgeo() has an output value "hd_geometry"
which is usually used by some application, if returns 0 (i.e.,
"success"), it will make some application get the wrong information.

Signed-off-by: Wenlin Kang &lt;wenlin.kang@windriver.com&gt;
Signed-off-by: Brian Norris &lt;computersforpeace@gmail.com&gt;
</content>
</entry>
<entry>
<title>mtd: fix: avoid race condition when accessing mtd-&gt;usecount</title>
<updated>2015-05-12T17:59:53+00:00</updated>
<author>
<name>Brian Norris</name>
<email>computersforpeace@gmail.com</email>
</author>
<published>2015-05-08T00:55:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=073db4a51ee43ccb827f54a4261c0583b028d5ab'/>
<id>urn:sha1:073db4a51ee43ccb827f54a4261c0583b028d5ab</id>
<content type='text'>
On A MIPS 32-cores machine a BUG_ON was triggered because some acesses to
mtd-&gt;usecount were done without taking mtd_table_mutex.
kernel: Call Trace:
kernel: [&lt;ffffffff80401818&gt;] __put_mtd_device+0x20/0x50
kernel: [&lt;ffffffff804086f4&gt;] blktrans_release+0x8c/0xd8
kernel: [&lt;ffffffff802577e0&gt;] __blkdev_put+0x1a8/0x200
kernel: [&lt;ffffffff802579a4&gt;] blkdev_close+0x1c/0x30
kernel: [&lt;ffffffff8022006c&gt;] __fput+0xac/0x250
kernel: [&lt;ffffffff80171208&gt;] task_work_run+0xd8/0x120
kernel: [&lt;ffffffff8012c23c&gt;] work_notifysig+0x10/0x18
kernel:
kernel:
        Code: 2442ffff  ac8202d8  000217fe &lt;00020336&gt; dc820128  10400003
               00000000  0040f809  00000000
kernel: ---[ end trace 080fbb4579b47a73 ]---

Fixed by taking the mutex in blktrans_open and blktrans_release.

Note that this locking is already suggested in
include/linux/mtd/blktrans.h:

struct mtd_blktrans_ops {
...
	/* Called with mtd_table_mutex held; no race with add/remove */
	int (*open)(struct mtd_blktrans_dev *dev);
	void (*release)(struct mtd_blktrans_dev *dev);
...
};

But we weren't following it.

Originally reported by (and patched by) Zhang and Giuseppe,
independently. Improved and rewritten.

Cc: stable@vger.kernel.org
Reported-by: Zhang Xingcai &lt;zhangxingcai@huawei.com&gt;
Reported-by: Giuseppe Cantavenera &lt;giuseppe.cantavenera.ext@nokia.com&gt;
Tested-by: Giuseppe Cantavenera &lt;giuseppe.cantavenera.ext@nokia.com&gt;
Acked-by: Alexander Sverdlin &lt;alexander.sverdlin@nokia.com&gt;
Signed-off-by: Brian Norris &lt;computersforpeace@gmail.com&gt;
</content>
</entry>
<entry>
<title>mtd: blkdevs: remove dead code</title>
<updated>2015-03-11T22:21:48+00:00</updated>
<author>
<name>Brian Norris</name>
<email>computersforpeace@gmail.com</email>
</author>
<published>2015-02-28T10:02:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=e22b7651ef23ad90eed4bdbe75f12194f47d7a4f'/>
<id>urn:sha1:e22b7651ef23ad90eed4bdbe75f12194f47d7a4f</id>
<content type='text'>
The only exit (break) from the preceding loop is nested within a
condition which yields req == NULL. This code is dead.

Coverity CID #752669

Signed-off-by: Brian Norris &lt;computersforpeace@gmail.com&gt;
</content>
</entry>
<entry>
<title>block: disable entropy contributions for nonrot devices</title>
<updated>2014-10-04T16:55:32+00:00</updated>
<author>
<name>Mike Snitzer</name>
<email>snitzer@redhat.com</email>
</author>
<published>2014-10-04T16:55:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b277da0a8a594308e17881f4926879bd5fca2a2d'/>
<id>urn:sha1:b277da0a8a594308e17881f4926879bd5fca2a2d</id>
<content type='text'>
Clear QUEUE_FLAG_ADD_RANDOM in all block drivers that set
QUEUE_FLAG_NONROT.

Historically, all block devices have automatically made entropy
contributions.  But as previously stated in commit e2e1a148 ("block: add
sysfs knob for turning off disk entropy contributions"):
    - On SSD disks, the completion times aren't as random as they
      are for rotational drives. So it's questionable whether they
      should contribute to the random pool in the first place.
    - Calling add_disk_randomness() has a lot of overhead.

There are more reliable sources for randomness than non-rotational block
devices.  From a security perspective it is better to err on the side of
caution than to allow entropy contributions from unreliable "random"
sources.

Signed-off-by: Mike Snitzer &lt;snitzer@redhat.com&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</content>
</entry>
</feed>
