From nobody Tue Dec 28 01:18:29 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 1FA43192100F; Tue, 28 Dec 2021 01:18:30 +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 4JNGrP5dbqz3hGj; Tue, 28 Dec 2021 01:18: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 965C1782; Tue, 28 Dec 2021 01:18: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 1BS1ITsa018843; Tue, 28 Dec 2021 01:18:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BS1ITpf018842; Tue, 28 Dec 2021 01:18:29 GMT (envelope-from git) Date: Tue, 28 Dec 2021 01:18:29 GMT Message-Id: <202112280118.1BS1ITpf018842@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: e161dfa91897 - main - Fix pmap_is_prefaultable() on arm64 and riscv 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: alc X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e161dfa918974b4392c7c5127bd51f28ea5f8b6a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640654309; 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=Mwqr45m8mVlMaLfnDXfXjJvYPV+esL5Stovkt06lZBE=; b=V/HnOJbCs77XSGakjdFWG7lmmYHg2m7B0/1RLUm13bfmX1i0/CMHxv0SyufESHFyurHqFV sp8lbm+iEem+yO+6XM/1jMt2LJ0JX4xy/958Z87x1UWaJDQtfFY6udlyDRx1ueCSN9khU4 uMYRz+rJBhA4TyTjXCMgPyoW84oI4tZSX5koD/dnUYrZOZTf7xgm6VCEf85XG7VyaYFzti 5O6WjdfUx4IqZuN9W5w1B2xy7zDA+qg7J3mFj044tuczpSJul4wwanoYhdO30c+4Kn/hnE Q12hmF4EgcItNvpXCz22S1Uhv0XYzBK6MBQJgO6lxRYpBQ4+wOVpPrr2xbWtXA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640654309; a=rsa-sha256; cv=none; b=qUM4RlsuGDTDwMEuEJmjtPCtIcbGTd447nmYACTlrLYQm7fJdxZbGtLf9XPZDw/QGnLXRm zlsU134a4e0rpTpIJAvlOguAhxgCuWz1mqgl2pcqrXl9Uw1Ut+P2j/PYi5BlfodKBigAK/ OxHuz0Dw76A8kQUUlOOutuKdzlBV86iANaKUNiV6MQJLfa/+LFip8G1lizcL+I7CMY5FK0 0k4PIyaVXgYwczNq1flbiWClass4CcYxjj3+H6GoSairmIV/K7MKNEatn79+I2QW76r6H9 eqICLSEegjQd/dTufBz9/Fhc/TyPH+F/JfcOMqF8xTN8TDWrPn0lq64R/MWc9Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by alc: URL: https://cgit.FreeBSD.org/src/commit/?id=e161dfa918974b4392c7c5127bd51f28ea5f8b6a commit e161dfa918974b4392c7c5127bd51f28ea5f8b6a Author: Alan Cox AuthorDate: 2021-12-25 03:54:01 +0000 Commit: Alan Cox CommitDate: 2021-12-28 01:17:14 +0000 Fix pmap_is_prefaultable() on arm64 and riscv The current implementations never correctly return TRUE. In all cases, when they currently return TRUE, they should have returned FALSE. And, in some cases, when they currently return FALSE, they should have returned TRUE. Except for its effects on performance, specifically, additional page faults and pointless calls to pmap_enter_quick() that abort, this error is harmless. That is why it has gone unnoticed. Add a comment to the amd64, arm64, and riscv implementations describing how their return values are computed. Reviewed by: kib, markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D33659 --- sys/amd64/amd64/pmap.c | 5 +++++ sys/arm64/arm64/pmap.c | 12 +++++++++--- sys/riscv/riscv/pmap.c | 6 +++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c index f6efce1303d4..42ad1bd24136 100644 --- a/sys/amd64/amd64/pmap.c +++ b/sys/amd64/amd64/pmap.c @@ -8567,6 +8567,11 @@ pmap_is_prefaultable(pmap_t pmap, vm_offset_t addr) boolean_t rv; PG_V = pmap_valid_bit(pmap); + + /* + * Return TRUE if and only if the PTE for the specified virtual + * address is allocated but invalid. + */ rv = FALSE; PMAP_LOCK(pmap); pde = pmap_pde(pmap, addr); diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c index 6d12f66807c3..4bd3eef7a18f 100644 --- a/sys/arm64/arm64/pmap.c +++ b/sys/arm64/arm64/pmap.c @@ -5246,15 +5246,21 @@ pmap_is_modified(vm_page_t m) boolean_t pmap_is_prefaultable(pmap_t pmap, vm_offset_t addr) { + pd_entry_t *pde; pt_entry_t *pte; boolean_t rv; int lvl; + /* + * Return TRUE if and only if the L3 entry for the specified virtual + * address is allocated but invalid. + */ rv = FALSE; PMAP_LOCK(pmap); - pte = pmap_pte(pmap, addr, &lvl); - if (pte != NULL && pmap_load(pte) != 0) { - rv = TRUE; + pde = pmap_pde(pmap, addr, &lvl); + if (pde != NULL && lvl == 2) { + pte = pmap_l2_to_l3(pde, addr); + rv = pmap_load(pte) == 0; } PMAP_UNLOCK(pmap); return (rv); diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c index 9abf75a731f5..1dc62418b165 100644 --- a/sys/riscv/riscv/pmap.c +++ b/sys/riscv/riscv/pmap.c @@ -3850,10 +3850,14 @@ pmap_is_prefaultable(pmap_t pmap, vm_offset_t addr) pt_entry_t *l3; boolean_t rv; + /* + * Return TRUE if and only if the L3 entry for the specified virtual + * address is allocated but invalid. + */ rv = FALSE; PMAP_LOCK(pmap); l3 = pmap_l3(pmap, addr); - if (l3 != NULL && pmap_load(l3) != 0) { + if (l3 != NULL && pmap_load(l3) == 0) { rv = TRUE; } PMAP_UNLOCK(pmap);