Skip to contentSkip to conversation

scsi: lpfc: Fix a sleep-in-atomic-context bug in lpfc_unreg_rpi()

PATCH New Jia-Ju Bai 1 participant 1 message Sep 15, 2018

Subsystems (2)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 scsi: lpfc: Fix a sleep-in-atomic-context bug in lpfc_unreg_rpi()

The driver may sleep in an interrupt handler.
The function call path (from bottom to top) in Linux-4.17 is:

[FUNC] mempool_alloc(GFP_KERNEL) drivers/scsi/lpfc/lpfc_hbadisc.c, 4738:
mempool_alloc in lpfc_unreg_rpi
drivers/scsi/lpfc/lpfc_els.c, 2825:
lpfc_unreg_rpi in lpfc_issue_els_logo
drivers/scsi/lpfc/lpfc_els.c, 9488:
lpfc_issue_els_logo in lpfc_sli_abts_recover_port
drivers/scsi/lpfc/lpfc_sli.c, 9806:
lpfc_sli_abts_recover_port in lpfc_sli_abts_err_handler
drivers/scsi/lpfc/lpfc_sli.c, 9914:
lpfc_sli_abts_err_handler in lpfc_sli_async_event_handler
drivers/scsi/lpfc/lpfc_sli.c, 2755:
[FUNC_PTR]lpfc_sli_async_event_handler in lpfc_sli_process_unsol_iocb
drivers/scsi/lpfc/lpfc_sli.c, 3359:
lpfc_sli_process_unsol_iocb in lpfc_sli_handle_fast_ring_event
drivers/scsi/lpfc/lpfc_sli.c, 12383:
lpfc_sli_handle_fast_ring_event in lpfc_sli_fp_intr_handler (interrupt handler)

Note that [FUNC_PTR] means a function pointer call is used.

To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC.

This bug is found by my static analysis tool DSAC.

---
 drivers/scsi/lpfc/lpfc_hbadisc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/lpfc/lpfc_hbadisc.c +1 -1
index eb71877f12f8..b10122e13d02 100644
@@ -4730,7 +4730,7 @@ lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
 					 "did x%x\n",
 					 ndlp->nlp_rpi, ndlp->nlp_flag,
 					 ndlp->nlp_DID);
-		mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
+		mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
 		if (mbox) {
 			/* SLI4 ports require the physical rpi value. */
 			rpi = ndlp->nlp_rpi;
Signature · 1 line
2.17.0