From nobody Sat Jul 06 20:49:34 2024 X-Original-To: dev-commits-src-all@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 4WGjDb0SNKz5PwW0; Sat, 06 Jul 2024 20:49:35 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WGjDZ6yw6z4G9v; Sat, 6 Jul 2024 20:49:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720298975; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NrLuodkjIwdDvG5g00oWfeghvczJg7pgVTIxOyqoHDk=; b=tZvVDb+pWSqPKlNmhIrcsOl5duAyFfl6gggsrheFgnwxxgXl4bAakJE1VVFivTk+dQOWQ0 EUVRPYimSx/JksXqvCqKMJEV3jc6LiuiIR3Hvz3bXT2jrME23irnQFbvBc6feAfdP59yzg Qj4D3E8/GO2BRW5LbXnCyd3FYFs8HgyCrcncxgjhnQeY9qFUVaEuK8+ES/KfJtdK51Sp7W IOM7UuN+VWyu1cFzYwoK8IoACFQzYAIj9+8MOfYxtxQjSGoErAT3iJPFWvKzPkyTkWqib6 aqWoN00YV/u1pPcuRoUQpb+ZlS+mDyhdELOk5K0sT1rozn9fEl71drswY7ostg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1720298975; a=rsa-sha256; cv=none; b=sxL3NhHZME5cFQ3qIGyq9+bqhb8oaPljouYhPn7BKXqxmsS8HmgumxsxaEFr/J0svCLrCr Kj5uTJlob/lztInHhSDsgokfRcErd4qv5TZ/sG+FNNC+rSWj6O8JCOH1SMRlLfa7QPPPBj yc1gFX3DQ16B7/xn40RhP1dkG7SVgLl8lCngp0IS/gWEWb26CpLkpa7D6KCV6NH6E129l6 8nVgSujRcGPyl6NkXOsRPPt5Erw9PRdbV3Y8+XGYMQ5wk/w+mNZbCl/AnvMnscv20jaYwE Vw2fznss/uYJ1B13r8/Zkk7x6ewIMdOFUOgRnuOHmqnTJmjZfYbZVdAmRSEMeA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720298975; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NrLuodkjIwdDvG5g00oWfeghvczJg7pgVTIxOyqoHDk=; b=uVJLMO9KVSXbg6am1+kGsCrN+KqHuUbuqRudKze7eFhW2188Nn4QoWOzIBDKZk9QVYjwSv 2IEyE717VEyCyisRlu0blRkJRfjfxfxYCaps4WRY3xgT5myWE4Bfyj2EWBoACXrt6BPNIK 6JdfqeeaTyrAdKOG2Wr9N1wi4utlhi0w8C68n6pTyVgEcDXtaub3hR7XW8IUvSd5eHDbrX QPHyqHShK4K8rZngnqdtTjADqRpXxM/8ZTEBVNVSl+rghxhU3tmQHloaWICuSH1wLdRGma IMs5yahTwx80ztatjaaPExAClZwTnZwLHBidgPpIqcFQCRO/MqJm/HakMdq26w== 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 4WGjDZ6XkWzvkl; Sat, 6 Jul 2024 20:49:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 466KnYtl029220; Sat, 6 Jul 2024 20:49:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 466KnYlQ029217; Sat, 6 Jul 2024 20:49:34 GMT (envelope-from git) Date: Sat, 6 Jul 2024 20:49:34 GMT Message-Id: <202407062049.466KnYlQ029217@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Cox Subject: git: fb32ba6aa44d - main - amd64/arm64: Eliminate unnecessary demotions in pmap_protect() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: alc X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fb32ba6aa44dc86e70ad06b44f93a9709e78f3d1 Auto-Submitted: auto-generated The branch main has been updated by alc: URL: https://cgit.FreeBSD.org/src/commit/?id=fb32ba6aa44dc86e70ad06b44f93a9709e78f3d1 commit fb32ba6aa44dc86e70ad06b44f93a9709e78f3d1 Author: Alan Cox AuthorDate: 2024-07-05 18:20:01 +0000 Commit: Alan Cox CommitDate: 2024-07-06 20:48:10 +0000 amd64/arm64: Eliminate unnecessary demotions in pmap_protect() In pmap_protect(), when the mapping isn't changing, we don't need to perform a superpage demotion, even though the requested change doesn't cover the entire superpage. Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D45886 --- sys/amd64/amd64/pmap.c | 21 +++++++++++++++++---- sys/arm64/arm64/pmap.c | 3 ++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c index 57943e815b5b..2bcf671be243 100644 --- a/sys/amd64/amd64/pmap.c +++ b/sys/amd64/amd64/pmap.c @@ -6796,8 +6796,7 @@ retry_pdpe: */ if ((ptpaddr & PG_PS) != 0) { /* - * Are we protecting the entire large page? If not, - * demote the mapping and fall through. + * Are we protecting the entire large page? */ if (sva + NBPDR == va_next && eva >= va_next) { /* @@ -6807,9 +6806,23 @@ retry_pdpe: if (pmap_protect_pde(pmap, pde, sva, prot)) anychanged = true; continue; - } else if (!pmap_demote_pde(pmap, pde, sva)) { + } + + /* + * Does the large page mapping need to change? If so, + * demote it and fall through. + */ + pbits = ptpaddr; + if ((prot & VM_PROT_WRITE) == 0) + pbits &= ~(PG_RW | PG_M); + if ((prot & VM_PROT_EXECUTE) == 0) + pbits |= pg_nx; + if (ptpaddr == pbits || !pmap_demote_pde(pmap, pde, + sva)) { /* - * The large page mapping was destroyed. + * Either the large page mapping doesn't need + * to change, or it was destroyed during + * demotion. */ continue; } diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c index a9cb8c7fe468..29552f722aa4 100644 --- a/sys/arm64/arm64/pmap.c +++ b/sys/arm64/arm64/pmap.c @@ -4373,7 +4373,8 @@ pmap_mask_set_locked(pmap_t pmap, vm_offset_t sva, vm_offset_t eva, pt_entry_t m if (sva + L2_SIZE == va_next && eva >= va_next) { pmap_protect_l2(pmap, l2, sva, mask, nbits); continue; - } else if (pmap_demote_l2(pmap, l2, sva) == NULL) + } else if ((pmap_load(l2) & mask) == nbits || + pmap_demote_l2(pmap, l2, sva) == NULL) continue; } KASSERT((pmap_load(l2) & ATTR_DESCR_MASK) == L2_TABLE,