^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * mm/debug.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * mm/ specific debug routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/trace_events.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/memcontrol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <trace/events/mmflags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/migrate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/page_owner.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/page_pinner.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) const char *migrate_reason_names[MR_TYPES] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) "compaction",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) "memory_failure",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) "memory_hotplug",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) "syscall_or_cpuset",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) "mempolicy_mbind",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) "numa_misplaced",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) "cma",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) const struct trace_print_flags pageflag_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) __def_pageflag_names,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {0, NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) const struct trace_print_flags gfpflag_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) __def_gfpflag_names,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {0, NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) const struct trace_print_flags vmaflag_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) __def_vmaflag_names,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {0, NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) void __dump_page(struct page *page, const char *reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct page *head = compound_head(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct address_space *mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) bool page_poisoned = PagePoisoned(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) bool compound = PageCompound(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * Accessing the pageblock without the zone lock. It could change to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * "isolate" again in the meantime, but since we are just dumping the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * state for debugging, it should be fine to accept a bit of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * inaccuracy here due to racing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) bool page_cma = is_migrate_cma_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int mapcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) char *type = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * If struct page is poisoned don't access Page*() functions as that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * leads to recursive loop. Page*() check for poisoned pages, and calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * dump_page() when detected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (page_poisoned) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) pr_warn("page:%px is uninitialized and poisoned", page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) goto hex_only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (page < head || (page >= head + MAX_ORDER_NR_PAGES)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * Corrupt page, so we cannot call page_mapping. Instead, do a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * safe subset of the steps that page_mapping() does. Caution:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * this will be misleading for tail pages, PageSwapCache pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * and potentially other situations. (See the page_mapping()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * implementation for what's missing here.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) unsigned long tmp = (unsigned long)page->mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (tmp & PAGE_MAPPING_ANON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) mapping = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) mapping = (void *)(tmp & ~PAGE_MAPPING_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) head = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) compound = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) mapping = page_mapping(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * Avoid VM_BUG_ON() in page_mapcount().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * page->_mapcount space in struct page is used by sl[aou]b pages to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * encode own info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) mapcount = PageSlab(head) ? 0 : page_mapcount(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) pr_warn("page:%p refcount:%d mapcount:%d mapping:%p index:%#lx pfn:%#lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) page, page_ref_count(head), mapcount, mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) page_to_pgoff(page), page_to_pfn(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (compound) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (hpage_pincount_available(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) pr_warn("head:%p order:%u compound_mapcount:%d compound_pincount:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) head, compound_order(head),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) head_compound_mapcount(head),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) head_compound_pincount(head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) pr_warn("head:%p order:%u compound_mapcount:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) head, compound_order(head),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) head_compound_mapcount(head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (PageKsm(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) type = "ksm ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) else if (PageAnon(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) type = "anon ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) else if (mapping) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct inode *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) const struct address_space_operations *a_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct hlist_node *dentry_first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct dentry *dentry_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct dentry dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) unsigned long ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * mapping can be invalid pointer and we don't want to crash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * accessing it, so probe everything depending on it carefully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (get_kernel_nofault(host, &mapping->host) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) get_kernel_nofault(a_ops, &mapping->a_ops)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) pr_warn("failed to read mapping contents, not a valid kernel address?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) goto out_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (!host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) pr_warn("aops:%ps\n", a_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) goto out_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (get_kernel_nofault(dentry_first, &host->i_dentry.first) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) get_kernel_nofault(ino, &host->i_ino)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) pr_warn("aops:%ps with invalid host inode %px\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) a_ops, host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) goto out_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (!dentry_first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) pr_warn("aops:%ps ino:%lx\n", a_ops, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) goto out_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) dentry_ptr = container_of(dentry_first, struct dentry, d_u.d_alias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (get_kernel_nofault(dentry, dentry_ptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) pr_warn("aops:%ps ino:%lx with invalid dentry %px\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) a_ops, ino, dentry_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * if dentry is corrupted, the %pd handler may still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * crash, but it's unlikely that we reach here with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * corrupted struct page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) pr_warn("aops:%ps ino:%lx dentry name:\"%pd\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) a_ops, ino, &dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) out_mapping:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) pr_warn("%sflags: %#lx(%pGp)%s\n", type, head->flags, &head->flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) page_cma ? " CMA" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) hex_only:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) print_hex_dump(KERN_WARNING, "raw: ", DUMP_PREFIX_NONE, 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) sizeof(unsigned long), page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) sizeof(struct page), false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (head != page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) print_hex_dump(KERN_WARNING, "head: ", DUMP_PREFIX_NONE, 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) sizeof(unsigned long), head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) sizeof(struct page), false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) pr_warn("page dumped because: %s\n", reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #ifdef CONFIG_MEMCG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (!page_poisoned && page->mem_cgroup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) pr_warn("page->mem_cgroup:%px\n", page->mem_cgroup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) void dump_page(struct page *page, const char *reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) __dump_page(page, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) dump_page_owner(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) dump_page_pinner(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) EXPORT_SYMBOL(dump_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #ifdef CONFIG_DEBUG_VM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) void dump_vma(const struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) pr_emerg("vma %px start %px end %px\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) "next %px prev %px mm %px\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) "prot %lx anon_vma %px vm_ops %px\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) "pgoff %lx file %px private_data %px\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) "flags: %#lx(%pGv)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) vma, (void *)vma->vm_start, (void *)vma->vm_end, vma->vm_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) vma->vm_prev, vma->vm_mm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) (unsigned long)pgprot_val(vma->vm_page_prot),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) vma->anon_vma, vma->vm_ops, vma->vm_pgoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) vma->vm_file, vma->vm_private_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) vma->vm_flags, &vma->vm_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) EXPORT_SYMBOL(dump_vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) void dump_mm(const struct mm_struct *mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) pr_emerg("mm %px mmap %px seqnum %llu task_size %lu\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) "get_unmapped_area %px\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) "mmap_base %lu mmap_legacy_base %lu highest_vm_end %lu\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) "pgd %px mm_users %d mm_count %d pgtables_bytes %lu map_count %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) "hiwater_rss %lx hiwater_vm %lx total_vm %lx locked_vm %lx\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) "pinned_vm %llx data_vm %lx exec_vm %lx stack_vm %lx\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) "start_code %lx end_code %lx start_data %lx end_data %lx\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) "start_brk %lx brk %lx start_stack %lx\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) "arg_start %lx arg_end %lx env_start %lx env_end %lx\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) "binfmt %px flags %lx core_state %px\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #ifdef CONFIG_AIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) "ioctx_table %px\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #ifdef CONFIG_MEMCG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) "owner %px "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) "exe_file %px\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #ifdef CONFIG_MMU_NOTIFIER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) "notifier_subscriptions %px\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #ifdef CONFIG_NUMA_BALANCING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) "numa_next_scan %lu numa_scan_offset %lu numa_scan_seq %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) "tlb_flush_pending %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) "def_flags: %#lx(%pGv)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) mm, mm->mmap, (long long) mm->vmacache_seqnum, mm->task_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) #ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) mm->get_unmapped_area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) mm->mmap_base, mm->mmap_legacy_base, mm->highest_vm_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) mm->pgd, atomic_read(&mm->mm_users),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) atomic_read(&mm->mm_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) mm_pgtables_bytes(mm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) mm->map_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) mm->hiwater_rss, mm->hiwater_vm, mm->total_vm, mm->locked_vm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) (u64)atomic64_read(&mm->pinned_vm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) mm->data_vm, mm->exec_vm, mm->stack_vm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) mm->start_code, mm->end_code, mm->start_data, mm->end_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) mm->start_brk, mm->brk, mm->start_stack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) mm->arg_start, mm->arg_end, mm->env_start, mm->env_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) mm->binfmt, mm->flags, mm->core_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) #ifdef CONFIG_AIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) mm->ioctx_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #ifdef CONFIG_MEMCG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) mm->owner,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) mm->exe_file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #ifdef CONFIG_MMU_NOTIFIER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) mm->notifier_subscriptions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) #ifdef CONFIG_NUMA_BALANCING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) mm->numa_next_scan, mm->numa_scan_offset, mm->numa_scan_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) atomic_read(&mm->tlb_flush_pending),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) mm->def_flags, &mm->def_flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static bool page_init_poisoning __read_mostly = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static int __init setup_vm_debug(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) bool __page_init_poisoning = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * Calling vm_debug with no arguments is equivalent to requesting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * to enable all debugging options we can control.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (*str++ != '=' || !*str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) __page_init_poisoning = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (*str == '-')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) while (*str) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) switch (tolower(*str)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) case'p':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) __page_init_poisoning = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) pr_err("vm_debug option '%c' unknown. skipped\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) *str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) str++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (page_init_poisoning && !__page_init_poisoning)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) pr_warn("Page struct poisoning disabled by kernel command line option 'vm_debug'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) page_init_poisoning = __page_init_poisoning;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) __setup("vm_debug", setup_vm_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) void page_init_poison(struct page *page, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (page_init_poisoning)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) memset(page, PAGE_POISON_PATTERN, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) EXPORT_SYMBOL_GPL(page_init_poison);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) #endif /* CONFIG_DEBUG_VM */