From: Quinn Tran <quinn.t...@cavium.com>

Prevent driver from endless loop or hang in the case of
NPort ID change.

Following stack trace is seen

Feb 12 08:21:17 localhost kernel: Call Trace:
Feb 12 08:21:17 localhost kernel: ? __schedule+0x254/0x840
Feb 12 08:21:17 localhost kernel: ? up+0x12/0x50
Feb 12 08:21:17 localhost kernel: schedule+0x28/0x70
Feb 12 08:21:17 localhost kernel: schedule_timeout+0x26d/0x390
Feb 12 08:21:17 localhost kernel: ? vprintk_emit+0x1e2/0x450
Feb 12 08:21:17 localhost kernel: wait_for_completion+0x11f/0x190
Feb 12 08:21:17 localhost kernel: ? wake_up_q+0x70/0x70
Feb 12 08:21:17 localhost kernel: flush_workqueue+0x14d/0x440
Feb 12 08:21:17 localhost kernel: qla2x00_wait_for_sess_deletion+0x98/0x1e0 
[qla2xxx]
Feb 12 08:21:17 localhost kernel: ? qla2x00_abort_all_cmds+0x42/0x60 [qla2xxx]
Feb 12 08:21:17 localhost kernel: qla2x00_remove_one+0x12c/0x410 [qla2xxx]
Feb 12 08:21:17 localhost kernel: pci_device_remove+0x3b/0xc0
Feb 12 08:21:17 localhost kernel: device_release_driver_internal+0x180/0x250
Feb 12 08:21:17 localhost kernel: driver_detach+0x39/0x6d
Feb 12 08:21:17 localhost kernel: bus_remove_driver+0x74/0xc6
Feb 12 08:21:17 localhost kernel: pci_unregister_driver+0x2a/0xa0
Feb 12 08:21:17 localhost kernel: qla2x00_module_exit+0x2d/0x90 [qla2xxx]
Feb 12 08:21:17 localhost kernel: __x64_sys_delete_module+0x139/0x270
Feb 12 08:21:17 localhost kernel: do_syscall_64+0x5b/0x1b0
Feb 12 08:21:17 localhost kernel: entry_SYSCALL_64_after_hwframe+0x65/0xca
Feb 12 08:21:17 localhost kernel: RIP: 0033:0x7f48e887a3bb
Feb 12 08:21:17 localhost kernel: Code: Bad RIP value.
Feb 12 08:21:17 localhost kernel: RSP: 002b:00007ffc088da478 EFLAGS: 00000206 
ORIG_RAX: 00000000000000b0

Fixes: 18b5110f8728 ("scsi: qla2xxx: Migrate NVME N2N handling into state 
machine")
Cc: sta...@vger.kernel.org # 4.19
Signed-off-by: Quinn Tran <quinn.t...@cavium.com>
Signed-off-by: Himanshu Madhani <hmadh...@marvell.com>
---
 drivers/scsi/qla2xxx/qla_init.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 0c700b140ce7..88eaf4b66875 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -602,12 +602,15 @@ static void qla24xx_handle_gnl_done_event(scsi_qla_host_t 
*vha,
                        break;
                default:
                        if ((id.b24 != fcport->d_id.b24 &&
-                           fcport->d_id.b24) ||
+                           fcport->d_id.b24 &&
+                           fcport->loop_id != FC_NO_LOOP_ID) ||
                            (fcport->loop_id != FC_NO_LOOP_ID &&
                                fcport->loop_id != loop_id)) {
                                ql_dbg(ql_dbg_disc, vha, 0x20e3,
                                    "%s %d %8phC post del sess\n",
                                    __func__, __LINE__, fcport->port_name);
+                               if (fcport->n2n_flag)
+                                       fcport->d_id.b24 = 0;
                                qlt_schedule_sess_for_deletion(fcport);
                                return;
                        }
@@ -615,6 +618,8 @@ static void qla24xx_handle_gnl_done_event(scsi_qla_host_t 
*vha,
                }
 
                fcport->loop_id = loop_id;
+               if (fcport->n2n_flag)
+                       fcport->d_id.b24 = id.b24;
 
                wwn = wwn_to_u64(fcport->port_name);
                qlt_find_sess_invalidate_other(vha, wwn,
-- 
2.12.0

Reply via email to