Skip to contentSkip to conversation

scsi: megaraid: Fix potential deadlock on &adapter->lock

PATCH New Chengfeng Ye 1 participant 1 message Jul 28, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: megaraid: Fix potential deadlock on &adapter->lock

As &adapter->lock is acquired by megaraid_isr_iomapped() under irq context, process context code acquiring the lock should disable irq, otherwise deadlock could happen if the irq preempt the execution while the lock is held in process context on the same CPU.

Lock acquisition of &adapter->lock in megaraid_reset_handler() does not disable irq. Inside the function there is a calling sequence shows like the below where irq is re-enabled by spin_unlock_irqrestore() on PENDING_LIST_LOCK(adapter).

  spin_lock_irqsave(PENDING_LIST_LOCK(adapter), flags);
  ...
  spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter), flags);

spin_lock(&adapter->lock)
...
spin_unlock(&adapter->lock)

This flaw was found by an experimental static analysis tool I am developing for irq-related deadlock.

The patch fix the potential deadlock by also use spin_lock_irqsave() on &adapter->lock.

---
 drivers/scsi/megaraid/megaraid_mbox.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/megaraid/megaraid_mbox.c +2 -2
index ef2b6380e19a..7edddefcc9a3 100644
@@ -2603,7 +2603,7 @@ megaraid_reset_handler(struct scsi_cmnd *scp)
 		msleep(1000);
 	}
 
-	spin_lock(&adapter->lock);
+	spin_lock_irqsave(&adapter->lock, flags);
 
 	// If still outstanding commands, bail out
 	if (adapter->outstanding_cmds) {
@@ -2643,7 +2643,7 @@ megaraid_reset_handler(struct scsi_cmnd *scp)
 	}
 
  out:
-	spin_unlock(&adapter->lock);
+	spin_unlock_irqrestore(&adapter->lock, flags);
 	return rval;
 }
 
Signature · 1 line
2.17.1