* [PATCH] scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock
@ 2023-07-26 12:56 Chengfeng Ye
2023-08-07 12:20 ` [EXT] " Manish Rangankar
2023-08-08 2:43 ` Martin K. Petersen
0 siblings, 2 replies; 4+ messages in thread
From: Chengfeng Ye @ 2023-07-26 12:56 UTC (permalink / raw)
To: njavali, mrangankar, GR-QLogic-Storage-Upstream, jejb, martin.petersen
Cc: linux-scsi, linux-kernel, Chengfeng Ye
As &qedi_percpu->p_work_lock is acquired by hard irq qedi_msix_handler(),
other acquisition of the same lock under process context 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.
qedi_cpu_offline() is one such function acquires the lock on process
context.
[Deadlock Scenario]
qedi_cpu_offline()
->spin_lock(&p->p_work_lock)
<irq>
->qedi_msix_handler()
->edi_process_completions()
->spin_lock_irqsave(&p->p_work_lock, flags); (deadlock here)
This flaw was found by an experimental static analysis tool I am
developing for irq-related deadlock.
The tentative patch fix the potential deadlock by spin_lock_irqsave()
under process context.
Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
---
drivers/scsi/qedi/qedi_main.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
index 450522b204d6..77a56a136678 100644
--- a/drivers/scsi/qedi/qedi_main.c
+++ b/drivers/scsi/qedi/qedi_main.c
@@ -1976,8 +1976,9 @@ static int qedi_cpu_offline(unsigned int cpu)
struct qedi_percpu_s *p = this_cpu_ptr(&qedi_percpu);
struct qedi_work *work, *tmp;
struct task_struct *thread;
+ unsigned long flags;
- spin_lock_bh(&p->p_work_lock);
+ spin_lock_irqsave(&p->p_work_lock, flags);
thread = p->iothread;
p->iothread = NULL;
@@ -1988,7 +1989,7 @@ static int qedi_cpu_offline(unsigned int cpu)
kfree(work);
}
- spin_unlock_bh(&p->p_work_lock);
+ spin_unlock_irqrestore(&p->p_work_lock, flags);
if (thread)
kthread_stop(thread);
return 0;
--
2.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [EXT] [PATCH] scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock
2023-07-26 12:56 [PATCH] scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock Chengfeng Ye
@ 2023-08-07 12:20 ` Manish Rangankar
2023-08-08 2:43 ` Martin K. Petersen
1 sibling, 0 replies; 4+ messages in thread
From: Manish Rangankar @ 2023-08-07 12:20 UTC (permalink / raw)
To: Chengfeng Ye, Nilesh Javali, GR-QLogic-Storage-Upstream, jejb,
martin.petersen
Cc: linux-scsi, linux-kernel
> -----Original Message-----
> From: Chengfeng Ye <dg573847474@gmail.com>
> Sent: Wednesday, July 26, 2023 6:27 PM
> To: Nilesh Javali <njavali@marvell.com>; Manish Rangankar
> <mrangankar@marvell.com>; GR-QLogic-Storage-Upstream <GR-QLogic-
> Storage-Upstream@marvell.com>; jejb@linux.ibm.com;
> martin.petersen@oracle.com
> Cc: linux-scsi@vger.kernel.org; linux-kernel@vger.kernel.org; Chengfeng Ye
> <dg573847474@gmail.com>
> Subject: [EXT] [PATCH] scsi: qedi: Fix potential deadlock on &qedi_percpu-
> >p_work_lock
>
> External Email
>
> ----------------------------------------------------------------------
> As &qedi_percpu->p_work_lock is acquired by hard irq qedi_msix_handler(),
> other acquisition of the same lock under process context 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.
>
> qedi_cpu_offline() is one such function acquires the lock on process context.
>
> [Deadlock Scenario]
> qedi_cpu_offline()
> ->spin_lock(&p->p_work_lock)
> <irq>
> ->qedi_msix_handler()
> ->edi_process_completions()
> ->spin_lock_irqsave(&p->p_work_lock, flags); (deadlock here)
>
> This flaw was found by an experimental static analysis tool I am developing
> for irq-related deadlock.
>
> The tentative patch fix the potential deadlock by spin_lock_irqsave() under
> process context.
>
> Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
> ---
> drivers/scsi/qedi/qedi_main.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
> index 450522b204d6..77a56a136678 100644
> --- a/drivers/scsi/qedi/qedi_main.c
> +++ b/drivers/scsi/qedi/qedi_main.c
> @@ -1976,8 +1976,9 @@ static int qedi_cpu_offline(unsigned int cpu)
> struct qedi_percpu_s *p = this_cpu_ptr(&qedi_percpu);
> struct qedi_work *work, *tmp;
> struct task_struct *thread;
> + unsigned long flags;
>
> - spin_lock_bh(&p->p_work_lock);
> + spin_lock_irqsave(&p->p_work_lock, flags);
> thread = p->iothread;
> p->iothread = NULL;
>
> @@ -1988,7 +1989,7 @@ static int qedi_cpu_offline(unsigned int cpu)
> kfree(work);
> }
>
> - spin_unlock_bh(&p->p_work_lock);
> + spin_unlock_irqrestore(&p->p_work_lock, flags);
> if (thread)
> kthread_stop(thread);
> return 0;
> --
> 2.17.1
Thanks for the patch,
Acked-by: Manish Rangankar <mrangankar@marvell.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock
2023-07-26 12:56 [PATCH] scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock Chengfeng Ye
2023-08-07 12:20 ` [EXT] " Manish Rangankar
@ 2023-08-08 2:43 ` Martin K. Petersen
2023-08-08 6:23 ` Chengfeng Ye
1 sibling, 1 reply; 4+ messages in thread
From: Martin K. Petersen @ 2023-08-08 2:43 UTC (permalink / raw)
To: njavali, mrangankar, GR-QLogic-Storage-Upstream, jejb, Chengfeng Ye
Cc: Martin K . Petersen, linux-scsi, linux-kernel
On Wed, 26 Jul 2023 12:56:55 +0000, Chengfeng Ye wrote:
> As &qedi_percpu->p_work_lock is acquired by hard irq qedi_msix_handler(),
> other acquisition of the same lock under process context 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.
>
> qedi_cpu_offline() is one such function acquires the lock on process
> context.
>
> [...]
Applied to 6.5/scsi-fixes, thanks!
[1/1] scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock
https://git.kernel.org/mkp/scsi/c/dd64f8058719
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock
2023-08-08 2:43 ` Martin K. Petersen
@ 2023-08-08 6:23 ` Chengfeng Ye
0 siblings, 0 replies; 4+ messages in thread
From: Chengfeng Ye @ 2023-08-08 6:23 UTC (permalink / raw)
To: Martin K. Petersen
Cc: njavali, mrangankar, GR-QLogic-Storage-Upstream, jejb,
linux-scsi, linux-kernel
Thanks for the review.
Best,
Chengfeng
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-08 16:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-26 12:56 [PATCH] scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock Chengfeng Ye
2023-08-07 12:20 ` [EXT] " Manish Rangankar
2023-08-08 2:43 ` Martin K. Petersen
2023-08-08 6:23 ` 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®