scsi: lpfc: Fix stale node accesses on stale RRQ request
authorJames Smart <jsmart2021@gmail.com>
Mon, 1 Mar 2021 17:18:03 +0000 (09:18 -0800)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 4 Mar 2021 22:37:04 +0000 (17:37 -0500)
Whenever an RRQ needs to be triggered, the DID from the node structure and
node pointer are stored in the RRQ data structure and the RRQ is scheduled
for later transmission. However, at the point in time that the timer
triggers, there's no validation on the node pointer. Reference counters may
have freed the structure. Additionally the DID in the node may no longer be
valid.

Fix by not tracking the node pointer in the RRQ, only the DID. At the time
of the timer expiration, look up the node with the did and if present, send
the RRQ. If no node exists, no need to send the RRQ.

Link: https://lore.kernel.org/r/20210301171821.3427-5-jsmart2021@gmail.com
Co-developed-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/lpfc/lpfc_disc.h
drivers/scsi/lpfc/lpfc_els.c
drivers/scsi/lpfc/lpfc_sli.c

index 8ce13ef3cac3ac7d434755c63db484ca22500e15..3bd5bb17035aa678b3497f8521246429bbdc6aa7 100644 (file)
@@ -159,7 +159,6 @@ struct lpfc_node_rrq {
        uint16_t rxid;
        uint32_t         nlp_DID;               /* FC D_ID of entry */
        struct lpfc_vport *vport;
-       struct lpfc_nodelist *ndlp;
        unsigned long rrq_stop_time;
 };
 
index f0a758138ae88f6808af26abb556e97ece38ad72..cc0b4f2661abbe4e0fed28368206a96701b4d4bb 100644 (file)
@@ -1849,7 +1849,7 @@ lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
 {
        struct lpfc_vport *vport = cmdiocb->vport;
        IOCB_t *irsp;
-       struct lpfc_nodelist *ndlp;
+       struct lpfc_nodelist *ndlp = cmdiocb->context1;
        struct lpfc_node_rrq *rrq;
 
        /* we pass cmdiocb to state machine which needs rspiocb as well */
@@ -1862,22 +1862,12 @@ lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
                irsp->ulpStatus, irsp->un.ulpWord[4],
                irsp->un.elsreq64.remoteID);
 
-       ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
-       if (!ndlp || ndlp != rrq->ndlp) {
-               lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
-                                "2882 RRQ completes to NPort x%x "
-                                "with no ndlp. Data: x%x x%x x%x\n",
-                                irsp->un.elsreq64.remoteID,
-                                irsp->ulpStatus, irsp->un.ulpWord[4],
-                                irsp->ulpIoTag);
-               goto out;
-       }
-
        /* rrq completes to NPort <nlp_DID> */
        lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
-                        "2880 RRQ completes to NPort x%x "
+                        "2880 RRQ completes to DID x%x "
                         "Data: x%x x%x x%x x%x x%x\n",
-                        ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
+                        irsp->un.elsreq64.remoteID,
+                        irsp->ulpStatus, irsp->un.ulpWord[4],
                         irsp->ulpTimeout, rrq->xritag, rrq->rxid);
 
        if (irsp->ulpStatus) {
@@ -1893,10 +1883,8 @@ lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
                                         ndlp->nlp_DID, irsp->ulpStatus,
                                         irsp->un.ulpWord[4]);
        }
-out:
-       if (rrq)
-               lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
 
+       lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
        lpfc_els_free_iocb(phba, cmdiocb);
        lpfc_nlp_put(ndlp);
        return;
@@ -7619,9 +7607,6 @@ lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
        uint16_t cmdsize;
        int ret;
 
-
-       if (ndlp != rrq->ndlp)
-               ndlp = rrq->ndlp;
        if (!ndlp)
                return 1;
 
@@ -7651,9 +7636,9 @@ lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
                did, rrq->xritag, rrq->rxid);
        elsiocb->context_un.rrq = rrq;
        elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
-       elsiocb->context1 = lpfc_nlp_get(ndlp);
-       if (!elsiocb->context1)
-               goto node_err;
+
+       lpfc_nlp_get(ndlp);
+       elsiocb->context1 = ndlp;
 
        ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
        if (ret == IOCB_ERROR)
@@ -7662,7 +7647,6 @@ lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
 
  io_err:
        lpfc_nlp_put(ndlp);
- node_err:
        lpfc_els_free_iocb(phba, elsiocb);
        return 1;
 }
index fa1a714a78f0996258d406383b79871cd939fa7e..99307bb7b62cefa472f4bb35ac72b1833fa7e202 100644 (file)
@@ -987,16 +987,10 @@ lpfc_clr_rrq_active(struct lpfc_hba *phba,
 {
        struct lpfc_nodelist *ndlp = NULL;
 
+       /* Lookup did to verify if did is still active on this vport */
        if (rrq->vport)
                ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
 
-       /* The target DID could have been swapped (cable swap)
-        * we should use the ndlp from the findnode if it is
-        * available.
-        */
-       if ((!ndlp) && rrq->ndlp)
-               ndlp = rrq->ndlp;
-
        if (!ndlp)
                goto out;
 
@@ -1118,9 +1112,14 @@ lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
                lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
        }
        spin_lock_irqsave(&phba->hbalock, iflags);
-       list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
-               if ((rrq->vport == vport) && (!ndlp  || rrq->ndlp == ndlp))
+       list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
+               if (rrq->vport != vport)
+                       continue;
+
+               if (!ndlp || ndlp == lpfc_findnode_did(vport, rrq->nlp_DID))
                        list_move(&rrq->list, &rrq_list);
+
+       }
        spin_unlock_irqrestore(&phba->hbalock, iflags);
 
        list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
@@ -1213,7 +1212,6 @@ lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
        rrq->xritag = xritag;
        rrq->rrq_stop_time = jiffies +
                                msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
-       rrq->ndlp = ndlp;
        rrq->nlp_DID = ndlp->nlp_DID;
        rrq->vport = ndlp->vport;
        rrq->rxid = rxid;