]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
59ea7463 JS |
2 | #ifndef LINUX_MM_DEBUG_H |
3 | #define LINUX_MM_DEBUG_H 1 | |
4 | ||
1d5cda40 | 5 | #include <linux/bug.h> |
e4f67422 DH |
6 | #include <linux/stringify.h> |
7 | ||
309381fe | 8 | struct page; |
0bf55139 | 9 | struct vm_area_struct; |
31c9afa6 | 10 | struct mm_struct; |
309381fe | 11 | |
d2f07ec0 | 12 | void dump_page(struct page *page, const char *reason); |
0bf55139 | 13 | void dump_vma(const struct vm_area_struct *vma); |
31c9afa6 | 14 | void dump_mm(const struct mm_struct *mm); |
309381fe | 15 | |
59ea7463 JS |
16 | #ifdef CONFIG_DEBUG_VM |
17 | #define VM_BUG_ON(cond) BUG_ON(cond) | |
e4f67422 DH |
18 | #define VM_BUG_ON_PAGE(cond, page) \ |
19 | do { \ | |
20 | if (unlikely(cond)) { \ | |
21 | dump_page(page, "VM_BUG_ON_PAGE(" __stringify(cond)")");\ | |
22 | BUG(); \ | |
23 | } \ | |
24 | } while (0) | |
fa3759cc SL |
25 | #define VM_BUG_ON_VMA(cond, vma) \ |
26 | do { \ | |
27 | if (unlikely(cond)) { \ | |
28 | dump_vma(vma); \ | |
29 | BUG(); \ | |
30 | } \ | |
31 | } while (0) | |
31c9afa6 SL |
32 | #define VM_BUG_ON_MM(cond, mm) \ |
33 | do { \ | |
34 | if (unlikely(cond)) { \ | |
35 | dump_mm(mm); \ | |
36 | BUG(); \ | |
37 | } \ | |
38 | } while (0) | |
a4055888 AS |
39 | #define VM_WARN_ON_ONCE_PAGE(cond, page) ({ \ |
40 | static bool __section(".data.once") __warned; \ | |
41 | int __ret_warn_once = !!(cond); \ | |
42 | \ | |
43 | if (unlikely(__ret_warn_once && !__warned)) { \ | |
44 | dump_page(page, "VM_WARN_ON_ONCE_PAGE(" __stringify(cond)")");\ | |
45 | __warned = true; \ | |
46 | WARN_ON(1); \ | |
47 | } \ | |
48 | unlikely(__ret_warn_once); \ | |
49 | }) | |
50 | ||
91241681 MH |
51 | #define VM_WARN_ON(cond) (void)WARN_ON(cond) |
52 | #define VM_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond) | |
53 | #define VM_WARN_ONCE(cond, format...) (void)WARN_ONCE(cond, format) | |
54 | #define VM_WARN(cond, format...) (void)WARN(cond, format) | |
59ea7463 | 55 | #else |
02602a18 | 56 | #define VM_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond) |
309381fe | 57 | #define VM_BUG_ON_PAGE(cond, page) VM_BUG_ON(cond) |
fa3759cc | 58 | #define VM_BUG_ON_VMA(cond, vma) VM_BUG_ON(cond) |
31c9afa6 | 59 | #define VM_BUG_ON_MM(cond, mm) VM_BUG_ON(cond) |
02a8efed AM |
60 | #define VM_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond) |
61 | #define VM_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond) | |
a4055888 | 62 | #define VM_WARN_ON_ONCE_PAGE(cond, page) BUILD_BUG_ON_INVALID(cond) |
ef6b571f | 63 | #define VM_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond) |
a54f9aeb | 64 | #define VM_WARN(cond, format...) BUILD_BUG_ON_INVALID(cond) |
59ea7463 JS |
65 | #endif |
66 | ||
67 | #ifdef CONFIG_DEBUG_VIRTUAL | |
68 | #define VIRTUAL_BUG_ON(cond) BUG_ON(cond) | |
69 | #else | |
7aa413de | 70 | #define VIRTUAL_BUG_ON(cond) do { } while (0) |
59ea7463 JS |
71 | #endif |
72 | ||
95ad9755 KS |
73 | #ifdef CONFIG_DEBUG_VM_PGFLAGS |
74 | #define VM_BUG_ON_PGFLAGS(cond, page) VM_BUG_ON_PAGE(cond, page) | |
75 | #else | |
76 | #define VM_BUG_ON_PGFLAGS(cond, page) BUILD_BUG_ON_INVALID(cond) | |
77 | #endif | |
78 | ||
59ea7463 | 79 | #endif |