WSL2-Linux-Kernel/drivers/s390/scsi
Steffen Maier 781a7dabea scsi: zfcp: Fix missing auto port scan and thus missing target ports
commit 4da8c5f768 upstream.

Case (1):
  The only waiter on wka_port->completion_wq is zfcp_fc_wka_port_get()
  trying to open a WKA port. As such it should only be woken up by WKA port
  *open* responses, not by WKA port close responses.

Case (2):
  A close WKA port response coming in just after having sent a new open WKA
  port request and before blocking for the open response with wait_event()
  in zfcp_fc_wka_port_get() erroneously renders the wait_event a NOP
  because the close handler overwrites wka_port->status. Hence the
  wait_event condition is erroneously true and it does not enter blocking
  state.

With non-negligible probability, the following time space sequence happens
depending on timing without this fix:

user process        ERP thread zfcp work queue tasklet system work queue
============        ========== =============== ======= =================
$ echo 1 > online
zfcp_ccw_set_online
zfcp_ccw_activate
zfcp_erp_adapter_reopen
msleep scan backoff zfcp_erp_strategy
|                   ...
|                   zfcp_erp_action_cleanup
|                   ...
|                   queue delayed scan_work
|                   queue ns_up_work
|                              ns_up_work:
|                              zfcp_fc_wka_port_get
|                               open wka request
|                                              open response
|                              GSPN FC-GS
|                              RSPN FC-GS [NPIV-only]
|                              zfcp_fc_wka_port_put
|                               (--wka->refcount==0)
|                               sched delayed wka->work
|
~~~Case (1)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
zfcp_erp_wait
flush scan_work
|                                                      wka->work:
|                                                      wka->status=CLOSING
|                                                      close wka request
|                              scan_work:
|                              zfcp_fc_wka_port_get
|                               (wka->status==CLOSING)
|                               wka->status=OPENING
|                               open wka request
|                               wait_event
|                               |              close response
|                               |              wka->status=OFFLINE
|                               |              wake_up /*WRONG*/
~~~Case (2)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|                                                      wka->work:
|                                                      wka->status=CLOSING
|                                                      close wka request
zfcp_erp_wait
flush scan_work
|                              scan_work:
|                              zfcp_fc_wka_port_get
|                               (wka->status==CLOSING)
|                               wka->status=OPENING
|                               open wka request
|                                              close response
|                                              wka->status=OFFLINE
|                                              wake_up /*WRONG&NOP*/
|                               wait_event /*NOP*/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|                               (wka->status!=ONLINE)
|                               return -EIO
|                              return early
                                               open response
                                               wka->status=ONLINE
                                               wake_up /*NOP*/

So we erroneously end up with no automatic port scan. This is a big problem
when it happens during boot. The timing is influenced by v3.19 commit
18f87a67e6 ("zfcp: auto port scan resiliency").

Fix it by fully mutually excluding zfcp_fc_wka_port_get() and
zfcp_fc_wka_port_offline(). For that to work, we make the latter block
until we got the response for a close WKA port. In order not to penalize
the system workqueue, we move wka_port->work to our own adapter workqueue.
Note that before v2.6.30 commit 828bc1212a ("[SCSI] zfcp: Set WKA-port to
offline on adapter deactivation"), zfcp did block in
zfcp_fc_wka_port_offline() as well, but with a different condition.

While at it, make non-functional cleanups to improve code reading in
zfcp_fc_wka_port_get(). If we cannot send the WKA port open request, don't
rely on the subsequent wait_event condition to immediately let this case
pass without blocking. Also don't want to rely on the additional condition
handling the refcount to be skipped just to finally return with -EIO.

Link: https://lore.kernel.org/r/20220729162529.1620730-1-maier@linux.ibm.com
Fixes: 5ab944f97e ("[SCSI] zfcp: attach and release SAN nameserver port on demand")
Cc: <stable@vger.kernel.org> #v2.6.28+
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-08-17 14:24:16 +02:00
..
Makefile scsi: zfcp: diagnostics buffer caching and use for exchange port data 2019-10-28 22:16:14 -04:00
zfcp_aux.c scsi: zfcp: Clean up sysfs code for SFP diagnostics 2021-04-15 22:19:40 -04:00
zfcp_ccw.c s390/zfcp: remove pm support from zfcp driver 2020-12-02 18:19:23 +01:00
zfcp_dbf.c scsi: zfcp: fix kernel doc comments 2021-09-08 14:23:31 +02:00
zfcp_dbf.h scsi: zfcp: trace FC Endpoint Security of FCP devices and connections 2020-03-17 13:12:40 -04:00
zfcp_def.h scsi: zfcp: Fix indentation coding style issue 2021-04-15 22:19:39 -04:00
zfcp_diag.c scsi: zfcp: Clean up sysfs code for SFP diagnostics 2021-04-15 22:19:40 -04:00
zfcp_diag.h scsi: zfcp: Clean up sysfs code for SFP diagnostics 2021-04-15 22:19:40 -04:00
zfcp_erp.c scsi: zfcp: Use list_first_entry_or_null() in zfcp_erp_thread() 2020-09-15 18:01:57 -04:00
zfcp_ext.h scsi: zfcp: Clean up sysfs code for SFP diagnostics 2021-04-15 22:19:40 -04:00
zfcp_fc.c scsi: zfcp: Fix missing auto port scan and thus missing target ports 2022-08-17 14:24:16 +02:00
zfcp_fc.h scsi: zfcp: Fix missing auto port scan and thus missing target ports 2022-08-17 14:24:16 +02:00
zfcp_fsf.c scsi: zfcp: Fix missing auto port scan and thus missing target ports 2022-08-17 14:24:16 +02:00
zfcp_fsf.h scsi: zfcp: Handle event-lost notification for Version Change events 2020-10-29 22:17:01 -04:00
zfcp_qdio.c scsi: zfcp: fix kernel doc comments 2021-09-08 14:23:31 +02:00
zfcp_qdio.h scsi: zfcp: Lift Request Queue tasklet & timer from qdio 2021-04-15 22:19:40 -04:00
zfcp_reqlist.h scsi: zfcp: silence remaining kdoc warnings in header files 2018-11-15 15:01:18 -05:00
zfcp_scsi.c scsi: core: Introduce scsi_build_sense() 2021-05-31 22:48:21 -04:00
zfcp_sysfs.c scsi: zfcp: Report port fc_security as unknown early during remote cable pull 2021-07-12 21:51:50 -04:00
zfcp_unit.c scsi: zfcp: fix kernel doc comments 2021-09-08 14:23:31 +02:00