s390/Kconfig: sort config S390 select list once again
[linux-2.6-microblaze.git] / include / linux / mmdebug.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef LINUX_MM_DEBUG_H
3 #define LINUX_MM_DEBUG_H 1
4
5 #include <linux/bug.h>
6 #include <linux/stringify.h>
7
8 struct page;
9 struct vm_area_struct;
10 struct mm_struct;
11
12 extern void dump_page(struct page *page, const char *reason);
13 extern void __dump_page(struct page *page, const char *reason);
14 void dump_vma(const struct vm_area_struct *vma);
15 void dump_mm(const struct mm_struct *mm);
16
17 #ifdef CONFIG_DEBUG_VM
18 #define VM_BUG_ON(cond) BUG_ON(cond)
19 #define VM_BUG_ON_PAGE(cond, page)                                      \
20         do {                                                            \
21                 if (unlikely(cond)) {                                   \
22                         dump_page(page, "VM_BUG_ON_PAGE(" __stringify(cond)")");\
23                         BUG();                                          \
24                 }                                                       \
25         } while (0)
26 #define VM_BUG_ON_VMA(cond, vma)                                        \
27         do {                                                            \
28                 if (unlikely(cond)) {                                   \
29                         dump_vma(vma);                                  \
30                         BUG();                                          \
31                 }                                                       \
32         } while (0)
33 #define VM_BUG_ON_MM(cond, mm)                                          \
34         do {                                                            \
35                 if (unlikely(cond)) {                                   \
36                         dump_mm(mm);                                    \
37                         BUG();                                          \
38                 }                                                       \
39         } while (0)
40 #define VM_WARN_ON_ONCE_PAGE(cond, page)        ({                      \
41         static bool __section(".data.once") __warned;                   \
42         int __ret_warn_once = !!(cond);                                 \
43                                                                         \
44         if (unlikely(__ret_warn_once && !__warned)) {                   \
45                 dump_page(page, "VM_WARN_ON_ONCE_PAGE(" __stringify(cond)")");\
46                 __warned = true;                                        \
47                 WARN_ON(1);                                             \
48         }                                                               \
49         unlikely(__ret_warn_once);                                      \
50 })
51
52 #define VM_WARN_ON(cond) (void)WARN_ON(cond)
53 #define VM_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond)
54 #define VM_WARN_ONCE(cond, format...) (void)WARN_ONCE(cond, format)
55 #define VM_WARN(cond, format...) (void)WARN(cond, format)
56 #else
57 #define VM_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond)
58 #define VM_BUG_ON_PAGE(cond, page) VM_BUG_ON(cond)
59 #define VM_BUG_ON_VMA(cond, vma) VM_BUG_ON(cond)
60 #define VM_BUG_ON_MM(cond, mm) VM_BUG_ON(cond)
61 #define VM_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond)
62 #define VM_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)
63 #define VM_WARN_ON_ONCE_PAGE(cond, page)  BUILD_BUG_ON_INVALID(cond)
64 #define VM_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond)
65 #define VM_WARN(cond, format...) BUILD_BUG_ON_INVALID(cond)
66 #endif
67
68 #ifdef CONFIG_DEBUG_VIRTUAL
69 #define VIRTUAL_BUG_ON(cond) BUG_ON(cond)
70 #else
71 #define VIRTUAL_BUG_ON(cond) do { } while (0)
72 #endif
73
74 #ifdef CONFIG_DEBUG_VM_PGFLAGS
75 #define VM_BUG_ON_PGFLAGS(cond, page) VM_BUG_ON_PAGE(cond, page)
76 #else
77 #define VM_BUG_ON_PGFLAGS(cond, page) BUILD_BUG_ON_INVALID(cond)
78 #endif
79
80 #endif