From: mpi Date: Tue, 15 Jun 2021 16:38:09 +0000 (+0000) Subject: Use a macro to assert that given uobjs correspond to anonymous objects. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=57296fa77041f09abfb1381e97904e41720fbd00;p=openbsd Use a macro to assert that given uobjs correspond to anonymous objects. Reduce the difference with NetBSD. ok kettenis@ --- diff --git a/sys/uvm/uvm_aobj.c b/sys/uvm/uvm_aobj.c index bce37bab02c..e187741a0fd 100644 --- a/sys/uvm/uvm_aobj.c +++ b/sys/uvm/uvm_aobj.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_aobj.c,v 1.96 2021/05/20 08:03:35 mpi Exp $ */ +/* $OpenBSD: uvm_aobj.c,v 1.97 2021/06/15 16:38:09 mpi Exp $ */ /* $NetBSD: uvm_aobj.c,v 1.39 2001/02/18 21:19:08 chs Exp $ */ /* @@ -143,7 +143,7 @@ struct pool uvm_aobj_pool; static struct uao_swhash_elt *uao_find_swhash_elt(struct uvm_aobj *, int, boolean_t); -static int uao_find_swslot(struct uvm_aobj *, int); +static int uao_find_swslot(struct uvm_object *, int); static boolean_t uao_flush(struct uvm_object *, voff_t, voff_t, int); static void uao_free(struct uvm_aobj *); @@ -242,8 +242,11 @@ uao_find_swhash_elt(struct uvm_aobj *aobj, int pageidx, boolean_t create) * uao_find_swslot: find the swap slot number for an aobj/pageidx */ inline static int -uao_find_swslot(struct uvm_aobj *aobj, int pageidx) +uao_find_swslot(struct uvm_object *uobj, int pageidx) { + struct uvm_aobj *aobj = (struct uvm_aobj *)uobj; + + KASSERT(UVM_OBJ_IS_AOBJ(uobj)); /* * if noswap flag is set, then we never return a slot @@ -284,6 +287,7 @@ uao_set_swslot(struct uvm_object *uobj, int pageidx, int slot) int oldslot; KERNEL_ASSERT_LOCKED(); + KASSERT(UVM_OBJ_IS_AOBJ(uobj)); /* * if noswap flag is set, then we can't set a slot @@ -353,6 +357,7 @@ uao_free(struct uvm_aobj *aobj) { struct uvm_object *uobj = &aobj->u_obj; + KASSERT(UVM_OBJ_IS_AOBJ(uobj)); uao_dropswap_range(uobj, 0, 0); if (UAO_USES_SWHASH(aobj)) { @@ -881,6 +886,7 @@ uao_flush(struct uvm_object *uobj, voff_t start, voff_t stop, int flags) struct vm_page *pp; voff_t curoff; + KASSERT(UVM_OBJ_IS_AOBJ(uobj)); KERNEL_ASSERT_LOCKED(); if (flags & PGO_ALLPAGES) { @@ -1007,6 +1013,7 @@ uao_get(struct uvm_object *uobj, voff_t offset, struct vm_page **pps, int lcv, gotpages, maxpages, swslot, rv, pageidx; boolean_t done; + KASSERT(UVM_OBJ_IS_AOBJ(uobj)); KERNEL_ASSERT_LOCKED(); /* @@ -1036,7 +1043,7 @@ uao_get(struct uvm_object *uobj, voff_t offset, struct vm_page **pps, * if page is new, attempt to allocate the page, * zero-fill'd. */ - if (ptmp == NULL && uao_find_swslot(aobj, + if (ptmp == NULL && uao_find_swslot(uobj, current_offset >> PAGE_SHIFT) == 0) { ptmp = uvm_pagealloc(uobj, current_offset, NULL, UVM_PGA_ZERO); @@ -1175,7 +1182,7 @@ uao_get(struct uvm_object *uobj, voff_t offset, struct vm_page **pps, * we have a "fake/busy/clean" page that we just allocated. * do the needed "i/o", either reading from swap or zeroing. */ - swslot = uao_find_swslot(aobj, pageidx); + swslot = uao_find_swslot(uobj, pageidx); /* just zero the page if there's nothing in swap. */ if (swslot == 0) { @@ -1241,6 +1248,8 @@ uao_dropswap(struct uvm_object *uobj, int pageidx) { int slot; + KASSERT(UVM_OBJ_IS_AOBJ(uobj)); + slot = uao_set_swslot(uobj, pageidx, 0); if (slot) { uvm_swap_free(slot, 1); @@ -1456,6 +1465,7 @@ uao_dropswap_range(struct uvm_object *uobj, voff_t start, voff_t end) struct uvm_aobj *aobj = (struct uvm_aobj *)uobj; int swpgonlydelta = 0; + KASSERT(UVM_OBJ_IS_AOBJ(uobj)); /* KASSERT(mutex_owned(uobj->vmobjlock)); */ if (end == 0) { diff --git a/sys/uvm/uvm_km.c b/sys/uvm/uvm_km.c index 84b4e7167cc..157a6f85841 100644 --- a/sys/uvm/uvm_km.c +++ b/sys/uvm/uvm_km.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_km.c,v 1.144 2021/05/16 15:10:20 deraadt Exp $ */ +/* $OpenBSD: uvm_km.c,v 1.145 2021/06/15 16:38:09 mpi Exp $ */ /* $NetBSD: uvm_km.c,v 1.42 2001/01/14 02:10:01 thorpej Exp $ */ /* @@ -246,7 +246,7 @@ uvm_km_pgremove(struct uvm_object *uobj, vaddr_t start, vaddr_t end) int slot; int swpgonlydelta = 0; - KASSERT(uobj->pgops == &aobj_pager); + KASSERT(UVM_OBJ_IS_AOBJ(uobj)); for (curoff = start ; curoff < end ; curoff += PAGE_SIZE) { pp = uvm_pagelookup(uobj, curoff); diff --git a/sys/uvm/uvm_object.h b/sys/uvm/uvm_object.h index ebee2ce1545..0b6d59d08da 100644 --- a/sys/uvm/uvm_object.h +++ b/sys/uvm/uvm_object.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_object.h,v 1.24 2020/10/21 09:08:14 mpi Exp $ */ +/* $OpenBSD: uvm_object.h,v 1.25 2021/06/15 16:38:09 mpi Exp $ */ /* $NetBSD: uvm_object.h,v 1.11 2001/03/09 01:02:12 chs Exp $ */ /* @@ -82,13 +82,16 @@ RBT_PROTOTYPE(uvm_objtree, vm_page, objt, uvm_pagecmp) #define UVM_OBJ_IS_VNODE(uobj) \ ((uobj)->pgops == &uvm_vnodeops) -#define UVM_OBJ_IS_DEVICE(uobj) \ +#define UVM_OBJ_IS_DEVICE(uobj) \ ((uobj)->pgops == &uvm_deviceops) #define UVM_OBJ_IS_VTEXT(uobj) \ ((uobj)->pgops == &uvm_vnodeops && \ ((struct vnode *)uobj)->v_flag & VTEXT) +#define UVM_OBJ_IS_AOBJ(uobj) \ + ((uobj)->pgops == &aobj_pager) + void uvm_objinit(struct uvm_object *, const struct uvm_pagerops *, int); int uvm_objwire(struct uvm_object *, voff_t, voff_t, struct pglist *); void uvm_objunwire(struct uvm_object *, voff_t, voff_t);