Commit Graph

1504 Commits

Author SHA1 Message Date
黄涛
d36caf0ebf block: fix loop on blk_drain_queue when __dm_destroy
when install apk to sdcard, vold will loop on blk_drain_queue:
vold            D c090e3a8     0   119      1 0x00000000
[<c090e3a8>] (__schedule+0x3b0/0x85c) from [<c090ed98>] (schedule_timeout+0x160/0x2dc)
[<c090ed98>] (schedule_timeout+0x160/0x2dc) from [<c047de38>] (msleep+0x14/0x20)
[<c047de38>] (msleep+0x14/0x20) from [<c05e6e04>] (blk_cleanup_queue+0xb4/0x218)
[<c05e6e04>] (blk_cleanup_queue+0xb4/0x218) from [<c071cca4>] (__dm_destroy+0x170/0x1c4)
[<c071cca4>] (__dm_destroy+0x170/0x1c4) from [<c0721d8c>] (dev_remove+0x74/0xa8)
[<c0721d8c>] (dev_remove+0x74/0xa8) from [<c0722534>] (dm_ctl_ioctl+0x1e4/0x2d4)
[<c0722534>] (dm_ctl_ioctl+0x1e4/0x2d4) from [<c05153c4>] (do_vfs_ioctl+0x80/0x5b0)
[<c05153c4>] (do_vfs_ioctl+0x80/0x5b0) from [<c051592c>] (sys_ioctl+0x38/0x60)
[<c051592c>] (sys_ioctl+0x38/0x60) from [<c0439540>] (ret_fast_syscall+0x0/0x30)
2013-03-23 09:32:38 +08:00
黄涛
134516e298 block: fix request_queue lifetime handling by making blk_queue_cleanup() properly shutdown
commit c9a929dde3 upstream.

request_queue is refcounted but actually depdends on lifetime
management from the queue owner - on blk_cleanup_queue(), block layer
expects that there's no request passing through request_queue and no
new one will.

This is fundamentally broken.  The queue owner (e.g. SCSI layer)
doesn't have a way to know whether there are other active users before
calling blk_cleanup_queue() and other users (e.g. bsg) don't have any
guarantee that the queue is and would stay valid while it's holding a
reference.

With delay added in blk_queue_bio() before queue_lock is grabbed, the
following oops can be easily triggered when a device is removed with
in-flight IOs.

 sd 0:0:1:0: [sdb] Stopping disk
 ata1.01: disabled
 general protection fault: 0000 [#1] PREEMPT SMP
 CPU 2
 Modules linked in:

 Pid: 648, comm: test_rawio Not tainted 3.1.0-rc3-work+ #56 Bochs Bochs
 RIP: 0010:[<ffffffff8137d651>]  [<ffffffff8137d651>] elv_rqhash_find+0x61/0x100
 ...
 Process test_rawio (pid: 648, threadinfo ffff880019efa000, task ffff880019ef8a80)
 ...
 Call Trace:
  [<ffffffff8137d774>] elv_merge+0x84/0xe0
  [<ffffffff81385b54>] blk_queue_bio+0xf4/0x400
  [<ffffffff813838ea>] generic_make_request+0xca/0x100
  [<ffffffff81383994>] submit_bio+0x74/0x100
  [<ffffffff811c53ec>] dio_bio_submit+0xbc/0xc0
  [<ffffffff811c610e>] __blockdev_direct_IO+0x92e/0xb40
  [<ffffffff811c39f7>] blkdev_direct_IO+0x57/0x60
  [<ffffffff8113b1c5>] generic_file_aio_read+0x6d5/0x760
  [<ffffffff8118c1ca>] do_sync_read+0xda/0x120
  [<ffffffff8118ce55>] vfs_read+0xc5/0x180
  [<ffffffff8118cfaa>] sys_pread64+0x9a/0xb0
  [<ffffffff81afaf6b>] system_call_fastpath+0x16/0x1b

This happens because blk_queue_cleanup() destroys the queue and
elevator whether IOs are in progress or not and DEAD tests are
sprinkled in the request processing path without proper
synchronization.

Similar problem exists for blk-throtl.  On queue cleanup, blk-throtl
is shutdown whether it has requests in it or not.  Depending on
timing, it either oopses or throttled bios are lost putting tasks
which are waiting for bio completion into eternal D state.

The way it should work is having the usual clear distinction between
shutdown and release.  Shutdown drains all currently pending requests,
marks the queue dead, and performs partial teardown of the now
unnecessary part of the queue.  Even after shutdown is complete,
reference holders are still allowed to issue requests to the queue
although they will be immmediately failed.  The rest of teardown
happens on release.

This patch makes the following changes to make blk_queue_cleanup()
behave as proper shutdown.

* QUEUE_FLAG_DEAD is now set while holding both q->exit_mutex and
  queue_lock.

* Unsynchronized DEAD check in generic_make_request_checks() removed.
  This couldn't make any meaningful difference as the queue could die
  after the check.

* blk_drain_queue() updated such that it can drain all requests and is
  now called during cleanup.

* blk_throtl updated such that it checks DEAD on grabbing queue_lock,
  drains all throttled bios during cleanup and free td when queue is
  released.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-03-18 17:15:50 +08:00
Tejun Heo
6bf3b25053 block: make get_request[_wait]() fail if queue is dead
Currently get_request[_wait]() allocates request whether queue is dead
or not.  This patch makes get_request[_wait]() return NULL if @q is
dead.  blk_queue_bio() is updated to fail the submitted bio if request
allocation fails.  While at it, add docbook comments for
get_request[_wait]().

Note that the current code has rather unclear (there are spurious DEAD
tests scattered around) assumption that the owner of a queue
guarantees that no request travels block layer if the queue is dead
and this patch in itself doesn't change much; however, this will allow
fixing the broken assumption in the next patch.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-03-18 17:01:00 +08:00
Akinobu Mita
4a8913795a fail_make_request: cleanup should_fail_request
This changes should_fail_request() to more usable wrapper function of
should_fail().  It can avoid putting #ifdef CONFIG_FAIL_MAKE_REQUEST in
the middle of a function.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-03-18 17:00:09 +08:00
黄涛
b77e0e8463 Merge remote-tracking branch 'stable/linux-3.0.y' into develop-3.0
Conflicts:
	Makefile
2012-12-12 17:18:39 +08:00
Jan Kara
9012327529 scsi: Silence unnecessary warnings about ioctl to partition
commit 6d93592807 upstream.

Sometimes, warnings about ioctls to partition happen often enough that they
form majority of the warnings in the kernel log and users complain. In some
cases warnings are about ioctls such as SG_IO so it's not good to get rid of
the warnings completely as they can ease debugging of userspace problems
when ioctl is refused.

Since I have seen warnings from lots of commands, including some proprietary
userspace applications, I don't think disallowing the ioctls for processes
with CAP_SYS_RAWIO will happen in the near future if ever. So lets just
stop warning for processes with CAP_SYS_RAWIO for which ioctl is allowed.

Acked-by: Paolo Bonzini <pbonzini@redhat.com>
CC: James Bottomley <JBottomley@parallels.com>
CC: linux-scsi@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Cc: Satoru Takeuchi <satoru.takeuchi@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-12-10 10:45:08 -08:00
黄涛
a7ba6e6853 Revert "rk292x (v86 & tr726) :add sd-vcc control while sd hw initial"
This reverts commit 64a1ccaaec.

Only revert block/blk-core.c and fs/fat/misc.c change.
2012-11-28 13:21:33 +08:00
hj
64a1ccaaec rk292x (v86 & tr726) :add sd-vcc control while sd hw initial 2012-11-28 11:45:11 +08:00
黄涛
903d694ab5 Merge remote-tracking branch 'stable/linux-3.0.y' into develop-3.0
Conflicts:
	Makefile
2012-11-01 17:13:08 +08:00
黄涛
fd3316fde0 Merge remote-tracking branch 'stable/linux-3.0.y' into develop-3.0
Conflicts:
	Makefile
2012-10-23 10:06:51 +08:00
Greg Kroah-Hartman
798e16a6e6 Revert "block: fix request_queue->flags initialization"
This reverts commit 2101aa5bb0 which is
commit 60ea8226cb upstream.

To quote Ben:
	This is not needed, as there is no QUEUE_FLAG_BYPASS in 3.0.y.

To quote Tejun:
	I don't think it will break anything as it simply changes
	assignment to |= to avoid overwriting existing flags.  That
	said, any patch can break anything, so if possible it would be
	better to drop for 3.0.y.

So I'll revert this to be safe.

Cc: Tejun Heo <tj@kernel.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-10-22 08:33:26 -07:00
Tejun Heo
2101aa5bb0 block: fix request_queue->flags initialization
commit 60ea8226cb upstream.

A queue newly allocated with blk_alloc_queue_node() has only
QUEUE_FLAG_BYPASS set.  For request-based drivers,
blk_init_allocated_queue() is called and q->queue_flags is overwritten
with QUEUE_FLAG_DEFAULT which doesn't include BYPASS even though the
initial bypass is still in effect.

In blk_init_allocated_queue(), or QUEUE_FLAG_DEFAULT to q->queue_flags
instead of overwriting.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-10-21 09:17:10 -07:00
黄涛
a2ad9f9801 Merge remote-tracking branch 'stable/linux-3.0.y' into develop-3.0-jb
Conflicts:
	drivers/net/usb/asix.c
	drivers/net/wireless/iwlwifi/iwl-agn-rs.c
	drivers/usb/serial/option.c
2012-07-12 18:46:41 +08:00
黄涛
30be6d7972 Merge remote-tracking branch 'common/android-3.0' into develop-3.0-jb
Conflicts:
	drivers/cpufreq/cpufreq_interactive.c
	drivers/misc/pmem.c
	drivers/net/usb/asix.c
	drivers/net/wireless/ath/ath9k/ani.c
	drivers/net/wireless/ath/ath9k/ar5008_phy.c
	drivers/net/wireless/ath/ath9k/ar9002_hw.c
	drivers/net/wireless/ath/ath9k/ar9003_calib.c
	drivers/net/wireless/ath/ath9k/ar9003_mac.c
	drivers/net/wireless/ath/ath9k/ar9003_phy.h
	drivers/net/wireless/ath/ath9k/calib.c
	drivers/net/wireless/ath/ath9k/hif_usb.c
	drivers/net/wireless/ath/ath9k/hw.c
	drivers/net/wireless/ath/ath9k/hw.h
	drivers/net/wireless/ath/ath9k/main.c
	drivers/net/wireless/ath/ath9k/rc.c
	drivers/net/wireless/ath/ath9k/recv.c
	drivers/net/wireless/b43/main.c
	drivers/net/wireless/bcm4319/aiutils.c
	drivers/net/wireless/bcm4319/bcmsdh.c
	drivers/net/wireless/bcm4319/bcmsdh_linux.c
	drivers/net/wireless/bcm4319/bcmsdh_sdmmc.c
	drivers/net/wireless/bcm4319/bcmsdh_sdmmc_linux.c
	drivers/net/wireless/bcm4319/bcmutils.c
	drivers/net/wireless/bcm4319/dhd_common.c
	drivers/net/wireless/bcm4319/dhd_proto.h
	drivers/net/wireless/bcm4319/dhd_sdio.c
	drivers/net/wireless/bcm4319/hndpmu.c
	drivers/net/wireless/bcm4319/include/aidmp.h
	drivers/net/wireless/bcm4319/include/bcmcdc.h
	drivers/net/wireless/bcm4319/include/bcmdefs.h
	drivers/net/wireless/bcm4319/include/bcmdevs.h
	drivers/net/wireless/bcm4319/include/bcmendian.h
	drivers/net/wireless/bcm4319/include/bcmpcispi.h
	drivers/net/wireless/bcm4319/include/bcmperf.h
	drivers/net/wireless/bcm4319/include/bcmsdbus.h
	drivers/net/wireless/bcm4319/include/bcmsdh.h
	drivers/net/wireless/bcm4319/include/bcmsdh_sdmmc.h
	drivers/net/wireless/bcm4319/include/bcmsdpcm.h
	drivers/net/wireless/bcm4319/include/bcmsdspi.h
	drivers/net/wireless/bcm4319/include/bcmsdstd.h
	drivers/net/wireless/bcm4319/include/bcmspi.h
	drivers/net/wireless/bcm4319/include/bcmutils.h
	drivers/net/wireless/bcm4319/include/bcmwifi.h
	drivers/net/wireless/bcm4319/include/dhdioctl.h
	drivers/net/wireless/bcm4319/include/epivers.h
	drivers/net/wireless/bcm4319/include/hndpmu.h
	drivers/net/wireless/bcm4319/include/hndrte_armtrap.h
	drivers/net/wireless/bcm4319/include/hndrte_cons.h
	drivers/net/wireless/bcm4319/include/hndsoc.h
	drivers/net/wireless/bcm4319/include/linux_osl.h
	drivers/net/wireless/bcm4319/include/linuxver.h
	drivers/net/wireless/bcm4319/include/miniopt.h
	drivers/net/wireless/bcm4319/include/msgtrace.h
	drivers/net/wireless/bcm4319/include/osl.h
	drivers/net/wireless/bcm4319/include/packed_section_end.h
	drivers/net/wireless/bcm4319/include/packed_section_start.h
	drivers/net/wireless/bcm4319/include/pcicfg.h
	drivers/net/wireless/bcm4319/include/proto/802.11e.h
	drivers/net/wireless/bcm4319/include/proto/802.1d.h
	drivers/net/wireless/bcm4319/include/proto/bcmeth.h
	drivers/net/wireless/bcm4319/include/proto/bcmevent.h
	drivers/net/wireless/bcm4319/include/proto/bcmip.h
	drivers/net/wireless/bcm4319/include/proto/eapol.h
	drivers/net/wireless/bcm4319/include/proto/ethernet.h
	drivers/net/wireless/bcm4319/include/proto/sdspi.h
	drivers/net/wireless/bcm4319/include/proto/vlan.h
	drivers/net/wireless/bcm4319/include/proto/wpa.h
	drivers/net/wireless/bcm4319/include/sbchipc.h
	drivers/net/wireless/bcm4319/include/sbconfig.h
	drivers/net/wireless/bcm4319/include/sbhnddma.h
	drivers/net/wireless/bcm4319/include/sbpcmcia.h
	drivers/net/wireless/bcm4319/include/sbsdio.h
	drivers/net/wireless/bcm4319/include/sbsdpcmdev.h
	drivers/net/wireless/bcm4319/include/sbsocram.h
	drivers/net/wireless/bcm4319/include/sdio.h
	drivers/net/wireless/bcm4319/include/sdioh.h
	drivers/net/wireless/bcm4319/include/sdiovar.h
	drivers/net/wireless/bcm4319/include/siutils.h
	drivers/net/wireless/bcm4319/include/trxhdr.h
	drivers/net/wireless/bcm4319/include/typedefs.h
	drivers/net/wireless/bcm4319/siutils.c
	drivers/net/wireless/bcm4319/wl_iw.c
	drivers/net/wireless/bcm4319/wl_iw.h
	drivers/net/wireless/bcmdhd/Kconfig
	drivers/net/wireless/bcmdhd/Makefile
	drivers/net/wireless/bcmdhd/bcmevent.c
	drivers/net/wireless/bcmdhd/dhd.h
	drivers/net/wireless/bcmdhd/dhd_cdc.c
	drivers/net/wireless/bcmdhd/dhd_linux.c
	drivers/net/wireless/bcmdhd/dhd_wlfc.h
	drivers/net/wireless/bcmdhd/include/Makefile
	drivers/net/wireless/bcmdhd/include/htsf.h
	drivers/net/wireless/bcmdhd/include/proto/802.11.h
	drivers/net/wireless/bcmdhd/include/proto/802.11_bta.h
	drivers/net/wireless/bcmdhd/include/proto/bt_amp_hci.h
	drivers/net/wireless/bcmdhd/include/proto/p2p.h
	drivers/net/wireless/bcmdhd/include/wlfc_proto.h
	drivers/net/wireless/bcmdhd/include/wlioctl.h
	drivers/net/wireless/bcmdhd/linux_osl.c
	drivers/net/wireless/bcmdhd/wl_android.c
	drivers/net/wireless/bcmdhd/wl_android.h
	drivers/net/wireless/bcmdhd/wl_cfg80211.c
	drivers/net/wireless/bcmdhd/wl_cfg80211.h
	drivers/net/wireless/bcmdhd/wl_cfgp2p.c
	drivers/net/wireless/bcmdhd/wl_cfgp2p.h
	drivers/net/wireless/bcmdhd/wl_linux_mon.c
	drivers/net/wireless/bcmdhd/wldev_common.c
	drivers/net/wireless/bcmdhd/wldev_common.h
	drivers/net/wireless/ipw2x00/ipw2200.c
	drivers/net/wireless/iwlwifi/iwl-agn-lib.c
	drivers/net/wireless/iwlwifi/iwl-agn-tx.c
	drivers/net/wireless/iwlwifi/iwl-agn-ucode.c
	drivers/net/wireless/iwlwifi/iwl-agn.c
	drivers/net/wireless/iwlwifi/iwl-agn.h
	drivers/net/wireless/iwlwifi/iwl-core.c
	drivers/net/wireless/iwlwifi/iwl-hcmd.c
	drivers/net/wireless/iwlwifi/iwl-rx.c
	drivers/net/wireless/iwlwifi/iwl-tx.c
	drivers/net/wireless/libertas/if_spi.c
	drivers/net/wireless/p54/p54spi.c
	drivers/net/wireless/rt2x00/rt2800lib.c
	drivers/net/wireless/rt2x00/rt2800pci.c
	drivers/net/wireless/rt2x00/rt2800usb.c
	drivers/net/wireless/rt2x00/rt2x00.h
	drivers/net/wireless/rt2x00/rt2x00dev.c
	drivers/net/wireless/rt2x00/rt2x00mac.c
	drivers/net/wireless/rt2x00/rt2x00queue.c
	drivers/usb/serial/option.c
2012-07-12 18:08:01 +08:00
Tejun Heo
19e40444eb block: fix buffer overflow when printing partition UUIDs
commit 05c69d298c upstream.

6d1d8050b4 "block, partition: add partition_meta_info to hd_struct"
added part_unpack_uuid() which assumes that the passed in buffer has
enough space for sprintfing "%pU" - 37 characters including '\0'.

Unfortunately, b5af921ec0 "init: add support for root devices
specified by partition UUID" supplied 33 bytes buffer to the function
leading to the following panic with stackprotector enabled.

  Kernel panic - not syncing: stack-protector: Kernel stack corrupted in: ffffffff81b14c7e

  [<ffffffff815e226b>] panic+0xba/0x1c6
  [<ffffffff81b14c7e>] ? printk_all_partitions+0x259/0x26xb
  [<ffffffff810566bb>] __stack_chk_fail+0x1b/0x20
  [<ffffffff81b15c7e>] printk_all_paritions+0x259/0x26xb
  [<ffffffff81aedfe0>] mount_block_root+0x1bc/0x27f
  [<ffffffff81aee0fa>] mount_root+0x57/0x5b
  [<ffffffff81aee23b>] prepare_namespace+0x13d/0x176
  [<ffffffff8107eec0>] ? release_tgcred.isra.4+0x330/0x30
  [<ffffffff81aedd60>] kernel_init+0x155/0x15a
  [<ffffffff81087b97>] ? schedule_tail+0x27/0xb0
  [<ffffffff815f4d24>] kernel_thread_helper+0x5/0x10
  [<ffffffff81aedc0b>] ? start_kernel+0x3c5/0x3c5
  [<ffffffff815f4d20>] ? gs_change+0x13/0x13

Increase the buffer size, remove the dangerous part_unpack_uuid() and
use snprintf() directly from printk_all_partitions().

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Szymon Gruszczynski <sz.gruszczynski@googlemail.com>
Cc: Will Drewry <wad@chromium.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-06-01 15:12:52 +08:00
Todd Poynor
94225ab0be Merge linux-stable 3.0.28 into android-3.0
Change-Id: Iee820738e53627f5d0447a87ceff34443aa72786
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2012-04-19 15:20:03 -07:00
Alan Stern
25705e3a3e Block: use a freezable workqueue for disk-event polling
commit 62d3c5439c upstream.

This patch (as1519) fixes a bug in the block layer's disk-events
polling.  The polling is done by a work routine queued on the
system_nrt_wq workqueue.  Since that workqueue isn't freezable, the
polling continues even in the middle of a system sleep transition.

Obviously, polling a suspended drive for media changes and such isn't
a good thing to do; in the case of USB mass-storage devices it can
lead to real problems requiring device resets and even re-enumeration.

The patch fixes things by creating a new system-wide, non-reentrant,
freezable workqueue and using it for disk-events polling.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-19 08:57:59 -07:00
Stanislaw Gruszka
aaa136d348 block: fix __blkdev_get and add_disk race condition
commit 9f53d2fe81 upstream.

The following situation might occur:

__blkdev_get:			add_disk:

				register_disk()
get_gendisk()

disk_block_events()
	disk->ev == NULL

				disk_add_events()

__disk_unblock_events()
	disk->ev != NULL
	--ev->block

Then we unblock events, when they are suppose to be blocked. This can
trigger events related block/genhd.c warnings, but also can crash in
sd_check_events() or other places.

I'm able to reproduce crashes with the following scripts (with
connected usb dongle as sdb disk).

<snip>
DEV=/dev/sdb
ENABLE=/sys/bus/usb/devices/1-2/bConfigurationValue

function stop_me()
{
	for i in `jobs -p` ; do kill $i 2> /dev/null ; done
	exit
}

trap stop_me SIGHUP SIGINT SIGTERM

for ((i = 0; i < 10; i++)) ; do
	while true; do fdisk -l $DEV  2>&1 > /dev/null ; done &
done

while true ; do
echo 1 > $ENABLE
sleep 1
echo 0 > $ENABLE
done
</snip>

I use the script to verify patch fixing oops in sd_revalidate_disk
http://marc.info/?l=linux-scsi&m=132935572512352&w=2
Without Jun'ichi Nomura patch titled "Fix NULL pointer dereference in
sd_revalidate_disk" or this one, script easily crash kernel within
a few seconds. With both patches applied I do not observe crash.
Unfortunately after some time (dozen of minutes), script will hung in:

[ 1563.906432]  [<c08354f5>] schedule_timeout_uninterruptible+0x15/0x20
[ 1563.906437]  [<c04532d5>] msleep+0x15/0x20
[ 1563.906443]  [<c05d60b2>] blk_drain_queue+0x32/0xd0
[ 1563.906447]  [<c05d6e00>] blk_cleanup_queue+0xd0/0x170
[ 1563.906454]  [<c06d278f>] scsi_free_queue+0x3f/0x60
[ 1563.906459]  [<c06d7e6e>] __scsi_remove_device+0x6e/0xb0
[ 1563.906463]  [<c06d4aff>] scsi_forget_host+0x4f/0x60
[ 1563.906468]  [<c06cd84a>] scsi_remove_host+0x5a/0xf0
[ 1563.906482]  [<f7f030fb>] quiesce_and_remove_host+0x5b/0xa0 [usb_storage]
[ 1563.906490]  [<f7f03203>] usb_stor_disconnect+0x13/0x20 [usb_storage]

Anyway I think this patch is some step forward.

As drawback, I do not teardown on sysfs file create error, because I do
not know how to nullify disk->ev (since it can be used). However add_disk
error handling practically does not exist too, and things will work
without this sysfs file, except events will not be exported to user
space.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-19 08:57:58 -07:00
Stanislaw Gruszka
b38d6b8e19 bsg: fix sysfs link remove warning
commit 37b40adf2d upstream.

We create "bsg" link if q->kobj.sd is not NULL, so remove it only
when the same condition is true.

Fixes:

WARNING: at fs/sysfs/inode.c:323 sysfs_hash_and_remove+0x2b/0x77()
sysfs: can not remove 'bsg', no directory
Call Trace:
  [<c0429683>] warn_slowpath_common+0x6a/0x7f
  [<c0537a68>] ? sysfs_hash_and_remove+0x2b/0x77
  [<c042970b>] warn_slowpath_fmt+0x2b/0x2f
  [<c0537a68>] sysfs_hash_and_remove+0x2b/0x77
  [<c053969a>] sysfs_remove_link+0x20/0x23
  [<c05d88f1>] bsg_unregister_queue+0x40/0x6d
  [<c0692263>] __scsi_remove_device+0x31/0x9d
  [<c069149f>] scsi_forget_host+0x41/0x52
  [<c0689fa9>] scsi_remove_host+0x71/0xe0
  [<f7de5945>] quiesce_and_remove_host+0x51/0x83 [usb_storage]
  [<f7de5a1e>] usb_stor_disconnect+0x18/0x22 [usb_storage]
  [<c06c29de>] usb_unbind_interface+0x4e/0x109
  [<c067a80f>] __device_release_driver+0x6b/0xa6
  [<c067a861>] device_release_driver+0x17/0x22
  [<c067a46a>] bus_remove_device+0xd6/0xe6
  [<c06785e2>] device_del+0xf2/0x137
  [<c06c101f>] usb_disable_device+0x94/0x1a0

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-03-12 10:32:57 -07:00
Paolo Bonzini
8bd8442fec block: fail SCSI passthrough ioctls on partition devices
commit 0bfc96cb77 upstream.

[ Changes with respect to 3.3: return -ENOTTY from scsi_verify_blk_ioctl
  and -ENOIOCTLCMD from sd_compat_ioctl. ]

Linux allows executing the SG_IO ioctl on a partition or LVM volume, and
will pass the command to the underlying block device.  This is
well-known, but it is also a large security problem when (via Unix
permissions, ACLs, SELinux or a combination thereof) a program or user
needs to be granted access only to part of the disk.

This patch lets partitions forward a small set of harmless ioctls;
others are logged with printk so that we can see which ioctls are
actually sent.  In my tests only CDROM_GET_CAPABILITY actually occurred.
Of course it was being sent to a (partition on a) hard disk, so it would
have failed with ENOTTY and the patch isn't changing anything in
practice.  Still, I'm treating it specially to avoid spamming the logs.

In principle, this restriction should include programs running with
CAP_SYS_RAWIO.  If for example I let a program access /dev/sda2 and
/dev/sdb, it still should not be able to read/write outside the
boundaries of /dev/sda2 independent of the capabilities.  However, for
now programs with CAP_SYS_RAWIO will still be allowed to send the
ioctls.  Their actions will still be logged.

This patch does not affect the non-libata IDE driver.  That driver
however already tests for bd != bd->bd_contains before issuing some
ioctl; it could be restricted further to forbid these ioctls even for
programs running with CAP_SYS_ADMIN/CAP_SYS_RAWIO.

Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Cc: James Bottomley <JBottomley@parallels.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
[ Make it also print the command name when warning - Linus ]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2012-01-25 17:24:54 -08:00
Paolo Bonzini
3b8373b85c block: add and use scsi_blk_cmd_ioctl
commit 577ebb374c upstream.

Introduce a wrapper around scsi_cmd_ioctl that takes a block device.

The function will then be enhanced to detect partition block devices
and, in that case, subject the ioctls to whitelisting.

Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Cc: James Bottomley <JBottomley@parallels.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2012-01-25 17:24:54 -08:00
Mike Snitzer
d27bf91d1a block: initialize request_queue's numa node during
commit 5151412dd4 upstream.

struct request_queue is allocated with __GFP_ZERO so its "node" field is
zero before initialization.  This causes an oops if node 0 is offline in
the page allocator because its zonelists are not initialized.  From Dave
Young's dmesg:

	SRAT: Node 1 PXM 2 0-d0000000
	SRAT: Node 1 PXM 2 100000000-330000000
	SRAT: Node 0 PXM 1 330000000-630000000
	Initmem setup node 1 0000000000000000-000000000affb000
	...
	Built 1 zonelists in Node order, mobility grouping on.
	...
	BUG: unable to handle kernel paging request at 0000000000001c08
	IP: [<ffffffff8111c355>] __alloc_pages_nodemask+0xb5/0x870

and __alloc_pages_nodemask+0xb5 translates to a NULL pointer on
zonelist->_zonerefs.

The fix is to initialize q->node at the time of allocation so the correct
node is passed to the slab allocator later.

Since blk_init_allocated_queue_node() is no longer needed, merge it with
blk_init_allocated_queue().

[rientjes@google.com: changelog, initializing q->node]
Reported-by: Dave Young <dyoung@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Tested-by: Dave Young <dyoung@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2012-01-06 14:13:48 -08:00
Yasuaki Ishimatsu
cec3c159f6 cfq-iosched: fix cfq_cic_link() race confition
commit 5eb46851de upstream.

cfq_cic_link() has race condition. When some processes which shared ioc
issue I/O to same block device simultaneously, cfq_cic_link() returns -EEXIST
sometimes. The race condition might stop I/O by following steps:

step  1: Process A: Issue an I/O to /dev/sda
step  2: Process A: Get an ioc (iocA here) in get_io_context() which does not
		    linked with a cic for the device
step  3: Process A: Get a new cic for the device (cicA here) in
		    cfq_alloc_io_context()

step  4: Process B: Issue an I/O to /dev/sda
step  5: Process B: Get iocA in get_io_context() since process A and B share the
		    same ioc
step  6: Process B: Get a new cic for the device (cicB here) in
		    cfq_alloc_io_context() since iocA has not been linked with a
		    cic for the device yet

step  7: Process A: Link cicA to iocA in cfq_cic_link()
step  8: Process A: Dispatch I/O to driver and finish it

step  9: Process B: Try to link cicB to iocA in cfq_cic_link()
		    But it fails with showing "cfq: cic link failed!" kernel
		    message, since iocA has already linked with cicA at step 7.
step 10: Process B: Wait for finishig I/O in get_request_wait()
		    The function does not wake up, when there is no I/O to the
		    device.

When cfq_cic_link() returns -EEXIST, it means ioc has already linked with cic.
So when cfq_cic_link() return -EEXIST, retry cfq_cic_lookup().

Signed-off-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2012-01-06 14:13:46 -08:00
majianpeng
8f8a594251 cfq-iosched: free cic_index if blkio_alloc_blkg_stats fails
commit 2984ff38cc upstream.

If we fail allocating the blkpg stats, we free cfqd and cfgq.
But we need to free the IDA cfqd->cic_index as well.

Signed-off-by: majianpeng <majianpeng@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2012-01-06 14:13:46 -08:00
xbw
94768d3d9e modify the failure of SD-sdio in some case,due to print too much to invalid 2011-12-15 11:04:31 +08:00