From nobody Thu Oct 06 22:05:42 2022 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 4Mk59L2pQPz4VBWd; Thu, 6 Oct 2022 22:05:42 +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 4Mk59L2KcNz3tc2; Thu, 6 Oct 2022 22:05:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665093942; 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=/EMl0DU4XQr/FE4ruIxMU7MoED+XtxmTW7dfiIcx84I=; b=c3YGPcCce0JgRyLRj3G+HBb0Mdkby8SZGFJQOVUfEtMEjmJV0WAdZ5rHHhUIxnQXKKZ7GI YlIBqUey3+1Egffxw0dXc2raO270ajDe0HzqbC0FfWmkYclF7iafj1FPgXgMcdSwmV+V2O 5G0qoEsbXlI7Sy9Je6jwNjHPwJPuFrCaUu4lIvtsnAMTKfRrHXWPqW6XdRtDYwYtzPJzDW fTUXfGtxk+u1/ILxBm2xGkk3jGwblAOhhe7mKWdI+CnxITrSdCacFkRXG/S3YWrNUVz25T RyJnFZyxrL6WVpRN0c8B5Pqhx72zPFRw37tAFAeh606VFmr49m4BmfKuEc+Rkg== 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 4Mk59L1Rk4zNmn; Thu, 6 Oct 2022 22:05:42 +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 296M5g22056194; Thu, 6 Oct 2022 22:05:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 296M5gcZ056193; Thu, 6 Oct 2022 22:05:42 GMT (envelope-from git) Date: Thu, 6 Oct 2022 22:05:42 GMT Message-Id: <202210062205.296M5gcZ056193@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 1f9cc5ffc505 - main - riscv: handle kernel PTE edge-case in pmap_enter_l2() 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1f9cc5ffc50523498545b6f7d50406feb18903be Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665093942; 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=/EMl0DU4XQr/FE4ruIxMU7MoED+XtxmTW7dfiIcx84I=; b=G2mmrgeTtXRDHWhPAnA9WSC5JwfVpZ1dqYNT3Xf6BCAObBaosaPk7y+23afG8Iyry5vqYy nhqJFpaRhOwHNTJw1ReFPN9ycnRduud9UxxvZl8wmm0rKiqPyeuwK8UYMV7u9B/xYgB+tS 1EEkc5fYg5QRAG+I1LsbuVOOA3oMHEeTdhmQC3uy1Ylv/uKg42DrxdATFZBR8BdrxKljxy hQwgBnpciU61rUOEXUMesCVJcbMOtdzuLTqAoYhYGc75MhgzesWiHGCZjSu5t8CQrojfzp KjKrtL4Dxz2CvICYEVD4jq1MqlvN/h+q91KFWS82mMMVJpYqwLeGJP4r7dFWdg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665093942; a=rsa-sha256; cv=none; b=s852tnlMmQXcgwBOp6qHMxION1ny7No3WlAGVLHLTuNDLY0h+Ub/I5a5OAAHrxW363+q/B sImct3tUW4pQMctBBfXks0kBJ1gFBbpaK5N2hTtq87LlLIXrBZ7rbZ7Q4jJfNol0UN5elz IK5wsgLqa13WXQy/NTtXzp5DNbD13EdEB5gkKXYli2nyIjd9l0fJhjrpIq/WeQGmerCOdk UpsZpXgJhPf4YELl0E0rGGVijoVm0cVdBdCpkM8U8/fWFAkahk2aK3/ffJgLC8uOvER2I2 4w6jZptkTIqcZ49wqKjtaeYymtPt1GbnNjvsUF5kbpJAwJhotjrHWhwzXr+hYg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=1f9cc5ffc50523498545b6f7d50406feb18903be commit 1f9cc5ffc50523498545b6f7d50406feb18903be Author: Mitchell Horne AuthorDate: 2022-10-05 16:14:36 +0000 Commit: Mitchell Horne CommitDate: 2022-10-06 22:04:53 +0000 riscv: handle kernel PTE edge-case in pmap_enter_l2() Page table pages are never freed from the kernel pmap, instead they are zeroed when a range is unmapped. This allows future mappings to be constructed more quickly. Detect this scenario in pmap_enter_l2(), so we don't fail to create a superpage mapping when the 2MB range is actually available. Reviewed by: markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D36885 --- sys/riscv/riscv/pmap.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c index de7f548b6519..a667bc73c95e 100644 --- a/sys/riscv/riscv/pmap.c +++ b/sys/riscv/riscv/pmap.c @@ -3146,6 +3146,24 @@ pmap_enter_2mpage(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot, PMAP_ENTER_NOREPLACE | PMAP_ENTER_NORECLAIM, NULL, lockp)); } +/* + * Returns true if every page table entry in the specified page table is + * zero. + */ +static bool +pmap_every_pte_zero(vm_paddr_t pa) +{ + pt_entry_t *pt_end, *pte; + + KASSERT((pa & PAGE_MASK) == 0, ("pa is misaligned")); + pte = (pt_entry_t *)PHYS_TO_DMAP(pa); + for (pt_end = pte + Ln_ENTRIES; pte < pt_end; pte++) { + if (*pte != 0) + return (false); + } + return (true); +} + /* * Tries to create the specified 2MB page mapping. Returns KERN_SUCCESS if * the mapping was created, and one of KERN_FAILURE, KERN_NO_SPACE, or @@ -3190,7 +3208,8 @@ pmap_enter_l2(pmap_t pmap, vm_offset_t va, pd_entry_t new_l2, u_int flags, "pmap_enter_l2: no space for va %#lx" " in pmap %p", va, pmap); return (KERN_NO_SPACE); - } else { + } else if (va < VM_MAXUSER_ADDRESS || + !pmap_every_pte_zero(L2PTE_TO_PHYS(oldl2))) { l2pg->ref_count--; CTR2(KTR_PMAP, "pmap_enter_l2:" " failed to replace existing mapping"