mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: megaraid: Fix potential deadlock on &adapter->lock
@ 2023-07-28 18:25 Chengfeng Ye
  0 siblings, 0 replies; only message in thread
From: Chengfeng Ye @ 2023-07-28 18:25 UTC (permalink / raw)
  To: kashyap.desai, sumit.saxena, shivasharan.srikanteshwara, jejb,
	martin.petersen, bvanassche
  Cc: megaraidlinux.pdl, linux-scsi, linux-kernel, Chengfeng Ye

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.

Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
---
 drivers/scsi/megaraid/megaraid_mbox.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index ef2b6380e19a..7edddefcc9a3 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -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;
 }
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-07-28 18:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-28 18:25 [PATCH] scsi: megaraid: Fix potential deadlock on &adapter->lock Chengfeng Ye

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®