Why CMA allocater fails if there is a signal pending?

From: Peter Chen
Date: Mon Mar 25 2019 - 04:38:29 EST


Hi Michal & Marek,

I meet an issue that the DMA (CMA used) allocation failed if there is a user
signal, Eg Ctrl+C, it causes the USB xHCI stack fails to resume due to
dma_alloc_coherent
failed. It can be easy to reproduce if the user press Ctrl+C at
suspend/resume test.
Below is the call stack:

[ 466.585755] [<ffff000008192f9c>] alloc_contig_range+0x1ac/0x3b8
[ 466.585763] [<ffff00000820956c>] cma_alloc+0x10c/0x2d8
[ 466.585772] [<ffff0000086de1bc>] dma_alloc_from_contiguous+0x3c/0x48
[ 466.585779] [<ffff00000809bf20>] __dma_alloc+0xa8/0x248
[ 466.585788] [<ffff0000089121e0>] xhci_mem_init+0x1c8/0x7f8
[ 466.585794] [<ffff0000089074bc>] xhci_init+0x74/0x170
[ 466.585800] [<ffff00000890a21c>] xhci_resume+0x184/0x630
[ 466.585807] [<ffff0000088efec4>] cdns3_host_resume+0x34/0x68
[ 466.585813] [<ffff0000088ebfd8>] cdns3_resume+0x1b0/0x2d0
[ 466.585820] [<ffff0000086e3c10>] dpm_run_callback+0x50/0xd0
[ 466.585825] [<ffff0000086e42a0>] device_resume+0xa0/0x288
[ 466.585832] [<ffff0000086e5834>] dpm_resume+0xfc/0x218
[ 466.585837] [<ffff0000086e5b5c>] dpm_resume_end+0x14/0x28
[ 466.585844] [<ffff000008114630>] suspend_devices_and_enter+0x140/0x5b0
[ 466.585849] [<ffff000008114d34>] pm_suspend+0x294/0x300
[ 466.585857] [<ffff0000081136e4>] state_store+0x84/0x108
[ 466.585865] [<ffff000008de9a2c>] kobj_attr_store+0x14/0x28
[ 466.585873] [<ffff00000828cb90>] sysfs_kf_write+0x48/0x58
[ 466.585879] [<ffff00000828be34>] kernfs_fop_write+0xcc/0x1c8
[ 466.585886] [<ffff00000820e764>] __vfs_write+0x1c/0x118
[ 466.585894] [<ffff00000820ea4c>] vfs_write+0xa4/0x1b0
[ 466.585901] [<ffff00000820ecfc>] SyS_write+0x44/0xa0

I added WARN_ON at below code for above stack:
__alloc_contig_migrate_range
while (pfn < end || !list_empty(&cc->migratepages)) {
if (fatal_signal_pending(current)) {
WARN_ON(1);
ret = -EINTR;
break;
}

The USB xHCI function can work well if I commented out above code.
Thanks.

BR,
Peter Chen