Patch "scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

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

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     scsi-qedi-fix-potential-deadlock-on-qedi_percpu-p_wo.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 0c7141b8f6f8e3e917d70054aaba557fdb8d4a2f
Author: Chengfeng Ye <dg573847474@xxxxxxxxx>
Date:   Wed Jul 26 12:56:55 2023 +0000

    scsi: qedi: Fix potential deadlock on &qedi_percpu->p_work_lock
    
    [ Upstream commit dd64f80587190265ca8a0f4be6c64c2fda6d3ac2 ]
    
    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@xxxxxxxxx>
    Link: https://lore.kernel.org/r/20230726125655.4197-1-dg573847474@xxxxxxxxx
    Acked-by: Manish Rangankar <mrangankar@xxxxxxxxxxx>
    Signed-off-by: Martin K. Petersen <martin.petersen@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
index 92c4a367b7bd7..6b47921202eba 100644
--- a/drivers/scsi/qedi/qedi_main.c
+++ b/drivers/scsi/qedi/qedi_main.c
@@ -1910,8 +1910,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;
 
@@ -1922,7 +1923,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;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux