From: sashiko-bot@kernel.org
To: "Ranjan Kumar" <ranjan.kumar@broadcom.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4 06/10] mpi3mr: Fix memory leak on operational queue creation failure
Date: Wed, 05 Aug 2026 11:40:27 +0000 [thread overview]
Message-ID: <20260805114028.3B0111F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260805110634.346670-7-ranjan.kumar@broadcom.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The threaded IRQ handler `mpi3mr_isr_poll` may exit early without re-enabling the IRQ, leaving the interrupt line permanently disabled.
- [High] Polling paths pass a potentially NULL `op_reply_q` pointer to `mpi3mr_process_op_reply_q`, leading to a kernel panic.
--
--- Patch [6]: [PATCH v4 06/10] mpi3mr: Fix memory leak on operational queue creation failure ---
commit 3a3eabe2f05c3500da7a32007ea4df206d106e35
Author: Ranjan Kumar <ranjan.kumar@broadcom.com>
mpi3mr: Fix memory leak on operational queue creation failure
When operational queue creation fails, the error path frees queue information
arrays but does not release DMA memory segments. This patch ensures partially
allocated segments are freed immediately. It also attempts to resolve races
in the queue segment free/alloc paths by clearing the queue pointer before
freeing.
Closes: https://sashiko.dev/#/patchset/20260626114109.43685-1-ranjan.kumar@broadcom.com?part=6
Closes: https://sashiko.dev/#/patchset/20260708183305.244485-1-ranjan.kumar@broadcom.com?part=6
Closes: https://sashiko.dev/#/patchset/20260724102505.115136-1-ranjan.kumar@broadcom.com?part=6
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> index e469507045dd6..880c07bdc9738 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
[ ... ]
> @@ -767,10 +770,15 @@ static irqreturn_t mpi3mr_isr_poll(int irq, void *privdata)
> {
> struct mpi3mr_intr_info *intr_info = privdata;
> struct mpi3mr_ioc *mrioc;
> + struct op_reply_qinfo *op_reply_q;
> u16 midx;
> u32 num_op_reply = 0;
>
> - if (!intr_info || !intr_info->op_reply_q)
> + if (!intr_info)
> + return IRQ_NONE;
> +
> + op_reply_q = READ_ONCE(intr_info->op_reply_q);
> + if (!op_reply_q)
> return IRQ_NONE;
[Severity: High]
Does returning early here leave the interrupt permanently masked?
If a concurrent queue deletion (e.g., from a reset) sets op_reply_q to NULL
right after mpi3mr_isr() reads it as non-NULL, the hardirq handler will
disable the IRQ and schedule this threaded handler:
mpi3mr_isr()
disable_irq_nosync(intr_info->os_irq);
return IRQ_WAKE_THREAD;
When mpi3mr_isr_poll() runs, it will read op_reply_q as NULL and return
IRQ_NONE without calling enable_irq(intr_info->os_irq). Future IOs on the
operational queue associated with this vector would hang.
>
> mrioc = intr_info->mrioc;
[ ... ]
> @@ -2021,10 +2032,17 @@ static void mpi3mr_free_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
> u16 j;
> int size;
> struct segments *segments;
> + u16 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(q_idx, mrioc->op_reply_q_offset);
>
> - segments = mrioc->op_reply_qinfo[q_idx].q_segments;
> - if (!segments)
> - return;
> + /*
> + * Stop the ISR/poll thread from picking up this queue before its
> + * segments are freed below, and wait for any in-flight handler
> + * that already has the old pointer to finish using it.
> + */
> + if (midx < mrioc->intr_info_count) {
> + WRITE_ONCE(mrioc->intr_info[midx].op_reply_q, NULL);
> + synchronize_irq(pci_irq_vector(mrioc->pdev, midx));
> + }
>
> if (mrioc->enable_segqueue) {
[Severity: High]
Could clearing op_reply_q to NULL here cause a NULL pointer dereference
in polling paths?
Polling paths read the op_reply_q pointer from the intr_info array and pass
it to mpi3mr_process_op_reply_q() without a NULL check:
mpi3mr_op_request_post()
mpi3mr_process_op_reply_q(mrioc, mrioc->intr_info[midx].op_reply_q);
mpi3mr_poll_pend_io_completions()
mpi3mr_process_op_reply_q(mrioc, mrioc->intr_info[i].op_reply_q);
If a concurrent controller reset frees the queues and sets this pointer
to NULL, mpi3mr_process_op_reply_q() will immediately dereference it.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805110634.346670-1-ranjan.kumar@broadcom.com?part=6
next prev parent reply other threads:[~2026-08-05 11:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 11:06 [PATCH v4 00/10] mpi3mr: Few Enhancements and minor fixes Ranjan Kumar
2026-08-05 11:06 ` [PATCH v4 01/10] mpi3mr: Skip device shutdown during unload per controller configuration Ranjan Kumar
2026-08-05 11:33 ` sashiko-bot
2026-08-05 11:06 ` [PATCH v4 02/10] mpi3mr: Update MPI Headers to revision 41 Ranjan Kumar
2026-08-05 11:33 ` sashiko-bot
2026-08-05 11:06 ` [PATCH v4 03/10] mpi3mr: Add early timestamp synchronization after driver load Ranjan Kumar
2026-08-05 11:06 ` [PATCH v4 04/10] mpi3mr: Fix NVMe page size caching for non-operational devices Ranjan Kumar
2026-08-05 11:40 ` sashiko-bot
2026-08-05 11:06 ` [PATCH v4 05/10] mpi3mr: Fix performance regression caused by extended IRQ poll sleep Ranjan Kumar
2026-08-05 11:32 ` sashiko-bot
2026-08-05 11:06 ` [PATCH v4 06/10] mpi3mr: Fix memory leak on operational queue creation failure Ranjan Kumar
2026-08-05 11:40 ` sashiko-bot [this message]
2026-08-05 11:06 ` [PATCH v4 07/10] mpi3mr: Fix firmware event reference leak during cleanup Ranjan Kumar
2026-08-05 11:38 ` sashiko-bot
2026-08-05 11:06 ` [PATCH v4 08/10] mpi3mr: Fix SAS port allocation and registration error handling Ranjan Kumar
2026-08-05 11:40 ` sashiko-bot
2026-08-05 11:06 ` [PATCH v4 09/10] mpi3mr: Fix SAS PHY cleanup in host addition error paths Ranjan Kumar
2026-08-05 11:06 ` [PATCH v4 10/10] mpi3mr: Driver version update to 8.18.0.8.50 Ranjan Kumar
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=20260805114028.3B0111F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=ranjan.kumar@broadcom.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