[RFC PATCH] scsi: aacraid: Fix reset_host deadlock behind a pending ioctl

From: Ziyu Zhang

Date: Mon Nov 30 2026 - 04:27:59 EST


aac_do_ioctl() holds ioctl_mutex for the whole command. FSACTL_SENDFIB,
FSACTL_SEND_LARGE_FIB and FSACTL_SEND_RAW_SRB hand a FIB to the adapter
with wait=1 and sleep on fib->event_wait without a timeout. When the
firmware stops answering, the only thing that can complete that wait is
the FIB flush in _aac_reset_adapter(), which completes every FIB that
expects a response or carries FIB_CONTEXT_FLAG_WAIT.

A reset through the reset_host sysfs attribute calls aac_reset_adapter()
with forced 0 or 1. It sets in_reset, blocks the host and calls
aac_send_shutdown(), which takes ioctl_mutex to set adapter_shutdown.
The reset then waits for the ioctl, and the ioctl waits for the reset to
reach the flush:

ioctl reset_host
----- ----------
aac_do_ioctl()
mutex_lock(ioctl_mutex)
aac_fib_send(..., wait=1)
wait_for_completion_*()
aac_reset_adapter()
in_reset = 1
scsi_host_block()
aac_send_shutdown()
mutex_lock(ioctl_mutex)
_aac_reset_adapter() /* never */
complete(&fib->event_wait)

The sysfs writer then sleeps uninterruptibly on the mutex, and the host
stays blocked with in_reset set, so I/O and SCSI EH resets stop until
the ioctl task is killed. aac_send_shutdown() takes the mutex only
while adapter_shutdown is clear, and skips it when the adapter fails its
health check, so the hang needs firmware that still looks healthy but
has stopped answering FIBs. That is the case a reset is meant to
recover from.

FSACTL_RESET_IOP does not hang this way: aac_send_reset_adapter() sets
adapter_shutdown, drops ioctl_mutex and calls aac_reset_adapter(), so
aac_send_shutdown() finds the flag already set and never takes the
mutex. Do the same for the reset_host path: set the flag in
aac_reset_adapter() before aac_send_shutdown(). New ioctls are still
refused for the duration of the reset, and the ioctl that is already
inside no longer delays it. aac_init_adapter() clears the flag once
the reset brings the adapter back, so nothing else has to; a reset that
fails before it gets that far leaves the flag set, and ioctls keep
failing with -EACCES until a reset or a resume clears it.

This only breaks the wait chain. An ioctl that has passed the
adapter_shutdown check but not submitted its FIB yet can still reach
the adapter during the reset, and the flush wakes the pending ioctl
without settling what it may do with the FIB before the communication
area is freed two seconds later. On an adapter in sync mode the reset
can still hang in aac_send_shutdown(): VM_CloseAll is queued behind the
FIB the firmware stopped answering on the single-FIB sync channel, and
that wait has no bound where the normal path has the three minute "time
out silently" loop.

Closing those needs a completion the waiter can tell apart from a
firmware response, a rule for when an aborted FIB returns to the pool,
and a submission gate that exempts the reset itself. That is not a
small change and is left out here on purpose.

Fixes: fbd185986eba ("aacraid: Fix AIF triggered IOP_RESET")
Signed-off-by: Ziyu Zhang <ziyuzhang201@xxxxxxxxx>
---
drivers/scsi/aacraid/commsup.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index 0dba44064..9faf883f1 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -1644,9 +1644,17 @@ int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)
*/
scsi_host_block(host);

- /* Quiesce build, flush cache, write through mode */
- if (forced < 2)
+ /*
+ * Quiesce build, flush cache, write through mode. An ioctl may be
+ * holding ioctl_mutex while it waits for a FIB that only
+ * _aac_reset_adapter() completes, so publish the shutdown flag here
+ * instead of letting aac_send_shutdown() take the mutex, the same
+ * way FSACTL_RESET_IOP does.
+ */
+ if (forced < 2) {
+ aac->adapter_shutdown = 1;
aac_send_shutdown(aac);
+ }
spin_lock_irqsave(&host->host_lock, flagv);
bled = forced ? forced :
(aac_check_reset != 0 && aac_check_reset != 1);
--
2.34.1