<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/drivers/mtd/mtd_blkdevs.c, branch v5.15.7</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v5.15.7</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v5.15.7'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2021-09-05T17:50:12+00:00</updated>
<entry>
<title>Merge tag 'mtd/for-5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux</title>
<updated>2021-09-05T17:50:12+00:00</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2021-09-05T17:50:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=6b6dc4f40c5264556223ba94693f20d83796ab1f'/>
<id>urn:sha1:6b6dc4f40c5264556223ba94693f20d83796ab1f</id>
<content type='text'>
Pull MTD updates from Miquel Raynal:
 "MTD changes:
   - blkdevs:
       - Simplify the refcounting in blktrans_{open, release}
       - Simplify blktrans_getgeo
       - Remove blktrans_ref_mutex
       - Simplify blktrans_dev_get
       - Use lockdep_assert_held
       - Don't hold del_mtd_blktrans_dev in blktrans_{open, release}
   - ftl:
       - Don't cast away the type when calling add_mtd_blktrans_dev
       - Don't cast away the type when calling add_mtd_blktrans_dev
       - Use container_of() rather than cast
       - Fix use-after-free
       - Add discard support
       - Allow use of MTD_RAM for testing purposes
   - concat:
       - Check _read, _write callbacks existence before assignment
       - Judge callback existence based on the master
   - maps:
       - Maps: remove dead MTD map driver for PMC-Sierra MSP boards
   - mtdblock:
       - Warn if added for a NAND device
       - Add comment about UBI block devices
       - Update old JFFS2 mention in Kconfig
   - partitions:
       - Redboot: convert to YAML

  NAND core changes:
   - Repair Miquel Raynal's email address in MAINTAINERS
   - Fix a couple of spelling mistakes in Kconfig
   - bbt: Skip bad blocks when searching for the BBT in NAND
   - Remove never changed ret variable

  Raw NAND changes:
   - cafe: Fix a resource leak in the error handling path of 'cafe_nand_probe()'
   - intel: Fix error handling in probe
   - omap: Fix kernel doc warning on 'calcuate' typo
   - gpmc: Fix the ECC bytes vs. OOB bytes equation

  SPI-NAND core changes:
   - Properly fill the OOB area.
   - Fix comment

  SPI-NAND drivers changes:
   - macronix: Add Quad support for serial NAND flash"

* tag 'mtd/for-5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux: (30 commits)
  mtd: rawnand: cafe: Fix a resource leak in the error handling path of 'cafe_nand_probe()'
  mtd_blkdevs: simplify the refcounting in blktrans_{open, release}
  mtd_blkdevs: simplify blktrans_getgeo
  mtd_blkdevs: remove blktrans_ref_mutex
  mtd_blkdevs: simplify blktrans_dev_get
  mtd/rfd_ftl: don't cast away the type when calling add_mtd_blktrans_dev
  mtd/ftl: don't cast away the type when calling add_mtd_blktrans_dev
  mtd_blkdevs: use lockdep_assert_held
  mtd_blkdevs: don't hold del_mtd_blktrans_dev in blktrans_{open, release}
  mtd: rawnand: intel: Fix error handling in probe
  mtd: mtdconcat: Check _read, _write callbacks existence before assignment
  mtd: mtdconcat: Judge callback existence based on the master
  mtd: maps: remove dead MTD map driver for PMC-Sierra MSP boards
  mtd: rfd_ftl: use container_of() rather than cast
  mtd: rfd_ftl: fix use-after-free
  mtd: rfd_ftl: add discard support
  mtd: rfd_ftl: allow use of MTD_RAM for testing purposes
  mtdblock: Warn if added for a NAND device
  mtd: spinand: macronix: Add Quad support for serial NAND flash
  mtdblock: Add comment about UBI block devices
  ...
</content>
</entry>
<entry>
<title>mtd_blkdevs: simplify the refcounting in blktrans_{open, release}</title>
<updated>2021-08-23T08:01:16+00:00</updated>
<author>
<name>Christoph Hellwig</name>
<email>hch@lst.de</email>
</author>
<published>2021-08-23T07:33:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=ee28b42006c37aaeb68c83300fe5608db662082f'/>
<id>urn:sha1:ee28b42006c37aaeb68c83300fe5608db662082f</id>
<content type='text'>
Always grab a reference to the mtd_blktrans_dev in -&gt;open instead of
just on the first open, and do away with the additional temporary
references in -&gt;open and -&gt;release.

Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210823073359.705281-9-hch@lst.de
</content>
</entry>
<entry>
<title>mtd_blkdevs: simplify blktrans_getgeo</title>
<updated>2021-08-23T08:01:13+00:00</updated>
<author>
<name>Christoph Hellwig</name>
<email>hch@lst.de</email>
</author>
<published>2021-08-23T07:33:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=37b143d12b5f099bb4375162303ff1df1692cc5e'/>
<id>urn:sha1:37b143d12b5f099bb4375162303ff1df1692cc5e</id>
<content type='text'>
No need to grab a mtd_blktrans_dev given that -&gt;open already holds one
and -&gt;getgeo can only be called on an open disk.

Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210823073359.705281-8-hch@lst.de
</content>
</entry>
<entry>
<title>mtd_blkdevs: remove blktrans_ref_mutex</title>
<updated>2021-08-23T08:01:11+00:00</updated>
<author>
<name>Christoph Hellwig</name>
<email>hch@lst.de</email>
</author>
<published>2021-08-23T07:33:57+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=560a3915e3df09125d7b20088a177b2872d2d680'/>
<id>urn:sha1:560a3915e3df09125d7b20088a177b2872d2d680</id>
<content type='text'>
blktrans_ref_mutex is not actually needed.  The kref is serialized
internally, and devnum assignment in add_mtd_blktrans_dev happens before
the disk is added and thus any of the block_device_operations methods
otherwise using it are called.  It  is also already serialized by the
global mtd_table_mutex.

Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210823073359.705281-7-hch@lst.de
</content>
</entry>
<entry>
<title>mtd_blkdevs: simplify blktrans_dev_get</title>
<updated>2021-08-23T08:01:09+00:00</updated>
<author>
<name>Christoph Hellwig</name>
<email>hch@lst.de</email>
</author>
<published>2021-08-23T07:33:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=89843828399ec825f8ec3e614634a428a951a2b3'/>
<id>urn:sha1:89843828399ec825f8ec3e614634a428a951a2b3</id>
<content type='text'>
-&gt;private_data is set before the disk is added and never cleared, so don't
bother trying to handle a NULL pointer there.

Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210823073359.705281-6-hch@lst.de
</content>
</entry>
<entry>
<title>mtd_blkdevs: use lockdep_assert_held</title>
<updated>2021-08-23T08:01:01+00:00</updated>
<author>
<name>Christoph Hellwig</name>
<email>hch@lst.de</email>
</author>
<published>2021-08-23T07:33:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f214eebf8de4d2e412a35ff140687d88f056143a'/>
<id>urn:sha1:f214eebf8de4d2e412a35ff140687d88f056143a</id>
<content type='text'>
Use lockdep_assert_held to ensure mtd_table_mutex is held instead of
mutex_trylock games.

Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210823073359.705281-3-hch@lst.de
</content>
</entry>
<entry>
<title>mtd_blkdevs: don't hold del_mtd_blktrans_dev in blktrans_{open, release}</title>
<updated>2021-08-23T08:00:59+00:00</updated>
<author>
<name>Christoph Hellwig</name>
<email>hch@lst.de</email>
</author>
<published>2021-08-23T07:33:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=799ae31c58ae766a4ce9b198658b286ecaf2c575'/>
<id>urn:sha1:799ae31c58ae766a4ce9b198658b286ecaf2c575</id>
<content type='text'>
There is nothing that this protects against except for slightly reducing
the window when new opens can appear just before calling del_gendisk.

Reported-by: Guenter Roeck &lt;linux@roeck-us.net&gt;
Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
Tested-by: Guenter Roeck &lt;linux@roeck-us.net&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210823073359.705281-2-hch@lst.de
</content>
</entry>
<entry>
<title>mtd: fix lock hierarchy in deregister_mtd_blktrans</title>
<updated>2021-08-06T19:44:16+00:00</updated>
<author>
<name>Desmond Cheong Zhi Xi</name>
<email>desmondcheongzx@gmail.com</email>
</author>
<published>2021-07-17T10:07:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b7abb051682263e51866bc78762fd0083d64c5ed'/>
<id>urn:sha1:b7abb051682263e51866bc78762fd0083d64c5ed</id>
<content type='text'>
There is a lock hierarchy of major_names_lock --&gt; mtd_table_mutex. One
existing chain is as follows:

1. major_names_lock --&gt; loop_ctl_mutex (when blk_request_module calls
loop_probe)

2. loop_ctl_mutex --&gt; bdev-&gt;bd_mutex (when loop_control_ioctl calls
loop_remove, which then calls del_gendisk)

3. bdev-&gt;bd_mutex --&gt; mtd_table_mutex (when blkdev_get_by_dev calls
__blkdev_get, which then calls blktrans_open)

Since unregister_blkdev grabs the major_names_lock, we need to call it
outside the critical section for mtd_table_mutex, otherwise we invert
the lock hierarchy.

Reported-by: Hillf Danton &lt;hdanton@sina.com&gt;
Signed-off-by: Desmond Cheong Zhi Xi &lt;desmondcheongzx@gmail.com&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210717100719.728829-1-desmondcheongzx@gmail.com
</content>
</entry>
<entry>
<title>mtd: break circular locks in register_mtd_blktrans</title>
<updated>2021-07-15T22:49:17+00:00</updated>
<author>
<name>Desmond Cheong Zhi Xi</name>
<email>desmondcheongzx@gmail.com</email>
</author>
<published>2021-06-17T16:09:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=962bf783ef65d15b0f8ca9c33342cf3b20bf0d2e'/>
<id>urn:sha1:962bf783ef65d15b0f8ca9c33342cf3b20bf0d2e</id>
<content type='text'>
Syzbot reported a circular locking dependency:
https://syzkaller.appspot.com/bug?id=7bd106c28e846d1023d4ca915718b1a0905444cb

This happens because of the following lock dependencies:

1. loop_ctl_mutex -&gt; bdev-&gt;bd_mutex (when loop_control_ioctl calls
loop_remove, which then calls del_gendisk; this also happens in
loop_exit which eventually calls loop_remove)

2. bdev-&gt;bd_mutex -&gt; mtd_table_mutex (when blkdev_get_by_dev calls
__blkdev_get, which then calls blktrans_open)

3. mtd_table_mutex -&gt; major_names_lock (when register_mtd_blktrans
calls __register_blkdev)

4. major_names_lock -&gt; loop_ctl_mutex (when blk_request_module calls
loop_probe)

Hence there's an overall dependency of:

loop_ctl_mutex   ----------&gt; bdev-&gt;bd_mutex
      ^                            |
      |                            |
      |                            v
major_names_lock &lt;---------  mtd_table_mutex

We can break this circular dependency by holding mtd_table_mutex only
for the required critical section in register_mtd_blktrans. This
avoids the mtd_table_mutex -&gt; major_names_lock dependency.

Reported-and-tested-by: syzbot+6a8a0d93c91e8fbf2e80@syzkaller.appspotmail.com
Co-developed-by: Christoph Hellwig &lt;hch@lst.de&gt;
Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
Signed-off-by: Desmond Cheong Zhi Xi &lt;desmondcheongzx@gmail.com&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210617160904.570111-1-desmondcheongzx@gmail.com
</content>
</entry>
<entry>
<title>mtd: mtd_blkdevs: Initialize rq.limits.discard_granularity</title>
<updated>2021-07-15T22:49:13+00:00</updated>
<author>
<name>Zhihao Cheng</name>
<email>chengzhihao1@huawei.com</email>
</author>
<published>2021-06-15T09:39:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=2b6d2833cd1d8a43a837a45da65860ef086443dc'/>
<id>urn:sha1:2b6d2833cd1d8a43a837a45da65860ef086443dc</id>
<content type='text'>
Since commit b35fd7422c2f8("block: check queue's limits.discard_granularity
in __blkdev_issue_discard()") checks rq.limits.discard_granularity in
__blkdev_issue_discard(), we may get following warnings on formatted ftl:

  WARNING: CPU: 2 PID: 7313 at block/blk-lib.c:51
  __blkdev_issue_discard+0x2a7/0x390

Reproducer:
  1. ftl_format /dev/mtd0
  2. modprobe ftl
  3. mkfs.vfat /dev/ftla
  4. mount -odiscard /dev/ftla temp
  5. dd if=/dev/zero of=temp/tst bs=1M count=10 oflag=direct
  6. dd if=/dev/zero of=temp/tst bs=1M count=10 oflag=direct

Fix it by initializing rq.limits.discard_granularity if device supports
discard operation.

Signed-off-by: Zhihao Cheng &lt;chengzhihao1@huawei.com&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210615093905.3473709-1-chengzhihao1@huawei.com
</content>
</entry>
</feed>
