From: sashiko-bot@kernel.org
To: "Jeff Layton" <jlayton@kernel.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 01/11] scsi: mpt3sas: Don't leave requeued firmware events pending at teardown
Date: Wed, 18 Nov 2026 23:33:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-222185@kernel.org> (raw)
In-Reply-To: <20261118-sas-abba-v3-1-5562d690cf61@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] scsi: mpt3sas: races in _scsih_fw_event_requeue() and cleanup
queue
--
commit 462c12ccec856fed92f29e6abf5abd84f2b713ca
Author: Jeff Layton <jlayton@kernel.org>
scsi: mpt3sas: Don't leave requeued firmware events pending at teardown
This commit initializes fw_event->delayed_work at allocation, skips
requeuing events when the queue is being cleaned up or the host is being
removed, and cancels pending delayed_work items during queue cleanup.
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> index 04255286a2a69..545913123d01f 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
[ ... ]
> @@ -3704,20 +3712,31 @@ _scsih_fw_event_requeue(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
> {
> unsigned long flags;
>
> - if (ioc->firmware_event_thread == NULL)
> - return;
> -
> spin_lock_irqsave(&ioc->fw_event_lock, flags);
> + /*
> + * Don't rearm the event while the queue is being flushed or the
> + * host is going away. _scsih_fw_event_cleanup_queue() may already
> + * be past it, and the timer could then fire after the workqueue
> + * has been destroyed.
> + */
> + if (!ioc->firmware_event_thread || ioc->remove_host ||
> + ioc->fw_events_cleanup)
> + goto drop;
> + fw_event->delayed_work_active = 1;
> + /*
> + * Cleanups can overlap, and one can clear fw_events_cleanup while
> + * another is cancelling, and so disabling, the delayed work.
> + */
> + if (!queue_delayed_work(ioc->firmware_event_thread,
> + &fw_event->delayed_work, msecs_to_jiffies(delay)))
> + goto drop;
> fw_event_work_get(fw_event);
> list_add_tail(&fw_event->list, &ioc->fw_event_list);
> - if (!fw_event->delayed_work_active) {
> - fw_event->delayed_work_active = 1;
> - INIT_DELAYED_WORK(&fw_event->delayed_work,
> - _firmware_event_work_delayed);
> - }
> - queue_delayed_work(ioc->firmware_event_thread, &fw_event->delayed_work,
> - msecs_to_jiffies(delay));
> spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
> + return;
> +drop:
> + spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
> + fw_event_work_put(fw_event);
> }
>
> /**
> @@ -3869,9 +3888,17 @@ _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
> *
> * If it did execute, we wait for it to finish, and the put will
> * happen from _firmware_event_work()
> + *
> + * An event requeued by _scsih_fw_event_requeue() is pending
> + * on its delayed_work instead, and its timer must not fire
> + * after the workqueue is destroyed.
> */
> - if (cancel_work_sync(&fw_event->work))
> + if (fw_event->delayed_work_active) {
> + if (cancel_delayed_work_sync(&fw_event->delayed_work))
> + fw_event_work_put(fw_event);
> + } else if (cancel_work_sync(&fw_event->work)) {
> fw_event_work_put(fw_event);
> + }
>
> }
> ioc->fw_events_cleanup = 0;
[Severity: High]
Can a delayed_work timer still fire after ioc->firmware_event_thread is
destroyed when two cleanups overlap, or can a stale topology change event
still requeue itself after a host reset cleanup?
_scsih_fw_event_cleanup_queue() does not serialize concurrent callers and
does not wait for a running topology change event (it skips waiting when
ioc->current_event->event != MPT3SAS_REMOVE_UNRESPONDING_DEVICES and
clears ioc->fw_events_cleanup = 0 as soon as the loop finishes). If a
reset cleanup overlaps with teardown in scsih_remove() or scsih_shutdown():
CPU0 (reset cleanup) CPU1 (scsih_shutdown / scsih_remove)
_scsih_fw_event_cleanup_queue()
fw_event = dequeue_next_fw_event()
_scsih_fw_event_cleanup_queue()
/* list_empty && !current_event */
return;
wq = ioc->firmware_event_thread;
ioc->firmware_event_thread = NULL;
destroy_workqueue(wq);
/* delayed_work timer fires on wq */
__queue_work() <-- use-after-free
cancel_delayed_work_sync()
In addition, when a host reset cleanup runs while a topology change event
is executing, _scsih_fw_event_cleanup_queue() sets
ioc->current_event->ignore = 1, clears ioc->current_event = NULL, and
resets ioc->fw_events_cleanup = 0 without cancelling or disabling
fw_event->delayed_work. If _scsih_add_device() or _scsih_pcie_add_device()
fails on the final entry of the event (or an earlier entry already set
requeue_event = 1), _scsih_sas_topology_change_event() exits its loop and
returns requeue_event = 1 without re-checking fw_event->ignore. When
_mpt3sas_fw_work() then calls _scsih_fw_event_requeue(),
ioc->fw_events_cleanup is already 0 and ioc->remove_host is 0, and
_scsih_fw_event_requeue() checks neither fw_event->ignore nor
ioc->shost_recovery, so the stale pre-reset event still requeues itself.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-sas-abba-v3-0-5562d690cf61@kernel.org?part=1
next prev parent reply other threads:[~2026-11-18 23:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 23:09 [PATCH v3 00/11] scsi: mpt3sas: Fix delayed not-responding block deadlock and related bugs Jeff Layton
2026-11-18 23:09 ` [PATCH v3 01/11] scsi: mpt3sas: Don't leave requeued firmware events pending at teardown Jeff Layton
2026-11-18 23:33 ` sashiko-bot [this message]
2026-11-18 23:09 ` [PATCH v3 02/11] scsi: mpt3sas: Hold event references while cleaning up the event queue Jeff Layton
2026-11-18 23:10 ` [PATCH v3 03/11] scsi: mpt3sas: Requeue topology events only for busy devices Jeff Layton
2026-11-18 23:10 ` [PATCH v3 04/11] scsi: mpt3sas: Fix pcie_device leak in _scsih_ublock_io_device_wait() Jeff Layton
2026-11-18 23:10 ` [PATCH v3 05/11] scsi: mpt3sas: Restore unblock retry " Jeff Layton
2026-11-18 23:10 ` [PATCH v3 06/11] scsi: mpt3sas: Stop polling devices when the unresponding scan is cancelled Jeff Layton
2026-11-18 23:27 ` sashiko-bot
2026-11-18 23:10 ` [PATCH v3 07/11] scsi: mpt3sas: Reset the TUR retry count for each device Jeff Layton
2026-11-18 23:10 ` [PATCH v3 08/11] scsi: mpt3sas: Cache the missing delays the IOC actually uses Jeff Layton
2026-11-18 23:10 ` [PATCH v3 09/11] scsi: mpt3sas: Serialize interrupt-time sdev block with hostdata teardown Jeff Layton
2026-11-18 23:10 ` [PATCH v3 10/11] scsi: mpt3sas: Don't use freed hostdata while polling devices Jeff Layton
2026-11-18 23:23 ` sashiko-bot
2026-11-18 23:10 ` [PATCH v3 11/11] scsi: mpt3sas: Time out delayed not-responding device blocks Jeff Layton
2026-11-18 23:33 ` sashiko-bot
2026-11-18 23:13 ` [PATCH v3 00/11] scsi: mpt3sas: Fix delayed not-responding block deadlock and related bugs Jeff Layton
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-222185@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=jlayton@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.