2022-11-02 00:14:02 +00:00
|
|
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
2022-06-20 01:21:28 +01:00
|
|
|
static struct drgn_error *parse_vmcoreinfo_u64(const char *value,
|
|
|
|
const char *newline, int base,
|
|
|
|
uint64_t *ret)
|
|
|
|
{
|
|
|
|
errno = 0;
|
|
|
|
char *end;
|
|
|
|
*ret = strtoull(value, &end, base);
|
|
|
|
if (errno == ERANGE) {
|
|
|
|
return drgn_error_create(DRGN_ERROR_OVERFLOW,
|
|
|
|
"number in VMCOREINFO is too large");
|
|
|
|
} else if (errno || end == value || end != newline) {
|
|
|
|
return drgn_error_create(DRGN_ERROR_OTHER,
|
|
|
|
"number in VMCOREINFO is invalid");
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct drgn_error *drgn_program_parse_vmcoreinfo(struct drgn_program *prog,
|
|
|
|
const char *desc,
|
|
|
|
size_t descsz)
|
|
|
|
{
|
|
|
|
struct drgn_error *err;
|
2023-06-30 00:28:12 +01:00
|
|
|
|
|
|
|
prog->vmcoreinfo.raw_size = descsz;
|
|
|
|
prog->vmcoreinfo.raw = memdup(desc, descsz);
|
|
|
|
if (!prog->vmcoreinfo.raw)
|
|
|
|
return &drgn_enomem;
|
2022-06-20 01:21:28 +01:00
|
|
|
for (const char *line = desc, *end = &desc[descsz], *newline;
|
|
|
|
(newline = memchr(line, '\n', end - line));
|
|
|
|
line = newline + 1) {
|
|
|
|
const char *equals = memchr(line, '=', newline - line);
|
|
|
|
if (!equals)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const char *value = equals + 1;
|
|
|
|
@memswitch (line, equals - line)@
|
2024-06-20 18:37:03 +01:00
|
|
|
@case "CRASHTIME"@
|
|
|
|
prog->vmcoreinfo.have_crashtime = true;
|
|
|
|
break;
|
2022-06-20 01:21:28 +01:00
|
|
|
@case "OSRELEASE"@
|
|
|
|
if ((size_t)(newline - value) >=
|
|
|
|
sizeof(prog->vmcoreinfo.osrelease)) {
|
|
|
|
return drgn_error_create(DRGN_ERROR_OTHER,
|
|
|
|
"OSRELEASE in VMCOREINFO is too long");
|
|
|
|
}
|
|
|
|
memcpy(prog->vmcoreinfo.osrelease, value,
|
|
|
|
newline - value);
|
|
|
|
prog->vmcoreinfo.osrelease[newline - value] = '\0';
|
|
|
|
break;
|
|
|
|
@case "PAGESIZE"@
|
|
|
|
err = parse_vmcoreinfo_u64(value, newline, 0,
|
|
|
|
&prog->vmcoreinfo.page_size);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
break;
|
|
|
|
@case "KERNELOFFSET"@
|
|
|
|
err = parse_vmcoreinfo_u64(value, newline, 16,
|
|
|
|
&prog->vmcoreinfo.kaslr_offset);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
break;
|
|
|
|
@case "SYMBOL(swapper_pg_dir)"@
|
|
|
|
err = parse_vmcoreinfo_u64(value, newline, 16,
|
|
|
|
&prog->vmcoreinfo.swapper_pg_dir);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
break;
|
2022-07-12 21:37:12 +01:00
|
|
|
@case "LENGTH(mem_section)"@
|
|
|
|
err = parse_vmcoreinfo_u64(value, newline, 0,
|
|
|
|
&prog->vmcoreinfo.mem_section_length);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
break;
|
2022-06-20 01:21:28 +01:00
|
|
|
@case "NUMBER(pgtable_l5_enabled)"@
|
|
|
|
{
|
|
|
|
uint64_t tmp;
|
|
|
|
err = parse_vmcoreinfo_u64(value, newline, 0, &tmp);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
prog->vmcoreinfo.pgtable_l5_enabled = tmp;
|
|
|
|
break;
|
|
|
|
}
|
libdrgn: x86_64: avoid recursive address translation for swapper_pg_dir
Most core dumps contain some virtual address mappings: usually at a
minimum, the kernel's direct map is represented in ELF vmcores via a
segment. So normally, drgn can rely on the vmcore to read the virtual
address of swapper_pg_dir. However, some vmcores only contain physical
address information, so when drgn reads memory at swapper_pg_dir, it
needs to first translate that address, thus causing a recursive
translation error like below:
>>> prog["slab_caches"]
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/stepbren/repos/drgn/drgn/cli.py", line 141, in _displayhook
text = value.format_(columns=shutil.get_terminal_size((0, 0)).columns)
_drgn.FaultError: recursive address translation; page table may be missing from core dump: 0xffffffff9662aff8
Debuggers like crash, as well as libkdumpfile, contain fallback code
which can translate swapper_pg_dir in order to bootstrap this address
translation. In fact, the above error does not occur in drgn when using
libkdumpfile. So, let's add this fallback case to drgn as well. Other
architectures will need to have equivalent support added.
Co-authored-by: Illia Ostapyshyn <ostapyshyn@sra.uni-hannover.de>
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2024-05-28 23:33:43 +01:00
|
|
|
@case "NUMBER(phys_base)"@
|
|
|
|
{
|
|
|
|
err = parse_vmcoreinfo_u64(value, newline, 0,
|
2024-06-21 21:45:59 +01:00
|
|
|
&prog->vmcoreinfo.phys_base);
|
libdrgn: x86_64: avoid recursive address translation for swapper_pg_dir
Most core dumps contain some virtual address mappings: usually at a
minimum, the kernel's direct map is represented in ELF vmcores via a
segment. So normally, drgn can rely on the vmcore to read the virtual
address of swapper_pg_dir. However, some vmcores only contain physical
address information, so when drgn reads memory at swapper_pg_dir, it
needs to first translate that address, thus causing a recursive
translation error like below:
>>> prog["slab_caches"]
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/stepbren/repos/drgn/drgn/cli.py", line 141, in _displayhook
text = value.format_(columns=shutil.get_terminal_size((0, 0)).columns)
_drgn.FaultError: recursive address translation; page table may be missing from core dump: 0xffffffff9662aff8
Debuggers like crash, as well as libkdumpfile, contain fallback code
which can translate swapper_pg_dir in order to bootstrap this address
translation. In fact, the above error does not occur in drgn when using
libkdumpfile. So, let's add this fallback case to drgn as well. Other
architectures will need to have equivalent support added.
Co-authored-by: Illia Ostapyshyn <ostapyshyn@sra.uni-hannover.de>
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2024-05-28 23:33:43 +01:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
break;
|
|
|
|
}
|
2022-06-20 06:09:36 +01:00
|
|
|
@case "NUMBER(KERNELPACMASK)"@
|
|
|
|
err = parse_vmcoreinfo_u64(value, newline, 16,
|
|
|
|
&prog->aarch64_insn_pac_mask);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
break;
|
2022-07-14 20:23:08 +01:00
|
|
|
@case "NUMBER(VA_BITS)"@
|
|
|
|
err = parse_vmcoreinfo_u64(value, newline, 0,
|
|
|
|
&prog->vmcoreinfo.va_bits);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
break;
|
2022-06-20 01:21:28 +01:00
|
|
|
@endswitch@
|
|
|
|
}
|
|
|
|
if (!prog->vmcoreinfo.osrelease[0]) {
|
|
|
|
return drgn_error_create(DRGN_ERROR_OTHER,
|
|
|
|
"VMCOREINFO does not contain valid OSRELEASE");
|
|
|
|
}
|
2022-07-08 22:23:09 +01:00
|
|
|
if (!is_power_of_two(prog->vmcoreinfo.page_size)) {
|
2022-06-20 01:21:28 +01:00
|
|
|
return drgn_error_create(DRGN_ERROR_OTHER,
|
|
|
|
"VMCOREINFO does not contain valid PAGESIZE");
|
|
|
|
}
|
2022-07-08 22:23:09 +01:00
|
|
|
prog->vmcoreinfo.page_shift = ctz(prog->vmcoreinfo.page_size);
|
2022-06-20 01:21:28 +01:00
|
|
|
if (!prog->vmcoreinfo.swapper_pg_dir) {
|
|
|
|
return drgn_error_create(DRGN_ERROR_OTHER,
|
|
|
|
"VMCOREINFO does not contain valid swapper_pg_dir");
|
|
|
|
}
|
2022-07-14 20:23:08 +01:00
|
|
|
// Everything else is optional.
|
2022-06-20 01:21:28 +01:00
|
|
|
return NULL;
|
|
|
|
}
|