usb: dma-mapping: prevent writeback deadlock in CMA allocator [1/1]
authorYue Wang <yue.wang@amlogic.com>
Tue, 16 Jul 2019 07:41:04 +0000 (15:41 +0800)
committerTao Zeng <tao.zeng@amlogic.com>
Tue, 16 Jul 2019 08:19:27 +0000 (01:19 -0700)
commit9ad60eaa9c491b3b6ecd507321abbee293fcd137
treef3114c165805506b6b4e5c2f0921fb650f036518
parentb398f1b75163d6dea766a6ae2510d7e56ed354cf
usb: dma-mapping: prevent writeback deadlock in CMA allocator [1/1]

PD#SWPL-11362

Problem:
A deadlock happens when a task initiates a CMA allocation that triggers
a page migration *AND* the tasks holding the subsequent pages have to
writeback their pages using CMA allocations.

In such a situation, the task that has triggered the page migration
holds a mutex that prevents other tasks from migrating their pages using
that same CMA allocator. This leads to a deadlock.

Solution:
The CMA is incapable of honoring the NOIO flags in some scenario, thus
cannot be used for writeback. The fix allows the code that chooses which
allocator to use in the ARM platform to avoid the CMA case for that
scenario.

The ARM DMA layer checks for allow blocking flag (_GFP_BDEV) to decide
whether to go for CMA or not. That test is not sufficient to cover the
case of writeback (GFP_NOIO).

The fix consists in adding a gfp_allow_writeback helper that tests for
the __GFP_IO flag. Then, the DMA layer uses it to decide not to go for
CMA in case of writeback.

Verify:
TL1

Change-Id: I175eb94de588234d3de2dc7f65dafe980e2636af
Signed-off-by: Yue Wang <yue.wang@amlogic.com>
arch/arm/mm/dma-mapping.c
drivers/usb/host/xhci.c