From nobody Mon Oct 02 12:56:02 2023 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 4RzgtW0stVz4w3NR; Mon, 2 Oct 2023 12:56:03 +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 4RzgtV6Lymz3RkV; Mon, 2 Oct 2023 12:56:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696251362; 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=I1rFiiXzi/E82UKLNQT2TY/UmFpkqy2FrY+oeFMFAjk=; b=v7FNKAgjA8+fJnErz1QbJC+RWFQlTB7fP/9W+7LLvNrqBXMeIBzvlmbzUKZxGf49aglLON FssxzQU1s5Bz1F2aCVVGTYq7zeBs1cGnf5wy0hKAdEhKb/agy3ONExHY6cibMXnzpKRb3b t/4tC5xVxuzdhsFBiNIbJATIF5XLJj4Q147oEF127sfl7/tTwzuPPltpwaoLyeOFiLAiIz 22vmEjdknLI0gwW5LtywOkFhs5VNIR8BWi8WpBqklivIJGArkzGbIM+2DLPSWOrd5eU9RD DUSRvweIgEmndRjIFO/vVQ+LTZ8ieELlsuDBL2Rg/G+/O9kW/spXWmnmF/Udsw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696251362; a=rsa-sha256; cv=none; b=yNfzTPrQZxbGelf34tYOf2s42NoEM9wqE9mJILg284VZG5XgrI8oBI4xKloZnSyZcvbHar b204lsxKLszSOmQH3tmOqD0DrLr9Qf0kOFdIkedC6b2gkTRrvkxJd8KhNAgBWow6/32qww nP9h3SUPNffQsQvfR56N86F3l7p5vvE9wr22sv2FrNhsH1sZMeZ13nXmbVk7qXs83eff1S NiFiuc91CQRCouZ3cWDDvnueOegQzYZHwhO4OBFE3rOZHFukT/iH+QXhsKss7NNoKB4qH9 PxUMkLQHUBPHSAPW1tNIlS+CUd0dc70r17zrbLaZSMHa6fG0P+wHGajtHakrTg== 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=1696251362; 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=I1rFiiXzi/E82UKLNQT2TY/UmFpkqy2FrY+oeFMFAjk=; b=Dw5XvSBam/pYUMgFcAsoRUlxDa2wELAyHJufSEezvHSxdlHCVyyk2dsyFtO1TKXkHUfiSO LL8GYlMsfKHdehluKU9fLQYwZsPPjPU0O99Y0FD6dcinGoD6fIB8jnbjOQGF05Y4udblqp Ixjhz+S7MTo7kXhQBUpSwP220z9GFuN4YYYMJ1KVo8pRWf3Fg8feAlo5MGBxQNt0BPcpjm oqUH2XbsqK9VriNoBv+ezf00ZjpJEm8squ8tOI2eAUlWVwziK9O3f07kXp6+kzAs7saiEQ O1ySvsJpvNv5TLLI6Md/0vXqQ5aejTL8g2p4vVJ1G0Hi2qt4K9+ZltcaJV2wuQ== 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 4RzgtV5Rx7z1CK6; Mon, 2 Oct 2023 12:56:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 392Cu2sg035983; Mon, 2 Oct 2023 12:56:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 392Cu2Zu035980; Mon, 2 Oct 2023 12:56:02 GMT (envelope-from git) Date: Mon, 2 Oct 2023 12:56:02 GMT Message-Id: <202310021256.392Cu2Zu035980@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: ca79521be1b8 - stable/14 - amd64: Add a leaf PTP when pmap_enter(psind=1) creates a wired mapping 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: ca79521be1b87b82381e091e36123471ca5648cc Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ca79521be1b87b82381e091e36123471ca5648cc commit ca79521be1b87b82381e091e36123471ca5648cc Author: Bojan Novković AuthorDate: 2023-09-15 10:41:10 +0000 Commit: Mark Johnston CommitDate: 2023-10-02 12:55:49 +0000 amd64: Add a leaf PTP when pmap_enter(psind=1) creates a wired mapping This patch reverts the changes made in D19670 and fixes the original issue by allocating and prepopulating a leaf page table page for wired userspace 2M pages. The original issue is an edge case that creates an unmapped, wired region in userspace. Subsequent faults on this region can trigger wired superpage creation, which leads to a panic in pmap_demote_pde_locked() as the pmap does not create a leaf page table page for the wired superpage. D19670 fixed this by disallowing preemptive creation of wired superpage mappings, but that fix is currently interfering with an ongoing effort of speeding up vm_map_wire for large, contiguous entries (e.g. bhyve wiring guest memory). Reviewed by: alc, markj Sponsored by: Google, Inc. (GSoC 2023) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D41132 (cherry picked from commit aa3bcaad51076ceb346fa0c64ab69a35e5241b20) --- sys/amd64/amd64/pmap.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c index b10997fd657b..ff83d8749313 100644 --- a/sys/amd64/amd64/pmap.c +++ b/sys/amd64/amd64/pmap.c @@ -7493,9 +7493,8 @@ pmap_enter_pde(pmap_t pmap, vm_offset_t va, pd_entry_t newpde, u_int flags, pd_entry_t oldpde, *pde; pt_entry_t PG_G, PG_RW, PG_V; vm_page_t mt, pdpg; + vm_page_t uwptpg; - KASSERT(pmap == kernel_pmap || (newpde & PG_W) == 0, - ("pmap_enter_pde: cannot create wired user mapping")); PG_G = pmap_global_bit(pmap); PG_RW = pmap_rw_bit(pmap); KASSERT((newpde & (pmap_modified_bit(pmap) | PG_RW)) != PG_RW, @@ -7592,6 +7591,22 @@ pmap_enter_pde(pmap_t pmap, vm_offset_t va, pd_entry_t newpde, u_int flags, } } + /* + * Allocate leaf ptpage for wired userspace pages. + */ + uwptpg = NULL; + if ((newpde & PG_W) != 0 && pmap != kernel_pmap) { + uwptpg = pmap_alloc_pt_page(pmap, pmap_pde_pindex(va), + VM_ALLOC_WIRED); + if (uwptpg == NULL) + return (KERN_RESOURCE_SHORTAGE); + if (pmap_insert_pt_page(pmap, uwptpg, true, false)) { + pmap_free_pt_page(pmap, uwptpg, false); + return (KERN_RESOURCE_SHORTAGE); + } + + uwptpg->ref_count = NPTEPG; + } if ((newpde & PG_MANAGED) != 0) { /* * Abort this mapping if its PV entry could not be created. @@ -7599,6 +7614,14 @@ pmap_enter_pde(pmap_t pmap, vm_offset_t va, pd_entry_t newpde, u_int flags, if (!pmap_pv_insert_pde(pmap, va, newpde, flags, lockp)) { if (pdpg != NULL) pmap_abort_ptp(pmap, va, pdpg); + if (uwptpg != NULL) { + mt = pmap_remove_pt_page(pmap, va); + KASSERT(mt == uwptpg, + ("removed pt page %p, expected %p", mt, + uwptpg)); + uwptpg->ref_count = 1; + pmap_free_pt_page(pmap, uwptpg, false); + } CTR2(KTR_PMAP, "pmap_enter_pde: failure for va %#lx" " in pmap %p", va, pmap); return (KERN_RESOURCE_SHORTAGE);