Skip to content

Commit 58effa3

Browse files
Gerd Bayerdavem330
authored andcommitted
s390/ism: fix receive message buffer allocation
Since [1], dma_alloc_coherent() does not accept requests for GFP_COMP anymore, even on archs that may be able to fulfill this. Functionality that relied on the receive buffer being a compound page broke at that point: The SMC-D protocol, that utilizes the ism device driver, passes receive buffers to the splice processor in a struct splice_pipe_desc with a single entry list of struct pages. As the buffer is no longer a compound page, the splice processor now rejects requests to handle more than a page worth of data. Replace dma_alloc_coherent() and allocate a buffer with folio_alloc and create a DMA map for it with dma_map_page(). Since only receive buffers on ISM devices use DMA, qualify the mapping as FROM_DEVICE. Since ISM devices are available on arch s390, only and on that arch all DMA is coherent, there is no need to introduce and export some kind of dma_sync_to_cpu() method to be called by the SMC-D protocol layer. Analogously, replace dma_free_coherent by a two step dma_unmap_page, then folio_put to free the receive buffer. [1] https://lore.kernel.org/all/[email protected]/ Fixes: c08004e ("s390/ism: don't pass bogus GFP_ flags to dma_alloc_coherent") Signed-off-by: Gerd Bayer <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d8a6213 commit 58effa3

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

drivers/s390/net/ism_drv.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <linux/err.h>
1515
#include <linux/ctype.h>
1616
#include <linux/processor.h>
17+
#include <linux/dma-mapping.h>
18+
#include <linux/mm.h>
1719

1820
#include "ism.h"
1921

@@ -292,13 +294,15 @@ static int ism_read_local_gid(struct ism_dev *ism)
292294
static void ism_free_dmb(struct ism_dev *ism, struct ism_dmb *dmb)
293295
{
294296
clear_bit(dmb->sba_idx, ism->sba_bitmap);
295-
dma_free_coherent(&ism->pdev->dev, dmb->dmb_len,
296-
dmb->cpu_addr, dmb->dma_addr);
297+
dma_unmap_page(&ism->pdev->dev, dmb->dma_addr, dmb->dmb_len,
298+
DMA_FROM_DEVICE);
299+
folio_put(virt_to_folio(dmb->cpu_addr));
297300
}
298301

299302
static int ism_alloc_dmb(struct ism_dev *ism, struct ism_dmb *dmb)
300303
{
301304
unsigned long bit;
305+
int rc;
302306

303307
if (PAGE_ALIGN(dmb->dmb_len) > dma_get_max_seg_size(&ism->pdev->dev))
304308
return -EINVAL;
@@ -315,14 +319,30 @@ static int ism_alloc_dmb(struct ism_dev *ism, struct ism_dmb *dmb)
315319
test_and_set_bit(dmb->sba_idx, ism->sba_bitmap))
316320
return -EINVAL;
317321

318-
dmb->cpu_addr = dma_alloc_coherent(&ism->pdev->dev, dmb->dmb_len,
319-
&dmb->dma_addr,
320-
GFP_KERNEL | __GFP_NOWARN |
321-
__GFP_NOMEMALLOC | __GFP_NORETRY);
322-
if (!dmb->cpu_addr)
323-
clear_bit(dmb->sba_idx, ism->sba_bitmap);
322+
dmb->cpu_addr =
323+
folio_address(folio_alloc(GFP_KERNEL | __GFP_NOWARN |
324+
__GFP_NOMEMALLOC | __GFP_NORETRY,
325+
get_order(dmb->dmb_len)));
324326

325-
return dmb->cpu_addr ? 0 : -ENOMEM;
327+
if (!dmb->cpu_addr) {
328+
rc = -ENOMEM;
329+
goto out_bit;
330+
}
331+
dmb->dma_addr = dma_map_page(&ism->pdev->dev,
332+
virt_to_page(dmb->cpu_addr), 0,
333+
dmb->dmb_len, DMA_FROM_DEVICE);
334+
if (dma_mapping_error(&ism->pdev->dev, dmb->dma_addr)) {
335+
rc = -ENOMEM;
336+
goto out_free;
337+
}
338+
339+
return 0;
340+
341+
out_free:
342+
kfree(dmb->cpu_addr);
343+
out_bit:
344+
clear_bit(dmb->sba_idx, ism->sba_bitmap);
345+
return rc;
326346
}
327347

328348
int ism_register_dmb(struct ism_dev *ism, struct ism_dmb *dmb,

0 commit comments

Comments
 (0)