03 Jan, 2020

1 commit

  • bsg_ioctl() calls into scsi_cmd_ioctl() for a couple of generic commands
    and relies on fs/compat_ioctl.c to handle it correctly in compat mode.

    Adding a private compat_ioctl() handler avoids that round-trip and lets
    us get rid of the generic emulation once this is done.

    Note that bsg implements an SG_IO command that is different from the
    other drivers and does not need emulation.

    Reviewed-by: Ben Hutchings
    Signed-off-by: Arnd Bergmann

    Arnd Bergmann
     

01 May, 2019

1 commit


06 Feb, 2019

2 commits


21 Dec, 2018

1 commit

  • Besides the OSD command set that never got traction, the only SCSI
    command using bidirectional buffers is XDWRITEREAD in the 10 and 32 byte
    variants, which is extremely esoteric and has been removed from the spec
    again as of SBC4r15. It probably doesn't make sense to keep the support
    code around just for that, so start deprecating the support.

    Signed-off-by: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     

16 Nov, 2018

1 commit

  • Various spots check for q->mq_ops being non-NULL, but provide
    a helper to do this instead.

    Where the ->mq_ops != NULL check is redundant, remove it.

    Since mq == rq-based now that legacy is gone, get rid of the
    queue_is_rq_based() and just use queue_is_mq() everywhere.

    Reviewed-by: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Jens Axboe
     

28 Aug, 2018

1 commit

  • Currently, variable ref_count within the bsg_device struct is of
    type atomic_t. For variables being used as reference counters,
    the refcount API should be used instead of atomic. The newer
    refcount API works to prevent counter overflows and use-after-free
    bugs. So, move this varable from the atomic API to refcount,
    potentially avoiding the issues mentioned.

    Signed-off-by: John Pittman
    Signed-off-by: Jens Axboe

    John Pittman
     

06 Aug, 2018

1 commit


12 Jul, 2018

1 commit

  • The code poses a security risk due to user memory access in ->release
    and had an API that can't be used reliably. As far as we know it was
    never used for real, but if that turns out wrong we'll have to revert
    this commit and come up with a band aid.

    Jann Horn did look software archives for users of this interface,
    and the only users found were example code in sg3_utils, and optional
    support in an optional module of the tgt user space iscsi target,
    which looks like a proof of concept extension of the /dev/sg
    read/write support.

    Tony Battersby chimes in that the code is basically unsafe to use in
    general:

    The read/write interface on /dev/bsg is impossible to use safely
    because the list of completed commands is per-device (bd->done_list)
    rather than per-fd like it is with /dev/sg. So if program A and
    program B are both using the write/read interface on the same bsg
    device, then their command responses will get mixed up, and program
    A will read() some command results from program B and vice versa.
    So no, I don't use read/write on /dev/bsg. From a security standpoint,
    it should definitely be fixed or removed.

    Signed-off-by: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     

11 Jul, 2018

1 commit

  • Fix a regression introduced in Linux kernel 4.17 where sending a SCSI
    command that does not transfer data (such as TEST UNIT READY) via
    /dev/bsg/* results in EINVAL.

    Fixes: 17cb960f29c2 ("bsg: split handling of SCSI CDBs vs transport requeues")
    Cc: # 4.17+
    Reviewed-by: Christoph Hellwig
    Signed-off-by: Tony Battersby
    Signed-off-by: Jens Axboe

    Tony Battersby
     

15 Jun, 2018

1 commit

  • The existing implementation allows races between bsg_unregister and
    bsg_open paths. bsg_unregister and request_queue cleanup and deletion
    may start and complete right after bsg_get_device (in bsg_open path)
    retrieves bsg_class_device and releases the mutex. Then bsg_open path
    touches freed memory of bsg_class_device and request_queue.

    One possible fix is to hold the mutex all the way through bsg_get_device
    instead of releasing it after bsg_class_device retrieval.

    Reviewed-by: Christoph Hellwig
    Signed-Off-By: Anatoliy Glagolev
    Signed-off-by: Jens Axboe

    Anatoliy Glagolev
     

30 May, 2018

1 commit

  • Bsg holding a reference to the parent device may result in a crash if a
    bsg file handle is closed after the parent device driver has unloaded.

    Holding a reference is not really needed: the parent device must exist
    between bsg_register_queue and bsg_unregister_queue. Before the device
    goes away the caller does blk_cleanup_queue so that all in-flight
    requests to the device are gone and all new requests cannot pass beyond
    the queue. The queue itself is a refcounted object and it will stay
    alive with a bsg file.

    Based on analysis, previous patch and changelog from Anatoliy Glagolev.

    Reported-by: Anatoliy Glagolev
    Reviewed-by: James E.J. Bottomley
    Signed-off-by: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     

14 May, 2018

1 commit


14 Mar, 2018

1 commit

  • The current BSG design tries to shoe-horn the transport-specific
    passthrough commands into the overall framework for SCSI passthrough
    requests. This has a couple problems:

    - each passthrough queue has to set the QUEUE_FLAG_SCSI_PASSTHROUGH flag
    despite not dealing with SCSI commands at all. Because of that these
    queues could also incorrectly accept SCSI commands from in-kernel
    users or through the legacy SCSI_IOCTL_SEND_COMMAND ioctl.
    - the real SCSI bsg queues also incorrectly accept bsg requests of the
    BSG_SUB_PROTOCOL_SCSI_TRANSPORT type
    - the bsg transport code is almost unredable because it tries to reuse
    different SCSI concepts for its own purpose.

    This patch instead adds a new bsg_ops structure to handle the two cases
    differently, and thus solves all of the above problems. Another side
    effect is that the bsg-lib queues also don't need to embedd a
    struct scsi_request anymore.

    Signed-off-by: Christoph Hellwig
    Reviewed-by: Hannes Reinecke
    Reviewed-by: Johannes Thumshirn
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     

12 Feb, 2018

1 commit

  • This is the mindless scripted replacement of kernel use of POLL*
    variables as described by Al, done by this script:

    for V in IN OUT PRI ERR RDNORM RDBAND WRNORM WRBAND HUP RDHUP NVAL MSG; do
    L=`git grep -l -w POLL$V | grep -v '^t' | grep -v /um/ | grep -v '^sa' | grep -v '/poll.h$'|grep -v '^D'`
    for f in $L; do sed -i "-es/^\([^\"]*\)\(\\)/\\1E\\2/" $f; done
    done

    with de-mangling cleanups yet to come.

    NOTE! On almost all architectures, the EPOLL* constants have the same
    values as the POLL* constants do. But they keyword here is "almost".
    For various bad reasons they aren't the same, and epoll() doesn't
    actually work quite correctly in some cases due to this on Sparc et al.

    The next patch from Al will sort out the final differences, and we
    should be all done.

    Scripted-by: Al Viro
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

31 Jan, 2018

1 commit

  • Pull poll annotations from Al Viro:
    "This introduces a __bitwise type for POLL### bitmap, and propagates
    the annotations through the tree. Most of that stuff is as simple as
    'make ->poll() instances return __poll_t and do the same to local
    variables used to hold the future return value'.

    Some of the obvious brainos found in process are fixed (e.g. POLLIN
    misspelled as POLL_IN). At that point the amount of sparse warnings is
    low and most of them are for genuine bugs - e.g. ->poll() instance
    deciding to return -EINVAL instead of a bitmap. I hadn't touched those
    in this series - it's large enough as it is.

    Another problem it has caught was eventpoll() ABI mess; select.c and
    eventpoll.c assumed that corresponding POLL### and EPOLL### were
    equal. That's true for some, but not all of them - EPOLL### are
    arch-independent, but POLL### are not.

    The last commit in this series separates userland POLL### values from
    the (now arch-independent) kernel-side ones, converting between them
    in the few places where they are copied to/from userland. AFAICS, this
    is the least disruptive fix preserving poll(2) ABI and making epoll()
    work on all architectures.

    As it is, it's simply broken on sparc - try to give it EPOLLWRNORM and
    it will trigger only on what would've triggered EPOLLWRBAND on other
    architectures. EPOLLWRBAND and EPOLLRDHUP, OTOH, are never triggered
    at all on sparc. With this patch they should work consistently on all
    architectures"

    * 'misc.poll' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (37 commits)
    make kernel-side POLL... arch-independent
    eventpoll: no need to mask the result of epi_item_poll() again
    eventpoll: constify struct epoll_event pointers
    debugging printk in sg_poll() uses %x to print POLL... bitmap
    annotate poll(2) guts
    9p: untangle ->poll() mess
    ->si_band gets POLL... bitmap stored into a user-visible long field
    ring_buffer_poll_wait() return value used as return value of ->poll()
    the rest of drivers/*: annotate ->poll() instances
    media: annotate ->poll() instances
    fs: annotate ->poll() instances
    ipc, kernel, mm: annotate ->poll() instances
    net: annotate ->poll() instances
    apparmor: annotate ->poll() instances
    tomoyo: annotate ->poll() instances
    sound: annotate ->poll() instances
    acpi: annotate ->poll() instances
    crypto: annotate ->poll() instances
    block: annotate ->poll() instances
    x86: annotate ->poll() instances
    ...

    Linus Torvalds
     

25 Jan, 2018

1 commit


28 Nov, 2017

1 commit


11 Nov, 2017

1 commit


30 Aug, 2017

1 commit


21 Jun, 2017

1 commit

  • Instead of explicitly calling scsi_req_init() after blk_get_request(),
    call that function from inside blk_get_request(). Add an
    .initialize_rq_fn() callback function to the block drivers that need
    it. Merge the IDE .init_rq_fn() function into .initialize_rq_fn()
    because it is too small to keep it as a separate function. Keep the
    scsi_req_init() call in ide_prep_sense() because it follows a
    blk_rq_init() call.

    References: commit 82ed4db499b8 ("block: split scsi_request out of struct request")
    Signed-off-by: Bart Van Assche
    Cc: Christoph Hellwig
    Cc: Hannes Reinecke
    Cc: Omar Sandoval
    Cc: Nicholas Bellinger
    Signed-off-by: Jens Axboe

    Bart Van Assche
     

09 Jun, 2017

1 commit

  • 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: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     

02 Jun, 2017

1 commit

  • Since BSG only supports request queues for which struct scsi_request
    is the first member of their private request data, refuse to register
    block layer queues for which struct scsi_request is not the first
    member of their private data.

    References: commit bd1599d931ca ("scsi_transport_sas: fix BSG ioctl memory corruption")
    References: commit 82ed4db499b8 ("block: split scsi_request out of struct request")
    Signed-off-by: Bart Van Assche
    Reviewed-by: Hannes Reinecke
    Reviewed-by: Christoph Hellwig
    Cc: Omar Sandoval
    Signed-off-by: Jens Axboe

    Bart Van Assche
     

02 May, 2017

1 commit

  • Pull uaccess unification updates from Al Viro:
    "This is the uaccess unification pile. It's _not_ the end of uaccess
    work, but the next batch of that will go into the next cycle. This one
    mostly takes copy_from_user() and friends out of arch/* and gets the
    zero-padding behaviour in sync for all architectures.

    Dealing with the nocache/writethrough mess is for the next cycle;
    fortunately, that's x86-only. Same for cleanups in iov_iter.c (I am
    sold on access_ok() in there, BTW; just not in this pile), same for
    reducing __copy_... callsites, strn*... stuff, etc. - there will be a
    pile about as large as this one in the next merge window.

    This one sat in -next for weeks. -3KLoC"

    * 'work.uaccess' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (96 commits)
    HAVE_ARCH_HARDENED_USERCOPY is unconditional now
    CONFIG_ARCH_HAS_RAW_COPY_USER is unconditional now
    m32r: switch to RAW_COPY_USER
    hexagon: switch to RAW_COPY_USER
    microblaze: switch to RAW_COPY_USER
    get rid of padding, switch to RAW_COPY_USER
    ia64: get rid of copy_in_user()
    ia64: sanitize __access_ok()
    ia64: get rid of 'segment' argument of __do_{get,put}_user()
    ia64: get rid of 'segment' argument of __{get,put}_user_check()
    ia64: add extable.h
    powerpc: get rid of zeroing, switch to RAW_COPY_USER
    esas2r: don't open-code memdup_user()
    alpha: fix stack smashing in old_adjtimex(2)
    don't open-code kernel_setsockopt()
    mips: switch to RAW_COPY_USER
    mips: get rid of tail-zeroing in primitives
    mips: make copy_from_user() zero tail explicitly
    mips: clean and reorder the forest of macros...
    mips: consolidate __invoke_... wrappers
    ...

    Linus Torvalds
     

21 Apr, 2017

1 commit

  • This passes on the scsi_cmnd result field to users of passthrough
    requests. Currently we abuse req->errors for this purpose, but that
    field will go away in its current form.

    Note that the old IDE code abuses the errors field in very creative
    ways and stores all kinds of different values in it. I didn't dare
    to touch this magic, so the abuses are brought forward 1:1.

    Signed-off-by: Christoph Hellwig
    Reviewed-by: Martin K. Petersen
    Reviewed-by: Bart Van Assche
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     

29 Mar, 2017

1 commit


28 Feb, 2017

1 commit

  • Now that %z is standartised in C99 there is no reason to support %Z.
    Unlike %L it doesn't even make format strings smaller.

    Use BUILD_BUG_ON in a couple ATM drivers.

    In case anyone didn't notice lib/vsprintf.o is about half of SLUB which
    is in my opinion is quite an achievement. Hopefully this patch inspires
    someone else to trim vsprintf.c more.

    Link: http://lkml.kernel.org/r/20170103230126.GA30170@avx2
    Signed-off-by: Alexey Dobriyan
    Cc: Andy Shevchenko
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     

01 Feb, 2017

1 commit

  • 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: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     

28 Jan, 2017

1 commit

  • And require all drivers that want to support BLOCK_PC to allocate it
    as the first thing of their private data. To support this the legacy
    IDE and BSG code is switched to set cmd_size on their queues to let
    the block layer allocate the additional space.

    Signed-off-by: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     

23 Dec, 2016

1 commit


03 Nov, 2016

1 commit


05 Feb, 2015

1 commit

  • It took me a few tries to figure out what this code did; lets rewrite
    it into a more regular form.

    The thing that makes this one 'special' is the BSG_F_BLOCK flag, if
    that is not set we're not supposed/allowed to block and should spin
    wait for completion.

    The (new) io_wait_event() will never see a false condition in case of
    the spinning and we will therefore not block.

    Cc: Linus Torvalds
    Signed-off-by: Peter Zijlstra (Intel)
    Signed-off-by: Jens Axboe

    Peter Zijlstra
     

29 Aug, 2014

2 commits

  • Dan writes:

    block/bsg.c:327 bsg_map_hdr() error: 'next_rq' dereferencing possible
    ERR_PTR().

    Fix this by setting next_rq to NULL, for the case where it can be
    != NULL but an error pointer.

    Reported-by: Dan Carpenter
    Signed-off-by: Jens Axboe

    Jens Axboe
     
  • 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
     

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
     

17 Apr, 2014

1 commit

  • bsg currently checks ->request_fn to check whether a queue can
    handle struct request. But with blk-mq, we don't have a request_fn
    yet are request based. Add a queue_is_rq_based() helper and use
    that in bsg, I'm guessing this is not the last place we need to
    update for this. Besides, it better explains what is being
    checked.

    Signed-off-by: Jens Axboe

    Jens Axboe
     

28 Feb, 2013

2 commits

  • I'm not sure why, but the hlist for each entry iterators were conceived

    list_for_each_entry(pos, head, member)

    The hlist ones were greedy and wanted an extra parameter:

    hlist_for_each_entry(tpos, pos, head, member)

    Why did they need an extra pos parameter? I'm not quite sure. Not only
    they don't really need it, it also prevents the iterator from looking
    exactly like the list iterator, which is unfortunate.

    Besides the semantic patch, there was some manual work required:

    - Fix up the actual hlist iterators in linux/list.h
    - Fix up the declaration of other iterators based on the hlist ones.
    - A very small amount of places were using the 'node' parameter, this
    was modified to use 'obj->member' instead.
    - Coccinelle didn't handle the hlist_for_each_entry_safe iterator
    properly, so those had to be fixed up manually.

    The semantic patch which is mostly the work of Peter Senna Tschudin is here:

    @@
    iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;

    type T;
    expression a,c,d,e;
    identifier b;
    statement S;
    @@

    -T b;

    [akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
    [akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
    [akpm@linux-foundation.org: checkpatch fixes]
    [akpm@linux-foundation.org: fix warnings]
    [akpm@linux-foudnation.org: redo intrusive kvm changes]
    Tested-by: Peter Senna Tschudin
    Acked-by: Paul E. McKenney
    Signed-off-by: Sasha Levin
    Cc: Wu Fengguang
    Cc: Marcelo Tosatti
    Cc: Gleb Natapov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sasha Levin
     
  • Convert to the much saner new idr interface. Both bsg and genhd
    protect idr w/ mutex making preloading unnecessary.

    Signed-off-by: Tejun Heo
    Acked-by: Jens Axboe
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tejun Heo
     

09 Feb, 2012

1 commit

  • 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:
    [] warn_slowpath_common+0x6a/0x7f
    [] ? sysfs_hash_and_remove+0x2b/0x77
    [] warn_slowpath_fmt+0x2b/0x2f
    [] sysfs_hash_and_remove+0x2b/0x77
    [] sysfs_remove_link+0x20/0x23
    [] bsg_unregister_queue+0x40/0x6d
    [] __scsi_remove_device+0x31/0x9d
    [] scsi_forget_host+0x41/0x52
    [] scsi_remove_host+0x71/0xe0
    [] quiesce_and_remove_host+0x51/0x83 [usb_storage]
    [] usb_stor_disconnect+0x18/0x22 [usb_storage]
    [] usb_unbind_interface+0x4e/0x109
    [] __device_release_driver+0x6b/0xa6
    [] device_release_driver+0x17/0x22
    [] bus_remove_device+0xd6/0xe6
    [] device_del+0xf2/0x137
    [] usb_disable_device+0x94/0x1a0

    Signed-off-by: Stanislaw Gruszka
    Signed-off-by: Jens Axboe

    Stanislaw Gruszka
     

16 Jan, 2012

1 commit

  • * 'for-3.3/core' of git://git.kernel.dk/linux-block: (37 commits)
    Revert "block: recursive merge requests"
    block: Stop using macro stubs for the bio data integrity calls
    blockdev: convert some macros to static inlines
    fs: remove unneeded plug in mpage_readpages()
    block: Add BLKROTATIONAL ioctl
    block: Introduce blk_set_stacking_limits function
    block: remove WARN_ON_ONCE() in exit_io_context()
    block: an exiting task should be allowed to create io_context
    block: ioc_cgroup_changed() needs to be exported
    block: recursive merge requests
    block, cfq: fix empty queue crash caused by request merge
    block, cfq: move icq creation and rq->elv.icq association to block core
    block, cfq: restructure io_cq creation path for io_context interface cleanup
    block, cfq: move io_cq exit/release to blk-ioc.c
    block, cfq: move icq cache management to block core
    block, cfq: move io_cq lookup to blk-ioc.c
    block, cfq: move cfqd->icq_list to request_queue and add request->elv.icq
    block, cfq: reorganize cfq_io_context into generic and cfq specific parts
    block: remove elevator_queue->ops
    block: reorder elevator switch sequence
    ...

    Fix up conflicts in:
    - block/blk-cgroup.c
    Switch from can_attach_task to can_attach
    - block/cfq-iosched.c
    conflict with now removed cic index changes (we now use q->id instead)

    Linus Torvalds