Skip to content

Commit 8378138

Browse files
Gerd Bayerdavem330
Gerd Bayer
authored andcommitted
s390/ism: Properly 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 cb178cc commit 8378138

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

drivers/s390/net/ism_drv.c

+28-9
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,16 @@ static int ism_read_local_gid(struct ism_dev *ism)
292292
static void ism_free_dmb(struct ism_dev *ism, struct ism_dmb *dmb)
293293
{
294294
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);
295+
dma_unmap_page(&ism->pdev->dev, dmb->dma_addr, dmb->dmb_len,
296+
DMA_FROM_DEVICE);
297+
folio_put(virt_to_folio(dmb->cpu_addr));
297298
}
298299

299300
static int ism_alloc_dmb(struct ism_dev *ism, struct ism_dmb *dmb)
300301
{
302+
struct folio *folio;
301303
unsigned long bit;
304+
int rc;
302305

303306
if (PAGE_ALIGN(dmb->dmb_len) > dma_get_max_seg_size(&ism->pdev->dev))
304307
return -EINVAL;
@@ -315,14 +318,30 @@ static int ism_alloc_dmb(struct ism_dev *ism, struct ism_dmb *dmb)
315318
test_and_set_bit(dmb->sba_idx, ism->sba_bitmap))
316319
return -EINVAL;
317320

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);
321+
folio = folio_alloc(GFP_KERNEL | __GFP_NOWARN | __GFP_NOMEMALLOC |
322+
__GFP_NORETRY, get_order(dmb->dmb_len));
324323

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

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

0 commit comments

Comments
 (0)