Skip to content

Commit

Permalink
scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock
Browse files Browse the repository at this point in the history
As &qedi_percpu->p_work_lock is acquired by hard IRQ qedi_msix_handler(),
other acquisitions of the same lock under process context should disable
IRQ, otherwise deadlock could happen if the IRQ preempts the execution
while the lock is held in process context on the same CPU.

qedi_cpu_offline() is one such function which acquires the lock in 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 deadlocks.

The tentative patch fix the potential deadlock by spin_lock_irqsave()
under process context.

Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
Link: https://lore.kernel.org/r/20230726125655.4197-1-dg573847474@gmail.com
Acked-by: Manish Rangankar <mrangankar@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Chengfeng Ye authored and Martin K. Petersen committed Aug 8, 2023
1 parent 8eebf0e commit dd64f80
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/scsi/qedi/qedi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit dd64f80

Please sign in to comment.