blob: 451a811f48f262cd951a69755b8e30fbb0cb1ce9 [file] [log] [blame]
Jiri Slaby59ea7462008-06-12 13:56:40 +02001#ifndef LINUX_MM_DEBUG_H
2#define LINUX_MM_DEBUG_H 1
3
James Morse1d5cda42015-12-18 14:22:07 -08004#include <linux/bug.h>
Dave Hansene4f67422014-06-04 16:07:02 -07005#include <linux/stringify.h>
6
Sasha Levin309381fea2014-01-23 15:52:54 -08007struct page;
Sasha Levin0bf55132014-10-09 15:28:06 -07008struct vm_area_struct;
Sasha Levin31c9afa2014-10-09 15:28:37 -07009struct mm_struct;
Sasha Levin309381fea2014-01-23 15:52:54 -080010
Kirill A. Shutemovd230dec2014-04-07 15:37:38 -070011extern void dump_page(struct page *page, const char *reason);
Vlastimil Babkaff8e8112016-03-15 14:56:24 -070012extern void __dump_page(struct page *page, const char *reason);
Sasha Levin0bf55132014-10-09 15:28:06 -070013void dump_vma(const struct vm_area_struct *vma);
Sasha Levin31c9afa2014-10-09 15:28:37 -070014void dump_mm(const struct mm_struct *mm);
Sasha Levin309381fea2014-01-23 15:52:54 -080015
Jiri Slaby59ea7462008-06-12 13:56:40 +020016#ifdef CONFIG_DEBUG_VM
17#define VM_BUG_ON(cond) BUG_ON(cond)
Dave Hansene4f67422014-06-04 16:07:02 -070018#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)
Sasha Levinfa3759c2014-10-09 15:28:08 -070025#define VM_BUG_ON_VMA(cond, vma) \
26 do { \
27 if (unlikely(cond)) { \
28 dump_vma(vma); \
29 BUG(); \
30 } \
31 } while (0)
Sasha Levin31c9afa2014-10-09 15:28:37 -070032#define VM_BUG_ON_MM(cond, mm) \
33 do { \
34 if (unlikely(cond)) { \
35 dump_mm(mm); \
36 BUG(); \
37 } \
38 } while (0)
Andrew Morton02a8efe2014-06-04 16:06:59 -070039#define VM_WARN_ON(cond) WARN_ON(cond)
40#define VM_WARN_ON_ONCE(cond) WARN_ON_ONCE(cond)
Andrew Mortonef6b5712014-08-06 16:06:30 -070041#define VM_WARN_ONCE(cond, format...) WARN_ONCE(cond, format)
Aneesh Kumar K.Va54f9ae2016-07-26 15:22:36 -070042#define VM_WARN(cond, format...) WARN(cond, format)
Jiri Slaby59ea7462008-06-12 13:56:40 +020043#else
Konstantin Khlebnikov02602a12012-05-29 15:06:28 -070044#define VM_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond)
Sasha Levin309381fea2014-01-23 15:52:54 -080045#define VM_BUG_ON_PAGE(cond, page) VM_BUG_ON(cond)
Sasha Levinfa3759c2014-10-09 15:28:08 -070046#define VM_BUG_ON_VMA(cond, vma) VM_BUG_ON(cond)
Sasha Levin31c9afa2014-10-09 15:28:37 -070047#define VM_BUG_ON_MM(cond, mm) VM_BUG_ON(cond)
Andrew Morton02a8efe2014-06-04 16:06:59 -070048#define VM_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond)
49#define VM_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)
Andrew Mortonef6b5712014-08-06 16:06:30 -070050#define VM_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond)
Aneesh Kumar K.Va54f9ae2016-07-26 15:22:36 -070051#define VM_WARN(cond, format...) BUILD_BUG_ON_INVALID(cond)
Jiri Slaby59ea7462008-06-12 13:56:40 +020052#endif
53
54#ifdef CONFIG_DEBUG_VIRTUAL
55#define VIRTUAL_BUG_ON(cond) BUG_ON(cond)
56#else
Ingo Molnar7aa413d2008-06-19 13:28:11 +020057#define VIRTUAL_BUG_ON(cond) do { } while (0)
Jiri Slaby59ea7462008-06-12 13:56:40 +020058#endif
59
Kirill A. Shutemov95ad9752016-01-15 16:51:21 -080060#ifdef CONFIG_DEBUG_VM_PGFLAGS
61#define VM_BUG_ON_PGFLAGS(cond, page) VM_BUG_ON_PAGE(cond, page)
62#else
63#define VM_BUG_ON_PGFLAGS(cond, page) BUILD_BUG_ON_INVALID(cond)
64#endif
65
Jiri Slaby59ea7462008-06-12 13:56:40 +020066#endif