From 32d2014ddea98d33b6b83fe2afadf5049d4b61e2 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Wed, 5 Jun 2019 20:21:17 +0000 Subject: [PATCH] In vm_map_entry_set_vnode_text(), tolerate tmpfs mappings for which vnode is no longer resident. Mapping of tmpfs file does not bump use count on the vnode, because backing object has swap type. As result, even during normal operations, and of course on forced unmount, we might end up with text mapping from tmpfs node which has no vnode in memory. In this case, there is no v_writecount to clear (this was done during reclaim), and no reason to assert that the vnode is present. Restructure the code to silently ignore OBJ_SWAP objects with OBJ_TMPFS_NODE flag set, but OBJ_TMPFS flag clear. Reported and tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week --- sys/vm/vm_map.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index b5c1a78bb61..72ee70eaf95 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -526,19 +526,31 @@ vm_map_entry_set_vnode_text(vm_map_entry_t entry, bool add) object = object1; } - /* - * For OBJT_DEAD objects, v_writecount was handled in - * vnode_pager_dealloc(). - */ - if (object->type != OBJT_DEAD) { - KASSERT(((object->flags & OBJ_TMPFS) == 0 && - object->type == OBJT_VNODE) || - ((object->flags & OBJ_TMPFS) != 0 && - object->type == OBJT_SWAP), + vp = NULL; + if (object->type == OBJT_DEAD) { + /* + * For OBJT_DEAD objects, v_writecount was handled in + * vnode_pager_dealloc(). + */ + } else if (object->type == OBJT_VNODE) { + vp = object->handle; + } else if (object->type == OBJT_SWAP) { + KASSERT((object->flags & OBJ_TMPFS_NODE) != 0, + ("vm_map_entry_set_vnode_text: swap and !TMPFS " + "entry %p, object %p, add %d", entry, object, add)); + /* + * Tmpfs VREG node, which was reclaimed, has + * OBJ_TMPFS_NODE flag set, but not OBJ_TMPFS. In + * this case there is no v_writecount to adjust. + */ + if ((object->flags & OBJ_TMPFS) != 0) + vp = object->un_pager.swp.swp_tmpfs; + } else { + KASSERT(0, ("vm_map_entry_set_vnode_text: wrong object type, " "entry %p, object %p, add %d", entry, object, add)); - vp = (object->flags & OBJ_TMPFS) == 0 ? object->handle : - object->un_pager.swp.swp_tmpfs; + } + if (vp != NULL) { if (add) VOP_SET_TEXT_CHECKED(vp); else -- 2.45.0