Skip to content

Commit 6777fe6

Browse files
author
Dave Anderson
committed
Fix for the "snap.so" extension module to pass the value of the ARM64
"kimage_voffset" value in the ELF header. Without the patch, it is necessary to use the "--machdep kvimage_offset=<value>" command line option, or the session fails with the message "crash: vmlinux and vmcore do not match!". ([email protected])
1 parent 60d35d8 commit 6777fe6

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

extensions/snap.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ generate_elf_header(int type, int fd, char *filename)
425425
struct node_table *nt;
426426
struct SNAP_info {
427427
ulonglong task_struct;
428-
ulonglong relocate;
428+
ulonglong arch_data;
429429
} SNAP_info;
430430

431431
num_segments = vt->numnodes;
@@ -610,7 +610,13 @@ generate_elf_header(int type, int fd, char *filename)
610610

611611
/* NT_TASKSTRUCT note */
612612
SNAP_info.task_struct = CURRENT_TASK();
613-
SNAP_info.relocate = kt->relocate;
613+
#ifdef X86_64
614+
SNAP_info.arch_data = kt->relocate;
615+
#elif ARM64
616+
SNAP_info.arch_data = machdep->machspec->kimage_voffset;
617+
#else
618+
SNAP_info.arch_data = 0;
619+
#endif
614620
len = dump_elf_note (ptr, NT_TASKSTRUCT, "SNAP",
615621
(char *)&SNAP_info, sizeof(struct SNAP_info));
616622
offset += len;

netdump.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,14 @@ netdump_memory_dump(FILE *fp)
11721172
netdump_print(" nt_prpsinfo: %lx\n", nd->nt_prpsinfo);
11731173
netdump_print(" nt_taskstruct: %lx\n", nd->nt_taskstruct);
11741174
netdump_print(" task_struct: %lx\n", nd->task_struct);
1175-
netdump_print(" relocate: %lx\n", nd->relocate);
1175+
netdump_print(" arch_data: ");
1176+
if (nd->arch_data) {
1177+
if (machine_type("X86_64"))
1178+
netdump_print("%lx (relocate)\n", nd->arch_data);
1179+
else if (machine_type("ARM64"))
1180+
netdump_print("%lx (kimage_voffset)\n", nd->arch_data);
1181+
} else
1182+
netdump_print("(unused)\n");
11761183
netdump_print(" switch_stack: %lx\n", nd->switch_stack);
11771184
netdump_print(" page_size: %d\n", nd->page_size);
11781185
dump_xen_kdump_data(fp);
@@ -1770,6 +1777,24 @@ vmcoreinfo_read_string(const char *key)
17701777
char *vmcoreinfo = (char *)nd->vmcoreinfo;
17711778
char *value = NULL;
17721779

1780+
/*
1781+
* Borrow this function for ELF vmcores created by the snap.so
1782+
* extension module, where arch-specific data may be passed in
1783+
* the NT_TASKSTRUCT note.
1784+
*/
1785+
if ((pc->flags2 & SNAP)) {
1786+
if (STREQ(key, "NUMBER(kimage_voffset)") && nd->arch_data) {
1787+
value = calloc(VADDR_PRLEN+1, sizeof(char));
1788+
sprintf(value, "%lx", nd->arch_data);
1789+
return value;
1790+
}
1791+
if (STREQ(key, "relocate") && nd->arch_data) {
1792+
value = calloc(VADDR_PRLEN+1, sizeof(char));
1793+
sprintf(value, "%lx", nd->arch_data);
1794+
return value;
1795+
}
1796+
}
1797+
17731798
if (!nd->vmcoreinfo)
17741799
return NULL;
17751800

@@ -2160,15 +2185,9 @@ dump_Elf64_Nhdr(Elf64_Off offset, int store)
21602185
nd->nt_taskstruct = (void *)note;
21612186
nd->task_struct = *((ulong *)(ptr + note->n_namesz));
21622187
if (pc->flags2 & SNAP) {
2163-
if (note->n_descsz == 16) {
2164-
nd->relocate = *((ulong *)
2188+
if (note->n_descsz == 16)
2189+
nd->arch_data = *((ulong *)
21652190
(ptr + note->n_namesz + sizeof(ulong)));
2166-
if (nd->relocate) {
2167-
kt->relocate = nd->relocate;
2168-
kt->flags |= RELOC_SET;
2169-
kt->flags2 |= KASLR;
2170-
}
2171-
}
21722191
} else if (machine_type("IA64"))
21732192
nd->switch_stack = *((ulong *)
21742193
(ptr + note->n_namesz + sizeof(ulong)));

netdump.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct vmcore_data {
7777
ulonglong backup_src_start;
7878
ulong backup_src_size;
7979
ulonglong backup_offset;
80-
ulong relocate;
80+
ulong arch_data;
8181
};
8282

8383
#define DUMP_ELF_INCOMPLETE 0x1 /* dumpfile is incomplete */

x86_64.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ x86_64_init(int when)
184184
machdep->get_kvaddr_ranges = x86_64_get_kvaddr_ranges;
185185
if (machdep->cmdline_args[0])
186186
parse_cmdline_args();
187+
if ((string = pc->read_vmcoreinfo("relocate"))) {
188+
kt->relocate = htol(string, QUIET, NULL);
189+
kt->flags |= RELOC_SET;
190+
kt->flags2 |= KASLR;
191+
free(string);
192+
}
187193
if ((string = pc->read_vmcoreinfo("NUMBER(KERNEL_IMAGE_SIZE)"))) {
188194
machdep->machspec->kernel_image_size = dtol(string, QUIET, NULL);
189195
free(string);

0 commit comments

Comments
 (0)