From: sashiko-bot@kernel.org
To: "Nigel Kirkland" <nkirkland2304@gmail.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v6 3/8] lpfc: Fix kernel oops when unmapping scsi dma buffers for an aborted cmd
Date: Tue, 13 Oct 2026 00:07:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-168775@kernel.org> (raw)
In-Reply-To: <20261013001648.62289-4-nkirkland2304@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] scsi: lpfc: incomplete fix leaves DMA unmap oops window open during LUN reset
- [High] scsi: lpfc: data race on cmd_flag can lose LPFC_DRIVER_ABORTED
--
commit 675425a729cb7c6ac7d9c7e57d4ee3019d93591f
Author: Nigel Kirkland <nkirkland2304@gmail.com>
lpfc: Fix kernel oops when unmapping scsi dma buffers for an aborted cmd
This commit attempts to fix a kernel oops at dma_unmap_sg_attrs by ensuring
inflight scsi I/Os are counted if either LPFC_IO_ON_TXCMPLQ or
LPFC_DRIVER_ABORTED is set. This is to keep the LLDD retaining an interest
in the scsi_cmnd and avoid premature unmapping.
> diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
> index a167ad96d2a62..7a187d0efaa92 100644
> --- a/drivers/scsi/lpfc/lpfc_sli.c
> +++ b/drivers/scsi/lpfc/lpfc_sli.c
> @@ -12739,8 +12739,12 @@ lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
[ ... ]
> - if (!(iocbq->cmd_flag & LPFC_IO_FCP) ||
> - !(iocbq->cmd_flag & LPFC_IO_ON_TXCMPLQ))
> + /* Only count FCP i/o */
> + if (!(iocbq->cmd_flag & LPFC_IO_FCP))
> + continue;
> + /* Count i/o whilst LLDD retains an interest in the scsi_cmnd */
> + if (!(iocbq->cmd_flag &
> + (LPFC_IO_ON_TXCMPLQ | LPFC_DRIVER_ABORTED)))
> continue;
[Severity: High]
Does this still leave a window open for the DMA unmap oops during LUN reset?
If a hardware completion arrives just before the SCSI error handler calls
lpfc_abort_handler(), the fast-path IRQ handler lpfc_sli_iocbq_lookup_by_tag()
removes the IOCB from TXCMPLQ and clears LPFC_IO_ON_TXCMPLQ.
Because the command is no longer on the TX queue, lpfc_abort_handler()
skips it and returns FAILED without ever setting LPFC_DRIVER_ABORTED:
drivers/scsi/lpfc/lpfc_scsi.c:lpfc_abort_handler() {
...
/* the command is in process of being cancelled */
if (!(iocb->cmd_flag & LPFC_IO_ON_TXCMPLQ)) {
lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
"3169 SCSI Layer abort requested I/O has been "
"cancelled by LLD.\n");
ret = FAILED;
goto out_unlock_ring;
}
...
}
If the SCSI error handler escalates to lpfc_device_reset_handler(), it
flushes I/Os by calling lpfc_sli_sum_iocb(). Since both LPFC_IO_ON_TXCMPLQ
and LPFC_DRIVER_ABORTED are 0, wouldn't lpfc_sli_sum_iocb() skip the
command and return 0?
This could allow the LUN reset handler to assume no commands are inflight
and finish, allowing the SCSI midlayer to free or repurpose the scsi_cmnd.
Finally, the delayed softirq completion handler lpfc_scsi_cmd_iocb_cmpl()
could execute and call lpfc_scsi_unprep_dma_buf() on the freed scsi_cmnd.
[Severity: High]
Can a data race on cmd_flag cause LPFC_DRIVER_ABORTED to be lost?
The cmd_flag is a 32-bit field updated using non-atomic bitwise operators.
The lpfc_sli_iocbq_lookup_by_tag() function clears LPFC_IO_ON_TXCMPLQ in
the completion handler holding only pring->ring_lock:
drivers/scsi/lpfc/lpfc_sli.c:lpfc_sli_iocbq_lookup_by_tag() {
...
cmd_iocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
...
}
Concurrently, abort handlers like lpfc_sli_issue_abort_iotag() and
lpfc_sli4_issue_abort_iotag() set LPFC_DRIVER_ABORTED holding buf_lock
and hbalock, but explicitly without pring->ring_lock:
drivers/scsi/lpfc/lpfc_sli.c:lpfc_sli4_issue_abort_iotag() {
...
cmdiocb->cmd_flag |= LPFC_DRIVER_ABORTED;
...
}
If LPFC_DRIVER_ABORTED is lost due to this race, lpfc_sli_sum_iocb()
could miss the command. This would bypass the logic introduced in this
patch and lead to early unload or unmap while hardware DMA is still active.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013001648.62289-1-nkirkland2304@gmail.com?part=3
next prev parent reply other threads:[~2026-10-13 0:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 0:16 [PATCH v6 0/8] lpfc: Update lpfc to revision 15.0.0.1 Nigel Kirkland
2026-10-13 0:16 ` [PATCH v6 1/8] lpfc: Fix use-after-free in lpfc_cmpl_ct_cmd_vmid Nigel Kirkland
2026-10-13 0:03 ` sashiko-bot
2026-10-13 0:16 ` [PATCH v6 2/8] lpfc: Early return out of lpfc_els_abort when HBA_SETUP flag is not set Nigel Kirkland
2026-10-13 0:05 ` sashiko-bot
2026-10-13 0:16 ` [PATCH v6 3/8] lpfc: Fix kernel oops when unmapping scsi dma buffers for an aborted cmd Nigel Kirkland
2026-10-13 0:07 ` sashiko-bot [this message]
2026-10-13 0:16 ` [PATCH v6 4/8] lpfc: Check fc4_xpt_flags before decrementing ndlp kref on FDISC error Nigel Kirkland
2026-10-13 0:16 ` [PATCH v6 5/8] lpfc: Rework I/O flush ordering when unloading driver Nigel Kirkland
2026-10-13 0:12 ` sashiko-bot
2026-10-13 0:16 ` [PATCH v6 6/8] lpfc: Refactor calls on fc_disctmo to lpfc_set_disctmo in RSCN handler Nigel Kirkland
2026-10-13 0:16 ` [PATCH v6 7/8] lpfc: Update correct ndlp refcnt when rejecting an unsolicited PLOGI Nigel Kirkland
2026-10-13 0:13 ` sashiko-bot
2026-10-13 0:16 ` [PATCH v6 8/8] lpfc: Update lpfc version to 15.0.0.1 Nigel Kirkland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-168775@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=nkirkland2304@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox