.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * crash.c - kernel crash support code. |
---|
3 | 4 | * Copyright (C) 2002-2004 Eric Biederman <ebiederm@xmission.com> |
---|
4 | | - * |
---|
5 | | - * This source code is licensed under the GNU General Public License, |
---|
6 | | - * Version 2. See the file COPYING for more details. |
---|
7 | 5 | */ |
---|
8 | 6 | |
---|
9 | 7 | #include <linux/crash_core.h> |
---|
.. | .. |
---|
12 | 10 | |
---|
13 | 11 | #include <asm/page.h> |
---|
14 | 12 | #include <asm/sections.h> |
---|
| 13 | + |
---|
| 14 | +#include <crypto/sha.h> |
---|
15 | 15 | |
---|
16 | 16 | /* vmcoreinfo stuff */ |
---|
17 | 17 | unsigned char *vmcoreinfo_data; |
---|
.. | .. |
---|
378 | 378 | } |
---|
379 | 379 | EXPORT_SYMBOL(paddr_vmcoreinfo_note); |
---|
380 | 380 | |
---|
| 381 | +#define NOTES_SIZE (&__stop_notes - &__start_notes) |
---|
| 382 | +#define BUILD_ID_MAX SHA1_DIGEST_SIZE |
---|
| 383 | +#define NT_GNU_BUILD_ID 3 |
---|
| 384 | + |
---|
| 385 | +struct elf_note_section { |
---|
| 386 | + struct elf_note n_hdr; |
---|
| 387 | + u8 n_data[]; |
---|
| 388 | +}; |
---|
| 389 | + |
---|
| 390 | +/* |
---|
| 391 | + * Add build ID from .notes section as generated by the GNU ld(1) |
---|
| 392 | + * or LLVM lld(1) --build-id option. |
---|
| 393 | + */ |
---|
| 394 | +static void add_build_id_vmcoreinfo(void) |
---|
| 395 | +{ |
---|
| 396 | + char build_id[BUILD_ID_MAX * 2 + 1]; |
---|
| 397 | + int n_remain = NOTES_SIZE; |
---|
| 398 | + |
---|
| 399 | + while (n_remain >= sizeof(struct elf_note)) { |
---|
| 400 | + const struct elf_note_section *note_sec = |
---|
| 401 | + &__start_notes + NOTES_SIZE - n_remain; |
---|
| 402 | + const u32 n_namesz = note_sec->n_hdr.n_namesz; |
---|
| 403 | + |
---|
| 404 | + if (note_sec->n_hdr.n_type == NT_GNU_BUILD_ID && |
---|
| 405 | + n_namesz != 0 && |
---|
| 406 | + !strcmp((char *)¬e_sec->n_data[0], "GNU")) { |
---|
| 407 | + if (note_sec->n_hdr.n_descsz <= BUILD_ID_MAX) { |
---|
| 408 | + const u32 n_descsz = note_sec->n_hdr.n_descsz; |
---|
| 409 | + const u8 *s = ¬e_sec->n_data[n_namesz]; |
---|
| 410 | + |
---|
| 411 | + s = PTR_ALIGN(s, 4); |
---|
| 412 | + bin2hex(build_id, s, n_descsz); |
---|
| 413 | + build_id[2 * n_descsz] = '\0'; |
---|
| 414 | + VMCOREINFO_BUILD_ID(build_id); |
---|
| 415 | + return; |
---|
| 416 | + } |
---|
| 417 | + pr_warn("Build ID is too large to include in vmcoreinfo: %u > %u\n", |
---|
| 418 | + note_sec->n_hdr.n_descsz, |
---|
| 419 | + BUILD_ID_MAX); |
---|
| 420 | + return; |
---|
| 421 | + } |
---|
| 422 | + n_remain -= sizeof(struct elf_note) + |
---|
| 423 | + ALIGN(note_sec->n_hdr.n_namesz, 4) + |
---|
| 424 | + ALIGN(note_sec->n_hdr.n_descsz, 4); |
---|
| 425 | + } |
---|
| 426 | +} |
---|
| 427 | + |
---|
381 | 428 | static int __init crash_save_vmcoreinfo_init(void) |
---|
382 | 429 | { |
---|
383 | 430 | vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL); |
---|
.. | .. |
---|
396 | 443 | } |
---|
397 | 444 | |
---|
398 | 445 | VMCOREINFO_OSRELEASE(init_uts_ns.name.release); |
---|
| 446 | + add_build_id_vmcoreinfo(); |
---|
399 | 447 | VMCOREINFO_PAGESIZE(PAGE_SIZE); |
---|
400 | 448 | |
---|
401 | 449 | VMCOREINFO_SYMBOL(init_uts_ns); |
---|
.. | .. |
---|
415 | 463 | VMCOREINFO_LENGTH(mem_section, NR_SECTION_ROOTS); |
---|
416 | 464 | VMCOREINFO_STRUCT_SIZE(mem_section); |
---|
417 | 465 | VMCOREINFO_OFFSET(mem_section, section_mem_map); |
---|
| 466 | + VMCOREINFO_NUMBER(SECTION_SIZE_BITS); |
---|
| 467 | + VMCOREINFO_NUMBER(MAX_PHYSMEM_BITS); |
---|
418 | 468 | #endif |
---|
419 | 469 | VMCOREINFO_STRUCT_SIZE(page); |
---|
420 | 470 | VMCOREINFO_STRUCT_SIZE(pglist_data); |
---|
.. | .. |
---|
464 | 514 | VMCOREINFO_NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE); |
---|
465 | 515 | #ifdef CONFIG_HUGETLB_PAGE |
---|
466 | 516 | VMCOREINFO_NUMBER(HUGETLB_PAGE_DTOR); |
---|
| 517 | +#define PAGE_OFFLINE_MAPCOUNT_VALUE (~PG_offline) |
---|
| 518 | + VMCOREINFO_NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE); |
---|
467 | 519 | #endif |
---|
468 | 520 | |
---|
469 | 521 | arch_crash_save_vmcoreinfo(); |
---|