Skip to content

Commit d778bb9

Browse files
sashalevinsfrothwell
authored andcommitted
mm: introduce VM_BUG_ON_MM
Very similar to VM_BUG_ON_PAGE and VM_BUG_ON_VMA, dump struct_mm when the bug is hit. Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 475e447 commit d778bb9

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

include/linux/mmdebug.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
struct page;
77
struct vm_area_struct;
8+
struct mm_struct;
89

910
extern void dump_page(struct page *page, const char *reason);
1011
extern void dump_page_badflags(struct page *page, const char *reason,
1112
unsigned long badflags);
1213
void dump_vma(const struct vm_area_struct *vma);
14+
void dump_mm(const struct mm_struct *mm);
1315

1416
#ifdef CONFIG_DEBUG_VM
1517
#define VM_BUG_ON(cond) BUG_ON(cond)
@@ -27,13 +29,21 @@ void dump_vma(const struct vm_area_struct *vma);
2729
BUG(); \
2830
} \
2931
} while (0)
32+
#define VM_BUG_ON_MM(cond, mm) \
33+
do { \
34+
if (unlikely(cond)) { \
35+
dump_mm(mm); \
36+
BUG(); \
37+
} \
38+
} while (0)
3039
#define VM_WARN_ON(cond) WARN_ON(cond)
3140
#define VM_WARN_ON_ONCE(cond) WARN_ON_ONCE(cond)
3241
#define VM_WARN_ONCE(cond, format...) WARN_ONCE(cond, format)
3342
#else
3443
#define VM_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond)
3544
#define VM_BUG_ON_PAGE(cond, page) VM_BUG_ON(cond)
3645
#define VM_BUG_ON_VMA(cond, vma) VM_BUG_ON(cond)
46+
#define VM_BUG_ON_MM(cond, mm) VM_BUG_ON(cond)
3747
#define VM_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond)
3848
#define VM_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)
3949
#define VM_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond)

mm/debug.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* mm/debug.c
3+
*
4+
* mm/ specific debug routines.
5+
*
6+
*/
7+
18
#include <linux/kernel.h>
29
#include <linux/mm.h>
310
#include <linux/ftrace_event.h>
@@ -159,4 +166,66 @@ void dump_vma(const struct vm_area_struct *vma)
159166
}
160167
EXPORT_SYMBOL(dump_vma);
161168

169+
void dump_mm(const struct mm_struct *mm)
170+
{
171+
printk(KERN_ALERT
172+
"mm %p mmap %p seqnum %d task_size %lu\n"
173+
#ifdef CONFIG_MMU
174+
"get_unmapped_area %p\n"
175+
#endif
176+
"mmap_base %lu mmap_legacy_base %lu highest_vm_end %lu\n"
177+
"pgd %p mm_users %d mm_count %d nr_ptes %lu map_count %d\n"
178+
"hiwater_rss %lx hiwater_vm %lx total_vm %lx locked_vm %lx\n"
179+
"pinned_vm %lx shared_vm %lx exec_vm %lx stack_vm %lx\n"
180+
"start_code %lx end_code %lx start_data %lx end_data %lx\n"
181+
"start_brk %lx brk %lx start_stack %lx\n"
182+
"arg_start %lx arg_end %lx env_start %lx env_end %lx\n"
183+
"binfmt %p flags %lx core_state %p\n"
184+
#ifdef CONFIG_AIO
185+
"ioctx_table %p\n"
186+
#endif
187+
"owner %p exe_file %p\n"
188+
#ifdef CONFIG_MMU_NOTIFIER
189+
"mmu_notifier_mm %p\n"
190+
#endif
191+
#ifdef CONFIG_NUMA_BALANCING
192+
"numa_next_scan %lu numa_scan_offset %lu numa_scan_seq %d\n"
193+
#endif
194+
#if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
195+
"tlb_flush_pending %d\n",
196+
#endif
197+
mm, mm->mmap, mm->vmacache_seqnum, mm->task_size,
198+
#ifdef CONFIG_MMU
199+
mm->get_unmapped_area,
200+
#endif
201+
mm->mmap_base, mm->mmap_legacy_base, mm->highest_vm_end,
202+
mm->pgd, atomic_read(&mm->mm_users),
203+
atomic_read(&mm->mm_count),
204+
atomic_long_read((atomic_long_t *)&mm->nr_ptes),
205+
mm->map_count,
206+
mm->hiwater_rss, mm->hiwater_vm, mm->total_vm, mm->locked_vm,
207+
mm->pinned_vm, mm->shared_vm, mm->exec_vm, mm->stack_vm,
208+
mm->start_code, mm->end_code, mm->start_data, mm->end_data,
209+
mm->start_brk, mm->brk, mm->start_stack,
210+
mm->arg_start, mm->arg_end, mm->env_start, mm->env_end,
211+
mm->binfmt, mm->flags, mm->core_state,
212+
#ifdef CONFIG_AIO
213+
mm->ioctx_table,
214+
#endif
215+
mm->owner, mm->exe_file,
216+
#ifdef CONFIG_MMU_NOTIFIER
217+
mm->mmu_notifier_mm,
218+
#endif
219+
#ifdef CONFIG_NUMA_BALANCING
220+
mm->numa_next_scan, mm->numa_scan_offset, mm->numa_scan_seq,
221+
#endif
222+
#if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
223+
mm->tlb_flush_pending
224+
#endif
225+
);
226+
227+
dump_flags(mm->def_flags, vmaflags_names,
228+
ARRAY_SIZE(vmaflags_names));
229+
}
230+
162231
#endif /* CONFIG_DEBUG_VM */

0 commit comments

Comments
 (0)