1. 13 8月, 2017 1 次提交
  2. 28 6月, 2017 1 次提交
  3. 09 6月, 2017 1 次提交
    • C
      block: introduce new block status code type · 2a842aca
      Christoph Hellwig 提交于
      Currently we use nornal Linux errno values in the block layer, and while
      we accept any error a few have overloaded magic meanings.  This patch
      instead introduces a new  blk_status_t value that holds block layer specific
      status codes and explicitly explains their meaning.  Helpers to convert from
      and to the previous special meanings are provided for now, but I suspect
      we want to get rid of them in the long run - those drivers that have a
      errno input (e.g. networking) usually get errnos that don't know about
      the special block layer overloads, and similarly returning them to userspace
      will usually return somethings that strictly speaking isn't correct
      for file system operations, but that's left as an exercise for later.
      
      For now the set of errors is a very limited set that closely corresponds
      to the previous overloaded errno values, but there is some low hanging
      fruite to improve it.
      
      blk_status_t (ab)uses the sparse __bitwise annotations to allow for sparse
      typechecking, so that we can easily catch places passing the wrong values.
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      2a842aca
  4. 01 2月, 2017 1 次提交
    • C
      block: fold cmd_type into the REQ_OP_ space · aebf526b
      Christoph Hellwig 提交于
      Instead of keeping two levels of indirection for requests types, fold it
      all into the operations.  The little caveat here is that previously
      cmd_type only applied to struct request, while the request and bio op
      fields were set to plain REQ_OP_READ/WRITE even for passthrough
      operations.
      
      Instead this patch adds new REQ_OP_* for SCSI passthrough and driver
      private requests, althought it has to add two for each so that we
      can communicate the data in/out nature of the request.
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      aebf526b
  5. 25 12月, 2016 1 次提交
  6. 28 6月, 2016 1 次提交
    • D
      block: convert to device_add_disk() · 0d52c756
      Dan Williams 提交于
      For block drivers that specify a parent device, convert them to use
      device_add_disk().
      
      This conversion was done with the following semantic patch:
      
          @@
          struct gendisk *disk;
          expression E;
          @@
      
          - disk->driverfs_dev = E;
          ...
          - add_disk(disk);
          + device_add_disk(E, disk);
      
          @@
          struct gendisk *disk;
          expression E1, E2;
          @@
      
          - disk->driverfs_dev = E1;
          ...
          E2 = disk;
          ...
          - add_disk(E2);
          + device_add_disk(E1, E2);
      
      ...plus some manual fixups for a few missed conversions.
      
      Cc: Jens Axboe <axboe@fb.com>
      Cc: Keith Busch <keith.busch@intel.com>
      Cc: Michael S. Tsirkin <mst@redhat.com>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: James Bottomley <James.Bottomley@hansenpartnership.com>
      Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
      Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Cc: Martin K. Petersen <martin.petersen@oracle.com>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Reviewed-by: NJohannes Thumshirn <jthumshirn@suse.de>
      Signed-off-by: NDan Williams <dan.j.williams@intel.com>
      0d52c756
  7. 08 6月, 2016 2 次提交
  8. 13 4月, 2016 1 次提交
  9. 31 10月, 2015 1 次提交
    • B
      mtd: blkdevs: fix potential deadlock + lockdep warnings · f3c63795
      Brian Norris 提交于
      Commit 073db4a5 ("mtd: fix: avoid race condition when accessing
      mtd->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.
      
       -> blktrans_open()
          ->  mutex_lock(&dev->lock);
          ->  mutex_lock(&mtd_table_mutex);
      
       -> del_mtd_device()
          ->  mutex_lock(&mtd_table_mutex);
          ->  blktrans_notify_remove() -> del_mtd_blktrans_dev()
             ->  mutex_lock(&dev->lock);
      
      This is a classic (potential) ABBA deadlock, which can be fixed by
      making the A->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 &dev->lock:
      
              if (mutex_trylock(&mtd_table_mutex)) {
                      mutex_unlock(&mtd_table_mutex);
                      BUG();
              }
      
      So, reverse the ordering of acquisition of &dev->lock and &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]  (&new->lock){+.+...}, at: [<c043fe4c>] del_mtd_blktrans_dev+0x80/0xdc
        [   53.457271]
        [   53.457271] but task is already holding lock:
        [   53.463372]  (mtd_table_mutex){+.+.+.}, at: [<c0439994>] 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]
        -> #1 (mtd_table_mutex){+.+.+.}:
        [   53.492331]        [<c043fc5c>] blktrans_open+0x34/0x1a4
        [   53.497879]        [<c01afce0>] __blkdev_get+0xc4/0x3b0
        [   53.503364]        [<c01b0bb8>] blkdev_get+0x108/0x320
        [   53.508743]        [<c01713c0>] do_dentry_open+0x218/0x314
        [   53.514496]        [<c0180454>] path_openat+0x4c0/0xf9c
        [   53.519959]        [<c0182044>] do_filp_open+0x5c/0xc0
        [   53.525336]        [<c0172758>] do_sys_open+0xfc/0x1cc
        [   53.530716]        [<c000f740>] ret_fast_syscall+0x0/0x1c
        [   53.536375]
        -> #0 (&new->lock){+.+...}:
        [   53.540587]        [<c063f124>] mutex_lock_nested+0x38/0x3cc
        [   53.546504]        [<c043fe4c>] del_mtd_blktrans_dev+0x80/0xdc
        [   53.552606]        [<c043f164>] blktrans_notify_remove+0x7c/0x84
        [   53.558891]        [<c04399f0>] del_mtd_device+0x74/0x100
        [   53.564544]        [<c043c670>] del_mtd_partitions+0x80/0xc8
        [   53.570451]        [<c0439aa0>] mtd_device_unregister+0x24/0x48
        [   53.576637]        [<c046ce6c>] spi_drv_remove+0x1c/0x34
        [   53.582207]        [<c03de0f0>] __device_release_driver+0x88/0x114
        [   53.588663]        [<c03de19c>] device_release_driver+0x20/0x2c
        [   53.594843]        [<c03dd9e8>] bus_remove_device+0xd8/0x108
        [   53.600748]        [<c03dacc0>] device_del+0x10c/0x210
        [   53.606127]        [<c03dadd0>] device_unregister+0xc/0x20
        [   53.611849]        [<c046d878>] __unregister+0x10/0x20
        [   53.617211]        [<c03da868>] device_for_each_child+0x50/0x7c
        [   53.623387]        [<c046eae8>] spi_unregister_master+0x58/0x8c
        [   53.629578]        [<c03e12f0>] release_nodes+0x15c/0x1c8
        [   53.635223]        [<c03de0f8>] __device_release_driver+0x90/0x114
        [   53.641689]        [<c03de900>] driver_detach+0xb4/0xb8
        [   53.647147]        [<c03ddc78>] bus_remove_driver+0x4c/0xa0
        [   53.652970]        [<c00cab50>] SyS_delete_module+0x11c/0x1e4
        [   53.658976]        [<c000f740>] 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(&new->lock);
        [   53.698306]                                lock(mtd_table_mutex);
        [   53.704658]   lock(&new->lock);
        [   53.707946]
        [   53.707946]  *** DEADLOCK ***
      
      Fixes: 073db4a5 ("mtd: fix: avoid race condition when accessing mtd->usecount")
      Reported-by: NFelipe Balbi <balbi@ti.com>
      Tested-by: NFelipe Balbi <balbi@ti.com>
      Signed-off-by: NBrian Norris <computersforpeace@gmail.com>
      Cc: <stable@vger.kernel.org>
      f3c63795
  10. 29 9月, 2015 1 次提交
    • P
      mtd: blktrans: fix multiplication overflow · 2ce401d5
      Peng Fan 提交于
      In drivers/mtd/mtd_blkdevs.c:
      406	set_capacity(gd, (new->size * tr->blksize) >> 9);
      The type of new->size is unsigned long and the type of tr->blksize is int,
      the result of 'new->size * tr->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->size is 0x800000 and tr->blksize is
      0x200, 'new->size * tr->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: NPeng Fan <van.freenix@gmail.com>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Signed-off-by: NBrian Norris <computersforpeace@gmail.com>
      2ce401d5
  11. 26 8月, 2015 1 次提交
  12. 17 7月, 2015 1 次提交
  13. 22 5月, 2015 1 次提交
  14. 21 5月, 2015 1 次提交
  15. 13 5月, 2015 1 次提交
    • B
      mtd: fix: avoid race condition when accessing mtd->usecount · 073db4a5
      Brian Norris 提交于
      On A MIPS 32-cores machine a BUG_ON was triggered because some acesses to
      mtd->usecount were done without taking mtd_table_mutex.
      kernel: Call Trace:
      kernel: [<ffffffff80401818>] __put_mtd_device+0x20/0x50
      kernel: [<ffffffff804086f4>] blktrans_release+0x8c/0xd8
      kernel: [<ffffffff802577e0>] __blkdev_put+0x1a8/0x200
      kernel: [<ffffffff802579a4>] blkdev_close+0x1c/0x30
      kernel: [<ffffffff8022006c>] __fput+0xac/0x250
      kernel: [<ffffffff80171208>] task_work_run+0xd8/0x120
      kernel: [<ffffffff8012c23c>] work_notifysig+0x10/0x18
      kernel:
      kernel:
              Code: 2442ffff  ac8202d8  000217fe <00020336> 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: NZhang Xingcai <zhangxingcai@huawei.com>
      Reported-by: NGiuseppe Cantavenera <giuseppe.cantavenera.ext@nokia.com>
      Tested-by: NGiuseppe Cantavenera <giuseppe.cantavenera.ext@nokia.com>
      Acked-by: NAlexander Sverdlin <alexander.sverdlin@nokia.com>
      Signed-off-by: NBrian Norris <computersforpeace@gmail.com>
      073db4a5
  16. 12 3月, 2015 1 次提交
  17. 05 10月, 2014 1 次提交
    • M
      block: disable entropy contributions for nonrot devices · b277da0a
      Mike Snitzer 提交于
      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: NMike Snitzer <snitzer@redhat.com>
      Signed-off-by: NJens Axboe <axboe@fb.com>
      b277da0a
  18. 16 4月, 2014 2 次提交
    • R
      mtd: mtd_blkdevs: handle REQ_FLUSH request and do explicit flush of writeback buffer · 566c0d6a
      Roman Peniaev 提交于
      mtd_blkdevs is device with volatile cache (writeback buffer), so it should support
      REQ_FLUSH to do explicit flush.
      
      Without this patch 'sync' does not guarantee that writeback buffer will be flushed
      on disk in case of power off, e.g.:
      
        $ cp some_file /mnt
        $ sync
      
        ### POWER OFF
      
      In case of this sequence writeback buffer will not be flushed on disk.
      
      This patch fixes this behaviour and explicitly reports to block layer that flush
      requests are being supported.
      Signed-off-by: NRoman Peniaev <r.peniaev@gmail.com>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: linux-mtd@lists.infradead.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NBrian Norris <computersforpeace@gmail.com>
      566c0d6a
    • J
      block: remove struct request buffer member · b4f42e28
      Jens Axboe 提交于
      This was used in the olden days, back when onions were proper
      yellow. Basically it mapped to the current buffer to be
      transferred. With highmem being added more than a decade ago,
      most drivers map pages out of a bio, and rq->buffer isn't
      pointing at anything valid.
      
      Convert old style drivers to just use bio_data().
      
      For the discard payload use case, just reference the page
      in the bio.
      Signed-off-by: NJens Axboe <axboe@fb.com>
      b4f42e28
  19. 11 3月, 2014 1 次提交
  20. 07 5月, 2013 1 次提交
  21. 06 5月, 2013 1 次提交
  22. 21 11月, 2012 2 次提交
  23. 27 3月, 2012 1 次提交
  24. 10 1月, 2012 1 次提交
    • B
      mtd: mtd_blkdevs: don't increase 'open' count on error path · 342ff28f
      Brian Norris 提交于
      Some error paths in mtd_blkdevs were fixed in the following commit:
      
          commit 94735ec4
          mtd: mtd_blkdevs: fix error path in blktrans_open
      
      But on these error paths, the block device's `dev->open' count is
      already incremented before we check for errors. This meant that, while
      the error path was handled correctly on the first time through
      blktrans_open(), the device is erroneously considered already open on
      the second time through.
      
      This problem can be seen, for instance, when a UBI volume is
      simultaneously mounted as a UBIFS partition and read through its
      corresponding gluebi mtdblockX device. This results in blktrans_open()
      passing its error checks (with `dev->open > 0') without actually having
      a handle on the device. Here's a summarized log of the actions and
      results with nandsim:
      
          # modprobe nandsim
          # modprobe mtdblock
          # modprobe gluebi
          # modprobe ubifs
          # ubiattach /dev/ubi_ctrl -m 0
          ...
          # ubimkvol /dev/ubi0 -N test -s 16MiB
          ...
          # mount -t ubifs ubi0:test /mnt
          # ls /dev/mtdblock*
          /dev/mtdblock0  /dev/mtdblock1
          # cat /dev/mtdblock1 > /dev/null
          cat: can't open '/dev/mtdblock4': Device or resource busy
          # cat /dev/mtdblock1 > /dev/null
      
          CPU 0 Unable to handle kernel paging request at virtual address
          fffffff0, epc == 8031536c, ra == 8031f280
          Oops[#1]:
          ...
          Call Trace:
          [<8031536c>] ubi_leb_read+0x14/0x164
          [<8031f280>] gluebi_read+0xf0/0x148
          [<802edba8>] mtdblock_readsect+0x64/0x198
          [<802ecfe4>] mtd_blktrans_thread+0x330/0x3f4
          [<8005be98>] kthread+0x88/0x90
          [<8000bc04>] kernel_thread_helper+0x10/0x18
      
      Cc: stable@kernel.org [3.0+]
      Signed-off-by: NBrian Norris <computersforpeace@gmail.com>
      Signed-off-by: NArtem Bityutskiy <Artem.Bityutskiy@linux.intel.com>
      Signed-off-by: NDavid Woodhouse <David.Woodhouse@intel.com>
      342ff28f
  25. 14 10月, 2011 1 次提交
  26. 25 5月, 2011 1 次提交
  27. 11 3月, 2011 4 次提交
  28. 30 10月, 2010 2 次提交
  29. 25 10月, 2010 3 次提交
  30. 05 10月, 2010 1 次提交
    • A
      block: autoconvert trivial BKL users to private mutex · 2a48fc0a
      Arnd Bergmann 提交于
      The block device drivers have all gained new lock_kernel
      calls from a recent pushdown, and some of the drivers
      were already using the BKL before.
      
      This turns the BKL into a set of per-driver mutexes.
      Still need to check whether this is safe to do.
      
      file=$1
      name=$2
      if grep -q lock_kernel ${file} ; then
          if grep -q 'include.*linux.mutex.h' ${file} ; then
                  sed -i '/include.*<linux\/smp_lock.h>/d' ${file}
          else
                  sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file}
          fi
          sed -i ${file} \
              -e "/^#include.*linux.mutex.h/,$ {
                      1,/^\(static\|int\|long\)/ {
                           /^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex);
      
      } }"  \
          -e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \
          -e '/[      ]*cycle_kernel_lock();/d'
      else
          sed -i -e '/include.*\<smp_lock.h\>/d' ${file}  \
                      -e '/cycle_kernel_lock()/d'
      fi
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      2a48fc0a
  31. 09 8月, 2010 1 次提交