dma-coherent: report a failed reserved memory assignment
PATCH 1/1 dma-coherent: report a failed reserved memory assignment
rmem_dma_device_init() drops the return value of dma_assign_coherent_memory() and always reports success. That call fails with -EBUSY when the device already has a coherent pool, and the file allows only "*one* such region of memory" per device.
of_reserved_mem_device_init_by_idx() reads the zero as success. It logs "assigned reserved memory node" for a region that was not assigned and records the pairing, so of_reserved_mem_device_release() later runs rmem_dma_device_release() for it. That clears dev->dma_mem without looking at which region it was called for, dropping the pool the device did get and leaving it on ordinary memory.
dma_declare_coherent_memory() checks the same call and releases the memory on failure, and rmem_swiotlb_device_init() propagates its own errors. Return the error here as well, so a device tree that assigns two pools to one device fails the probe instead of half working.
---
Compile-tested only, with CONFIG_DMA_DECLARE_COHERENT=y and CONFIG_OF_RESERVED_MEM=y. I do not have a board that assigns two shared-dma-pool regions to one device; the release path was traced through of_reserved_mem_device_release() and rmem_dma_device_release() rather than observed.
kernel/dma/coherent.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/dma/coherent.c +1 -2
@@ -352,8 +352,7 @@ static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev) min_not_zero(dev->coherent_dma_mask, dev->bus_dma_limit))dev_warn (dev,"reserved memory is beyond device's set DMA address range\n" ); -dma_assign_coherent_memory (dev, mem); -return 0 ; +return dma_assign_coherent_memory (dev, mem); } static void rmem_dma_device_release(struct reserved_mem *rmem,
Signature · 1 line
2.53.0
Quoted 12 lines · Donggeun Yoo
rmem_dma_device_init()drops the return value ofdma_assign_coherent_memory()and always reports success. That call fails with-EBUSYwhen the device already has a coherent pool, and the file allows only "*one* such region of memory" per device.
of_reserved_mem_device_init_by_idx()reads the zero as success. It logs "assigned reserved memory node" for a region that was not assigned and records the pairing, soof_reserved_mem_device_release()later runsrmem_dma_device_release()for it. That clearsdev->dma_memwithout looking at which region it was called for, dropping the pool the device did get and leaving it on ordinary memory.
Quoted 7 lines
dma_declare_coherent_memory()checks the same call and releases the memory on failure, andrmem_swiotlb_device_init()propagates its own errors. Return the error here as well, so a device tree that assigns two pools to one device fails the probe instead of half working.Fixes 7bfa5ab6fa1b ("drivers: dma-coherent: add initialization from device tree")Signed-off-by Donggeun Yoo <[email protected]>
Applied to dma-mapping-fixes, thanks!
Quoted 15 lines
---
Compile-tested only, withCONFIG_DMA_DECLARE_COHERENT=yandCONFIG_OF_RESERVED_MEM=y. I do not have a board that assigns two shared-dma-pool regions to one device; the release path was traced throughof_reserved_mem_device_release()andrmem_dma_device_release()rather than observed.kernel/dma/coherent.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/dma/coherent.c +0
-0
kernel/dma/coherent.c static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev) · line 358
Quoted 9 lines
kernel/dma/coherent.c +1
-2@@ -352,8 +352,7 @@ static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev) min_not_zero(dev->coherent_dma_mask, dev->bus_dma_limit))dev_warn (dev,"reserved memory is beyond device's set DMA address range\n" ); -dma_assign_coherent_memory (dev, mem); -return 0 ; +return dma_assign_coherent_memory (dev, mem); } static void rmem_dma_device_release(struct reserved_mem *rmem,
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland