Changeset View
Changeset View
Standalone View
Standalone View
sys/arm64/arm64/minidump_machdep.c
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
#include <vm/pmap.h> | #include <vm/pmap.h> | ||||
#include <machine/md_var.h> | #include <machine/md_var.h> | ||||
#include <machine/pte.h> | #include <machine/pte.h> | ||||
#include <machine/minidump.h> | #include <machine/minidump.h> | ||||
CTASSERT(sizeof(struct kerneldumpheader) == 512); | CTASSERT(sizeof(struct kerneldumpheader) == 512); | ||||
uint64_t *vm_page_dump; | |||||
int vm_page_dump_size; | |||||
static struct kerneldumpheader kdh; | static struct kerneldumpheader kdh; | ||||
/* Handle chunked writes. */ | /* Handle chunked writes. */ | ||||
static size_t fragsz; | static size_t fragsz; | ||||
static void *dump_va; | static void *dump_va; | ||||
static size_t counter, progress, dumpsize; | static size_t counter, progress, dumpsize; | ||||
static uint64_t tmpbuffer[Ln_ENTRIES]; | static uint64_t tmpbuffer[Ln_ENTRIES]; | ||||
CTASSERT(sizeof(*vm_page_dump) == 8); | |||||
static int | static int | ||||
is_dumpable(vm_paddr_t pa) | is_dumpable(vm_paddr_t pa) | ||||
{ | { | ||||
vm_page_t m; | vm_page_t m; | ||||
int i; | int i; | ||||
if ((m = vm_phys_paddr_to_vm_page(pa)) != NULL) | if ((m = vm_phys_paddr_to_vm_page(pa)) != NULL) | ||||
return ((m->flags & PG_NODUMP) == 0); | return ((m->flags & PG_NODUMP) == 0); | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
minidumpsys(struct dumperinfo *di) | minidumpsys(struct dumperinfo *di) | ||||
{ | { | ||||
struct minidumphdr mdhdr; | struct minidumphdr mdhdr; | ||||
pd_entry_t *l0, *l1, *l2; | pd_entry_t *l0, *l1, *l2; | ||||
pt_entry_t *l3; | pt_entry_t *l3; | ||||
vm_offset_t va; | vm_offset_t va; | ||||
vm_paddr_t pa; | vm_paddr_t pa; | ||||
uint64_t bits; | |||||
uint32_t pmapsize; | uint32_t pmapsize; | ||||
int bit, error, i, j, retry_count; | int bit, error, i, j, retry_count; | ||||
retry_count = 0; | retry_count = 0; | ||||
retry: | retry: | ||||
retry_count++; | retry_count++; | ||||
error = 0; | error = 0; | ||||
pmapsize = 0; | pmapsize = 0; | ||||
Show All 25 Lines | if ((*l1 & ATTR_DESCR_MASK) == L1_BLOCK) { | ||||
dump_add_page(pa); | dump_add_page(pa); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/* Calculate dump size. */ | /* Calculate dump size. */ | ||||
dumpsize = pmapsize; | dumpsize = pmapsize; | ||||
dumpsize += round_page(msgbufp->msg_size); | dumpsize += round_page(msgbufp->msg_size); | ||||
dumpsize += round_page(vm_page_dump_size); | dumpsize += round_page(BITSET_SIZE(vm_page_dump_pages)); | ||||
for (i = 0; i < vm_page_dump_size / sizeof(*vm_page_dump); i++) { | VM_PAGE_DUMP_FOREACH(bit, pa) { | ||||
bits = vm_page_dump[i]; | |||||
while (bits) { | |||||
bit = ffsl(bits) - 1; | |||||
pa = (((uint64_t)i * sizeof(*vm_page_dump) * NBBY) + | |||||
bit) * PAGE_SIZE; | |||||
/* Clear out undumpable pages now if needed */ | |||||
if (is_dumpable(pa)) | if (is_dumpable(pa)) | ||||
dumpsize += PAGE_SIZE; | dumpsize += PAGE_SIZE; | ||||
else | else | ||||
dump_drop_page(pa); | dump_drop_page(pa); | ||||
bits &= ~(1ul << bit); | |||||
} | } | ||||
} | |||||
dumpsize += PAGE_SIZE; | dumpsize += PAGE_SIZE; | ||||
progress = dumpsize; | progress = dumpsize; | ||||
/* Initialize mdhdr */ | /* Initialize mdhdr */ | ||||
bzero(&mdhdr, sizeof(mdhdr)); | bzero(&mdhdr, sizeof(mdhdr)); | ||||
strcpy(mdhdr.magic, MINIDUMP_MAGIC); | strcpy(mdhdr.magic, MINIDUMP_MAGIC); | ||||
mdhdr.version = MINIDUMP_VERSION; | mdhdr.version = MINIDUMP_VERSION; | ||||
mdhdr.msgbufsize = msgbufp->msg_size; | mdhdr.msgbufsize = msgbufp->msg_size; | ||||
mdhdr.bitmapsize = vm_page_dump_size; | mdhdr.bitmapsize = BITSET_SIZE(vm_page_dump_pages); | ||||
mdhdr.pmapsize = pmapsize; | mdhdr.pmapsize = pmapsize; | ||||
mdhdr.kernbase = VM_MIN_KERNEL_ADDRESS; | mdhdr.kernbase = VM_MIN_KERNEL_ADDRESS; | ||||
mdhdr.dmapphys = DMAP_MIN_PHYSADDR; | mdhdr.dmapphys = DMAP_MIN_PHYSADDR; | ||||
mdhdr.dmapbase = DMAP_MIN_ADDRESS; | mdhdr.dmapbase = DMAP_MIN_ADDRESS; | ||||
mdhdr.dmapend = DMAP_MAX_ADDRESS; | mdhdr.dmapend = DMAP_MAX_ADDRESS; | ||||
dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_AARCH64_VERSION, | dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_AARCH64_VERSION, | ||||
dumpsize); | dumpsize); | ||||
Show All 15 Lines | retry: | ||||
/* Dump msgbuf up front */ | /* Dump msgbuf up front */ | ||||
error = blk_write(di, (char *)msgbufp->msg_ptr, 0, | error = blk_write(di, (char *)msgbufp->msg_ptr, 0, | ||||
round_page(msgbufp->msg_size)); | round_page(msgbufp->msg_size)); | ||||
if (error) | if (error) | ||||
goto fail; | goto fail; | ||||
/* Dump bitmap */ | /* Dump bitmap */ | ||||
error = blk_write(di, (char *)vm_page_dump, 0, | error = blk_write(di, (char *)vm_page_dump, 0, | ||||
round_page(vm_page_dump_size)); | round_page(BITSET_SIZE(vm_page_dump_pages))); | ||||
if (error) | if (error) | ||||
goto fail; | goto fail; | ||||
/* Dump kernel page directory pages */ | /* Dump kernel page directory pages */ | ||||
bzero(&tmpbuffer, sizeof(tmpbuffer)); | bzero(&tmpbuffer, sizeof(tmpbuffer)); | ||||
for (va = VM_MIN_KERNEL_ADDRESS; va < kernel_vm_end; va += L2_SIZE) { | for (va = VM_MIN_KERNEL_ADDRESS; va < kernel_vm_end; va += L2_SIZE) { | ||||
if (!pmap_get_tables(pmap_kernel(), va, &l0, &l1, &l2, &l3)) { | if (!pmap_get_tables(pmap_kernel(), va, &l0, &l1, &l2, &l3)) { | ||||
/* We always write a page, even if it is zero */ | /* We always write a page, even if it is zero */ | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | if (!pmap_get_tables(pmap_kernel(), va, &l0, &l1, &l2, &l3)) { | ||||
error = blk_write(di, NULL, pa, PAGE_SIZE); | error = blk_write(di, NULL, pa, PAGE_SIZE); | ||||
if (error) | if (error) | ||||
goto fail; | goto fail; | ||||
} | } | ||||
} | } | ||||
/* Dump memory chunks */ | /* Dump memory chunks */ | ||||
for (i = 0; i < vm_page_dump_size / sizeof(*vm_page_dump); i++) { | VM_PAGE_DUMP_FOREACH(bit, pa) { | ||||
bits = vm_page_dump[i]; | |||||
while (bits) { | |||||
bit = ffsl(bits) - 1; | |||||
pa = (((uint64_t)i * sizeof(*vm_page_dump) * NBBY) + | |||||
bit) * PAGE_SIZE; | |||||
error = blk_write(di, 0, pa, PAGE_SIZE); | error = blk_write(di, 0, pa, PAGE_SIZE); | ||||
if (error) | if (error) | ||||
goto fail; | goto fail; | ||||
bits &= ~(1ul << bit); | |||||
} | } | ||||
} | |||||
error = blk_flush(di); | error = blk_flush(di); | ||||
if (error) | if (error) | ||||
goto fail; | goto fail; | ||||
error = dump_finish(di, &kdh); | error = dump_finish(di, &kdh); | ||||
if (error != 0) | if (error != 0) | ||||
goto fail; | goto fail; | ||||
Show All 17 Lines | fail: | ||||
else if (error == ECANCELED) | else if (error == ECANCELED) | ||||
printf("Dump aborted\n"); | printf("Dump aborted\n"); | ||||
else if (error == E2BIG) { | else if (error == E2BIG) { | ||||
printf("Dump failed. Partition too small (about %lluMB were " | printf("Dump failed. Partition too small (about %lluMB were " | ||||
"needed this time).\n", (long long)dumpsize >> 20); | "needed this time).\n", (long long)dumpsize >> 20); | ||||
} else | } else | ||||
printf("** DUMP FAILED (ERROR %d) **\n", error); | printf("** DUMP FAILED (ERROR %d) **\n", error); | ||||
return (error); | return (error); | ||||
} | |||||
void | |||||
dump_add_page(vm_paddr_t pa) | |||||
{ | |||||
int idx, bit; | |||||
pa >>= PAGE_SHIFT; | |||||
idx = pa >> 6; /* 2^6 = 64 */ | |||||
bit = pa & 63; | |||||
atomic_set_long(&vm_page_dump[idx], 1ul << bit); | |||||
} | |||||
void | |||||
dump_drop_page(vm_paddr_t pa) | |||||
{ | |||||
int idx, bit; | |||||
pa >>= PAGE_SHIFT; | |||||
idx = pa >> 6; /* 2^6 = 64 */ | |||||
bit = pa & 63; | |||||
atomic_clear_long(&vm_page_dump[idx], 1ul << bit); | |||||
} | } |