Linux 6.10-rc4
[linux-block.git] / include / linux / mmdebug.h
CommitLineData
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 8struct page;
0bf55139 9struct vm_area_struct;
31c9afa6 10struct mm_struct;
b50e195f 11struct vma_iterator;
309381fe 12
b3a32033 13void dump_page(const struct page *page, const char *reason);
0bf55139 14void dump_vma(const struct vm_area_struct *vma);
31c9afa6 15void dump_mm(const struct mm_struct *mm);
b50e195f 16void vma_iter_dump_tree(const struct vma_iterator *vmi);
309381fe 17
59ea7463
JS
18#ifdef CONFIG_DEBUG_VM
19#define VM_BUG_ON(cond) BUG_ON(cond)
e4f67422
DH
20#define VM_BUG_ON_PAGE(cond, page) \
21 do { \
22 if (unlikely(cond)) { \
23 dump_page(page, "VM_BUG_ON_PAGE(" __stringify(cond)")");\
24 BUG(); \
25 } \
26 } while (0)
9e9edb20
MWO
27#define VM_BUG_ON_FOLIO(cond, folio) \
28 do { \
29 if (unlikely(cond)) { \
30 dump_page(&folio->page, "VM_BUG_ON_FOLIO(" __stringify(cond)")");\
31 BUG(); \
32 } \
33 } while (0)
fa3759cc
SL
34#define VM_BUG_ON_VMA(cond, vma) \
35 do { \
36 if (unlikely(cond)) { \
37 dump_vma(vma); \
38 BUG(); \
39 } \
40 } while (0)
31c9afa6
SL
41#define VM_BUG_ON_MM(cond, mm) \
42 do { \
43 if (unlikely(cond)) { \
44 dump_mm(mm); \
45 BUG(); \
46 } \
47 } while (0)
a4055888
AS
48#define VM_WARN_ON_ONCE_PAGE(cond, page) ({ \
49 static bool __section(".data.once") __warned; \
50 int __ret_warn_once = !!(cond); \
51 \
52 if (unlikely(__ret_warn_once && !__warned)) { \
53 dump_page(page, "VM_WARN_ON_ONCE_PAGE(" __stringify(cond)")");\
54 __warned = true; \
55 WARN_ON(1); \
56 } \
57 unlikely(__ret_warn_once); \
58})
020bc44a
JL
59#define VM_WARN_ON_FOLIO(cond, folio) ({ \
60 int __ret_warn = !!(cond); \
61 \
62 if (unlikely(__ret_warn)) { \
63 dump_page(&folio->page, "VM_WARN_ON_FOLIO(" __stringify(cond)")");\
64 WARN_ON(1); \
65 } \
66 unlikely(__ret_warn); \
67})
9e9edb20
MWO
68#define VM_WARN_ON_ONCE_FOLIO(cond, folio) ({ \
69 static bool __section(".data.once") __warned; \
70 int __ret_warn_once = !!(cond); \
71 \
72 if (unlikely(__ret_warn_once && !__warned)) { \
73 dump_page(&folio->page, "VM_WARN_ON_ONCE_FOLIO(" __stringify(cond)")");\
74 __warned = true; \
75 WARN_ON(1); \
76 } \
77 unlikely(__ret_warn_once); \
78})
b50e195f
LH
79#define VM_WARN_ON_ONCE_MM(cond, mm) ({ \
80 static bool __section(".data.once") __warned; \
81 int __ret_warn_once = !!(cond); \
82 \
83 if (unlikely(__ret_warn_once && !__warned)) { \
84 dump_mm(mm); \
85 __warned = true; \
86 WARN_ON(1); \
87 } \
88 unlikely(__ret_warn_once); \
89})
a4055888 90
91241681
MH
91#define VM_WARN_ON(cond) (void)WARN_ON(cond)
92#define VM_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond)
93#define VM_WARN_ONCE(cond, format...) (void)WARN_ONCE(cond, format)
94#define VM_WARN(cond, format...) (void)WARN(cond, format)
59ea7463 95#else
02602a18 96#define VM_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond)
309381fe 97#define VM_BUG_ON_PAGE(cond, page) VM_BUG_ON(cond)
9e9edb20 98#define VM_BUG_ON_FOLIO(cond, folio) VM_BUG_ON(cond)
fa3759cc 99#define VM_BUG_ON_VMA(cond, vma) VM_BUG_ON(cond)
31c9afa6 100#define VM_BUG_ON_MM(cond, mm) VM_BUG_ON(cond)
02a8efed
AM
101#define VM_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond)
102#define VM_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)
a4055888 103#define VM_WARN_ON_ONCE_PAGE(cond, page) BUILD_BUG_ON_INVALID(cond)
020bc44a 104#define VM_WARN_ON_FOLIO(cond, folio) BUILD_BUG_ON_INVALID(cond)
9e9edb20 105#define VM_WARN_ON_ONCE_FOLIO(cond, folio) BUILD_BUG_ON_INVALID(cond)
b50e195f 106#define VM_WARN_ON_ONCE_MM(cond, mm) BUILD_BUG_ON_INVALID(cond)
ef6b571f 107#define VM_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond)
a54f9aeb 108#define VM_WARN(cond, format...) BUILD_BUG_ON_INVALID(cond)
59ea7463
JS
109#endif
110
a738e9ba
TG
111#ifdef CONFIG_DEBUG_VM_IRQSOFF
112#define VM_WARN_ON_IRQS_ENABLED() WARN_ON_ONCE(!irqs_disabled())
113#else
114#define VM_WARN_ON_IRQS_ENABLED() do { } while (0)
115#endif
116
59ea7463
JS
117#ifdef CONFIG_DEBUG_VIRTUAL
118#define VIRTUAL_BUG_ON(cond) BUG_ON(cond)
119#else
7aa413de 120#define VIRTUAL_BUG_ON(cond) do { } while (0)
59ea7463
JS
121#endif
122
95ad9755
KS
123#ifdef CONFIG_DEBUG_VM_PGFLAGS
124#define VM_BUG_ON_PGFLAGS(cond, page) VM_BUG_ON_PAGE(cond, page)
125#else
126#define VM_BUG_ON_PGFLAGS(cond, page) BUILD_BUG_ON_INVALID(cond)
127#endif
128
59ea7463 129#endif