Revert "dma-contiguous: do not allocate a single page from CMA area"
Subsystems (2)
PATCH 1/1 Revert "dma-contiguous: do not allocate a single page from CMA area"
This reverts commit d222e42e88168fd67e6d131984b86477af1fc256.
The original change breaks omap dss:
omapdss_dispc 58001000.dispc:
dispc_errata_i734_wa_init: dma_alloc_writecombine failed
Let's revert it first and then find a safer solution instead.
---
Tony,
Would you please test and verify? Thanks!
kernel/dma/contiguous.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-)
kernel/dma/contiguous.c +3 -19
@@ -186,32 +186,16 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,* * This function allocates memory buffer for specified device. It uses * device specific contiguous memory area if available or the default -* global one. -* -* However, it skips one-page size of allocations from the global area. -* As the addresses within one page are always contiguous, so there is -* no need to waste CMA pages for that kind; it also helps reduce the -* fragmentations in the CMA area. So a caller should be the rebounder -* in such case to allocate a normal page upon NULL return value. -* -* Requires architecture specific dev_get_cma_area() helper function. +* global one. Requires architecture specific dev_get_cma_area() helper +* function. */ struct page *dma_alloc_from_contiguous (struct device *dev,size_t count,unsigned int align,bool no_warn) { -struct cma *cma; -if (align >CONFIG_CMA_ALIGNMENT ) align =CONFIG_CMA_ALIGNMENT ; -if (dev && dev->cma_area) - cma = dev->cma_area; -else if (count >1 ) - cma = dma_contiguous_default_area; -else -return NULL ; - -return cma_alloc (cma, count, align, no_warn); +return cma_alloc (dev_get_cma_area (dev), count, align, no_warn); }/**
Signature · 1 line
2.17.1
Robin Murphy
reviewerQuoted 7 lines · Nicolin Chen
This reverts commit
d222e42e88168fd67e6d131984b86477af1fc256.The original change breaks omap dss:
omapdss_dispc58001000.dispc:
dispc_errata_i734_wa_init:dma_alloc_writecombinefailedLet's revert it first and then find a safer solution instead.
Ah, I think I see the problem - once arch/arm's __dma_alloc() has decided to use CMA (because dev_get_cma_area(dev) returns the global area), it then won't fall back to trying a regular page allocation if dma_alloc_from_contiguous() returns NULL. Thus anything on 32-bit Arm trying to allocate a single-page buffer in blockable context with a CMA-enabled config is just going to fail. Similarly, it looks like none of the DMA_ATTR_FORCE_CONTIGUOUS cases are prepared to handle this change either (amd_iommu appears technically affected, but is already using dma_alloc_from_contiguous() backwards compared to everyone else, hmm).
I guess the question is whether to add alloc_page()/free_page() fallbacks to those call sites, or stuff them directly into the CMA helpers here.
Robin.
Quoted 51 lines
Reported-by Tony Lindgren <[email protected]>Signed-off-by Nicolin Chen <[email protected]>---
Tony,Would you please test and verify? Thanks!
kernel/dma/contiguous.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-)kernel/dma/contiguous.c +3
-19@@ -186,32 +186,16 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,* * This function allocates memory buffer for specified device. It uses * device specific contiguous memory area if available or the default -* global one. -* -* However, it skips one-page size of allocations from the global area. -* As the addresses within one page are always contiguous, so there is -* no need to waste CMA pages for that kind; it also helps reduce the -* fragmentations in the CMA area. So a caller should be the rebounder -* in such case to allocate a normal page upon NULL return value. -* -* Requires architecture specific dev_get_cma_area() helper function. +* global one. Requires architecture specific dev_get_cma_area() helper +* function. */ struct page *dma_alloc_from_contiguous (struct device *dev,size_t count,unsigned int align,bool no_warn) { -struct cma *cma; -if (align >CONFIG_CMA_ALIGNMENT ) align =CONFIG_CMA_ALIGNMENT ; -if (dev && dev->cma_area) - cma = dev->cma_area; -else if (count >1 ) - cma = dma_contiguous_default_area; -else -return NULL ; - -return cma_alloc (cma, count, align, no_warn); +return cma_alloc (dev_get_cma_area (dev), count, align, no_warn); }/**
Tony Lindgren
Tested-byQuoted 8 lines · Robin Murphy
Quoted 7 lines · Nicolin Chen
This reverts commit
d222e42e88168fd67e6d131984b86477af1fc256.The original change breaks omap dss:
omapdss_dispc58001000.dispc:
dispc_errata_i734_wa_init:dma_alloc_writecombinefailedLet's revert it first and then find a safer solution instead.
Sounds like a good idea since we're only have few days left before the merge window.
Quoted 10 lines
Ah, I think I see the problem - once arch/arm's
__dma_alloc()has decided to use CMA (becausedev_get_cma_area(dev)returns the global area), it then won't fall back to trying a regular page allocation ifdma_alloc_from_contiguous()returns NULL. Thus anything on 32-bit Arm trying to allocate a single-page buffer in blockable context with a CMA-enabled config is just going to fail. Similarly, it looks like none of theDMA_ATTR_FORCE_CONTIGUOUScases are prepared to handle this change either (amd_iommuappears technically affected, but is already usingdma_alloc_from_contiguous()backwards compared to everyone else, hmm).
Quoted 2 lines
I guess the question is whether to add alloc_page()/free_page() fallbacks to those call sites, or stuff them directly into the CMA helpers here.
Well if you come up with some test patch, I can easily test it :)
Quoted 1 line
Quoted 1 line
Would you please test and verify? Thanks!
Yes this revert works for me:
Quoted 9 lines · Robin Murphy
Quoted 7 lines · Nicolin Chen
This reverts commit
d222e42e88168fd67e6d131984b86477af1fc256.The original change breaks omap dss:
omapdss_dispc58001000.dispc:
dispc_errata_i734_wa_init:dma_alloc_writecombinefailedLet's revert it first and then find a safer solution instead.
Quoted 9 lines
Ah, I think I see the problem - once arch/arm's
__dma_alloc()has decided to use CMA (becausedev_get_cma_area(dev)returns the global area), it then won't fall back to trying a regular page allocation ifdma_alloc_from_contiguous()returns NULL. Thus anything on 32-bit Arm trying to allocate a single-page buffer in blockable context with a CMA-enabled config is just going to fail. Similarly, it looks like none of theDMA_ATTR_FORCE_CONTIGUOUScases are prepared to handle this change either (amd_iommuappears technically affected, but is already usingdma_alloc_from_contiguous()backwards compared to everyone else, hmm).
Yea, I searched the tree and got the same results.
Quoted 2 lines
I guess the question is whether to add alloc_page()/free_page() fallbacks to those call sites, or stuff them directly into the CMA helpers here.
Probably would be safer/easier to do the later one I feel.
Quoted 11 lines · Nicolin Chen
This reverts commit
d222e42e88168fd67e6d131984b86477af1fc256.The original change breaks omap dss:
omapdss_dispc58001000.dispc:
dispc_errata_i734_wa_init:dma_alloc_writecombinefailedLet's revert it first and then find a safer solution instead.
Reported-by Tony Lindgren <[email protected]>Signed-off-by Nicolin Chen <[email protected]>
Quoted 7 lines
---
Tony,Would you please test and verify? Thanks!
kernel/dma/contiguous.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-)
This fixes broken (since yesterday) linux-next on Exynos boards (ARMv7), errors like:
dma-pl330: probe of 121a0000.pdma failed with error -12 exynos-ehci 12110000.usb: can't setup: -12 exynos-ehci 12110000.usb: USB bus 1 deregistered exynos-ehci 12110000.usb: Failed to add USB HCD
Best regards,
Krzysztof
Quoted 6 lines · Nicolin Chen
This reverts commit
d222e42e88168fd67e6d131984b86477af1fc256.The original change breaks omap dss:
omapdss_dispc58001000.dispc:
dispc_errata_i734_wa_init:dma_alloc_writecombinefailed
Quoted 8 lines
Let's revert it first and then find a safer solution instead.
Reported-by Tony Lindgren <[email protected]>Signed-off-by Nicolin Chen <[email protected]>---
Tony,Would you please test and verify? Thanks!
This also fixes various memory allocation failures we have seen on 32-bit Tegra as well.
Cheers
Jon
Signature · 1 line
nvpublic