1. 10 6月, 2020 1 次提交
  2. 08 5月, 2020 1 次提交
  3. 22 2月, 2020 1 次提交
  4. 13 2月, 2020 1 次提交
  5. 20 11月, 2019 2 次提交
    • B
      scsi: target: core: Release SPC-2 reservations when closing a session · 80647a89
      Bart Van Assche 提交于
      The SCSI specs require releasing SPC-2 reservations when a session is
      closed. Make sure that the target core does this.
      
      Running the libiscsi tests triggers the KASAN complaint shown below.  This
      patch fixes that use-after-free.
      
      BUG: KASAN: use-after-free in target_check_reservation+0x171/0x980 [target_core_mod]
      Read of size 8 at addr ffff88802ecd1878 by task iscsi_trx/17200
      
      CPU: 0 PID: 17200 Comm: iscsi_trx Not tainted 5.4.0-rc1-dbg+ #1
      Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
      Call Trace:
       dump_stack+0x8a/0xd6
       print_address_description.constprop.0+0x40/0x60
       __kasan_report.cold+0x1b/0x34
       kasan_report+0x16/0x20
       __asan_load8+0x58/0x90
       target_check_reservation+0x171/0x980 [target_core_mod]
       __target_execute_cmd+0xb1/0xf0 [target_core_mod]
       target_execute_cmd+0x22d/0x4d0 [target_core_mod]
       transport_generic_new_cmd+0x31f/0x5b0 [target_core_mod]
       transport_handle_cdb_direct+0x6f/0x90 [target_core_mod]
       iscsit_execute_cmd+0x381/0x3f0 [iscsi_target_mod]
       iscsit_sequence_cmd+0x13b/0x1f0 [iscsi_target_mod]
       iscsit_process_scsi_cmd+0x4c/0x130 [iscsi_target_mod]
       iscsit_get_rx_pdu+0x8e8/0x15f0 [iscsi_target_mod]
       iscsi_target_rx_thread+0x105/0x1b0 [iscsi_target_mod]
       kthread+0x1bc/0x210
       ret_from_fork+0x24/0x30
      
      Allocated by task 1079:
       save_stack+0x23/0x90
       __kasan_kmalloc.constprop.0+0xcf/0xe0
       kasan_slab_alloc+0x12/0x20
       kmem_cache_alloc+0xfe/0x3a0
       transport_alloc_session+0x29/0x80 [target_core_mod]
       iscsi_target_login_thread+0xceb/0x1920 [iscsi_target_mod]
       kthread+0x1bc/0x210
       ret_from_fork+0x24/0x30
      
      Freed by task 17193:
       save_stack+0x23/0x90
       __kasan_slab_free+0x13a/0x190
       kasan_slab_free+0x12/0x20
       kmem_cache_free+0xc8/0x3e0
       transport_free_session+0x179/0x2f0 [target_core_mod]
       transport_deregister_session+0x121/0x170 [target_core_mod]
       iscsit_close_session+0x12c/0x350 [iscsi_target_mod]
       iscsit_logout_post_handler+0x136/0x380 [iscsi_target_mod]
       iscsit_response_queue+0x8fa/0xc00 [iscsi_target_mod]
       iscsi_target_tx_thread+0x28e/0x390 [iscsi_target_mod]
       kthread+0x1bc/0x210
       ret_from_fork+0x24/0x30
      
      The buggy address belongs to the object at ffff88802ecd1860
       which belongs to the cache se_sess_cache of size 352
      The buggy address is located 24 bytes inside of
       352-byte region [ffff88802ecd1860, ffff88802ecd19c0)
      The buggy address belongs to the page:
      page:ffffea0000bb3400 refcount:1 mapcount:0 mapping:ffff8880bef2ed00 index:0x0 compound_mapcount: 0
      flags: 0x1000000000010200(slab|head)
      raw: 1000000000010200 dead000000000100 dead000000000122 ffff8880bef2ed00
      raw: 0000000000000000 0000000080270027 00000001ffffffff 0000000000000000
      page dumped because: kasan: bad access detected
      
      Memory state around the buggy address:
       ffff88802ecd1700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
       ffff88802ecd1780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      >ffff88802ecd1800: fb fb fb fb fc fc fc fc fc fc fc fc fb fb fb fb
                                                                      ^
       ffff88802ecd1880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
       ffff88802ecd1900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      
      Cc: Mike Christie <mchristi@redhat.com>
      Link: https://lore.kernel.org/r/20191113220508.198257-2-bvanassche@acm.orgReviewed-by: NRoman Bolshakov <r.bolshakov@yadro.com>
      Signed-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      80647a89
    • B
      scsi: target: core: Document target_cmd_size_check() · 11bf1d14
      Bart Van Assche 提交于
      Since it is nontrivial to derive the meaning of the size argument from the
      code, add a documentation header above target_cmd_size_check().
      
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Hannes Reinecke <hare@suse.de>
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Link: https://lore.kernel.org/r/20191107215458.64242-1-bvanassche@acm.orgSigned-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      11bf1d14
  6. 31 5月, 2019 1 次提交
  7. 05 2月, 2019 3 次提交
  8. 19 12月, 2018 1 次提交
  9. 08 12月, 2018 9 次提交
    • B
      scsi: target/core: Reduce the amount of code executed with a spinlock held · 3ad98002
      Bart Van Assche 提交于
      Due to the "make ABORT and LUN RESET handling synchronous" patch, cmd->work
      is only modified from the regular command execution path and no longer
      asynchronously by the code that executes task management functions. Since
      the regular command execution code is sequential per command, no locking is
      required to manipulate cmd->work. Hence stop protecting cmd->work
      manipulations with locking.
      
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Disseldorp <ddiss@suse.de>
      Cc: Hannes Reinecke <hare@suse.de>
      Signed-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      3ad98002
    • B
      scsi: target/core: Make ABORT and LUN RESET handling synchronous · 2c9fa49e
      Bart Van Assche 提交于
      Instead of invoking target driver callback functions from the context that
      handles an abort or LUN RESET task management function, only set the abort
      flag from that context and perform the actual abort handling from the
      context of the regular command processing flow. This approach has the
      advantage that the task management code becomes much easier to read and to
      verify since the number of potential race conditions against the command
      processing flow is strongly reduced.
      
      This patch has been tested by running the following two shell commands
      concurrently for about ten minutes for both the iSCSI and the SRP target
      drivers ($dev is an initiator device node connected with storage provided
      by the target driver under test):
      
       * fio with data verification enabled on a filesystem mounted on top of
         $dev.
      
       * while true; do sg_reset -d $dev; echo -n .; sleep .1; done
      
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Disseldorp <ddiss@suse.de>
      Cc: Hannes Reinecke <hare@suse.de>
      Signed-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      2c9fa49e
    • B
      scsi: target/core: Fix TAS handling for aborted commands · aaa00cc9
      Bart Van Assche 提交于
      The TASK ABORTED STATUS (TAS) bit is defined as follows in SAM:
      "TASK_ABORTED: this status shall be returned if a command is aborted by a
      command or task management function on another I_T nexus and the control
      mode page TAS bit is set to one". TAS handling is spread over the target
      core and the iSCSI target driver. If a LUN RESET is received, the target
      core will send the TASK_ABORTED response for all commands for which such a
      response has to be sent. If an ABORT TASK is received, only the iSCSI
      target driver will send the TASK_ABORTED response for the commands for
      which that response has to be sent.  That is a bug since all target drivers
      have to honor the TAS bit. Fix this by moving the code that handles TAS
      from the iSCSI target driver into the target core. Additionally, if a
      command has been aborted, instead of sending the TASK_ABORTED status from
      the context that processes the SCSI command send it from the context of the
      ABORT TMF.  The core_tmr_abort_task() change in this patch causes the
      CMD_T_TAS flag to be set if a TASK_ABORTED status has to be sent back to
      the initiator that submitted the command. If that flag has been set
      transport_cmd_finish_abort() will send the TASK_ABORTED response.
      
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Disseldorp <ddiss@suse.de>
      Cc: Hannes Reinecke <hare@suse.de>
      Signed-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      aaa00cc9
    • B
      scsi: target/core: Simplify the code for aborting SCSI commands · fbbd4923
      Bart Van Assche 提交于
      Instead of allowing the code that aborts a SCSI command to finish before
      all iSCSI data frames have been received, make that code wait until all
      iSCSI data frames have been received. Introduce a new member variable in
      the target driver template to communicate that information from the iSCSI
      target driver to the target core. This change allows to leave out the check
      whether or not it is already safe to send the TASK_ABORTED reply from
      transport_send_task_abort().
      
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Disseldorp <ddiss@suse.de>
      Cc: Hannes Reinecke <hare@suse.de>
      Signed-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      fbbd4923
    • B
      scsi: target/core: Make it possible to wait from more than one context for command completion · a014c364
      Bart Van Assche 提交于
      This patch does not change any functionality but makes the patch that makes
      TMF handling synchronous easier to read.
      
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Disseldorp <ddiss@suse.de>
      Cc: Hannes Reinecke <hare@suse.de>
      Signed-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      a014c364
    • B
      scsi: target/core: Use system workqueues for TMF · db5b21a2
      Bart Van Assche 提交于
      A quote from SAM-5: "The order in which task management requests are
      processed is not specified by the SCSI architecture model.  The SCSI
      architecture model does not require in-order delivery of such task
      management requests or processing by the task manager in the order
      received. To guarantee the processing order of task management requests
      referencing sent to a specific logical unit, an application client should
      not have more than one such task management request pending to that logical
      unit." This means that it is safe to use the system workqueues instead of
      tmr_wq for processing TMFs. An intended side effect of this patch is that
      it enables concurrent processing of TMFs.
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: David Disseldorp <ddiss@suse.de>
      Cc: Hannes Reinecke <hare@suse.de>
      Signed-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      db5b21a2
    • B
      scsi: target/core: Make sure that target_wait_for_sess_cmds() waits long enough · ad669505
      Bart Van Assche 提交于
      A session must only be released after all code that accesses the session
      structure has finished. Make sure that this is the case by introducing a
      new command counter per session that is only decremented after the
      .release_cmd() callback has finished. This patch fixes the following crash:
      
      BUG: KASAN: use-after-free in do_raw_spin_lock+0x1c/0x130
      Read of size 4 at addr ffff8801534b16e4 by task rmdir/14805
      CPU: 16 PID: 14805 Comm: rmdir Not tainted 4.18.0-rc2-dbg+ #5
      Call Trace:
      dump_stack+0xa4/0xf5
      print_address_description+0x6f/0x270
      kasan_report+0x241/0x360
      __asan_load4+0x78/0x80
      do_raw_spin_lock+0x1c/0x130
      _raw_spin_lock_irqsave+0x52/0x60
      srpt_set_ch_state+0x27/0x70 [ib_srpt]
      srpt_disconnect_ch+0x1b/0xc0 [ib_srpt]
      srpt_close_session+0xa8/0x260 [ib_srpt]
      target_shutdown_sessions+0x170/0x180 [target_core_mod]
      core_tpg_del_initiator_node_acl+0xf3/0x200 [target_core_mod]
      target_fabric_nacl_base_release+0x25/0x30 [target_core_mod]
      config_item_release+0x9c/0x110 [configfs]
      config_item_put+0x26/0x30 [configfs]
      configfs_rmdir+0x3b8/0x510 [configfs]
      vfs_rmdir+0xb3/0x1e0
      do_rmdir+0x262/0x2c0
      do_syscall_64+0x77/0x230
      entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Disseldorp <ddiss@suse.de>
      Cc: Hannes Reinecke <hare@suse.de>
      Signed-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      ad669505
    • B
      scsi: target/core: Simplify transport_clear_lun_ref() · a95be384
      Bart Van Assche 提交于
      Since transport_clear_lun_ref() already waits until the percpu-refcount
      .release() method is called, it is not necessary to wait first until
      percpu_ref_kill_and_confirm() has finished transitioning the refcount into
      atomic mode. Remove the code that waits for percpu_ref_kill_and_confirm()
      to complete and also the completion object that is used by that code.  This
      patch does not change the behavior of the SCSI target code.
      
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Disseldorp <ddiss@suse.de>
      Cc: Hannes Reinecke <hare@suse.de>
      Signed-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      a95be384
    • B
      scsi: target/core: Use kvcalloc() instead of open-coding it · 5d6cd9fe
      Bart Van Assche 提交于
      This patch does not change any functionality. Note: the code that frees
      sess_cmd_map already uses kvfree() so that code does not need to be
      modified.
      Reviewed-by: NDavid Disseldorp <ddiss@suse.de>
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Hannes Reinecke <hare@suse.de>
      Signed-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      5d6cd9fe
  10. 29 11月, 2018 1 次提交
  11. 06 11月, 2018 1 次提交
  12. 24 10月, 2018 1 次提交
  13. 16 10月, 2018 3 次提交
    • B
      scsi: target/core: Always call transport_complete_callback() upon failure · aa73237d
      Bart Van Assche 提交于
      COMPARE AND WRITE command execution starts with a call of
      sbc_compare_and_write(). That function locks the caw_sem member in the
      backend device data structure and submits a read request to the backend
      driver. Upon successful completion of the read compare_and_write_callback()
      gets called. That last function compares the data that has been read. If it
      matches transport_complete_callback is set to compare_and_write_post and a
      write request is submitted. compare_and_write_post() submits a write request
      to the backend driver.
      
      XDWRITEREAD command execution starts with sbc_execute_rw() submitting a
      read to the backend device. Upon successful completion of the read the
      xdreadwrite_callback() gets called. That function xors the data that has
      been read with the data in the data-out buffer and stores the result in
      the data-in buffer.
      
      Call transport_complete_callback() not only if COMPARE AND WRITE fails but
      also if XDWRITEREAD fails. This makes the code more systematic. Make sure
      that the callback functions handle (cmd, false, NULL) argument triples fine.
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Reviewed-by: NNicholas Bellinger <nab@linux-iscsi.org>
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: Hannes Reinecke <hare@suse.de>
      Signed-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      aa73237d
    • B
      scsi: target/core: Fix spelling in two source code comments · 4240d448
      Bart Van Assche 提交于
      Change one occurrence of "aleady" into "already" and one occurrence of
      "is" into "if".
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      Cc: Nicholas Bellinger <nab@linux-iscsi.org>
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: Hannes Reinecke <hare@suse.de>
      Signed-off-by: NBart Van Assche <bvanassche@acm.org>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      4240d448
    • N
      scsi: target: Fix target_wait_for_sess_cmds breakage with active signals · 38fe73cc
      Nicholas Bellinger 提交于
      With the addition of commit 00d909a1 ("scsi: target: Make the session
      shutdown code also wait for commands that are being aborted") in v4.19-rc, it
      incorrectly assumes no signals will be pending for task_struct executing the
      normal session shutdown and I/O quiesce code-path.
      
      For example, iscsi-target and iser-target issue SIGINT to all kthreads as part
      of session shutdown.  This has been the behaviour since day one.
      
      As-is when signals are pending with se_cmds active in se_sess->sess_cmd_list,
      wait_event_interruptible_lock_irq_timeout() returns a negative number and
      immediately kills the machine because of the do while (ret <= 0) loop that was
      added in commit 00d909a1 to spin while backend I/O is taking any amount of
      extended time (say 30 seconds) to complete.
      
      Here's what it looks like in action with debug plus delayed backend I/O
      completion:
      
      [ 4951.909951] se_sess: 000000003e7e08fa before target_wait_for_sess_cmds
      [ 4951.914600] target_wait_for_sess_cmds: signal_pending: 1
      [ 4951.918015] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 0
      [ 4951.921639] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 1
      [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 2
      [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 3
      [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 4
      [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 5
      [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 6
      [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 7
      [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 8
      [ 4951.921944] wait_event_interruptible_lock_irq_timeout ret: -512 signal_pending: 1 loop count: 9
      
      ... followed by the usual RCU CPU stalls and deadlock.
      
      There was never a case pre commit 00d909a1 where
      wait_for_complete(&se_cmd->cmd_wait_comp) was able to be interrupted, so to
      address this for v4.19+ moving forward go ahead and use
      wait_event_lock_irq_timeout() instead so new code works with all fabric
      drivers.
      
      Also for commit 00d909a1, fix a minor regression in
      target_release_cmd_kref() to only wake_up the new se_sess->cmd_list_wq only
      when shutdown has actually been triggered via se_sess->sess_tearing_down.
      
      Fixes: 00d909a1 ("scsi: target: Make the session shutdown code also wait for commands that are being aborted")
      Cc: <stable@vger.kernel.org> # v4.19+
      Cc: Bart Van Assche <bvanassche@acm.org>
      Cc: Mike Christie <mchristi@redhat.com>
      Cc: Hannes Reinecke <hare@suse.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Sagi Grimberg <sagi@grimberg.me>
      Cc: Bryant G. Ly <bryantly@linux.vnet.ibm.com>
      Tested-by: NNicholas Bellinger <nab@linux-iscsi.org>
      Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
      Reviewed-by: NBryant G. Ly <bly@catalogicsoftware.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      38fe73cc
  14. 03 8月, 2018 4 次提交
  15. 03 7月, 2018 10 次提交