diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c --- a/sys/i386/i386/pmap.c +++ b/sys/i386/i386/pmap.c @@ -3935,12 +3935,11 @@ struct spglist free; pd_entry_t oldpde, *pde; vm_page_t mt; + vm_page_t uwptpg = NULL; rw_assert(&pvh_global_lock, RA_WLOCKED); KASSERT((newpde & (PG_M | PG_RW)) != PG_RW, ("pmap_enter_pde: newpde is missing PG_M")); - KASSERT(pmap == kernel_pmap || (newpde & PG_W) == 0, - ("pmap_enter_pde: cannot create wired user mapping")); PMAP_LOCK_ASSERT(pmap, MA_OWNED); pde = pmap_pde(pmap, va); oldpde = *pde; @@ -3983,11 +3982,39 @@ panic("pmap_enter_pde: trie insert failed"); } } + + /* + * Allocate a leaf ptpage for wired userspace pages. + */ + if ((newpde & PG_W) != 0 && pmap != kernel_pmap) { + uwptpg = vm_page_alloc_noobj(VM_ALLOC_WIRED); + if (uwptpg == NULL) { + return (KERN_RESOURCE_SHORTAGE); + } + uwptpg->pindex = va >> PDRSHIFT; + if (pmap_insert_pt_page(pmap, uwptpg, false)) { + vm_page_unwire_noq(uwptpg); + vm_page_free(uwptpg); + return (KERN_RESOURCE_SHORTAGE); + } + pmap->pm_stats.resident_count++; + uwptpg->ref_count = NPTEPG; + } if ((newpde & PG_MANAGED) != 0) { /* * Abort this mapping if its PV entry could not be created. */ if (!pmap_pv_insert_pde(pmap, va, newpde, flags)) { + if (uwptpg != NULL) { + mt = pmap_remove_pt_page(pmap, va); + KASSERT(mt == uwptpg, + ("removed pt page %p, expected %p", mt, + uwptpg)); + pmap->pm_stats.resident_count--; + uwptpg->ref_count = 1; + vm_page_unwire_noq(uwptpg); + vm_page_free(uwptpg); + } CTR2(KTR_PMAP, "pmap_enter_pde: failure for va %#lx" " in pmap %p", va, pmap); return (KERN_RESOURCE_SHORTAGE);