Skip to content

Commit e1280f3

Browse files
jiribohacakpm00
authored andcommitted
kdump: wait for DMA to finish when using CMA
When re-using the CMA area for kdump there is a risk of pending DMA into pinned user pages in the CMA area. Pages residing in CMA areas can usually not get long-term pinned and are instead migrated away from the CMA area, so long-term pinning is typically not a concern. (BUGs in the kernel might still lead to long-term pinning of such pages if everything goes wrong.) Pages pinned without FOLL_LONGTERM remain in the CMA and may possibly be the source or destination of a pending DMA transfer. Although there is no clear specification how long a page may be pinned without FOLL_LONGTERM, pinning without the flag shows an intent of the caller to only use the memory for short-lived DMA transfers, not a transfer initiated by a device asynchronously at a random time in the future. Add a delay of CMA_DMA_TIMEOUT_SEC seconds before starting the kdump kernel, giving such short-lived DMA transfers time to finish before the CMA memory is re-used by the kdump kernel. Set CMA_DMA_TIMEOUT_SEC to 10 seconds - chosen arbitrarily as both a huge margin for a DMA transfer, yet not increasing the kdump time too significantly. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Jiri Bohac <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Baoquan He <[email protected]> Cc: Dave Young <[email protected]> Cc: Donald Dutile <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Philipp Rudo <[email protected]> Cc: Pingfan Liu <[email protected]> Cc: Tao Liu <[email protected]> Cc: Vivek Goyal <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ce1bf19 commit e1280f3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

kernel/crash_core.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/reboot.h>
2222
#include <linux/btf.h>
2323
#include <linux/objtool.h>
24+
#include <linux/delay.h>
2425

2526
#include <asm/page.h>
2627
#include <asm/sections.h>
@@ -33,6 +34,11 @@
3334
/* Per cpu memory for storing cpu states in case of system crash. */
3435
note_buf_t __percpu *crash_notes;
3536

37+
/* time to wait for possible DMA to finish before starting the kdump kernel
38+
* when a CMA reservation is used
39+
*/
40+
#define CMA_DMA_TIMEOUT_SEC 10
41+
3642
#ifdef CONFIG_CRASH_DUMP
3743

3844
int kimage_crash_copy_vmcoreinfo(struct kimage *image)
@@ -97,6 +103,14 @@ int kexec_crash_loaded(void)
97103
}
98104
EXPORT_SYMBOL_GPL(kexec_crash_loaded);
99105

106+
static void crash_cma_clear_pending_dma(void)
107+
{
108+
if (!crashk_cma_cnt)
109+
return;
110+
111+
mdelay(CMA_DMA_TIMEOUT_SEC * 1000);
112+
}
113+
100114
/*
101115
* No panic_cpu check version of crash_kexec(). This function is called
102116
* only when panic_cpu holds the current CPU number; this is the only CPU
@@ -119,6 +133,7 @@ void __noclone __crash_kexec(struct pt_regs *regs)
119133
crash_setup_regs(&fixed_regs, regs);
120134
crash_save_vmcoreinfo();
121135
machine_crash_shutdown(&fixed_regs);
136+
crash_cma_clear_pending_dma();
122137
machine_kexec(kexec_crash_image);
123138
}
124139
kexec_unlock();

0 commit comments

Comments
 (0)