Skip to content

Commit 311950f

Browse files
Christoph Hellwigmartinkpetersen
authored andcommitted
scsi: mptfusion: Don't use GFP_ATOMIC for larger DMA allocations
The mpt fusion driver still uses the legacy PCI DMA API which hardcodes atomic allocations. This caused the driver to fail to load on some powerpc VMs with incoherent DMA and small memory sizes. Switch to use the modern DMA API and sleeping allocations for large allocations instead. This is not a full cleanup of the PCI DMA API usage yet, but just enough to fix the regression caused by reducing the default atomic pool size. Link: https://lore.kernel.org/r/[email protected] Fixes: 3ee06a6 ("dma-pool: fix too large DMA pools on medium memory size systems") Reported-by: Guenter Roeck <[email protected]> Tested-by: Guenter Roeck <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 823a654 commit 311950f

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

drivers/message/fusion/mptbase.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,13 +1324,13 @@ mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init)
13241324
return 0; /* fw doesn't need any host buffers */
13251325

13261326
/* spin till we get enough memory */
1327-
while(host_page_buffer_sz > 0) {
1328-
1329-
if((ioc->HostPageBuffer = pci_alloc_consistent(
1330-
ioc->pcidev,
1331-
host_page_buffer_sz,
1332-
&ioc->HostPageBuffer_dma)) != NULL) {
1333-
1327+
while (host_page_buffer_sz > 0) {
1328+
ioc->HostPageBuffer =
1329+
dma_alloc_coherent(&ioc->pcidev->dev,
1330+
host_page_buffer_sz,
1331+
&ioc->HostPageBuffer_dma,
1332+
GFP_KERNEL);
1333+
if (ioc->HostPageBuffer) {
13341334
dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
13351335
"host_page_buffer @ %p, dma @ %x, sz=%d bytes\n",
13361336
ioc->name, ioc->HostPageBuffer,
@@ -2741,8 +2741,8 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
27412741
sz = ioc->alloc_sz;
27422742
dexitprintk(ioc, printk(MYIOC_s_INFO_FMT "free @ %p, sz=%d bytes\n",
27432743
ioc->name, ioc->alloc, ioc->alloc_sz));
2744-
pci_free_consistent(ioc->pcidev, sz,
2745-
ioc->alloc, ioc->alloc_dma);
2744+
dma_free_coherent(&ioc->pcidev->dev, sz, ioc->alloc,
2745+
ioc->alloc_dma);
27462746
ioc->reply_frames = NULL;
27472747
ioc->req_frames = NULL;
27482748
ioc->alloc = NULL;
@@ -2751,8 +2751,8 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
27512751

27522752
if (ioc->sense_buf_pool != NULL) {
27532753
sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
2754-
pci_free_consistent(ioc->pcidev, sz,
2755-
ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
2754+
dma_free_coherent(&ioc->pcidev->dev, sz, ioc->sense_buf_pool,
2755+
ioc->sense_buf_pool_dma);
27562756
ioc->sense_buf_pool = NULL;
27572757
ioc->alloc_total -= sz;
27582758
}
@@ -2802,7 +2802,7 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
28022802
"HostPageBuffer free @ %p, sz=%d bytes\n",
28032803
ioc->name, ioc->HostPageBuffer,
28042804
ioc->HostPageBuffer_sz));
2805-
pci_free_consistent(ioc->pcidev, ioc->HostPageBuffer_sz,
2805+
dma_free_coherent(&ioc->pcidev->dev, ioc->HostPageBuffer_sz,
28062806
ioc->HostPageBuffer, ioc->HostPageBuffer_dma);
28072807
ioc->HostPageBuffer = NULL;
28082808
ioc->HostPageBuffer_sz = 0;
@@ -4497,7 +4497,8 @@ PrimeIocFifos(MPT_ADAPTER *ioc)
44974497
ioc->name, sz, sz, num_chain));
44984498

44994499
total_size += sz;
4500-
mem = pci_alloc_consistent(ioc->pcidev, total_size, &alloc_dma);
4500+
mem = dma_alloc_coherent(&ioc->pcidev->dev, total_size,
4501+
&alloc_dma, GFP_KERNEL);
45014502
if (mem == NULL) {
45024503
printk(MYIOC_s_ERR_FMT "Unable to allocate Reply, Request, Chain Buffers!\n",
45034504
ioc->name);
@@ -4574,8 +4575,8 @@ PrimeIocFifos(MPT_ADAPTER *ioc)
45744575
spin_unlock_irqrestore(&ioc->FreeQlock, flags);
45754576

45764577
sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
4577-
ioc->sense_buf_pool =
4578-
pci_alloc_consistent(ioc->pcidev, sz, &ioc->sense_buf_pool_dma);
4578+
ioc->sense_buf_pool = dma_alloc_coherent(&ioc->pcidev->dev, sz,
4579+
&ioc->sense_buf_pool_dma, GFP_KERNEL);
45794580
if (ioc->sense_buf_pool == NULL) {
45804581
printk(MYIOC_s_ERR_FMT "Unable to allocate Sense Buffers!\n",
45814582
ioc->name);
@@ -4613,18 +4614,16 @@ PrimeIocFifos(MPT_ADAPTER *ioc)
46134614

46144615
if (ioc->alloc != NULL) {
46154616
sz = ioc->alloc_sz;
4616-
pci_free_consistent(ioc->pcidev,
4617-
sz,
4618-
ioc->alloc, ioc->alloc_dma);
4617+
dma_free_coherent(&ioc->pcidev->dev, sz, ioc->alloc,
4618+
ioc->alloc_dma);
46194619
ioc->reply_frames = NULL;
46204620
ioc->req_frames = NULL;
46214621
ioc->alloc_total -= sz;
46224622
}
46234623
if (ioc->sense_buf_pool != NULL) {
46244624
sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
4625-
pci_free_consistent(ioc->pcidev,
4626-
sz,
4627-
ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
4625+
dma_free_coherent(&ioc->pcidev->dev, sz, ioc->sense_buf_pool,
4626+
ioc->sense_buf_pool_dma);
46284627
ioc->sense_buf_pool = NULL;
46294628
}
46304629

0 commit comments

Comments
 (0)