Skip to contentSkip to conversation

drivers/scsi/csiostor: do not sleep with a spin lock held

PATCH In review [email protected] 2 participants 5 messages Jan 19, 2022 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/scsi/csiostor: do not sleep with a spin lock held

From: Minghao Chi <[email protected]>

The might_sleep_if function in the mempool_alloc may cause a sleep lock.We can't mempool_alloc() with a spin lock held, so bring it up front.

---
 drivers/scsi/csiostor/csio_attr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/csiostor/csio_attr.c +2 -2
index 200e50089711..3d4ab439c756 100644
@@ -424,8 +424,8 @@ csio_fcoe_alloc_vnp(struct csio_hw *hw, struct csio_lnode *ln)
 
 	/* Issue VNP cmd to alloc vport */
 	/* Allocate Mbox request */
-	spin_lock_irq(&hw->lock);
 	mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
+	spin_lock_irq(&hw->lock);
 	if (!mbp) {
 		CSIO_INC_STATS(hw, n_err_nomem);
 		ret = -ENOMEM;
@@ -505,8 +505,8 @@ csio_fcoe_free_vnp(struct csio_hw *hw, struct csio_lnode *ln)
 	/* Issue VNP cmd to free vport */
 	/* Allocate Mbox request */
 
-	spin_lock_irq(&hw->lock);
 	mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
+	spin_lock_irq(&hw->lock);
 	if (!mbp) {
 		CSIO_INC_STATS(hw, n_err_nomem);
 		ret = -ENOMEM;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 5 lines · On 1/19/22 14:59, [email protected] wrote:

From: Minghao Chi <[email protected]>

The might_sleep_if function in the mempool_alloc may cause a sleep lock.We can't mempool_alloc() with a spin lock held, so bring it up front.

But the allocation is GFP_ATOMIC, which does not have __GFP_DIRECT_RECLAIM, so how come mempool_alloc() triggers the might_sleep() warning ?

Quoted 32 lines
---
 drivers/scsi/csiostor/csio_attr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/csiostor/csio_attr.c +2 -2
index 200e50089711..3d4ab439c756 100644
@@ -424,8 +424,8 @@ csio_fcoe_alloc_vnp(struct csio_hw *hw, struct csio_lnode *ln)
 
 	/* Issue VNP cmd to alloc vport */
 	/* Allocate Mbox request */
-	spin_lock_irq(&hw->lock);
 	mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
+	spin_lock_irq(&hw->lock);
 	if (!mbp) {
 		CSIO_INC_STATS(hw, n_err_nomem);
 		ret = -ENOMEM;
@@ -505,8 +505,8 @@ csio_fcoe_free_vnp(struct csio_hw *hw, struct csio_lnode *ln)
 	/* Issue VNP cmd to free vport */
 	/* Allocate Mbox request */
 
-	spin_lock_irq(&hw->lock);
 	mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
+	spin_lock_irq(&hw->lock);
 	if (!mbp) {
 		CSIO_INC_STATS(hw, n_err_nomem);
 		ret = -ENOMEM;
Signature · 2 lines
Damien Le Moal
Western Digital Research
#2 lore raw

The might_sleep_if(gfp_mask & __GFP_DIRECT_RECLAIM) in the mempool_alloc function uses __GFP_DIRECT_RECLAIM.

#3 lore raw
Quoted 3 lines · On 1/19/22 17:57, [email protected] wrote:

The might_sleep_if(gfp_mask & __GFP_DIRECT_RECLAIM) in the mempool_alloc function uses __GFP_DIRECT_RECLAIM.

But the call to mempool_alloc() specifies GFP_ATOMIC, which does not have __GFP_DIRECT_RECLAIM, so "gfp_mask & __GFP_DIRECT_RECLAIM" should be false, and the might_sleep_if() not triggering. How can you see the might sleep warning ?

Signature · 2 lines
Damien Le Moal
Western Digital Research