Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock

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>

authored by

Chengfeng Ye and committed by
Martin K. Petersen
dd64f805 8eebf0e8

+3 -2
+3 -2
drivers/scsi/qedi/qedi_main.c
··· 1976 1976 struct qedi_percpu_s *p = this_cpu_ptr(&qedi_percpu); 1977 1977 struct qedi_work *work, *tmp; 1978 1978 struct task_struct *thread; 1979 + unsigned long flags; 1979 1980 1980 - spin_lock_bh(&p->p_work_lock); 1981 + spin_lock_irqsave(&p->p_work_lock, flags); 1981 1982 thread = p->iothread; 1982 1983 p->iothread = NULL; 1983 1984 ··· 1989 1988 kfree(work); 1990 1989 } 1991 1990 1992 - spin_unlock_bh(&p->p_work_lock); 1991 + spin_unlock_irqrestore(&p->p_work_lock, flags); 1993 1992 if (thread) 1994 1993 kthread_stop(thread); 1995 1994 return 0;