From nobody Mon Oct 11 10:44:28 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4C08D1804941; Mon, 11 Oct 2021 10:44:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HSb5T13NJz3rNG; Mon, 11 Oct 2021 10:44:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 024B41FA47; Mon, 11 Oct 2021 10:44:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19BAiSMg028716; Mon, 11 Oct 2021 10:44:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19BAiS9G028715; Mon, 11 Oct 2021 10:44:28 GMT (envelope-from git) Date: Mon, 11 Oct 2021 10:44:28 GMT Message-Id: <202110111044.19BAiS9G028715@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 806a88e74200 - main - Only demote when needed in the arm64 pmap_change_props_locked List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 806a88e742002b0e82a4ea06f8e147f627947c2c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=806a88e742002b0e82a4ea06f8e147f627947c2c commit 806a88e742002b0e82a4ea06f8e147f627947c2c Author: Andrew Turner AuthorDate: 2021-10-06 16:38:22 +0000 Commit: Andrew Turner CommitDate: 2021-10-11 09:29:44 +0000 Only demote when needed in the arm64 pmap_change_props_locked When changing page table properties there is no need to demote a level 1 or level 2 block if we are changing the entire memory range the block is mapping. In this case just change the block directly. Reported by: alc, kib, markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D32339 --- sys/arm64/arm64/pmap.c | 76 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c index 259e0a0c2e62..9fbd473abe3a 100644 --- a/sys/arm64/arm64/pmap.c +++ b/sys/arm64/arm64/pmap.c @@ -5982,7 +5982,8 @@ pmap_change_props_locked(vm_offset_t va, vm_size_t size, vm_prot_t prot, int mode) { vm_offset_t base, offset, tmpva; - pt_entry_t l3, *pte, *newpte; + vm_size_t pte_size; + pt_entry_t pte, *ptep, *newpte; pt_entry_t bits, mask; int lvl, rv; @@ -6028,11 +6029,11 @@ pmap_change_props_locked(vm_offset_t va, vm_size_t size, vm_prot_t prot, } for (tmpva = base; tmpva < base + size; ) { - pte = pmap_pte(kernel_pmap, tmpva, &lvl); - if (pte == NULL) + ptep = pmap_pte(kernel_pmap, tmpva, &lvl); + if (ptep == NULL) return (EINVAL); - if ((pmap_load(pte) & mask) == bits) { + if ((pmap_load(ptep) & mask) == bits) { /* * We already have the correct attribute, * ignore this entry. @@ -6059,47 +6060,60 @@ pmap_change_props_locked(vm_offset_t va, vm_size_t size, vm_prot_t prot, default: panic("Invalid DMAP table level: %d\n", lvl); case 1: - newpte = pmap_demote_l1(kernel_pmap, pte, + if ((tmpva & L1_OFFSET) == 0 && + (base + size - tmpva) >= L1_SIZE) { + pte_size = L1_SIZE; + break; + } + newpte = pmap_demote_l1(kernel_pmap, ptep, tmpva & ~L1_OFFSET); if (newpte == NULL) return (EINVAL); - pte = pmap_l1_to_l2(pte, tmpva); + ptep = pmap_l1_to_l2(ptep, tmpva); + /* FALLTHROUGH */ case 2: - newpte = pmap_demote_l2(kernel_pmap, pte, + if ((tmpva & L2_OFFSET) == 0 && + (base + size - tmpva) >= L2_SIZE) { + pte_size = L2_SIZE; + break; + } + newpte = pmap_demote_l2(kernel_pmap, ptep, tmpva); if (newpte == NULL) return (EINVAL); - pte = pmap_l2_to_l3(pte, tmpva); + ptep = pmap_l2_to_l3(ptep, tmpva); + /* FALLTHROUGH */ case 3: - /* Update the entry */ - l3 = pmap_load(pte); - l3 &= ~mask; - l3 |= bits; + pte_size = PAGE_SIZE; + break; + } - pmap_update_entry(kernel_pmap, pte, l3, tmpva, - PAGE_SIZE); + /* Update the entry */ + pte = pmap_load(ptep); + pte &= ~mask; + pte |= bits; - if (!VIRT_IN_DMAP(tmpva)) { - /* - * Keep the DMAP memory in sync. - */ - rv = pmap_change_props_locked( - PHYS_TO_DMAP(l3 & ~ATTR_MASK), - L3_SIZE, prot, mode); - if (rv != 0) - return (rv); - } + pmap_update_entry(kernel_pmap, ptep, pte, tmpva, + pte_size); + if (!VIRT_IN_DMAP(tmpva)) { /* - * If moving to a non-cacheable entry flush - * the cache. + * Keep the DMAP memory in sync. */ - if (mode == VM_MEMATTR_UNCACHEABLE) - cpu_dcache_wbinv_range(tmpva, L3_SIZE); - - break; + rv = pmap_change_props_locked( + PHYS_TO_DMAP(pte & ~ATTR_MASK), pte_size, + prot, mode); + if (rv != 0) + return (rv); } - tmpva += PAGE_SIZE; + + /* + * If moving to a non-cacheable entry flush + * the cache. + */ + if (mode == VM_MEMATTR_UNCACHEABLE) + cpu_dcache_wbinv_range(tmpva, pte_size); + tmpva += pte_size; } }