Thomas Gleixner | 40b0b3f | 2019-06-03 07:44:46 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 2 | /* |
| 3 | * crash.c - kernel crash support code. |
| 4 | * Copyright (C) 2002-2004 Eric Biederman <ebiederm@xmission.com> |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Stephen Boyd | 44e8a5e | 2021-07-07 18:09:49 -0700 | [diff] [blame] | 7 | #include <linux/buildid.h> |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 8 | #include <linux/crash_core.h> |
Philipp Rudo | 71d2bce | 2021-12-24 21:12:39 -0800 | [diff] [blame] | 9 | #include <linux/init.h> |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 10 | #include <linux/utsname.h> |
| 11 | #include <linux/vmalloc.h> |
Tao Liu | 46d36b1 | 2022-06-27 15:44:41 +0800 | [diff] [blame] | 12 | #include <linux/sizes.h> |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 13 | |
| 14 | #include <asm/page.h> |
| 15 | #include <asm/sections.h> |
| 16 | |
Eric Biggers | a24d22b | 2020-11-12 21:20:21 -0800 | [diff] [blame] | 17 | #include <crypto/sha1.h> |
Vijay Balakrishna | 0935288 | 2020-08-11 18:36:33 -0700 | [diff] [blame] | 18 | |
Stephen Brennan | 5fd8fea | 2022-05-16 17:05:08 -0700 | [diff] [blame] | 19 | #include "kallsyms_internal.h" |
| 20 | |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 21 | /* vmcoreinfo stuff */ |
Omar Sandoval | 23c8509 | 2018-08-21 21:55:20 -0700 | [diff] [blame] | 22 | unsigned char *vmcoreinfo_data; |
| 23 | size_t vmcoreinfo_size; |
Xunlei Pang | 203e9e4 | 2017-07-12 14:33:14 -0700 | [diff] [blame] | 24 | u32 *vmcoreinfo_note; |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 25 | |
Xunlei Pang | 1229384 | 2017-07-12 14:33:21 -0700 | [diff] [blame] | 26 | /* trusted vmcoreinfo, e.g. we can make a copy in the crash memory */ |
| 27 | static unsigned char *vmcoreinfo_data_safecopy; |
| 28 | |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 29 | /* |
| 30 | * parsing the "crashkernel" commandline |
| 31 | * |
| 32 | * this code is intended to be called from architecture specific code |
| 33 | */ |
| 34 | |
| 35 | |
| 36 | /* |
| 37 | * This function parses command lines in the format |
| 38 | * |
| 39 | * crashkernel=ramsize-range:size[,...][@offset] |
| 40 | * |
| 41 | * The function returns 0 on success and -EINVAL on failure. |
| 42 | */ |
| 43 | static int __init parse_crashkernel_mem(char *cmdline, |
| 44 | unsigned long long system_ram, |
| 45 | unsigned long long *crash_size, |
| 46 | unsigned long long *crash_base) |
| 47 | { |
| 48 | char *cur = cmdline, *tmp; |
Tao Liu | 46d36b1 | 2022-06-27 15:44:41 +0800 | [diff] [blame] | 49 | unsigned long long total_mem = system_ram; |
| 50 | |
| 51 | /* |
| 52 | * Firmware sometimes reserves some memory regions for its own use, |
| 53 | * so the system memory size is less than the actual physical memory |
| 54 | * size. Work around this by rounding up the total size to 128M, |
| 55 | * which is enough for most test cases. |
| 56 | */ |
| 57 | total_mem = roundup(total_mem, SZ_128M); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 58 | |
| 59 | /* for each entry of the comma-separated list */ |
| 60 | do { |
| 61 | unsigned long long start, end = ULLONG_MAX, size; |
| 62 | |
| 63 | /* get the start of the range */ |
| 64 | start = memparse(cur, &tmp); |
| 65 | if (cur == tmp) { |
| 66 | pr_warn("crashkernel: Memory value expected\n"); |
| 67 | return -EINVAL; |
| 68 | } |
| 69 | cur = tmp; |
| 70 | if (*cur != '-') { |
| 71 | pr_warn("crashkernel: '-' expected\n"); |
| 72 | return -EINVAL; |
| 73 | } |
| 74 | cur++; |
| 75 | |
| 76 | /* if no ':' is here, than we read the end */ |
| 77 | if (*cur != ':') { |
| 78 | end = memparse(cur, &tmp); |
| 79 | if (cur == tmp) { |
| 80 | pr_warn("crashkernel: Memory value expected\n"); |
| 81 | return -EINVAL; |
| 82 | } |
| 83 | cur = tmp; |
| 84 | if (end <= start) { |
| 85 | pr_warn("crashkernel: end <= start\n"); |
| 86 | return -EINVAL; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | if (*cur != ':') { |
| 91 | pr_warn("crashkernel: ':' expected\n"); |
| 92 | return -EINVAL; |
| 93 | } |
| 94 | cur++; |
| 95 | |
| 96 | size = memparse(cur, &tmp); |
| 97 | if (cur == tmp) { |
| 98 | pr_warn("Memory value expected\n"); |
| 99 | return -EINVAL; |
| 100 | } |
| 101 | cur = tmp; |
Tao Liu | 46d36b1 | 2022-06-27 15:44:41 +0800 | [diff] [blame] | 102 | if (size >= total_mem) { |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 103 | pr_warn("crashkernel: invalid size\n"); |
| 104 | return -EINVAL; |
| 105 | } |
| 106 | |
| 107 | /* match ? */ |
Tao Liu | 46d36b1 | 2022-06-27 15:44:41 +0800 | [diff] [blame] | 108 | if (total_mem >= start && total_mem < end) { |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 109 | *crash_size = size; |
| 110 | break; |
| 111 | } |
| 112 | } while (*cur++ == ','); |
| 113 | |
| 114 | if (*crash_size > 0) { |
| 115 | while (*cur && *cur != ' ' && *cur != '@') |
| 116 | cur++; |
| 117 | if (*cur == '@') { |
| 118 | cur++; |
| 119 | *crash_base = memparse(cur, &tmp); |
| 120 | if (cur == tmp) { |
| 121 | pr_warn("Memory value expected after '@'\n"); |
| 122 | return -EINVAL; |
| 123 | } |
| 124 | } |
Dave Young | de40cce | 2017-11-17 15:30:12 -0800 | [diff] [blame] | 125 | } else |
| 126 | pr_info("crashkernel size resulted in zero bytes\n"); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * That function parses "simple" (old) crashkernel command lines like |
| 133 | * |
| 134 | * crashkernel=size[@offset] |
| 135 | * |
| 136 | * It returns 0 on success and -EINVAL on failure. |
| 137 | */ |
| 138 | static int __init parse_crashkernel_simple(char *cmdline, |
| 139 | unsigned long long *crash_size, |
| 140 | unsigned long long *crash_base) |
| 141 | { |
| 142 | char *cur = cmdline; |
| 143 | |
| 144 | *crash_size = memparse(cmdline, &cur); |
| 145 | if (cmdline == cur) { |
| 146 | pr_warn("crashkernel: memory value expected\n"); |
| 147 | return -EINVAL; |
| 148 | } |
| 149 | |
| 150 | if (*cur == '@') |
| 151 | *crash_base = memparse(cur+1, &cur); |
| 152 | else if (*cur != ' ' && *cur != '\0') { |
| 153 | pr_warn("crashkernel: unrecognized char: %c\n", *cur); |
| 154 | return -EINVAL; |
| 155 | } |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | #define SUFFIX_HIGH 0 |
| 161 | #define SUFFIX_LOW 1 |
| 162 | #define SUFFIX_NULL 2 |
| 163 | static __initdata char *suffix_tbl[] = { |
| 164 | [SUFFIX_HIGH] = ",high", |
| 165 | [SUFFIX_LOW] = ",low", |
| 166 | [SUFFIX_NULL] = NULL, |
| 167 | }; |
| 168 | |
| 169 | /* |
| 170 | * That function parses "suffix" crashkernel command lines like |
| 171 | * |
| 172 | * crashkernel=size,[high|low] |
| 173 | * |
| 174 | * It returns 0 on success and -EINVAL on failure. |
| 175 | */ |
| 176 | static int __init parse_crashkernel_suffix(char *cmdline, |
| 177 | unsigned long long *crash_size, |
| 178 | const char *suffix) |
| 179 | { |
| 180 | char *cur = cmdline; |
| 181 | |
| 182 | *crash_size = memparse(cmdline, &cur); |
| 183 | if (cmdline == cur) { |
| 184 | pr_warn("crashkernel: memory value expected\n"); |
| 185 | return -EINVAL; |
| 186 | } |
| 187 | |
| 188 | /* check with suffix */ |
| 189 | if (strncmp(cur, suffix, strlen(suffix))) { |
| 190 | pr_warn("crashkernel: unrecognized char: %c\n", *cur); |
| 191 | return -EINVAL; |
| 192 | } |
| 193 | cur += strlen(suffix); |
| 194 | if (*cur != ' ' && *cur != '\0') { |
| 195 | pr_warn("crashkernel: unrecognized char: %c\n", *cur); |
| 196 | return -EINVAL; |
| 197 | } |
| 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | static __init char *get_last_crashkernel(char *cmdline, |
| 203 | const char *name, |
| 204 | const char *suffix) |
| 205 | { |
| 206 | char *p = cmdline, *ck_cmdline = NULL; |
| 207 | |
| 208 | /* find crashkernel and use the last one if there are more */ |
| 209 | p = strstr(p, name); |
| 210 | while (p) { |
| 211 | char *end_p = strchr(p, ' '); |
| 212 | char *q; |
| 213 | |
| 214 | if (!end_p) |
| 215 | end_p = p + strlen(p); |
| 216 | |
| 217 | if (!suffix) { |
| 218 | int i; |
| 219 | |
| 220 | /* skip the one with any known suffix */ |
| 221 | for (i = 0; suffix_tbl[i]; i++) { |
| 222 | q = end_p - strlen(suffix_tbl[i]); |
| 223 | if (!strncmp(q, suffix_tbl[i], |
| 224 | strlen(suffix_tbl[i]))) |
| 225 | goto next; |
| 226 | } |
| 227 | ck_cmdline = p; |
| 228 | } else { |
| 229 | q = end_p - strlen(suffix); |
| 230 | if (!strncmp(q, suffix, strlen(suffix))) |
| 231 | ck_cmdline = p; |
| 232 | } |
| 233 | next: |
| 234 | p = strstr(p+1, name); |
| 235 | } |
| 236 | |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 237 | return ck_cmdline; |
| 238 | } |
| 239 | |
| 240 | static int __init __parse_crashkernel(char *cmdline, |
| 241 | unsigned long long system_ram, |
| 242 | unsigned long long *crash_size, |
| 243 | unsigned long long *crash_base, |
| 244 | const char *name, |
| 245 | const char *suffix) |
| 246 | { |
| 247 | char *first_colon, *first_space; |
| 248 | char *ck_cmdline; |
| 249 | |
| 250 | BUG_ON(!crash_size || !crash_base); |
| 251 | *crash_size = 0; |
| 252 | *crash_base = 0; |
| 253 | |
| 254 | ck_cmdline = get_last_crashkernel(cmdline, name, suffix); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 255 | if (!ck_cmdline) |
Zhen Lei | 2e5920b | 2022-05-06 19:43:57 +0800 | [diff] [blame] | 256 | return -ENOENT; |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 257 | |
| 258 | ck_cmdline += strlen(name); |
| 259 | |
| 260 | if (suffix) |
| 261 | return parse_crashkernel_suffix(ck_cmdline, crash_size, |
| 262 | suffix); |
| 263 | /* |
| 264 | * if the commandline contains a ':', then that's the extended |
| 265 | * syntax -- if not, it must be the classic syntax |
| 266 | */ |
| 267 | first_colon = strchr(ck_cmdline, ':'); |
| 268 | first_space = strchr(ck_cmdline, ' '); |
| 269 | if (first_colon && (!first_space || first_colon < first_space)) |
| 270 | return parse_crashkernel_mem(ck_cmdline, system_ram, |
| 271 | crash_size, crash_base); |
| 272 | |
| 273 | return parse_crashkernel_simple(ck_cmdline, crash_size, crash_base); |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * That function is the entry point for command line parsing and should be |
| 278 | * called from the arch-specific code. |
| 279 | */ |
| 280 | int __init parse_crashkernel(char *cmdline, |
| 281 | unsigned long long system_ram, |
| 282 | unsigned long long *crash_size, |
| 283 | unsigned long long *crash_base) |
| 284 | { |
| 285 | return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, |
| 286 | "crashkernel=", NULL); |
| 287 | } |
| 288 | |
| 289 | int __init parse_crashkernel_high(char *cmdline, |
| 290 | unsigned long long system_ram, |
| 291 | unsigned long long *crash_size, |
| 292 | unsigned long long *crash_base) |
| 293 | { |
| 294 | return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, |
| 295 | "crashkernel=", suffix_tbl[SUFFIX_HIGH]); |
| 296 | } |
| 297 | |
| 298 | int __init parse_crashkernel_low(char *cmdline, |
| 299 | unsigned long long system_ram, |
| 300 | unsigned long long *crash_size, |
| 301 | unsigned long long *crash_base) |
| 302 | { |
| 303 | return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base, |
| 304 | "crashkernel=", suffix_tbl[SUFFIX_LOW]); |
| 305 | } |
| 306 | |
Philipp Rudo | 71d2bce | 2021-12-24 21:12:39 -0800 | [diff] [blame] | 307 | /* |
| 308 | * Add a dummy early_param handler to mark crashkernel= as a known command line |
| 309 | * parameter and suppress incorrect warnings in init/main.c. |
| 310 | */ |
| 311 | static int __init parse_crashkernel_dummy(char *arg) |
| 312 | { |
| 313 | return 0; |
| 314 | } |
| 315 | early_param("crashkernel", parse_crashkernel_dummy); |
| 316 | |
Hari Bathini | 51dbd92 | 2017-05-08 15:56:21 -0700 | [diff] [blame] | 317 | Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type, |
| 318 | void *data, size_t data_len) |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 319 | { |
Hari Bathini | 51dbd92 | 2017-05-08 15:56:21 -0700 | [diff] [blame] | 320 | struct elf_note *note = (struct elf_note *)buf; |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 321 | |
Hari Bathini | 51dbd92 | 2017-05-08 15:56:21 -0700 | [diff] [blame] | 322 | note->n_namesz = strlen(name) + 1; |
| 323 | note->n_descsz = data_len; |
| 324 | note->n_type = type; |
| 325 | buf += DIV_ROUND_UP(sizeof(*note), sizeof(Elf_Word)); |
| 326 | memcpy(buf, name, note->n_namesz); |
| 327 | buf += DIV_ROUND_UP(note->n_namesz, sizeof(Elf_Word)); |
| 328 | memcpy(buf, data, data_len); |
| 329 | buf += DIV_ROUND_UP(data_len, sizeof(Elf_Word)); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 330 | |
| 331 | return buf; |
| 332 | } |
| 333 | |
Hari Bathini | 51dbd92 | 2017-05-08 15:56:21 -0700 | [diff] [blame] | 334 | void final_note(Elf_Word *buf) |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 335 | { |
Hari Bathini | 51dbd92 | 2017-05-08 15:56:21 -0700 | [diff] [blame] | 336 | memset(buf, 0, sizeof(struct elf_note)); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | static void update_vmcoreinfo_note(void) |
| 340 | { |
| 341 | u32 *buf = vmcoreinfo_note; |
| 342 | |
| 343 | if (!vmcoreinfo_size) |
| 344 | return; |
| 345 | buf = append_elf_note(buf, VMCOREINFO_NOTE_NAME, 0, vmcoreinfo_data, |
| 346 | vmcoreinfo_size); |
| 347 | final_note(buf); |
| 348 | } |
| 349 | |
Xunlei Pang | 1229384 | 2017-07-12 14:33:21 -0700 | [diff] [blame] | 350 | void crash_update_vmcoreinfo_safecopy(void *ptr) |
| 351 | { |
| 352 | if (ptr) |
| 353 | memcpy(ptr, vmcoreinfo_data, vmcoreinfo_size); |
| 354 | |
| 355 | vmcoreinfo_data_safecopy = ptr; |
| 356 | } |
| 357 | |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 358 | void crash_save_vmcoreinfo(void) |
| 359 | { |
Xunlei Pang | 203e9e4 | 2017-07-12 14:33:14 -0700 | [diff] [blame] | 360 | if (!vmcoreinfo_note) |
| 361 | return; |
| 362 | |
Xunlei Pang | 1229384 | 2017-07-12 14:33:21 -0700 | [diff] [blame] | 363 | /* Use the safe copy to generate vmcoreinfo note if have */ |
| 364 | if (vmcoreinfo_data_safecopy) |
| 365 | vmcoreinfo_data = vmcoreinfo_data_safecopy; |
| 366 | |
Arnd Bergmann | 91bc9aa | 2018-08-21 21:55:49 -0700 | [diff] [blame] | 367 | vmcoreinfo_append_str("CRASHTIME=%lld\n", ktime_get_real_seconds()); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 368 | update_vmcoreinfo_note(); |
| 369 | } |
| 370 | |
| 371 | void vmcoreinfo_append_str(const char *fmt, ...) |
| 372 | { |
| 373 | va_list args; |
| 374 | char buf[0x50]; |
| 375 | size_t r; |
| 376 | |
| 377 | va_start(args, fmt); |
| 378 | r = vscnprintf(buf, sizeof(buf), fmt, args); |
| 379 | va_end(args); |
| 380 | |
Xunlei Pang | 5203f49 | 2017-07-12 14:33:17 -0700 | [diff] [blame] | 381 | r = min(r, (size_t)VMCOREINFO_BYTES - vmcoreinfo_size); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 382 | |
| 383 | memcpy(&vmcoreinfo_data[vmcoreinfo_size], buf, r); |
| 384 | |
| 385 | vmcoreinfo_size += r; |
Stephen Brennan | 08fc35f | 2022-10-27 13:50:08 -0700 | [diff] [blame] | 386 | |
| 387 | WARN_ONCE(vmcoreinfo_size == VMCOREINFO_BYTES, |
| 388 | "vmcoreinfo data exceeds allocated size, truncating"); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /* |
| 392 | * provide an empty default implementation here -- architecture |
| 393 | * code may override this |
| 394 | */ |
| 395 | void __weak arch_crash_save_vmcoreinfo(void) |
| 396 | {} |
| 397 | |
| 398 | phys_addr_t __weak paddr_vmcoreinfo_note(void) |
| 399 | { |
Xunlei Pang | 203e9e4 | 2017-07-12 14:33:14 -0700 | [diff] [blame] | 400 | return __pa(vmcoreinfo_note); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 401 | } |
Marc-André Lureau | 43d4cb4 | 2018-02-28 16:06:13 +0100 | [diff] [blame] | 402 | EXPORT_SYMBOL(paddr_vmcoreinfo_note); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 403 | |
| 404 | static int __init crash_save_vmcoreinfo_init(void) |
| 405 | { |
Xunlei Pang | 203e9e4 | 2017-07-12 14:33:14 -0700 | [diff] [blame] | 406 | vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL); |
| 407 | if (!vmcoreinfo_data) { |
| 408 | pr_warn("Memory allocation for vmcoreinfo_data failed\n"); |
| 409 | return -ENOMEM; |
| 410 | } |
| 411 | |
| 412 | vmcoreinfo_note = alloc_pages_exact(VMCOREINFO_NOTE_SIZE, |
| 413 | GFP_KERNEL | __GFP_ZERO); |
| 414 | if (!vmcoreinfo_note) { |
| 415 | free_page((unsigned long)vmcoreinfo_data); |
| 416 | vmcoreinfo_data = NULL; |
| 417 | pr_warn("Memory allocation for vmcoreinfo_note failed\n"); |
| 418 | return -ENOMEM; |
| 419 | } |
| 420 | |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 421 | VMCOREINFO_OSRELEASE(init_uts_ns.name.release); |
Stephen Boyd | 44e8a5e | 2021-07-07 18:09:49 -0700 | [diff] [blame] | 422 | VMCOREINFO_BUILD_ID(); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 423 | VMCOREINFO_PAGESIZE(PAGE_SIZE); |
| 424 | |
| 425 | VMCOREINFO_SYMBOL(init_uts_ns); |
Alexander Egorenkov | ca4a924 | 2020-12-15 20:45:31 -0800 | [diff] [blame] | 426 | VMCOREINFO_OFFSET(uts_namespace, name); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 427 | VMCOREINFO_SYMBOL(node_online_map); |
| 428 | #ifdef CONFIG_MMU |
Omar Sandoval | eff4345 | 2018-08-21 21:55:17 -0700 | [diff] [blame] | 429 | VMCOREINFO_SYMBOL_ARRAY(swapper_pg_dir); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 430 | #endif |
| 431 | VMCOREINFO_SYMBOL(_stext); |
| 432 | VMCOREINFO_SYMBOL(vmap_area_list); |
| 433 | |
Mike Rapoport | a9ee6cf | 2021-06-28 19:43:01 -0700 | [diff] [blame] | 434 | #ifndef CONFIG_NUMA |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 435 | VMCOREINFO_SYMBOL(mem_map); |
| 436 | VMCOREINFO_SYMBOL(contig_page_data); |
| 437 | #endif |
| 438 | #ifdef CONFIG_SPARSEMEM |
Kirill A. Shutemov | a0b1280 | 2018-01-12 16:53:14 -0800 | [diff] [blame] | 439 | VMCOREINFO_SYMBOL_ARRAY(mem_section); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 440 | VMCOREINFO_LENGTH(mem_section, NR_SECTION_ROOTS); |
| 441 | VMCOREINFO_STRUCT_SIZE(mem_section); |
| 442 | VMCOREINFO_OFFSET(mem_section, section_mem_map); |
Pingfan Liu | 4f5aecd | 2021-06-15 18:23:36 -0700 | [diff] [blame] | 443 | VMCOREINFO_NUMBER(SECTION_SIZE_BITS); |
Bhupesh Sharma | 1d50e5d | 2020-05-14 00:22:36 +0530 | [diff] [blame] | 444 | VMCOREINFO_NUMBER(MAX_PHYSMEM_BITS); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 445 | #endif |
| 446 | VMCOREINFO_STRUCT_SIZE(page); |
| 447 | VMCOREINFO_STRUCT_SIZE(pglist_data); |
| 448 | VMCOREINFO_STRUCT_SIZE(zone); |
| 449 | VMCOREINFO_STRUCT_SIZE(free_area); |
| 450 | VMCOREINFO_STRUCT_SIZE(list_head); |
| 451 | VMCOREINFO_SIZE(nodemask_t); |
| 452 | VMCOREINFO_OFFSET(page, flags); |
| 453 | VMCOREINFO_OFFSET(page, _refcount); |
| 454 | VMCOREINFO_OFFSET(page, mapping); |
| 455 | VMCOREINFO_OFFSET(page, lru); |
| 456 | VMCOREINFO_OFFSET(page, _mapcount); |
| 457 | VMCOREINFO_OFFSET(page, private); |
| 458 | VMCOREINFO_OFFSET(page, compound_dtor); |
| 459 | VMCOREINFO_OFFSET(page, compound_order); |
| 460 | VMCOREINFO_OFFSET(page, compound_head); |
| 461 | VMCOREINFO_OFFSET(pglist_data, node_zones); |
| 462 | VMCOREINFO_OFFSET(pglist_data, nr_zones); |
Mike Rapoport | 43b02ba | 2021-06-28 19:43:05 -0700 | [diff] [blame] | 463 | #ifdef CONFIG_FLATMEM |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 464 | VMCOREINFO_OFFSET(pglist_data, node_mem_map); |
| 465 | #endif |
| 466 | VMCOREINFO_OFFSET(pglist_data, node_start_pfn); |
| 467 | VMCOREINFO_OFFSET(pglist_data, node_spanned_pages); |
| 468 | VMCOREINFO_OFFSET(pglist_data, node_id); |
| 469 | VMCOREINFO_OFFSET(zone, free_area); |
| 470 | VMCOREINFO_OFFSET(zone, vm_stat); |
| 471 | VMCOREINFO_OFFSET(zone, spanned_pages); |
| 472 | VMCOREINFO_OFFSET(free_area, free_list); |
| 473 | VMCOREINFO_OFFSET(list_head, next); |
| 474 | VMCOREINFO_OFFSET(list_head, prev); |
| 475 | VMCOREINFO_OFFSET(vmap_area, va_start); |
| 476 | VMCOREINFO_OFFSET(vmap_area, list); |
| 477 | VMCOREINFO_LENGTH(zone.free_area, MAX_ORDER); |
| 478 | log_buf_vmcoreinfo_setup(); |
| 479 | VMCOREINFO_LENGTH(free_area.free_list, MIGRATE_TYPES); |
| 480 | VMCOREINFO_NUMBER(NR_FREE_PAGES); |
| 481 | VMCOREINFO_NUMBER(PG_lru); |
| 482 | VMCOREINFO_NUMBER(PG_private); |
| 483 | VMCOREINFO_NUMBER(PG_swapcache); |
Petr Tesarik | 1cbf29d | 2018-04-13 15:35:34 -0700 | [diff] [blame] | 484 | VMCOREINFO_NUMBER(PG_swapbacked); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 485 | VMCOREINFO_NUMBER(PG_slab); |
| 486 | #ifdef CONFIG_MEMORY_FAILURE |
| 487 | VMCOREINFO_NUMBER(PG_hwpoison); |
| 488 | #endif |
| 489 | VMCOREINFO_NUMBER(PG_head_mask); |
Matthew Wilcox | 6e292b9 | 2018-06-07 17:08:18 -0700 | [diff] [blame] | 490 | #define PAGE_BUDDY_MAPCOUNT_VALUE (~PG_buddy) |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 491 | VMCOREINFO_NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE); |
| 492 | #ifdef CONFIG_HUGETLB_PAGE |
| 493 | VMCOREINFO_NUMBER(HUGETLB_PAGE_DTOR); |
David Hildenbrand | e04b742 | 2019-03-05 15:42:27 -0800 | [diff] [blame] | 494 | #define PAGE_OFFLINE_MAPCOUNT_VALUE (~PG_offline) |
| 495 | VMCOREINFO_NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE); |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 496 | #endif |
| 497 | |
Stephen Brennan | 5fd8fea | 2022-05-16 17:05:08 -0700 | [diff] [blame] | 498 | #ifdef CONFIG_KALLSYMS |
| 499 | VMCOREINFO_SYMBOL(kallsyms_names); |
Stephen Brennan | f09bddb | 2022-08-08 13:54:10 -0700 | [diff] [blame] | 500 | VMCOREINFO_SYMBOL(kallsyms_num_syms); |
Stephen Brennan | 5fd8fea | 2022-05-16 17:05:08 -0700 | [diff] [blame] | 501 | VMCOREINFO_SYMBOL(kallsyms_token_table); |
| 502 | VMCOREINFO_SYMBOL(kallsyms_token_index); |
| 503 | #ifdef CONFIG_KALLSYMS_BASE_RELATIVE |
| 504 | VMCOREINFO_SYMBOL(kallsyms_offsets); |
| 505 | VMCOREINFO_SYMBOL(kallsyms_relative_base); |
| 506 | #else |
| 507 | VMCOREINFO_SYMBOL(kallsyms_addresses); |
| 508 | #endif /* CONFIG_KALLSYMS_BASE_RELATIVE */ |
| 509 | #endif /* CONFIG_KALLSYMS */ |
| 510 | |
Hari Bathini | 692f66f | 2017-05-08 15:56:18 -0700 | [diff] [blame] | 511 | arch_crash_save_vmcoreinfo(); |
| 512 | update_vmcoreinfo_note(); |
| 513 | |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | subsys_initcall(crash_save_vmcoreinfo_init); |