From 422fe502b3ca589d522a791ab29bb07c9e277b77 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Sat, 21 Oct 2017 17:28:12 +0000 Subject: [PATCH] Check that the page which is freed as zeroed, indeed has all-zero content. This catches some rare mysterious failures at the source. The check is only performed on architectures which implement direct map, and only enabled with option DIAGNOSTIC, similar to other costly consistency checks. Reviewed by: alc, markj Sponsored by: The FreeBSD Foundation MFC after: 2 weeks --- sys/vm/vm_page.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index dafcab4e2d7d..7311d19da89a 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -2780,6 +2780,16 @@ bool vm_page_free_prep(vm_page_t m, bool pagequeue_locked) { +#if defined(DIAGNOSTIC) && defined(PHYS_TO_DMAP) + if ((m->flags & PG_ZERO) != 0) { + uint64_t *p; + int i; + p = (uint64_t *)PHYS_TO_DMAP(VM_PAGE_TO_PHYS(m)); + for (i = 0; i < PAGE_SIZE / sizeof(uint64_t); i++, p++) + KASSERT(*p == 0, ("vm_page_free_prep %p PG_ZERO %d %jx", + m, i, (uintmax_t)*p)); + } +#endif if ((m->oflags & VPO_UNMANAGED) == 0) { vm_page_lock_assert(m, MA_OWNED); KASSERT(!pmap_page_is_mapped(m),