From owner-svn-src-head@freebsd.org Fri Jul 13 17:12:51 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2AB8B10448ED; Fri, 13 Jul 2018 17:12:51 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D0F498F6EB; Fri, 13 Jul 2018 17:12:50 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B1E60131EE; Fri, 13 Jul 2018 17:12:50 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6DHCoK8004266; Fri, 13 Jul 2018 17:12:50 GMT (envelope-from alc@FreeBSD.org) Received: (from alc@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6DHCocI004265; Fri, 13 Jul 2018 17:12:50 GMT (envelope-from alc@FreeBSD.org) Message-Id: <201807131712.w6DHCocI004265@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: alc set sender to alc@FreeBSD.org using -f From: Alan Cox Date: Fri, 13 Jul 2018 17:12:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336248 - head/sys/mips/mips X-SVN-Group: head X-SVN-Commit-Author: alc X-SVN-Commit-Paths: head/sys/mips/mips X-SVN-Commit-Revision: 336248 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Jul 2018 17:12:51 -0000 Author: alc Date: Fri Jul 13 17:12:50 2018 New Revision: 336248 URL: https://svnweb.freebsd.org/changeset/base/336248 Log: Invalidate the mapping before updating its physical address. Doing so ensures that all threads sharing the pmap have a consistent view of the mapping. This fixes the problem described in the commit log message for r329254 without the overhead of an extra fault in the common case. (Once the riscv pmap_enter() implementation is similarly modified, the workaround added in r329254 can be removed, reducing the overhead of CoW faults.) See also r335784 for amd64. The mips implementation of pmap_enter() already reused the PV entry from the old mapping. Reviewed by: kib, markj MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D16199 Modified: head/sys/mips/mips/pmap.c Modified: head/sys/mips/mips/pmap.c ============================================================================== --- head/sys/mips/mips/pmap.c Fri Jul 13 16:43:29 2018 (r336247) +++ head/sys/mips/mips/pmap.c Fri Jul 13 17:12:50 2018 (r336248) @@ -2037,6 +2037,8 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, v if (is_kernel_pmap(pmap)) newpte |= PTE_G; PMAP_PTE_SET_CACHE_BITS(newpte, pa, m); + if ((m->oflags & VPO_UNMANAGED) == 0) + newpte |= PTE_MANAGED; mpte = NULL; @@ -2066,8 +2068,11 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, v panic("pmap_enter: invalid page directory, pdir=%p, va=%p", (void *)pmap->pm_segtab, (void *)va); } - om = NULL; + origpte = *pte; + KASSERT(!pte_test(&origpte, PTE_D | PTE_RO | PTE_V), + ("pmap_enter: modified page not writable: va: %p, pte: %#jx", + (void *)va, (uintmax_t)origpte)); opa = TLBLO_PTE_TO_PA(origpte); /* @@ -2086,10 +2091,6 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, v PTE_W)) pmap->pm_stats.wired_count--; - KASSERT(!pte_test(&origpte, PTE_D | PTE_RO), - ("%s: modified page not writable: va: %p, pte: %#jx", - __func__, (void *)va, (uintmax_t)origpte)); - /* * Remove extra pte reference */ @@ -2098,8 +2099,6 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, v if (pte_test(&origpte, PTE_MANAGED)) { m->md.pv_flags |= PV_TABLE_REF; - om = m; - newpte |= PTE_MANAGED; if (!pte_test(&newpte, PTE_RO)) vm_page_aflag_set(m, PGA_WRITEABLE); } @@ -2113,13 +2112,29 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, v * handle validating new mapping. */ if (opa) { + if (is_kernel_pmap(pmap)) + *pte = PTE_G; + else + *pte = 0; if (pte_test(&origpte, PTE_W)) pmap->pm_stats.wired_count--; - if (pte_test(&origpte, PTE_MANAGED)) { om = PHYS_TO_VM_PAGE(opa); + if (pte_test(&origpte, PTE_D)) + vm_page_dirty(om); + if ((om->md.pv_flags & PV_TABLE_REF) != 0) { + om->md.pv_flags &= ~PV_TABLE_REF; + vm_page_aflag_set(om, PGA_REFERENCED); + } pv = pmap_pvh_remove(&om->md, pmap, va); + if (!pte_test(&newpte, PTE_MANAGED)) + free_pv_entry(pmap, pv); + if ((om->aflags & PGA_WRITEABLE) != 0 && + TAILQ_EMPTY(&om->md.pv_list)) + vm_page_aflag_clear(om, PGA_WRITEABLE); } + pmap_invalidate_page(pmap, va); + origpte = 0; if (mpte != NULL) { mpte->wire_count--; KASSERT(mpte->wire_count > 0, @@ -2132,17 +2147,16 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, v /* * Enter on the PV list if part of our managed memory. */ - if ((m->oflags & VPO_UNMANAGED) == 0) { + if (pte_test(&newpte, PTE_MANAGED)) { m->md.pv_flags |= PV_TABLE_REF; - if (pv == NULL) + if (pv == NULL) { pv = get_pv_entry(pmap, FALSE); - pv->pv_va = va; + pv->pv_va = va; + } TAILQ_INSERT_TAIL(&m->md.pv_list, pv, pv_list); - newpte |= PTE_MANAGED; if (!pte_test(&newpte, PTE_RO)) vm_page_aflag_set(m, PGA_WRITEABLE); - } else if (pv != NULL) - free_pv_entry(pmap, pv); + } /* * Increment counters @@ -2163,21 +2177,11 @@ validate: if (origpte != newpte) { *pte = newpte; if (pte_test(&origpte, PTE_V)) { - if (pte_test(&origpte, PTE_MANAGED) && opa != pa) { - if (om->md.pv_flags & PV_TABLE_REF) - vm_page_aflag_set(om, PGA_REFERENCED); - om->md.pv_flags &= ~PV_TABLE_REF; - } + KASSERT(opa == pa, ("pmap_enter: invalid update")); if (pte_test(&origpte, PTE_D)) { - KASSERT(!pte_test(&origpte, PTE_RO), - ("pmap_enter: modified page not writable:" - " va: %p, pte: %#jx", (void *)va, (uintmax_t)origpte)); if (pte_test(&origpte, PTE_MANAGED)) - vm_page_dirty(om); + vm_page_dirty(m); } - if (pte_test(&origpte, PTE_MANAGED) && - TAILQ_EMPTY(&om->md.pv_list)) - vm_page_aflag_clear(om, PGA_WRITEABLE); pmap_update_page(pmap, va, newpte); } }