Linux Audio

Check our new training course

Loading...
v5.9
 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
 8struct page;
 9struct vm_area_struct;
10struct mm_struct;
 
11
12extern void dump_page(struct page *page, const char *reason);
13extern void __dump_page(struct page *page, const char *reason);
14void dump_vma(const struct vm_area_struct *vma);
15void 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(cond) (void)WARN_ON(cond)
41#define VM_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond)
42#define VM_WARN_ONCE(cond, format...) (void)WARN_ONCE(cond, format)
43#define VM_WARN(cond, format...) (void)WARN(cond, format)
44#else
45#define VM_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond)
46#define VM_BUG_ON_PAGE(cond, page) VM_BUG_ON(cond)
 
47#define VM_BUG_ON_VMA(cond, vma) VM_BUG_ON(cond)
48#define VM_BUG_ON_MM(cond, mm) VM_BUG_ON(cond)
49#define VM_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond)
50#define VM_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)
 
 
 
 
51#define VM_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond)
52#define VM_WARN(cond, format...) BUILD_BUG_ON_INVALID(cond)
 
 
 
 
 
 
53#endif
54
55#ifdef CONFIG_DEBUG_VIRTUAL
56#define VIRTUAL_BUG_ON(cond) BUG_ON(cond)
57#else
58#define VIRTUAL_BUG_ON(cond) do { } while (0)
59#endif
60
61#ifdef CONFIG_DEBUG_VM_PGFLAGS
62#define VM_BUG_ON_PGFLAGS(cond, page) VM_BUG_ON_PAGE(cond, page)
63#else
64#define VM_BUG_ON_PGFLAGS(cond, page) BUILD_BUG_ON_INVALID(cond)
65#endif
66
67#endif
v6.9.4
  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
  8struct page;
  9struct vm_area_struct;
 10struct mm_struct;
 11struct vma_iterator;
 12
 13void dump_page(const struct page *page, const char *reason);
 
 14void dump_vma(const struct vm_area_struct *vma);
 15void dump_mm(const struct mm_struct *mm);
 16void vma_iter_dump_tree(const struct vma_iterator *vmi);
 17
 18#ifdef CONFIG_DEBUG_VM
 19#define VM_BUG_ON(cond) BUG_ON(cond)
 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)
 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)
 34#define VM_BUG_ON_VMA(cond, vma)					\
 35	do {								\
 36		if (unlikely(cond)) {					\
 37			dump_vma(vma);					\
 38			BUG();						\
 39		}							\
 40	} while (0)
 41#define VM_BUG_ON_MM(cond, mm)						\
 42	do {								\
 43		if (unlikely(cond)) {					\
 44			dump_mm(mm);					\
 45			BUG();						\
 46		}							\
 47	} while (0)
 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})
 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})
 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})
 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})
 90
 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)
 95#else
 96#define VM_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond)
 97#define VM_BUG_ON_PAGE(cond, page) VM_BUG_ON(cond)
 98#define VM_BUG_ON_FOLIO(cond, folio) VM_BUG_ON(cond)
 99#define VM_BUG_ON_VMA(cond, vma) VM_BUG_ON(cond)
100#define VM_BUG_ON_MM(cond, mm) VM_BUG_ON(cond)
101#define VM_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond)
102#define VM_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)
103#define VM_WARN_ON_ONCE_PAGE(cond, page)  BUILD_BUG_ON_INVALID(cond)
104#define VM_WARN_ON_FOLIO(cond, folio)  BUILD_BUG_ON_INVALID(cond)
105#define VM_WARN_ON_ONCE_FOLIO(cond, folio)  BUILD_BUG_ON_INVALID(cond)
106#define VM_WARN_ON_ONCE_MM(cond, mm)  BUILD_BUG_ON_INVALID(cond)
107#define VM_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond)
108#define VM_WARN(cond, format...) BUILD_BUG_ON_INVALID(cond)
109#endif
110
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
117#ifdef CONFIG_DEBUG_VIRTUAL
118#define VIRTUAL_BUG_ON(cond) BUG_ON(cond)
119#else
120#define VIRTUAL_BUG_ON(cond) do { } while (0)
121#endif
122
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
129#endif