All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] scsi: efct: Use GFP_ATOMIC under spin lock
@ 2021-12-21 11:37 Yang Yingliang
  2021-12-21 14:28 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Yingliang @ 2021-12-21 11:37 UTC (permalink / raw)
  To: linux-kernel, target-devel, linux-scsi; +Cc: hch, james.smart, martin.petersen

A spin lock is taken here so we should use GFP_ATOMIC.

Fixes: efac162a4e4d ("scsi: efct: Don't pass GFP_DMA to dma_alloc_coherent()")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/scsi/elx/libefc/efc_els.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/elx/libefc/efc_els.c b/drivers/scsi/elx/libefc/efc_els.c
index 7bb4f9aad2c8..7043a61d553d 100644
--- a/drivers/scsi/elx/libefc/efc_els.c
+++ b/drivers/scsi/elx/libefc/efc_els.c
@@ -71,7 +71,7 @@ efc_els_io_alloc_size(struct efc_node *node, u32 reqlen, u32 rsplen)
 	/* now allocate DMA for request and response */
 	els->io.req.size = reqlen;
 	els->io.req.virt = dma_alloc_coherent(&efc->pci->dev, els->io.req.size,
-					      &els->io.req.phys, GFP_KERNEL);
+					      &els->io.req.phys, GFP_ATOMIC);
 	if (!els->io.req.virt) {
 		mempool_free(els, efc->els_io_pool);
 		spin_unlock_irqrestore(&node->els_ios_lock, flags);
@@ -80,7 +80,7 @@ efc_els_io_alloc_size(struct efc_node *node, u32 reqlen, u32 rsplen)
 
 	els->io.rsp.size = rsplen;
 	els->io.rsp.virt = dma_alloc_coherent(&efc->pci->dev, els->io.rsp.size,
-					      &els->io.rsp.phys, GFP_KERNEL);
+					      &els->io.rsp.phys, GFP_ATOMIC);
 	if (!els->io.rsp.virt) {
 		dma_free_coherent(&efc->pci->dev, els->io.req.size,
 				  els->io.req.virt, els->io.req.phys);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH -next] scsi: efct: Use GFP_ATOMIC under spin lock
  2021-12-21 11:37 [PATCH -next] scsi: efct: Use GFP_ATOMIC under spin lock Yang Yingliang
@ 2021-12-21 14:28 ` Christoph Hellwig
  2021-12-23  3:56   ` Yang Yingliang
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2021-12-21 14:28 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: linux-kernel, target-devel, linux-scsi, hch, james.smart,
	martin.petersen

On Tue, Dec 21, 2021 at 07:37:06PM +0800, Yang Yingliang wrote:
> A spin lock is taken here so we should use GFP_ATOMIC.
> 
> Fixes: efac162a4e4d ("scsi: efct: Don't pass GFP_DMA to dma_alloc_coherent()")

No, it does not fix that commit.  The driver did sleeping allocations
even before the commit.

But wher is "here"?  Can we look into not holding that lock over an
allocation if it is preferable?  If not we should at least pass down
the gfp_flags so that only the caller(s) that can't sleep pass GFP_ATOMIC.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next] scsi: efct: Use GFP_ATOMIC under spin lock
  2021-12-21 14:28 ` Christoph Hellwig
@ 2021-12-23  3:56   ` Yang Yingliang
  2022-01-10  8:54     ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Yingliang @ 2021-12-23  3:56 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-kernel, target-devel, linux-scsi, james.smart, martin.petersen


On 2021/12/21 22:28, Christoph Hellwig wrote:
> On Tue, Dec 21, 2021 at 07:37:06PM +0800, Yang Yingliang wrote:
>> A spin lock is taken here so we should use GFP_ATOMIC.
>>
>> Fixes: efac162a4e4d ("scsi: efct: Don't pass GFP_DMA to dma_alloc_coherent()")
> No, it does not fix that commit.  The driver did sleeping allocations
> even before the commit.
>
> But wher is "here"?  Can we look into not holding that lock over an
> allocation if it is preferable?  If not we should at least pass down
> the gfp_flags so that only the caller(s) that can't sleep pass GFP_ATOMIC.

According the comment of els_ios_lock, it's used to protect els ios 
list, I think we

can move down the spin lock like this:


--- a/drivers/scsi/elx/libefc/efc_els.c
+++ b/drivers/scsi/elx/libefc/efc_els.c
@@ -46,8 +46,6 @@ efc_els_io_alloc_size(struct efc_node *node, u32 
reqlen, u32 rsplen)

         efc = node->efc;

-       spin_lock_irqsave(&node->els_ios_lock, flags);
-
         if (!node->els_io_enabled) {
                 efc_log_err(efc, "els io alloc disabled\n");
                 spin_unlock_irqrestore(&node->els_ios_lock, flags);
@@ -88,6 +86,8 @@ efc_els_io_alloc_size(struct efc_node *node, u32 
reqlen, u32 rsplen)
                 els = NULL;
         }

+       spin_lock_irqsave(&node->els_ios_lock, flags);
+
         if (els) {
                 /* initialize fields */
                 els->els_retries_remaining = EFC_FC_ELS_DEFAULT_RETRIES;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next] scsi: efct: Use GFP_ATOMIC under spin lock
  2021-12-23  3:56   ` Yang Yingliang
@ 2022-01-10  8:54     ` Christoph Hellwig
  0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2022-01-10  8:54 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: Christoph Hellwig, linux-kernel, target-devel, linux-scsi,
	james.smart, martin.petersen

On Thu, Dec 23, 2021 at 11:56:08AM +0800, Yang Yingliang wrote:
>
> On 2021/12/21 22:28, Christoph Hellwig wrote:
>> On Tue, Dec 21, 2021 at 07:37:06PM +0800, Yang Yingliang wrote:
>>> A spin lock is taken here so we should use GFP_ATOMIC.
>>>
>>> Fixes: efac162a4e4d ("scsi: efct: Don't pass GFP_DMA to dma_alloc_coherent()")
>> No, it does not fix that commit.  The driver did sleeping allocations
>> even before the commit.
>>
>> But wher is "here"?  Can we look into not holding that lock over an
>> allocation if it is preferable?  If not we should at least pass down
>> the gfp_flags so that only the caller(s) that can't sleep pass GFP_ATOMIC.
>
> According the comment of els_ios_lock, it's used to protect els ios list, I 
> think we
>
> can move down the spin lock like this:

This looks sensible to me.  Please submit it to the maintainer as a proper
patch.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-10  8:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-21 11:37 [PATCH -next] scsi: efct: Use GFP_ATOMIC under spin lock Yang Yingliang
2021-12-21 14:28 ` Christoph Hellwig
2021-12-23  3:56   ` Yang Yingliang
2022-01-10  8:54     ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.