Patch "IB/hfi1: Fix potential deadlock on &irq_src_lock and &dd->uctxt_lock" has been added to the 6.1-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

    IB/hfi1: Fix potential deadlock on &irq_src_lock and &dd->uctxt_lock

to the 6.1-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:
     ib-hfi1-fix-potential-deadlock-on-irq_src_lock-and-d.patch
and it can be found in the queue-6.1 subdirectory.

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



commit b2adc9a02c56230cdd6caf4c0852fd0b29c44cb5
Author: Chengfeng Ye <dg573847474@xxxxxxxxx>
Date:   Tue Sep 26 10:11:16 2023 +0000

    IB/hfi1: Fix potential deadlock on &irq_src_lock and &dd->uctxt_lock
    
    [ Upstream commit 2f19c4b8395ccb6eb25ccafee883c8cfbe3fc193 ]
    
    handle_receive_interrupt_napi_sp() running inside interrupt handler
    could introduce inverse lock ordering between &dd->irq_src_lock
    and &dd->uctxt_lock, if read_mod_write() is preempted by the isr.
    
              [CPU0]                                        |          [CPU1]
    hfi1_ipoib_dev_open()                                   |
    --> hfi1_netdev_enable_queues()                         |
    --> enable_queues(rx)                                   |
    --> hfi1_rcvctrl()                                      |
    --> set_intr_bits()                                     |
    --> read_mod_write()                                    |
    --> spin_lock(&dd->irq_src_lock)                        |
                                                            | hfi1_poll()
                                                            | --> poll_next()
                                                            | --> spin_lock_irq(&dd->uctxt_lock)
                                                            |
                                                            | --> hfi1_rcvctrl()
                                                            | --> set_intr_bits()
                                                            | --> read_mod_write()
                                                            | --> spin_lock(&dd->irq_src_lock)
    <interrupt>                                             |
       --> handle_receive_interrupt_napi_sp()               |
       --> set_all_fastpath()                               |
       --> hfi1_rcd_get_by_index()                          |
       --> spin_lock_irqsave(&dd->uctxt_lock)               |
    
    This flaw was found by an experimental static analysis tool I am
    developing for irq-related deadlock.
    
    To prevent the potential deadlock, the patch use spin_lock_irqsave()
    on &dd->irq_src_lock inside read_mod_write() to prevent the possible
    deadlock scenario.
    
    Signed-off-by: Chengfeng Ye <dg573847474@xxxxxxxxx>
    Link: https://lore.kernel.org/r/20230926101116.2797-1-dg573847474@xxxxxxxxx
    Acked-by: Dennis Dalessandro <dennis.dalessandro@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Leon Romanovsky <leon@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/infiniband/hw/hfi1/chip.c b/drivers/infiniband/hw/hfi1/chip.c
index 194cac40da653..c560552244ae8 100644
--- a/drivers/infiniband/hw/hfi1/chip.c
+++ b/drivers/infiniband/hw/hfi1/chip.c
@@ -13183,15 +13183,16 @@ static void read_mod_write(struct hfi1_devdata *dd, u16 src, u64 bits,
 {
 	u64 reg;
 	u16 idx = src / BITS_PER_REGISTER;
+	unsigned long flags;
 
-	spin_lock(&dd->irq_src_lock);
+	spin_lock_irqsave(&dd->irq_src_lock, flags);
 	reg = read_csr(dd, CCE_INT_MASK + (8 * idx));
 	if (set)
 		reg |= bits;
 	else
 		reg &= ~bits;
 	write_csr(dd, CCE_INT_MASK + (8 * idx), reg);
-	spin_unlock(&dd->irq_src_lock);
+	spin_unlock_irqrestore(&dd->irq_src_lock, flags);
 }
 
 /**




[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