23 Feb, 2017

1 commit

  • errata:
    When a read command returns less data than specified in the PRDs (for
    example, there are two PRDs for this command, but the device returns a
    number of bytes which is less than in the first PRD), the second PRD of
    this command is not read out of the PRD FIFO, causing the next command
    to use this PRD erroneously.

    workaround
    - forces sg_tablesize = 1
    - modified the sg_io function in block/scsi_ioctl.c to use a 64k buffer
    allocated with dma_alloc_coherent during the probe in ahci_imx
    - In order to fix the scsi/sata hang, when CD_ROM and HDD are
    accessed simultaneously after the workaround is applied.
    Do not go to sleep in scsi_eh_handler, when there is host failed.

    Signed-off-by: Richard Zhu

    Richard Zhu
     

07 Nov, 2015

1 commit

  • __GFP_WAIT was used to signal that the caller was in atomic context and
    could not sleep. Now it is possible to distinguish between true atomic
    context and callers that are not willing to sleep. The latter should
    clear __GFP_DIRECT_RECLAIM so kswapd will still wake. As clearing
    __GFP_WAIT behaves differently, there is a risk that people will clear the
    wrong flags. This patch renames __GFP_WAIT to __GFP_RECLAIM to clearly
    indicate what it does -- setting it allows all reclaim activity, clearing
    them prevents it.

    [akpm@linux-foundation.org: fix build]
    [akpm@linux-foundation.org: coding-style fixes]
    Signed-off-by: Mel Gorman
    Acked-by: Michal Hocko
    Acked-by: Vlastimil Babka
    Acked-by: Johannes Weiner
    Cc: Christoph Lameter
    Acked-by: David Rientjes
    Cc: Vitaly Wool
    Cc: Rik van Riel
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Mel Gorman
     

28 Jun, 2015

1 commit

  • Whenever blk_fill_sghdr_rq fails, its errno code is ignored and changed to
    EFAULT. This can cause very confusing errors:

    $ sg_persist -k /dev/sda
    persistent reservation in: pass through os error: Bad address

    The fix is trivial, just propagate the return value from
    blk_fill_sghdr_rq.

    Signed-off-by: Paolo Bonzini
    Acked-by: Jeff Moyer
    Signed-off-by: Jens Axboe

    Paolo Bonzini
     

12 Apr, 2015

1 commit


06 Feb, 2015

1 commit

  • Make use of a new interface provided by iov_iter, backed by
    scatter-gather list of iovec, instead of the old interface based on
    sg_iovec. Also use iov_iter_advance() instead of manual iteration.

    This commit should contain only literal replacements, without
    functional changes.

    Cc: Christoph Hellwig
    Cc: Jens Axboe
    Cc: Doug Gilbert
    Cc: "James E.J. Bottomley"
    Signed-off-by: Kent Overstreet
    [dpark: add more description in commit message]
    Signed-off-by: Dongsu Park
    [hch: fixed to do a deep clone of the iov_iter, and to properly use
    the iov_iter direction]
    Signed-off-by: Christoph Hellwig
    Reviewed-by: Ming Lei
    Signed-off-by: Jens Axboe

    Kent Overstreet
     

08 Dec, 2014

1 commit


25 Nov, 2014

1 commit


11 Nov, 2014

1 commit


23 Oct, 2014

1 commit

  • When sg_scsi_ioctl() fails to prepare request to submit in
    blk_rq_map_kern() we jump to a label where we just end up copying
    (luckily zeroed-out) kernel buffer to userspace instead of reporting
    error. Fix the problem by jumping to the right label.

    CC: Jens Axboe
    CC: linux-scsi@vger.kernel.org
    CC: stable@vger.kernel.org
    Coverity-id: 1226871
    Signed-off-by: Jan Kara

    Fixed up the, now unused, out label.

    Signed-off-by: Jens Axboe

    Jan Kara
     

11 Sep, 2014

1 commit


29 Aug, 2014

1 commit

  • The blk_get_request function may fail in low-memory conditions or during
    device removal (even if __GFP_WAIT is set). To distinguish between these
    errors, modify the blk_get_request call stack to return the appropriate
    ERR_PTR. Verify that all callers check the return status and consider
    IS_ERR instead of a simple NULL pointer check.

    For consistency, make a similar change to the blk_mq_alloc_request leg
    of blk_get_request. It may fail if the queue is dead, or the caller was
    unwilling to wait.

    Signed-off-by: Joe Lawrence
    Acked-by: Jiri Kosina [for pktdvd]
    Acked-by: Boaz Harrosh [for osd]
    Reviewed-by: Jeff Moyer
    Signed-off-by: Jens Axboe

    Joe Lawrence
     

27 Aug, 2014

1 commit

  • The blk-core dead queue checks introduce an error scenario to
    blk_get_request that returns NULL if the request queue has been
    shutdown. This affects the behavior for __GFP_WAIT callers, who should
    verify the return value before dereferencing.

    Signed-off-by: Joe Lawrence
    Acked-by: Jiri Kosina [for pktdvd]
    Reviewed-by: Jeff Moyer
    Signed-off-by: Jens Axboe

    Joe Lawrence
     

26 Aug, 2014

1 commit

  • Before commit 2cada584b200 ("block: cleanup error handling in sg_io"),
    we had ret = 0 before entering the last big if block of sg_io.

    Since 2cada584b200, ret = -EFAULT, which breaks hdparm:

    /dev/sda:
    setting Advanced Power Management level to 0xc8 (200)
    HDIO_DRIVE_CMD failed: Bad address
    APM_level = 128

    Signed-off-by: Sabrina Dubroca
    Fixes: 2cada584b200 ("block: cleanup error handling in sg_io")
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Sabrina Dubroca
     

23 Aug, 2014

1 commit

  • blk_rq_set_block_pc() memsets rq->cmd to 0, so it should come
    immediately after blk_get_request() to avoid overwriting the
    user-supplied CDB. Also check for failure to allocate rq.

    Fixes: f27b087b81b7 ("block: add blk_rq_set_block_pc()")
    Cc: # 3.16.x
    Signed-off-by: Tony Battersby
    Signed-off-by: Jens Axboe

    Tony Battersby
     

22 Aug, 2014

2 commits


02 Jul, 2014

2 commits

  • After the SG_IO ioctl was copied into the block layer and
    later into the bsg driver, subtle differences emerged.

    One difference is the way injected commands are queued through
    the block layer (i.e. this is not SCSI device queueing nor SATA
    NCQ). Summarizing:
    - SG_IO on block layer device: blk_exec*(at_head=false)
    - sg device SG_IO: at_head=true
    - bsg device SG_IO: at_head=true

    Some time ago Boaz Harrosh introduced a sg v4 flag called
    BSG_FLAG_Q_AT_TAIL to override the bsg driver default. A
    recent patch titled: "sg: add SG_FLAG_Q_AT_TAIL flag"
    allowed the sg driver default to be overridden. This patch
    allows a SG_IO ioctl sent to a block layer device to have
    its default overridden.

    ChangeLog:
    - introduce SG_FLAG_Q_AT_HEAD flag in sg.h to cause
    commands that are injected via a block layer
    device SG_IO ioctl to set at_head=true
    - make comments clearer about queueing in sg.h since the
    header is used both by the sg device and block layer
    device implementations of the SG_IO ioctl.
    - introduce BSG_FLAG_Q_AT_HEAD in bsg.h for compatibility
    (it does nothing) and update comments.

    Signed-off-by: Douglas Gilbert
    Reviewed-by: Christoph Hellwig
    Reviewed-by: Mike Christie
    Signed-off-by: Jens Axboe

    Douglas Gilbert
     
  • SG_GET_RESERVED_SIZE and SG_SET_RESERVED_SIZE ioctls access a reserved
    buffer in bytes as int type. The value needs to be capped at the request
    queue's max_sectors. But integer overflow is not correctly handled in
    the calculation when converting max_sectors from sectors to bytes.

    Signed-off-by: Akinobu Mita
    Cc: Jens Axboe
    Cc: "James E.J. Bottomley"
    Cc: Douglas Gilbert
    Cc: linux-scsi@vger.kernel.org
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Akinobu Mita
     

06 Jun, 2014

1 commit

  • With the optimizations around not clearing the full request at alloc
    time, we are leaving some of the needed init for REQ_TYPE_BLOCK_PC
    up to the user allocating the request.

    Add a blk_rq_set_block_pc() that sets the command type to
    REQ_TYPE_BLOCK_PC, and properly initializes the members associated
    with this type of request. Update callers to use this function instead
    of manipulating rq->cmd_type directly.

    Includes fixes from Christoph Hellwig for my half-assed
    attempt.

    Signed-off-by: Jens Axboe

    Jens Axboe
     

30 May, 2014

1 commit


22 Jan, 2014

1 commit


09 Nov, 2013

1 commit


08 May, 2013

1 commit

  • Faster kernel compiles by way of fewer unnecessary includes.

    [akpm@linux-foundation.org: fix fallout]
    [akpm@linux-foundation.org: fix build]
    Signed-off-by: Kent Overstreet
    Cc: Zach Brown
    Cc: Felipe Balbi
    Cc: Greg Kroah-Hartman
    Cc: Mark Fasheh
    Cc: Joel Becker
    Cc: Rusty Russell
    Cc: Jens Axboe
    Cc: Asai Thambi S P
    Cc: Selvan Mani
    Cc: Sam Bradshaw
    Cc: Jeff Moyer
    Cc: Al Viro
    Cc: Benjamin LaHaise
    Reviewed-by: "Theodore Ts'o"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kent Overstreet
     

15 Jun, 2012

1 commit

  • 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.

    CC: Paolo Bonzini
    CC: James Bottomley
    CC: linux-scsi@vger.kernel.org
    Acked-by: Paolo Bonzini
    Signed-off-by: Jan Kara
    Signed-off-by: Jens Axboe

    Jan Kara
     

15 Jan, 2012

2 commits

  • 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
    Cc: James Bottomley
    Signed-off-by: Paolo Bonzini
    [ Make it also print the command name when warning - Linus ]
    Signed-off-by: Linus Torvalds

    Paolo Bonzini
     
  • 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
    Cc: James Bottomley
    Signed-off-by: Paolo Bonzini
    Signed-off-by: Linus Torvalds

    Paolo Bonzini
     

19 Oct, 2011

1 commit

  • blk_get/put_queue() in scsi_cmd_ioctl() and throtl_get_tg() are
    completely bogus. The caller must have a reference to the queue on
    entry and taking an extra reference doesn't change anything.

    For scsi_cmd_ioctl(), the only effect is that it ends up checking
    QUEUE_FLAG_DEAD on entry; however, this is bogus as queue can die
    right after blk_get_queue(). Dead queue should be and is handled in
    request issue path (it's somewhat broken now but that's a separate
    problem and doesn't affect this one much).

    throtl_get_tg() incorrectly assumes that q is rcu freed. Also, it
    doesn't check return value of blk_get_queue(). If the queue is
    already dead, it ends up doing an extra put.

    Drop them.

    Signed-off-by: Tejun Heo
    Cc: Vivek Goyal
    Signed-off-by: Jens Axboe

    Tejun Heo
     

10 Nov, 2010

1 commit


04 Nov, 2009

1 commit

  • Quiet sparse noise about symbol's not being declared.

    Symbol blk_default_cmd_filter is only used locally and should be static.

    The function blk_scsi_ioctl_init() is a fs_initcall and should also be
    static.

    Signed-off-by: H Hartley Sweeten
    Cc: James Bottomley
    Signed-off-by: Jens Axboe

    H Hartley Sweeten
     

11 Jul, 2009

1 commit

  • Currently, blk_scsi_ioctl_init() is not called since it lacks
    an initcall marking. This causes the command table to be
    unitialized, hence somce commands are block when they should
    not have been.

    This fixes a regression introduced by commit
    018e0446890661504783f92388ecce7138c1566d

    Signed-off-by: FUJITA Tomonori
    Signed-off-by: Jens Axboe

    FUJITA Tomonori
     

01 Jul, 2009

1 commit

  • The initial patches to support this through sysfs export were broken
    and have been if 0'ed out in any release. So lets just kill the code
    and reclaim some space in struct request_queue, if anyone would later
    like to fixup the sysfs bits, the git history can easily restore
    the removed bits.

    Signed-off-by: Jens Axboe

    Jens Axboe
     

23 May, 2009

1 commit


11 May, 2009

1 commit

  • rq->data_len served two purposes - the length of data buffer on issue
    and the residual count on completion. This duality creates some
    headaches.

    First of all, block layer and low level drivers can't really determine
    what rq->data_len contains while a request is executing. It could be
    the total request length or it coulde be anything else one of the
    lower layers is using to keep track of residual count. This
    complicates things because blk_rq_bytes() and thus
    [__]blk_end_request_all() relies on rq->data_len for PC commands.
    Drivers which want to report residual count should first cache the
    total request length, update rq->data_len and then complete the
    request with the cached data length.

    Secondly, it makes requests default to reporting full residual count,
    ie. reporting that no data transfer occurred. The residual count is
    an exception not the norm; however, the driver should clear
    rq->data_len to zero to signify the normal cases while leaving it
    alone means no data transfer occurred at all. This reverse default
    behavior complicates code unnecessarily and renders block PC on some
    drivers (ide-tape/floppy) unuseable.

    This patch adds rq->resid_len which is used only for residual count.

    While at it, remove now unnecessasry blk_rq_bytes() caching in
    ide_pc_intr() as rq->data_len is not changed anymore.

    Boaz : spotted missing conversion in osd
    Sergei : spotted too early conversion to blk_rq_bytes() in ide-tape

    [ Impact: cleanup residual count handling, report 0 resid by default ]

    Signed-off-by: Tejun Heo
    Cc: James Bottomley
    Cc: Bartlomiej Zolnierkiewicz
    Cc: Borislav Petkov
    Cc: Sergei Shtylyov
    Cc: Mike Miller
    Cc: Eric Moore
    Cc: Alan Stern
    Cc: FUJITA Tomonori
    Cc: Doug Gilbert
    Cc: Mike Miller
    Cc: Eric Moore
    Cc: Darrick J. Wong
    Cc: Pete Zaitcev
    Cc: Boaz Harrosh
    Signed-off-by: Jens Axboe

    Tejun Heo
     

28 Apr, 2009

2 commits

  • blk_get_request() always returns properly zeroed requests. Don't set
    fields to zero/NULL unnecessarily.

    [ Impact: cleanup ]

    Signed-off-by: Tejun Heo
    Signed-off-by: Jens Axboe

    Tejun Heo
     
  • Now that all block request data transfer is done via bio, rq->data
    isn't used. Kill it.

    While at it, make the roles of rq->special and buffer clear.

    [ Impact: drop now unncessary field from struct request ]

    Signed-off-by: Tejun Heo
    Cc: Boaz Harrosh

    Tejun Heo
     

22 Apr, 2009

1 commit

  • Impact: fix SG_IO behavior such that it matches the documentation

    SG_IO howto says that if ->dxfer_len and sum of iovec disagress, the
    shorter one wins. However, the current implementation returns -EINVAL
    for such cases. Trim iovc if it's longer than ->dxfer_len.

    This patch uses iov_*() helpers which take struct iovec * by casting
    struct sg_iovec * to it. sg_iovec is always identical to iovec and
    this will be further cleaned up with later patches.

    Signed-off-by: Tejun Heo
    Signed-off-by: Jens Axboe

    Tejun Heo
     

15 Apr, 2009

1 commit


26 Mar, 2009

1 commit

  • Put a WARN_ON in __blk_put_request if it is about to
    leak bio(s). This is a serious bug that can happen in error
    handling code paths.

    For this to work I have fixed a couple of places in block/ where
    request->bio != NULL ownership was not honored. And a small cleanup
    at sg_io() while at it.

    Signed-off-by: Boaz Harrosh
    Signed-off-by: Jens Axboe

    Boaz Harrosh
     

29 Dec, 2008

1 commit


06 Dec, 2008

1 commit

  • There's no point in having too short SG_IO timeouts, since if the
    command does end up timing out, we'll end up through the reset sequence
    that is several seconds long in order to abort the command that timed
    out.

    As a result, shorter timeouts than a few seconds simply do not make
    sense, as the recovery would be longer than the timeout itself.

    Add a BLK_MIN_SG_TIMEOUT to match the existign BLK_DEFAULT_SG_TIMEOUT.

    Suggested-by: Alan Cox
    Acked-by: Tejun Heo
    Acked-by: Jens Axboe
    Cc: Jeff Garzik
    Signed-off-by: Linus Torvalds

    Linus Torvalds