From: Chengfeng Ye <dg573847474@gmail.com>
To: kashyap.desai@broadcom.com, sumit.saxena@broadcom.com,
shivasharan.srikanteshwara@broadcom.com, jejb@linux.ibm.com,
martin.petersen@oracle.com, bvanassche@acm.org
Cc: megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org,
Chengfeng Ye <dg573847474@gmail.com>
Subject: [PATCH] scsi: megaraid: Fix potential deadlock on &adapter->lock
Date: Fri, 28 Jul 2023 18:25:54 +0000 [thread overview]
Message-ID: <20230728182554.5112-1-dg573847474@gmail.com> (raw)
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
reply other threads:[~2023-07-28 18:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230728182554.5112-1-dg573847474@gmail.com \
--to=dg573847474@gmail.com \
--cc=bvanassche@acm.org \
--cc=jejb@linux.ibm.com \
--cc=kashyap.desai@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=megaraidlinux.pdl@broadcom.com \
--cc=shivasharan.srikanteshwara@broadcom.com \
--cc=sumit.saxena@broadcom.com \
/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
all inboxes | Powered by JetHome®