Fix for the handling of 32-bit ELF xendump dumpfiles if the guest

was configured with more than 4GB of memory.  Without the patch, the
crash session may fail during initialization with the error message
"crash: vmlinux and <dumpfile> do not match!".
(dslutz@verizon.com)
This commit is contained in:
Dave Anderson 2014-06-12 10:42:33 -04:00
parent 625e9d3eb8
commit 77537c1273
4 changed files with 56 additions and 52 deletions

10
x86.c
View File

@ -4897,7 +4897,7 @@ x86_xendump_p2m_create(struct xendump_data *xd)
"MEMBER_OFFSET(vcpu_guest_context, ctrlreg): %ld\n",
ctrlreg_offset);
offset = (off_t)xd->xc_core.header.xch_ctxt_offset +
offset = xd->xc_core.header.xch_ctxt_offset +
(off_t)ctrlreg_offset;
if (lseek(xd->xfd, offset, SEEK_SET) == -1)
@ -4997,7 +4997,7 @@ x86_pvops_xendump_p2m_create(struct xendump_data *xd)
"MEMBER_OFFSET(vcpu_guest_context, ctrlreg): %ld\n",
ctrlreg_offset);
offset = (off_t)xd->xc_core.header.xch_ctxt_offset +
offset = xd->xc_core.header.xch_ctxt_offset +
(off_t)ctrlreg_offset;
if (lseek(xd->xfd, offset, SEEK_SET) == -1)
@ -5369,7 +5369,7 @@ x86_xendump_panic_task(struct xendump_data *xd)
INVALID_MEMBER(cpu_user_regs_esp))
return NO_TASK;
offset = (off_t)xd->xc_core.header.xch_ctxt_offset +
offset = xd->xc_core.header.xch_ctxt_offset +
(off_t)OFFSET(vcpu_guest_context_user_regs) +
(off_t)OFFSET(cpu_user_regs_esp);
@ -5419,7 +5419,7 @@ x86_get_xendump_regs(struct xendump_data *xd, struct bt_info *bt, ulong *eip, ul
INVALID_MEMBER(cpu_user_regs_esp))
goto generic;
offset = (off_t)xd->xc_core.header.xch_ctxt_offset +
offset = xd->xc_core.header.xch_ctxt_offset +
(off_t)OFFSET(vcpu_guest_context_user_regs) +
(off_t)OFFSET(cpu_user_regs_esp);
if (lseek(xd->xfd, offset, SEEK_SET) == -1)
@ -5427,7 +5427,7 @@ x86_get_xendump_regs(struct xendump_data *xd, struct bt_info *bt, ulong *eip, ul
if (read(xd->xfd, &xesp, sizeof(ulong)) != sizeof(ulong))
goto generic;
offset = (off_t)xd->xc_core.header.xch_ctxt_offset +
offset = xd->xc_core.header.xch_ctxt_offset +
(off_t)OFFSET(vcpu_guest_context_user_regs) +
(off_t)OFFSET(cpu_user_regs_eip);
if (lseek(xd->xfd, offset, SEEK_SET) == -1)

View File

@ -6184,7 +6184,7 @@ x86_64_xendump_p2m_create(struct xendump_data *xd)
"MEMBER_OFFSET(vcpu_guest_context, ctrlreg): %ld\n",
ctrlreg_offset);
offset = (off_t)xd->xc_core.header.xch_ctxt_offset +
offset = xd->xc_core.header.xch_ctxt_offset +
(off_t)ctrlreg_offset;
if (lseek(xd->xfd, offset, SEEK_SET) == -1)
@ -6270,7 +6270,7 @@ x86_64_pvops_xendump_p2m_create(struct xendump_data *xd)
"MEMBER_OFFSET(vcpu_guest_context, ctrlreg): %ld\n",
ctrlreg_offset);
offset = (off_t)xd->xc_core.header.xch_ctxt_offset +
offset = xd->xc_core.header.xch_ctxt_offset +
(off_t)ctrlreg_offset;
if (lseek(xd->xfd, offset, SEEK_SET) == -1)
@ -6601,7 +6601,7 @@ x86_64_xendump_panic_task(struct xendump_data *xd)
INVALID_MEMBER(cpu_user_regs_esp))
return NO_TASK;
offset = (off_t)xd->xc_core.header.xch_ctxt_offset +
offset = xd->xc_core.header.xch_ctxt_offset +
(off_t)OFFSET(vcpu_guest_context_user_regs) +
(off_t)OFFSET(cpu_user_regs_rsp);
@ -6653,7 +6653,7 @@ x86_64_get_xendump_regs(struct xendump_data *xd, struct bt_info *bt, ulong *rip,
INVALID_MEMBER(cpu_user_regs_rsp))
goto generic;
offset = (off_t)xd->xc_core.header.xch_ctxt_offset +
offset = xd->xc_core.header.xch_ctxt_offset +
(off_t)OFFSET(vcpu_guest_context_user_regs) +
(off_t)OFFSET(cpu_user_regs_rsp);
if (lseek(xd->xfd, offset, SEEK_SET) == -1)
@ -6661,7 +6661,7 @@ x86_64_get_xendump_regs(struct xendump_data *xd, struct bt_info *bt, ulong *rip,
if (read(xd->xfd, &xrsp, sizeof(ulong)) != sizeof(ulong))
goto generic;
offset = (off_t)xd->xc_core.header.xch_ctxt_offset +
offset = xd->xc_core.header.xch_ctxt_offset +
(off_t)OFFSET(vcpu_guest_context_user_regs) +
(off_t)OFFSET(cpu_user_regs_rip);
if (lseek(xd->xfd, offset, SEEK_SET) == -1)

View File

@ -1,8 +1,8 @@
/*
* xendump.c
*
* Copyright (C) 2006-2011, 2013 David Anderson
* Copyright (C) 2006-2011, 2013 Red Hat, Inc. All rights reserved.
* Copyright (C) 2006-2011, 2013-2014 David Anderson
* Copyright (C) 2006-2011, 2013-2014 Red Hat, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -126,9 +126,9 @@ xc_core_verify(char *file, char *buf)
xd->xc_core.header.xch_magic = xcp->xch_magic;
xd->xc_core.header.xch_nr_vcpus = xcp->xch_nr_vcpus;
xd->xc_core.header.xch_nr_pages = xcp->xch_nr_pages;
xd->xc_core.header.xch_ctxt_offset = (ulong)xcp->xch_ctxt_offset;
xd->xc_core.header.xch_index_offset = (ulong)xcp->xch_index_offset;
xd->xc_core.header.xch_pages_offset = (ulong)xcp->xch_pages_offset;
xd->xc_core.header.xch_ctxt_offset = (off_t)xcp->xch_ctxt_offset;
xd->xc_core.header.xch_index_offset = (off_t)xcp->xch_index_offset;
xd->xc_core.header.xch_pages_offset = (off_t)xcp->xch_pages_offset;
xd->flags |= (XENDUMP_LOCAL | XC_CORE_ORIG | XC_CORE_P2M_CREATE);
@ -187,7 +187,7 @@ xc_core_read(void *bufptr, int cnt, ulong addr, physaddr_t paddr)
PFN_NOT_FOUND)
return READ_ERROR;
offset = (off_t)xd->xc_core.header.xch_pages_offset +
offset = xd->xc_core.header.xch_pages_offset +
((off_t)(page_index) * (off_t)xd->page_size);
if (lseek(xd->xfd, offset, SEEK_SET) == -1)
@ -852,7 +852,7 @@ read_xendump_hyper(int fd, void *bufptr, int cnt, ulong addr, physaddr_t paddr)
if ((page_index = xc_core_mfn_to_page_index(pfn)) == PFN_NOT_FOUND)
return READ_ERROR;
offset = (off_t)xd->xc_core.header.xch_pages_offset +
offset = xd->xc_core.header.xch_pages_offset +
((off_t)(page_index) * (off_t)xd->page_size);
if (lseek(xd->xfd, offset, SEEK_SET) == -1)
@ -1040,15 +1040,15 @@ xendump_memory_dump(FILE *fp)
fprintf(fp, " xch_nr_pages: %d (0x%x)\n",
xd->xc_core.header.xch_nr_pages,
xd->xc_core.header.xch_nr_pages);
fprintf(fp, " xch_ctxt_offset: %ld (0x%lx)\n",
xd->xc_core.header.xch_ctxt_offset,
xd->xc_core.header.xch_ctxt_offset);
fprintf(fp, " xch_index_offset: %ld (0x%lx)\n",
xd->xc_core.header.xch_index_offset,
xd->xc_core.header.xch_index_offset);
fprintf(fp, " xch_pages_offset: %ld (0x%lx)\n",
xd->xc_core.header.xch_pages_offset,
xd->xc_core.header.xch_pages_offset);
fprintf(fp, " xch_ctxt_offset: %llu (0x%llx)\n",
(ulonglong)xd->xc_core.header.xch_ctxt_offset,
(ulonglong)xd->xc_core.header.xch_ctxt_offset);
fprintf(fp, " xch_index_offset: %llu (0x%llx)\n",
(ulonglong)xd->xc_core.header.xch_index_offset,
(ulonglong)xd->xc_core.header.xch_index_offset);
fprintf(fp, " xch_pages_offset: %llu (0x%llx)\n",
(ulonglong)xd->xc_core.header.xch_pages_offset,
(ulonglong)xd->xc_core.header.xch_pages_offset);
fprintf(fp, " elf_class: %s\n", xd->xc_core.elf_class == ELFCLASS64 ? "ELFCLASS64" :
xd->xc_core.elf_class == ELFCLASS32 ? "ELFCLASS32" : "n/a");
@ -1285,7 +1285,7 @@ xc_core_mfn_to_page(ulong mfn, char *pgbuf)
if (xd->flags & XC_CORE_ELF)
return xc_core_elf_mfn_to_page(mfn, pgbuf);
if (lseek(xd->xfd, (off_t)xd->xc_core.header.xch_index_offset,
if (lseek(xd->xfd, xd->xc_core.header.xch_index_offset,
SEEK_SET) == -1) {
error(INFO, "cannot lseek to page index\n");
return NULL;
@ -1325,7 +1325,7 @@ xc_core_mfn_to_page(ulong mfn, char *pgbuf)
return NULL;
}
if (lseek(xd->xfd, (off_t)xd->xc_core.header.xch_pages_offset,
if (lseek(xd->xfd, xd->xc_core.header.xch_pages_offset,
SEEK_SET) == -1) {
error(INFO, "cannot lseek to xch_pages_offset\n");
return NULL;
@ -1400,7 +1400,7 @@ xc_core_elf_mfn_to_page(ulong mfn, char *pgbuf)
return NULL;
}
if (lseek(xd->xfd, (off_t)xd->xc_core.header.xch_pages_offset,
if (lseek(xd->xfd, xd->xc_core.header.xch_pages_offset,
SEEK_SET) == -1)
error(FATAL, "cannot lseek to xch_pages_offset\n");
@ -1434,7 +1434,7 @@ xc_core_mfn_to_page_index(ulong mfn)
if (xd->flags & XC_CORE_ELF)
return xc_core_elf_mfn_to_page_index(mfn);
if (lseek(xd->xfd, (off_t)xd->xc_core.header.xch_index_offset,
if (lseek(xd->xfd, xd->xc_core.header.xch_index_offset,
SEEK_SET) == -1) {
error(INFO, "cannot lseek to page index\n");
return MFN_NOT_FOUND;
@ -1527,7 +1527,7 @@ xc_core_mfns(ulong arg, FILE *ofp)
ulonglong tmp64[MAX_BATCH_SIZE];
size_t size;
if (lseek(xd->xfd, (off_t)xd->xc_core.header.xch_index_offset,
if (lseek(xd->xfd, xd->xc_core.header.xch_index_offset,
SEEK_SET) == -1) {
error(INFO, "cannot lseek to page index\n");
return FALSE;
@ -1677,7 +1677,7 @@ xc_core_pfn_to_page_index(ulong pfn)
p2m_idx = xd->xc_core.p2m_frame_index_list[idx];
if (lseek(xd->xfd, (off_t)xd->xc_core.header.xch_pages_offset,
if (lseek(xd->xfd, xd->xc_core.header.xch_pages_offset,
SEEK_SET) == -1) {
error(INFO, "cannot lseek to xch_pages_offset\n");
return PFN_NOT_FOUND;
@ -1801,7 +1801,7 @@ xc_core_pfn_valid(ulong pfn)
if (pfn >= (ulong)xd->xc_core.header.xch_nr_pages)
return FALSE;
offset = (off_t)xd->xc_core.header.xch_index_offset;
offset = xd->xc_core.header.xch_index_offset;
if (xd->flags & XC_CORE_64BIT_HOST)
offset += (off_t)(pfn * sizeof(ulonglong));
@ -2542,25 +2542,27 @@ xc_core_dump_Elf32_Shdr(Elf32_Off offset, int store)
return;
if (STREQ(name, ".xen_prstatus"))
xd->xc_core.header.xch_ctxt_offset =
(unsigned long)shdr.sh_offset;
xd->xc_core.header.xch_ctxt_offset =
(off_t)shdr.sh_offset;
if (STREQ(name, ".xen_shared_info"))
xd->xc_core.shared_info_offset = (off_t)shdr.sh_offset;
if (STREQ(name, ".xen_pfn")) {
xd->xc_core.header.xch_index_offset = shdr.sh_offset;
xd->xc_core.header.xch_index_offset =
(off_t)shdr.sh_offset;
xd->flags |= (XC_CORE_NO_P2M|XC_CORE_PFN_CREATE);
}
if (STREQ(name, ".xen_p2m")) {
xd->xc_core.header.xch_index_offset = shdr.sh_offset;
xd->xc_core.header.xch_index_offset =
(off_t)shdr.sh_offset;
xd->flags |= XC_CORE_P2M_CREATE;
}
if (STREQ(name, ".xen_pages"))
xd->xc_core.header.xch_pages_offset =
(unsigned long)shdr.sh_offset;
xd->xc_core.header.xch_pages_offset =
(off_t)shdr.sh_offset;
if (STREQ(name, ".xen_ia64_mapped_regs"))
xd->xc_core.ia64_mapped_regs_offset =
@ -2642,25 +2644,27 @@ xc_core_dump_Elf64_Shdr(Elf64_Off offset, int store)
return;
if (STREQ(name, ".xen_prstatus"))
xd->xc_core.header.xch_ctxt_offset =
(unsigned long)shdr.sh_offset;
xd->xc_core.header.xch_ctxt_offset =
(off_t)shdr.sh_offset;
if (STREQ(name, ".xen_shared_info"))
xd->xc_core.shared_info_offset = (off_t)shdr.sh_offset;
if (STREQ(name, ".xen_pfn")) {
xd->xc_core.header.xch_index_offset = shdr.sh_offset;
xd->xc_core.header.xch_index_offset =
(off_t)shdr.sh_offset;
xd->flags |= (XC_CORE_NO_P2M|XC_CORE_PFN_CREATE);
}
if (STREQ(name, ".xen_p2m")) {
xd->xc_core.header.xch_index_offset = shdr.sh_offset;
xd->xc_core.header.xch_index_offset =
(off_t)shdr.sh_offset;
xd->flags |= XC_CORE_P2M_CREATE;
}
if (STREQ(name, ".xen_pages"))
xd->xc_core.header.xch_pages_offset =
(unsigned long)shdr.sh_offset;
xd->xc_core.header.xch_pages_offset =
(off_t)shdr.sh_offset;
if (STREQ(name, ".xen_ia64_mapped_regs"))
xd->xc_core.ia64_mapped_regs_offset =
@ -2814,7 +2818,7 @@ xc_core_elf_pfn_init(void)
chunk = xd->xc_core.header.xch_nr_pages/INDEX_PFN_COUNT;
for (i = c = 0; i < INDEX_PFN_COUNT; i++, c += chunk) {
offset = (off_t)xd->xc_core.header.xch_index_offset +
offset = xd->xc_core.header.xch_index_offset +
(off_t)(c * sizeof(uint64_t));
if (lseek(xd->xfd, offset, SEEK_SET) == -1)
@ -2834,7 +2838,7 @@ xc_core_elf_pfn_init(void)
chunk = xd->xc_core.header.xch_nr_pages/INDEX_PFN_COUNT;
for (i = c = 0; i < INDEX_PFN_COUNT; i++, c += chunk) {
offset = (off_t)xd->xc_core.header.xch_index_offset +
offset = xd->xc_core.header.xch_index_offset +
(off_t)(c * sizeof(struct xen_dumpcore_p2m));
if (lseek(xd->xfd, offset, SEEK_SET) == -1)

View File

@ -1,8 +1,8 @@
/*
* xendump.h
*
* Copyright (C) 2006, 2007, 2009, 2010 David Anderson
* Copyright (C) 2006, 2007, 2009, 2010 Red Hat, Inc. All rights reserved.
* Copyright (C) 2006, 2007, 2009, 2010, 2014 David Anderson
* Copyright (C) 2006, 2007, 2009, 2010, 2014 Red Hat, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -42,9 +42,9 @@ struct xen_core_header {
unsigned int xch_magic;
unsigned int xch_nr_vcpus;
unsigned int xch_nr_pages;
unsigned long xch_ctxt_offset;
unsigned long xch_index_offset;
unsigned long xch_pages_offset;
off_t xch_ctxt_offset;
off_t xch_index_offset;
off_t xch_pages_offset;
};
struct pfn_offset_cache {