1. 25 Apr, 2023 3 commits
  2. 19 Apr, 2023 2 commits
  3. 12 Apr, 2023 11 commits
  4. 03 Apr, 2023 24 commits
    • Martin K. Petersen's avatar
      Merge patch series "Fix shost command overloading issues" · dc70c961
      Martin K. Petersen authored
      John Garry <john.g.garry@oracle.com> says:
      
      It's easy to get scsi_debug to error on throughput testing when we have
      multiple shosts:
      
      $ lsscsi
      [7:0:0:0]       disk    Linux   scsi_debug      0191
      [0:0:0:0]       disk    Linux   scsi_debug      0191
      
      $ fio --filename=/dev/sda --filename=/dev/sdb --direct=1 --rw=read
      --bs=4k --iodepth=256 --runtime=60 --numjobs=40 --time_based --name=jpg
      --eta-newline=1 --readonly --ioengine=io_uring --hipri --exitall_on_error
      jpg: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring, iodepth=256
      ...
      fio-3.28
      Starting 40 processes
      [   27.521809] hrtimer: interrupt took 33067 ns
      [   27.904660] sd 7:0:0:0: [sdb] tag#171 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=0s
      [   27.904660] sd 0:0:0:0: [sda] tag#58 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=0s
      fio: io_u error [   27.904667] sd 0:0:0:0: [sda] tag#58 CDB: Read(10) 28 00 00 00 27 00 00 01 18 00
      on file /dev/sda[   27.904670] sd 0:0:0:0: [sda] tag#62 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=0s
      
      The issue is related to how the driver manages submit queues and tags. A
      single array of submit queues - sdebug_q_arr - with its own set of tags is
      shared among all shosts. As such, for occasions when we have more than one
      host it is possible to overload the submit queues and run out of tags.
      
      Another separate issue that we may reduce the shost submit queue depth,
      sdebug_max_queue, dynamically causing the shost to be overloaded. How many
      IOs which the shost may be sent is fixed at can_queue at init time, which
      is the same initial value for sdebug_max_queue. So reducing
      sdebug_max_queue means that the shost may be sent more IOs than it is
      configured to handle, causing overloading.
      
      This series removes the scsi_debug submit queue concept and uses
      pre-existing APIs to manage and examine tags, like scsi_block_requests()
      and blk_mq_tagset_busy_iter(). Using standard APIs makes the driver more
      maintainable and extensible in future.
      
      A restriction is also added to allow sdebug_max_queue only be modified when
      no shosts are present, i.e. we need to remove shosts, modify
      sdebug_max_queue, and then re-add the shosts.
      
      Link: https://lore.kernel.org/r/20230327074310.1862889-1-john.g.garry@oracle.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      dc70c961
    • John Garry's avatar
      scsi: scsi_debug: Drop sdebug_queue · f1437cd1
      John Garry authored
      It's easy to get scsi_debug to error on throughput testing when we have
      multiple shosts:
      
      $ lsscsi
      [7:0:0:0]       disk    Linux   scsi_debug      0191
      [0:0:0:0]       disk    Linux   scsi_debug      0191
      
      $ fio --filename=/dev/sda --filename=/dev/sdb --direct=1 --rw=read --bs=4k
      --iodepth=256 --runtime=60 --numjobs=40 --time_based --name=jpg
      --eta-newline=1 --readonly --ioengine=io_uring --hipri --exitall_on_error
      jpg: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring, iodepth=256
      ...
      fio-3.28
      Starting 40 processes
      [   27.521809] hrtimer: interrupt took 33067 ns
      [   27.904660] sd 7:0:0:0: [sdb] tag#171 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=0s
      [   27.904660] sd 0:0:0:0: [sda] tag#58 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=0s
      fio: io_u error [   27.904667] sd 0:0:0:0: [sda] tag#58 CDB: Read(10) 28 00 00 00 27 00 00 01 18 00
      on file /dev/sda[   27.904670] sd 0:0:0:0: [sda] tag#62 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=0s
      
      The issue is related to how the driver manages submit queues and tags. A
      single array of submit queues - sdebug_q_arr - with its own set of tags is
      shared among all shosts. As such, for occasions when we have more than one
      shost it is possible to overload the submit queues and run out of tags.
      
      The struct sdebug_queue is to manage tags and hold the associated
      queued command entry pointer (for that tag).
      
      Since the tagset iters are now used for functions like
      sdebug_blk_mq_poll(), there is no need to manage these queues. Indeed,
      blk-mq already provides what we need for managing tags and queues.
      
      Drop sdebug_queue and all its usage in the driver.
      Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20230327074310.1862889-12-john.g.garry@oracle.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      f1437cd1
    • John Garry's avatar
      scsi: scsi_debug: Only allow sdebug_max_queue be modified when no shosts · 57f7225a
      John Garry authored
      The shost->can_queue value is initially used to set per-HW queue context
      tag depth in the block layer. This ensures that the shost is not sent too
      many commands which it can deal with. However lowering sdebug_max_queue
      separately means that we can easily overload the shost, as in the following
      example:
      
      $ cat /sys/bus/pseudo/drivers/scsi_debug/max_queue
      192
      $ cat /sys/class/scsi_host/host0/can_queue
      192
      $ echo 100 > /sys/bus/pseudo/drivers/scsi_debug/max_queue
      $ cat /sys/class/scsi_host/host0/can_queue
      192
      $ fio --filename=/dev/sda --direct=1 --rw=read --bs=4k --iodepth=256
      --runtime=1200 --numjobs=10 --time_based --group_reporting
      --name=iops-test-job --eta-newline=1 --readonly    --ioengine=io_uring
      --hipri --exitall_on_error
      iops-test-job: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=io_uring, iodepth=256
      ...
      fio-3.28
      Starting 10 processes
      [  111.269885] scsi_io_completion_action: 400 callbacks suppressed
      [  111.269885] blk_print_req_error: 400 callbacks suppressed
      [  111.269889] I/O error, dev sda, sector 440 op 0x0:(READ) flags 0x1200000 phys_seg 1 prio class 2
      [  111.269892] sd 0:0:0:0: [sda] tag#132 FAILED Result: hostbyte=DID_ABORT driverbyte=DRIVER_OK cmd_age=0s
      [  111.269897] sd 0:0:0:0: [sda] tag#132 CDB: Read(10) 28 00 00 00 01 68 00 00 08 00
      [  111.277058] I/O error, dev sda, sector 360 op 0x0:(READ) flags 0x1200000 phys_seg 1 prio class 2
      
      [...]
      
      Ensure that this cannot happen by allowing sdebug_max_queue be modified
      only when we have no shosts. As such, any shost->can_queue value will match
      sdebug_max_queue, and sdebug_max_queue cannot be modified separately.
      
      Since retired_max_queue is no longer set, remove support.
      
      Continue to apply the restriction that sdebug_host_max_queue cannot be
      modified when sdebug_host_max_queue is set. Adding support for that would
      mean extra code, and no one has complained about this restriction
      previously.
      
      A command like the following may be used to remove a shost:
      echo -1 > /sys/bus/pseudo/drivers/scsi_debug/add_host
      Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20230327074310.1862889-11-john.g.garry@oracle.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      57f7225a
    • John Garry's avatar
      scsi: scsi_debug: Use scsi_host_busy() in delay_store() and ndelay_store() · 12f3eef0
      John Garry authored
      The functions to update ndelay and delay value first check whether we have
      any in-flight IO for any host. It does this by checking if any tag is used
      in the global submit queues.
      
      We can achieve the same by setting the host as blocked and then ensuring
      that we have no in-flight commands with scsi_host_busy().
      
      Note that scsi_host_busy() checks SCMD_STATE_INFLIGHT flag, which is only
      set per command after we ensure that the host is not blocked, i.e. we see
      more commands active after the check for scsi_host_busy() returns 0.
      Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20230327074310.1862889-10-john.g.garry@oracle.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      12f3eef0
    • John Garry's avatar
      scsi: scsi_debug: Use blk_mq_tagset_busy_iter() in stop_all_queued() · 9c559c9b
      John Garry authored
      Instead of iterating all deferred commands in the submission queue
      structures, use blk_mq_tagset_busy_iter(), which is a standard API for
      this.
      Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20230327074310.1862889-9-john.g.garry@oracle.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      9c559c9b
    • John Garry's avatar
      scsi: scsi_debug: Use blk_mq_tagset_busy_iter() in sdebug_blk_mq_poll() · 600d9ead
      John Garry authored
      Instead of iterating all deferred commands in the submission queue
      structures, use blk_mq_tagset_busy_iter(), which is a standard API for
      this.
      Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20230327074310.1862889-8-john.g.garry@oracle.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      600d9ead
    • John Garry's avatar
      scsi: scsi_debug: Dynamically allocate sdebug_queued_cmd · 1107c7b2
      John Garry authored
      Eventually we will drop the sdebug_queue struct as it is not really
      required, so start with making the sdebug_queued_cmd dynamically allocated
      for the lifetime of the scsi_cmnd in the driver.
      
      As an interim measure, make sdebug_queued_cmd.sd_dp a pointer to struct
      sdebug_defer. Also keep a value of the index allocated in
      sdebug_queued_cmd.qc_arr in struct sdebug_queued_cmd.
      
      To deal with an races in accessing the scsi cmnd allocated struct
      sdebug_queued_cmd, add a spinlock for the scsi command in its priv area.
      Races may be between scheduling a command for completion, aborting a
      command, and the command actually completing and freeing the struct
      sdebug_queued_cmd.
      
      [mkp: typo fix]
      Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20230327074310.1862889-7-john.g.garry@oracle.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      1107c7b2
    • John Garry's avatar
      scsi: scsi_debug: Use scsi_block_requests() to block queues · a0473bf3
      John Garry authored
      The feature to block queues is quite dubious, since it races with in-flight
      IO. Indeed, it seems unnecessary for block queues for any times we do so.
      
      Anyway, to keep the same behaviour, use standard SCSI API to stop IO being
      sent - scsi_{un}block_requests().
      Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20230327074310.1862889-6-john.g.garry@oracle.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      a0473bf3
    • John Garry's avatar
      scsi: scsi_debug: Protect block_unblock_all_queues() with mutex · 25b80b2c
      John Garry authored
      There is no reason that calls to block_unblock_all_queues() from different
      context can't race with one another, so protect with the
      sdebug_host_list_mutex. There's no need for a more fine-grained per shost
      locking here (and we don't have a per-host lock anyway).
      
      Also simplify some touched code in sdebug_change_qdepth().
      Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20230327074310.1862889-5-john.g.garry@oracle.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      25b80b2c
    • John Garry's avatar
      scsi: scsi_debug: Change shost list lock to a mutex · 0aaa3fad
      John Garry authored
      The shost list lock, sdebug_host_list_lock, is a spinlock. We would only
      lock in non-atomic context in this driver, so use a mutex instead, which is
      friendlier if we need to schedule when iterating.
      Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20230327074310.1862889-4-john.g.garry@oracle.comAcked-by: default avatarDouglas Gilbert <dgilbert@interlog.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      0aaa3fad
    • John Garry's avatar
      scsi: scsi_debug: Don't iter all shosts in clear_luns_changed_on_target() · 00f9d622
      John Garry authored
      In clear_luns_changed_on_target(), we iter all devices for all shosts to
      conditionally clear the SDEBUG_UA_LUNS_CHANGED flag in the per-device
      uas_bm.
      
      One condition to see whether we clear the flag is to test whether the host
      for the device under consideration is the same as the matching device's
      (devip) host. This check will only ever pass for devices for the same
      shost, so only iter the devices for the matching device shost.
      
      We can now drop the spinlock'ing of the sdebug_host_list_lock in the same
      function. This will allow us to use a mutex instead of the spinlock for the
      global shost lock, as clear_luns_changed_on_target() could be called in
      non-blocking context, in scsi_debug_queuecommand() -> make_ua() ->
      clear_luns_changed_on_target() (which is why required a spinlock).
      Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20230327074310.1862889-3-john.g.garry@oracle.comAcked-by: default avatarDouglas Gilbert <dgilbert@interlog.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      00f9d622
    • John Garry's avatar
      scsi: scsi_debug: Fix check for sdev queue full · 6500d204
      John Garry authored
      There is a report that the blktests scsi/004 test for "TASK SET FULL" (TSF)
      now fails.
      
      The condition upon we should issue this TSF is when the sdev queue is
      full. The check for a full queue has an off-by-1 error. Previously we would
      increment the number of requests in the queue after testing if the queue
      would be full, i.e. test if one less than full. Since we now use
      scsi_device_busy() to count the number of requests in the queue, this would
      already account for the current request, so fix the test for queue full
      accordingly.
      
      Fixes: 151f0ec9 ("scsi: scsi_debug: Drop sdebug_dev_info.num_in_q")
      Reported-by: default avatarkernel test robot <oliver.sang@intel.com>
      Link: https://lore.kernel.org/oe-lkp/202303201334.18b30edc-oliver.sang@intel.comSigned-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20230327074310.1862889-2-john.g.garry@oracle.comAcked-by: default avatarDouglas Gilbert <dgilbert@interlog.com>
      Tested-by: default avatarYi Zhang <yi.zhang@redhat.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      6500d204
    • Martin K. Petersen's avatar
      Merge patch series "scsi: hisi_sas: Some misc changes" · 60b3f355
      Martin K. Petersen authored
      chenxiang <chenxiang66@hisilicon.com> says:
      
      This series contain some fixes including:
      
       - Grab sas_dev lock when traversing sas_dev list to avoid NULL
         pointer
      
       - Handle NCQ error when IPTT is valid
      
       - Ensure all enabled PHYs up during controller reset
      
       - Exit suspend state when usage count of runtime PM is greater than 0
      
      https://lore.kernel.org/r/1679283265-115066-1-git-send-email-chenxiang66@hisilicon.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      60b3f355
    • Yihang Li's avatar
      scsi: hisi_sas: Exit suspend state when usage count is greater than 0 · e368d38c
      Yihang Li authored
      When the current status of the host controller is suspended, enabling a
      local PHY just after disabling all local PHYs in expander environment, a
      hang as follows occurs:
      
      [  486.854655] INFO: task kworker/u256:1:899 blocked for more than 120 seconds.
      [  486.862207]       Not tainted 6.1.0-rc4+ #1
      [  486.870545] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
      [  486.878893] task:kworker/u256:1  state:D stack:0     pid:899   ppid:2      flags:0x00000008
      [  486.887745] Workqueue: 0000:74:02.0_disco_q sas_discover_domain [libsas]
      [  486.894704] Call trace:
      [  486.897400]  __switch_to+0xf0/0x170
      [  486.901146]  __schedule+0x3e4/0x1160
      [  486.904970]  schedule+0x64/0x104
      [  486.908442]  rpm_resume+0x158/0x6a0
      [  486.912163]  __pm_runtime_resume+0x5c/0x84
      [  486.916489]  smp_execute_task_sg+0x1f8/0x264 [libsas]
      [  486.921773]  sas_discover_expander.part.0+0xbc/0x720 [libsas]
      [  486.927750]  sas_discover_root_expander+0x90/0x154 [libsas]
      [  486.933552]  sas_discover_domain+0x444/0x6d0 [libsas]
      [  486.938826]  process_one_work+0x1e0/0x450
      [  486.943057]  worker_thread+0x150/0x44c
      [  486.947015]  kthread+0x114/0x120
      [  486.950447]  ret_from_fork+0x10/0x20
      [  486.954292] INFO: task kworker/u256:2:1780 blocked for more than 120 seconds.
      [  486.961637]       Not tainted 6.1.0-rc4+ #1
      [  486.966087] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
      [  486.974356] task:kworker/u256:2  state:D stack:0     pid:1780  ppid:2      flags:0x00000208
      [  486.983141] Workqueue: 0000:74:02.0_event_q sas_port_event_worker [libsas]
      [  486.990252] Call trace:
      [  486.992930]  __switch_to+0xf0/0x170
      [  486.996645]  __schedule+0x3e4/0x1160
      [  487.000439]  schedule+0x64/0x104
      [  487.003886]  schedule_timeout+0x17c/0x1c0
      [  487.008102]  wait_for_completion+0x7c/0x160
      [  487.012488]  __flush_workqueue+0x104/0x3e0
      [  487.016782]  sas_porte_bytes_dmaed+0x414/0x454 [libsas]
      [  487.022203]  sas_port_event_worker+0x38/0x60 [libsas]
      [  487.027449]  process_one_work+0x1e0/0x450
      [  487.031645]  worker_thread+0x150/0x44c
      [  487.035594]  kthread+0x114/0x120
      [  487.039017]  ret_from_fork+0x10/0x20
      [  487.042828] INFO: task bash:11488 blocked for more than 121 seconds.
      [  487.049366]       Not tainted 6.1.0-rc4+ #1
      [  487.053746] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
      [  487.061953] task:bash            state:D stack:0     pid:11488 ppid:10977  flags:0x00000204
      [  487.070698] Call trace:
      [  487.073355]  __switch_to+0xf0/0x170
      [  487.077050]  __schedule+0x3e4/0x1160
      [  487.080833]  schedule+0x64/0x104
      [  487.084270]  schedule_timeout+0x17c/0x1c0
      [  487.088474]  wait_for_completion+0x7c/0x160
      [  487.092851]  __flush_workqueue+0x104/0x3e0
      [  487.097137]  drain_workqueue+0xb8/0x160
      [  487.101159]  __sas_drain_work+0x50/0x90 [libsas]
      [  487.105963]  sas_suspend_ha+0x64/0xd4 [libsas]
      [  487.110590]  suspend_v3_hw+0x198/0x1e8 [hisi_sas_v3_hw]
      [  487.115989]  pci_pm_runtime_suspend+0x5c/0x1d0
      [  487.120606]  __rpm_callback+0x50/0x150
      [  487.124535]  rpm_callback+0x74/0x80
      [  487.128204]  rpm_suspend+0x110/0x640
      [  487.131955]  rpm_idle+0x1f4/0x2d0
      [  487.135447]  __pm_runtime_idle+0x58/0x94
      [  487.139538]  queue_phy_enable+0xcc/0xf0 [libsas]
      [  487.144330]  store_sas_phy_enable+0x74/0x100
      [  487.148770]  dev_attr_store+0x20/0x34
      [  487.152606]  sysfs_kf_write+0x4c/0x5c
      [  487.156437]  kernfs_fop_write_iter+0x120/0x1b0
      [  487.161049]  vfs_write+0x2d0/0x36c
      [  487.164625]  ksys_write+0x70/0x100
      [  487.168194]  __arm64_sys_write+0x24/0x30
      [  487.172280]  invoke_syscall+0x50/0x120
      [  487.176186]  el0_svc_common.constprop.0+0x168/0x190
      [  487.181214]  do_el0_svc+0x34/0xc0
      [  487.184680]  el0_svc+0x2c/0xb4
      [  487.187879]  el0t_64_sync_handler+0xb8/0xbc
      [  487.192205]  el0t_64_sync+0x19c/0x1a0
      
      We find that when all local PHYs are disabled, all the devices will be
      removed, the ->runtime_suspend() callback suspend_v3_hw() directly execute
      since the controller usage count drop to 0. On the other side, the first
      local PHY is enabled through the sysfs interface, and ensures that function
      phy_up_v3_hw() is completed due to suspend_v3_hw()->
      interrupt_disable_v3_hw(). In the expander scenario,
      sas_discover_root_expander() is executed in event work
      DISCE_DISCOVER_DOMAIN, which will increases the controller usage count and
      carry out a resume and sends SMPIO, it cannot be completed because the
      runtime PM status of the controller is RPM_SUSPENDING. At the same time,
      the ->runtime_suspend() callback suspend_v3_hw() also cannot complete the
      process because of drain libsas event queue in sas_suspend_ha(), so hung
      occurs.
      
                 (thread 1)                   |        (thread 2)
      ...                                     |
      rpm_idle()                              |
       ...                                    |
       __update_runtime_status(RPM_SUSPENDING)|
        ...                                   | ...
        suspend_v3_hw()                       | smp_execute_task_sg()
         ...                                  |  ...
         interrupt_disable_v3_hw()            |  pm_runtime_get_sync()
                                              |   ...
         ...                                  |   rpm_resume() //RPM_SUSPENDING
                                              |
          __sas_drain_work()                  |
      
      To fix this, check if the current runtime PM status of the controller
      allows to be suspended continue after interrupt_disable_v3_hw(), return
      immediately if not.
      Signed-off-by: default avatarYihang Li <liyihang9@huawei.com>
      Signed-off-by: default avatarXiang Chen <chenxiang66@hislicon.com>
      Link: https://lore.kernel.org/r/1679283265-115066-5-git-send-email-chenxiang66@hisilicon.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      e368d38c
    • Yihang Li's avatar
      scsi: hisi_sas: Ensure all enabled PHYs up during controller reset · 89954f02
      Yihang Li authored
      For the controller reset operation, hisi_sas_phy_enable() is executed for
      each enabled local PHY, and refresh the port id of each device based on the
      latest hisi_sas_phy->port_id after 1 second sleep, hisi_sas_phy->port_id is
      configured in the interrupt processing function phy_up_v3_hw(). However, in
      directly attached scenario, for some SATA disks the amount of time for
      phyup more than 1s sometimes. In this case, incorrect port id may be
      configured in hisi_sas_refresh_port_id().  As a result, all the internal
      IOs fail and disk lost, such as follows:
      
      [10717.666565] hisi_sas_v3_hw 0000:74:02.0: phyup: phy1 link_rate=10(sata)
      [10718.826813] hisi_sas_v3_hw 0000:74:02.0: erroneous completion iptt=63
      task=00000000c1ab1c2b dev id=200 addr=5000000000000501 CQ hdr: 0x8000007 0xc8003f 0x0
      0x0 Error info: 0x0 0x0 0x0 0x0
      [10718.843428] sas: TMF task open reject failed  5000000000000501
      [10718.849242] hisi_sas_v3_hw 0000:74:02.0: erroneous completion iptt=64
      task=00000000c1ab1c2b dev id=200 addr=5000000000000501 CQ hdr: 0x8000007 0xc80040 0x0
      0x0 Error info: 0x0 0x0 0x0 0x0
      [10718.865856] sas: TMF task open reject failed  5000000000000501
      [10718.871670] hisi_sas_v3_hw 0000:74:02.0: erroneous completion iptt=65
      task=00000000c1ab1c2b dev id=200 addr=5000000000000501 CQ hdr: 0x8000007 0xc80041 0x0
      0x0 Error info: 0x0 0x0 0x0 0x0
      [10718.888284] sas: TMF task open reject failed  5000000000000501
      [10718.894093] sas: executing TMF for 5000000000000501 failed after 3 attempts!
      [10718.901114] hisi_sas_v3_hw 0000:74:02.0: ata disk 5000000000000501 reset failed
      [10718.908410] hisi_sas_v3_hw 0000:74:02.0: controller reset complete
      .....
      [10773.298633] ata216.00: revalidation failed (errno=-19)
      [10773.303753] ata216.00: disable device
      
      So the time of waitting for PHYs up is 1s which may be not enough. To solve
      the issue, running hisi_sas_phy_enable() in parallel through async
      operations and use wait_for_completion_timeout() to wait for PHYs come up
      instead of directly sleep for 1 second.
      Signed-off-by: default avatarYihang Li <liyihang9@huawei.com>
      Signed-off-by: default avatarXiang Chen <chenxiang66@hisilicon.com>
      Link: https://lore.kernel.org/r/1679283265-115066-4-git-send-email-chenxiang66@hisilicon.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      89954f02
    • Xingui Yang's avatar
      scsi: hisi_sas: Handle NCQ error when IPTT is valid · bb544224
      Xingui Yang authored
      If an NCQ error occurs when the IPTT is valid and slot->abort flag is set
      in completion path, sas_task_abort() will be called to abort only one NCQ
      command now, and the host would be set to SHOST_RECOVERY state. But this
      may not kick-off EH Immediately until other outstanding QCs timeouts. As a
      result, the host may remain in the SHOST_RECOVERY state for up to 30
      seconds, such as follows:
      
      [7972317.645234] hisi_sas_v3_hw 0000:74:04.0: erroneous completion iptt=3264 task=00000000466116b8 dev id=2 sas_addr=0x5000000000000502 CQ hdr: 0x1883 0x20cc0 0x40000 0x20420000 Error info: 0x0 0x0 0x200000 0x0
      [7972341.508264] sas: Enter sas_scsi_recover_host busy: 32 failed: 32
      [7972341.984731] sas: --- Exit sas_scsi_recover_host: busy: 0 failed: 32 tries: 1
      
      All NCQ commands that are in the queue should be aborted when an NCQ error
      occurs in this scenario.
      
      Fixes: 05d91b55 ("scsi: hisi_sas: Directly trigger SCSI error handling for completion errors")
      Signed-off-by: default avatarXingui Yang <yangxingui@huawei.com>
      Signed-off-by: default avatarXiang Chen <chenxiang66@hisilicon.com>
      Link: https://lore.kernel.org/r/1679283265-115066-3-git-send-email-chenxiang66@hisilicon.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      bb544224
    • Xingui Yang's avatar
      scsi: hisi_sas: Grab sas_dev lock when traversing the members of sas_dev.list · 71fb36b5
      Xingui Yang authored
      When freeing slots in function slot_complete_v3_hw(), it is possible that
      sas_dev.list is being traversed elsewhere, and it may trigger a NULL
      pointer exception, such as follows:
      
      ==>cq thread                    ==>scsi_eh_6
      
                                      ==>scsi_error_handler()
      				  ==>sas_eh_handle_sas_errors()
      				    ==>sas_scsi_find_task()
      				      ==>lldd_abort_task()
      ==>slot_complete_v3_hw()              ==>hisi_sas_abort_task()
        ==>hisi_sas_slot_task_free()	        ==>dereg_device_v3_hw()
          ==>list_del_init()        		  ==>list_for_each_entry_safe()
      
      [ 7165.434918] sas: Enter sas_scsi_recover_host busy: 32 failed: 32
      [ 7165.434926] sas: trying to find task 0x00000000769b5ba5
      [ 7165.434927] sas: sas_scsi_find_task: aborting task 0x00000000769b5ba5
      [ 7165.434940] hisi_sas_v3_hw 0000:b4:02.0: slot complete: task(00000000769b5ba5) aborted
      [ 7165.434964] hisi_sas_v3_hw 0000:b4:02.0: slot complete: task(00000000c9f7aa07) ignored
      [ 7165.434965] hisi_sas_v3_hw 0000:b4:02.0: slot complete: task(00000000e2a1cf01) ignored
      [ 7165.434968] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
      [ 7165.434972] hisi_sas_v3_hw 0000:b4:02.0: slot complete: task(0000000022d52d93) ignored
      [ 7165.434975] hisi_sas_v3_hw 0000:b4:02.0: slot complete: task(0000000066a7516c) ignored
      [ 7165.434976] Mem abort info:
      [ 7165.434982]   ESR = 0x96000004
      [ 7165.434991]   Exception class = DABT (current EL), IL = 32 bits
      [ 7165.434992]   SET = 0, FnV = 0
      [ 7165.434993]   EA = 0, S1PTW = 0
      [ 7165.434994] Data abort info:
      [ 7165.434994]   ISV = 0, ISS = 0x00000004
      [ 7165.434995]   CM = 0, WnR = 0
      [ 7165.434997] user pgtable: 4k pages, 48-bit VAs, pgdp = 00000000f29543f2
      [ 7165.434998] [0000000000000000] pgd=0000000000000000
      [ 7165.435003] Internal error: Oops: 96000004 [#1] SMP
      [ 7165.439863] Process scsi_eh_6 (pid: 4109, stack limit = 0x00000000c43818d5)
      [ 7165.468862] pstate: 00c00009 (nzcv daif +PAN +UAO)
      [ 7165.473637] pc : dereg_device_v3_hw+0x68/0xa8 [hisi_sas_v3_hw]
      [ 7165.479443] lr : dereg_device_v3_hw+0x2c/0xa8 [hisi_sas_v3_hw]
      [ 7165.485247] sp : ffff00001d623bc0
      [ 7165.488546] x29: ffff00001d623bc0 x28: ffffa027d03b9508
      [ 7165.493835] x27: ffff80278ed50af0 x26: ffffa027dd31e0a8
      [ 7165.499123] x25: ffffa027d9b27f88 x24: ffffa027d9b209f8
      [ 7165.504411] x23: ffffa027c45b0d60 x22: ffff80278ec07c00
      [ 7165.509700] x21: 0000000000000008 x20: ffffa027d9b209f8
      [ 7165.514988] x19: ffffa027d9b27f88 x18: ffffffffffffffff
      [ 7165.520276] x17: 0000000000000000 x16: 0000000000000000
      [ 7165.525564] x15: ffff0000091d9708 x14: ffff0000093b7dc8
      [ 7165.530852] x13: ffff0000093b7a23 x12: 6e7265746e692067
      [ 7165.536140] x11: 0000000000000000 x10: 0000000000000bb0
      [ 7165.541429] x9 : ffff00001d6238f0 x8 : ffffa027d877af00
      [ 7165.546718] x7 : ffffa027d6329600 x6 : ffff7e809f58ca00
      [ 7165.552006] x5 : 0000000000001f8a x4 : 000000000000088e
      [ 7165.557295] x3 : ffffa027d9b27fa8 x2 : 0000000000000000
      [ 7165.562583] x1 : 0000000000000000 x0 : 000000003000188e
      [ 7165.567872] Call trace:
      [ 7165.570309]  dereg_device_v3_hw+0x68/0xa8 [hisi_sas_v3_hw]
      [ 7165.575775]  hisi_sas_abort_task+0x248/0x358 [hisi_sas_main]
      [ 7165.581415]  sas_eh_handle_sas_errors+0x258/0x8e0 [libsas]
      [ 7165.586876]  sas_scsi_recover_host+0x134/0x458 [libsas]
      [ 7165.592082]  scsi_error_handler+0xb4/0x488
      [ 7165.596163]  kthread+0x134/0x138
      [ 7165.599380]  ret_from_fork+0x10/0x18
      [ 7165.602940] Code: d5033e9f b9000040 aa0103e2 eb03003f (f9400021)
      [ 7165.609004] kernel fault(0x1) notification starting on CPU 75
      [ 7165.700728] ---[ end trace fc042cbbea224efc ]---
      [ 7165.705326] Kernel panic - not syncing: Fatal exception
      
      To fix the issue, grab sas_dev lock when traversing the members of
      sas_dev.list in dereg_device_v3_hw() and hisi_sas_release_tasks() to avoid
      concurrency of adding and deleting member. When function
      hisi_sas_release_tasks() calls hisi_sas_do_release_task() to free slot, the
      lock cannot be grabbed again in hisi_sas_slot_task_free(), then a bool
      parameter need_lock is added.
      Signed-off-by: default avatarXingui Yang <yangxingui@huawei.com>
      Signed-off-by: default avatarXiang Chen <chenxiang66@hisilicon.com>
      Link: https://lore.kernel.org/r/1679283265-115066-2-git-send-email-chenxiang66@hisilicon.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      71fb36b5
    • Tom Rix's avatar
      scsi: qla4xxx: Remove unused 'count' variable · 3d2efb54
      Tom Rix authored
      clang with W=1 reports:
      
      drivers/scsi/qla4xxx/ql4_isr.c:475:11: error: variable
        'count' set but not used [-Werror,-Wunused-but-set-variable]
              uint32_t count = 0;
                       ^
      This variable is not used so remove it.
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Link: https://lore.kernel.org/r/20230331175757.1860780-1-trix@redhat.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      3d2efb54
    • Tom Rix's avatar
      scsi: snic: Remove unused 'xfer_len' variable · 4e0966a4
      Tom Rix authored
      clang with W=1 reports:
      
      drivers/scsi/snic/snic_scsi.c:490:6: error: variable
        'xfer_len' set but not used [-Werror,-Wunused-but-set-variable]
              u64 xfer_len = 0;
                  ^
      This variable is not used so remove it.
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Link: https://lore.kernel.org/r/20230328001647.1778448-1-trix@redhat.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      4e0966a4
    • Tom Rix's avatar
      scsi: qedf: Remove unused 'num_handled' variable · 7866e03b
      Tom Rix authored
      clang with W=1 reports:
      
      drivers/scsi/qedf/qedf_main.c:2227:6: error: variable
        'num_handled' set but not used [-Werror,-Wunused-but-set-variable]
              int num_handled = 0;
                  ^
      This variable is not used so remove it.
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Link: https://lore.kernel.org/r/20230330203444.1842425-1-trix@redhat.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      7866e03b
    • Adrian Hunter's avatar
    • Tom Rix's avatar
      scsi: scsi_transport_fc: Remove unused 'desc_cnt' variable · e324dd00
      Tom Rix authored
      clang with W=1 reports:
      
      drivers/scsi/scsi_transport_fc.c:908:6: error: variable
        'desc_cnt' set but not used [-Werror,-Wunused-but-set-variable]
              u32 desc_cnt = 0, bytes_remain;
                  ^
      This variable is not used so remove it.
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Link: https://lore.kernel.org/r/20230326003222.1343671-1-trix@redhat.comReviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
      Reviewed-by: default avatarBenjamin Block <bblock@linux.ibm.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      e324dd00
    • Enze Li's avatar
      scsi: sr: Simplify the sr_open() function · ca62009e
      Enze Li authored
      Simplify the sr_open() by removing the goto label as the function only
      returns one error code.
      Signed-off-by: default avatarEnze Li <lienze@kylinos.cn>
      Link: https://lore.kernel.org/r/20230327030237.3407253-1-lienze@kylinos.cnReviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
      Reviewed-by: default avatarBenjamin Block <bblock@linux.ibm.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      ca62009e
    • Tom Rix's avatar
      scsi: target: core: Remove unused 'prod_len' variable · aa4d7812
      Tom Rix authored
      clang with W=1 reports:
      
      drivers/target/target_core_spc.c:229:6: error: variable
        'prod_len' set but not used [-Werror,-Wunused-but-set-variable]
              u32 prod_len;
                  ^
      This variable is not used so remove it.
      Signed-off-by: default avatarTom Rix <trix@redhat.com>
      Link: https://lore.kernel.org/r/20230329132421.1809362-1-trix@redhat.comReviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      aa4d7812