diff mbox series

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

Message ID 20220119055955.931355-1-chi.minghao@zte.com.cn
State New
Headers show
Series drivers/scsi/csiostor: do not sleep with a spin lock held | expand

Commit Message

Lv Ruyi Jan. 19, 2022, 5:59 a.m. UTC
From: Minghao Chi <chi.minghao@zte.com.cn>

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.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
Signed-off-by: CGEL ZTE <cgel.zte@gmail.com>
---
 drivers/scsi/csiostor/csio_attr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Damien Le Moal Jan. 19, 2022, 8:45 a.m. UTC | #1
On 1/19/22 14:59, cgel.zte@gmail.com wrote:
> From: Minghao Chi <chi.minghao@zte.com.cn>
> 
> 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 ?

> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
> Signed-off-by: CGEL ZTE <cgel.zte@gmail.com>
> ---
>  drivers/scsi/csiostor/csio_attr.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/csiostor/csio_attr.c b/drivers/scsi/csiostor/csio_attr.c
> index 200e50089711..3d4ab439c756 100644
> --- a/drivers/scsi/csiostor/csio_attr.c
> +++ b/drivers/scsi/csiostor/csio_attr.c
> @@ -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;
diff mbox series

Patch

diff --git a/drivers/scsi/csiostor/csio_attr.c b/drivers/scsi/csiostor/csio_attr.c
index 200e50089711..3d4ab439c756 100644
--- a/drivers/scsi/csiostor/csio_attr.c
+++ b/drivers/scsi/csiostor/csio_attr.c
@@ -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;