From ab041f713aeccdf23b4805ffb71815c8d4aa9c88 Mon Sep 17 00:00:00 2001 From: D Scott Phillips Date: Mon, 21 Sep 2020 22:20:37 +0000 Subject: Move vm_page_dump bitset array definition to MI code These definitions were repeated by all architectures, with small variations. Consolidate the common definitons in machine independent code and use bitset(9) macros for manipulation. Many opportunities for deduplication remain in the machine dependent minidump logic. The only intended functional change is increasing the bit index type to vm_pindex_t, allowing the indexing of pages with address of 8 TiB and greater. Reviewed by: kib, markj Approved by: scottl (implicit) MFC after: 1 week Sponsored by: Ampere Computing, Inc. Differential Revision: https://reviews.freebsd.org/D26129 --- sys/i386/i386/minidump_machdep.c | 27 --------------------- sys/i386/i386/minidump_machdep_base.c | 44 ++++++++++++----------------------- sys/i386/include/md_var.h | 1 - sys/i386/include/vmparam.h | 5 ++++ 4 files changed, 20 insertions(+), 57 deletions(-) (limited to 'sys/i386') diff --git a/sys/i386/i386/minidump_machdep.c b/sys/i386/i386/minidump_machdep.c index 5ef23cbc34ec..d2a7999cb2c3 100644 --- a/sys/i386/i386/minidump_machdep.c +++ b/sys/i386/i386/minidump_machdep.c @@ -49,33 +49,6 @@ __FBSDID("$FreeBSD$"); CTASSERT(sizeof(struct kerneldumpheader) == 512); -uint32_t *vm_page_dump; -int vm_page_dump_size; - -CTASSERT(sizeof(*vm_page_dump) == 4); - -void -dump_add_page(vm_paddr_t pa) -{ - int idx, bit; - - pa >>= PAGE_SHIFT; - idx = pa >> 5; /* 2^5 = 32 */ - bit = pa & 31; - atomic_set_int(&vm_page_dump[idx], 1ul << bit); -} - -void -dump_drop_page(vm_paddr_t pa) -{ - int idx, bit; - - pa >>= PAGE_SHIFT; - idx = pa >> 5; /* 2^5 = 32 */ - bit = pa & 31; - atomic_clear_int(&vm_page_dump[idx], 1ul << bit); -} - int minidumpsys(struct dumperinfo *di) { diff --git a/sys/i386/i386/minidump_machdep_base.c b/sys/i386/i386/minidump_machdep_base.c index 49400b0cc2ae..1c963907a430 100644 --- a/sys/i386/i386/minidump_machdep_base.c +++ b/sys/i386/i386/minidump_machdep_base.c @@ -62,8 +62,6 @@ static size_t fragsz; static void *dump_va; static uint64_t counter, progress; -CTASSERT(sizeof(*vm_page_dump) == 4); - static int is_dumpable(vm_paddr_t pa) { @@ -181,11 +179,10 @@ minidumpsys(struct dumperinfo *di) uint32_t ptesize; vm_offset_t va; int error; - uint32_t bits; uint64_t pa; pd_entry_t *pd; pt_entry_t *pt; - int i, j, k, bit; + int j, k; struct minidumphdr mdhdr; counter = 0; @@ -227,19 +224,13 @@ minidumpsys(struct dumperinfo *di) /* Calculate dump size. */ dumpsize = ptesize; dumpsize += round_page(msgbufp->msg_size); - dumpsize += round_page(vm_page_dump_size); - for (i = 0; i < vm_page_dump_size / sizeof(*vm_page_dump); i++) { - bits = vm_page_dump[i]; - while (bits) { - bit = bsfl(bits); - pa = (((uint64_t)i * sizeof(*vm_page_dump) * NBBY) + bit) * PAGE_SIZE; - /* Clear out undumpable pages now if needed */ - if (is_dumpable(pa)) { - dumpsize += PAGE_SIZE; - } else { - dump_drop_page(pa); - } - bits &= ~(1ul << bit); + dumpsize += round_page(BITSET_SIZE(vm_page_dump_pages)); + VM_PAGE_DUMP_FOREACH(pa) { + /* Clear out undumpable pages now if needed */ + if (is_dumpable(pa)) { + dumpsize += PAGE_SIZE; + } else { + dump_drop_page(pa); } } dumpsize += PAGE_SIZE; @@ -251,7 +242,7 @@ minidumpsys(struct dumperinfo *di) strcpy(mdhdr.magic, MINIDUMP_MAGIC); mdhdr.version = MINIDUMP_VERSION; mdhdr.msgbufsize = msgbufp->msg_size; - mdhdr.bitmapsize = vm_page_dump_size; + mdhdr.bitmapsize = round_page(BITSET_SIZE(vm_page_dump_pages)); mdhdr.ptesize = ptesize; mdhdr.kernbase = KERNBASE; mdhdr.paemode = pae_mode; @@ -279,7 +270,8 @@ minidumpsys(struct dumperinfo *di) goto fail; /* Dump bitmap */ - error = blk_write(di, (char *)vm_page_dump, 0, round_page(vm_page_dump_size)); + error = blk_write(di, (char *)vm_page_dump, 0, + round_page(BITSET_SIZE(vm_page_dump_pages))); if (error) goto fail; @@ -321,16 +313,10 @@ minidumpsys(struct dumperinfo *di) } /* Dump memory chunks */ - for (i = 0; i < vm_page_dump_size / sizeof(*vm_page_dump); i++) { - bits = vm_page_dump[i]; - while (bits) { - bit = bsfl(bits); - pa = (((uint64_t)i * sizeof(*vm_page_dump) * NBBY) + bit) * PAGE_SIZE; - error = blk_write(di, 0, pa, PAGE_SIZE); - if (error) - goto fail; - bits &= ~(1ul << bit); - } + VM_PAGE_DUMP_FOREACH(pa) { + error = blk_write(di, 0, pa, PAGE_SIZE); + if (error) + goto fail; } error = blk_flush(di); diff --git a/sys/i386/include/md_var.h b/sys/i386/include/md_var.h index b20446dce12b..c41de85b9bc9 100644 --- a/sys/i386/include/md_var.h +++ b/sys/i386/include/md_var.h @@ -47,7 +47,6 @@ extern int szfreebsd4_sigcode; extern int szosigcode; extern int sz_lcall_tramp; #endif -extern uint32_t *vm_page_dump; extern vm_offset_t proc0kstack; extern uintptr_t setidt_disp; diff --git a/sys/i386/include/vmparam.h b/sys/i386/include/vmparam.h index c7cf4de8cf75..212ddf758d17 100644 --- a/sys/i386/include/vmparam.h +++ b/sys/i386/include/vmparam.h @@ -240,4 +240,9 @@ #define PHYS_TO_DMAP(x) ({ panic("No direct map exists"); 0; }) #define DMAP_TO_PHYS(x) ({ panic("No direct map exists"); 0; }) +/* + * Need a page dump array for minidump. + */ +#define MINIDUMP_PAGE_TRACKING 1 + #endif /* _MACHINE_VMPARAM_H_ */ -- cgit v1.2.3