vm_page_replace: add wrapper to KASSERT about old page

It turns out the callers of vm_page_replace know exactly which page they are
replacing and would like to assert about it.  Change those from hard panics to
KASSERTs, and provide them with a wrapper so they don't have to deal with
warnings from an INVARIANTS-dependent dead store of the return value of
vm_page_replace.

Submitted by:	Ryan Libby <rlibby@gmail.com>
Reviewed by:	alc, kib (earlier version)
Sponsored by:	EMC / Isilon Storage Division
Differential Revision:	https://reviews.freebsd.org/D4497
This commit is contained in:
Conrad Meyer 2015-12-17 17:48:57 +00:00
parent 122493cf95
commit 8170d6e52b
3 changed files with 17 additions and 4 deletions

View File

@ -347,8 +347,7 @@ old_dev_pager_fault(vm_object_t object, vm_ooffset_t offset, int prot,
*/
page = vm_page_getfake(paddr, memattr);
VM_OBJECT_WLOCK(object);
if (vm_page_replace(page, object, (*mres)->pindex) != *mres)
panic("old_dev_pager_fault: invalid page replacement");
vm_page_replace_checked(page, object, (*mres)->pindex, *mres);
vm_page_lock(*mres);
vm_page_free(*mres);
vm_page_unlock(*mres);

View File

@ -188,8 +188,7 @@ sg_pager_getpages(vm_object_t object, vm_page_t *m, int count, int *rbehind,
page = vm_page_getfake(paddr, memattr);
VM_OBJECT_WLOCK(object);
TAILQ_INSERT_TAIL(&object->un_pager.sgp.sgp_pglist, page, plinks.q);
if (vm_page_replace(page, object, offset) != m[0])
panic("sg_pager_getpages: invalid place replacement");
vm_page_replace_checked(page, object, offset, m[0]);
m[0] = page;
page->valid = VM_PAGE_BITS_ALL;

View File

@ -678,5 +678,20 @@ vm_page_undirty(vm_page_t m)
m->dirty = 0;
}
static inline void
vm_page_replace_checked(vm_page_t mnew, vm_object_t object, vm_pindex_t pindex,
vm_page_t mold)
{
vm_page_t mret;
mret = vm_page_replace(mnew, object, pindex);
KASSERT(mret == mold,
("invalid page replacement, mold=%p, mret=%p", mold, mret));
/* Unused if !INVARIANTS. */
(void)mold;
(void)mret;
}
#endif /* _KERNEL */
#endif /* !_VM_PAGE_ */