Skip to content

Commit

Permalink
libdrgn: x86_64: avoid recursive address translation for swapper_pg_dir
Browse files Browse the repository at this point in the history
Co-authored-by: Illia Ostapyshyn <[email protected]>
Signed-off-by: Stephen Brennan <[email protected]>
  • Loading branch information
brenns10 and iostapyshyn committed May 29, 2024
1 parent 153325e commit ea77cc5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libdrgn/arch_x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "arch_x86_64_defs.inc"

#define START_KERNEL_MAP 0xffffffff80000000ULL

static const struct drgn_cfi_row default_dwarf_cfi_row_x86_64 = DRGN_CFI_ROW(
// The System V psABI defines the CFA as the value of rsp in the calling
// frame.
Expand Down Expand Up @@ -616,7 +618,13 @@ linux_kernel_pgtable_iterator_next_x86_64(struct drgn_program *prog,
for (;; level--) {
uint64_t table;
bool table_physical;
if (level == levels) {
if (level == levels && prog->vmcoreinfo.swapper_pg_dir &&
it->it.pgtable == prog->vmcoreinfo.swapper_pg_dir) {
// Avoid recursive address translation on swapper_pg_dir by
// directly resolving to a physical address
table = it->it.pgtable + prog->vmcoreinfo.phys_base - START_KERNEL_MAP;
table_physical = true;
} else if (level == levels) {
table = it->it.pgtable;
table_physical = false;
} else {
Expand Down
9 changes: 9 additions & 0 deletions libdrgn/drgn_program_parse_vmcoreinfo.inc.strswitch
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ struct drgn_error *drgn_program_parse_vmcoreinfo(struct drgn_program *prog,
prog->vmcoreinfo.pgtable_l5_enabled = tmp;
break;
}
@case "NUMBER(phys_base)"@
{
err = parse_vmcoreinfo_u64(value, newline, 0,
&prog->vmcoreinfo.phys_base);;
if (err)
return err;
break;
}
@case "NUMBER(KERNELPACMASK)"@
err = parse_vmcoreinfo_u64(value, newline, 16,
&prog->aarch64_insn_pac_mask);
Expand All @@ -92,6 +100,7 @@ struct drgn_error *drgn_program_parse_vmcoreinfo(struct drgn_program *prog,
if (err)
return err;
break;

@endswitch@
}
if (!prog->vmcoreinfo.osrelease[0]) {
Expand Down
2 changes: 2 additions & 0 deletions libdrgn/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ struct drgn_program {
uint64_t va_bits;
/** Whether 5-level paging was enabled on x86-64. */
bool pgtable_l5_enabled;
/** phys_base on x86_64 */
uint64_t phys_base;
/** PAGE_SHIFT of the kernel (derived from PAGE_SIZE). */
int page_shift;

Expand Down

0 comments on commit ea77cc5

Please sign in to comment.