From nobody Mon Mar 14 14:46:12 2022 X-Original-To: dev-commits-src-branches@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 639BC1A2715A; Mon, 14 Mar 2022 14:46:14 +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 4KHK9K1XgDz3hSV; Mon, 14 Mar 2022 14:46:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647269173; 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=GMLYJ+4Iu29yhRPKRPPPSkqsgQOx3/YuqedCB2aeCV4=; b=MUxo6xH9byhqc8H4zcpQvmuZy4sGVV7FMEID0K5oEGJ+atq6emMnJNxc1u8jyiA9Wm8UvY u71em5uMBucu+8PUm+/zGoo67mcu+DANfHbVDju+ffcrojM8cJPxK0YbEGQWwUOQwlbFRh BBNSoWYeA1jTJS6kLPoc3F/ii0hKbN8rnKfd3yKK1OqSWdaOAc2qDxuqehBme2KhPZsRud r4BFSSClPKm4SDklgevikIChnuufVHx3XasAo6D8yal6UBzbPk2lspGWTpxMLyyyB1bicj QVPmuWyf2SuniTUzWPJBrPHg6QSOtFIwqdx8TmnWG52xqop6OORUTechgzg96g== 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 CA7776F73; Mon, 14 Mar 2022 14:46:12 +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 22EEkCJc052024; Mon, 14 Mar 2022 14:46:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22EEkCiJ052023; Mon, 14 Mar 2022 14:46:12 GMT (envelope-from git) Date: Mon, 14 Mar 2022 14:46:12 GMT Message-Id: <202203141446.22EEkCiJ052023@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: 89b4150af5b1 - stable/13 - riscv: Add pmap helper functions required by four-level page tables List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/13 X-Git-Reftype: branch X-Git-Commit: 89b4150af5b169bf2db38a91d7bafc13b0bf28ea Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647269173; 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=GMLYJ+4Iu29yhRPKRPPPSkqsgQOx3/YuqedCB2aeCV4=; b=jakr/jidWqCmobVFv0f0yEo58pH/BXjrlUSC3j43HCJTndC3R8CwJOosc8ByaQ+15gihuX ut2RAjeXJJb3NVTjISM4i1n/NsiWJL7rJ7wEZoJMEa/4Kbfh26htOt2gNRYXjoc2Jvj+QZ 1A1T4aNmF1L1YrkiAUpEVqaWyVfkG6uq7y03SeNOoBBBEFZjT3JEdhE1/TPGr5lyQY2aKv aau9LPyfuqeLTk+cTGDWEdjtHo4/t6tdnRsnbp/iGOULt8WVp3w0Yx58q9cwOSNKqKJRoK 3RDI4qpaRjUatMGpj0xV8dnCRVjb+R0icX04+0NFjdJADLDY8SCuZnWmP7k0WQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647269173; a=rsa-sha256; cv=none; b=by9YZddn/PGIzGYnzqRcEp82/kbF5thOH2iiecoIG/LamOn77IzCpceKc4wr0RTrrWm3SI ZGuRiXSKLiAHPFsCbK/BEyn+FhNYMF9cEqLNLcNh8OEAEqD61XmNQdLFNne0jEE2DMuz8G 1nRs0qlAUFgdQm2zpG3etz7dOkpFFBAB1SsJZJj86jmJo5ABPG0Ma1o8oLdVBm2wnlP5hf bYg6MmU+osvdKTR/xKyCR5ZUiVZZh23Miup0A5jnTC3UkEs9jvzuPCj3qjP1DJ4hhdVzzf M+wJtM8LMMYx2rPtlkSoWpsWQBDRGVAN+I1YbIGI82Jx8FEC9t7fYPRyt/y8fA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=89b4150af5b169bf2db38a91d7bafc13b0bf28ea commit 89b4150af5b169bf2db38a91d7bafc13b0bf28ea Author: Mark Johnston AuthorDate: 2022-03-01 14:06:15 +0000 Commit: Mark Johnston CommitDate: 2022-03-14 14:45:40 +0000 riscv: Add pmap helper functions required by four-level page tables No functional change intended. Reviewed by: jhb Sponsored by: The FreeBSD Foundation (cherry picked from commit 5cf3a8216e3adad06f1ab02c9a9b201cebcd4809) --- sys/riscv/riscv/pmap.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c index ac6b854ac3c3..74192a16341c 100644 --- a/sys/riscv/riscv/pmap.c +++ b/sys/riscv/riscv/pmap.c @@ -363,13 +363,45 @@ pagezero(void *p) #define L2PTE_TO_PHYS(l2) \ ((((l2) & ~PTE_HI_MASK) >> PTE_PPN1_S) << L2_SHIFT) +static __inline pd_entry_t * +pmap_l0(pmap_t pmap, vm_offset_t va) +{ + KASSERT(pmap_mode != PMAP_MODE_SV39, ("%s: in SV39 mode", __func__)); + KASSERT(VIRT_IS_VALID(va), + ("%s: malformed virtual address %#lx", __func__, va)); + return (&pmap->pm_top[pmap_l0_index(va)]); +} + +static __inline pd_entry_t * +pmap_l0_to_l1(pd_entry_t *l0, vm_offset_t va) +{ + vm_paddr_t phys; + pd_entry_t *l1; + + KASSERT(pmap_mode != PMAP_MODE_SV39, ("%s: in SV39 mode", __func__)); + phys = PTE_TO_PHYS(pmap_load(l0)); + l1 = (pd_entry_t *)PHYS_TO_DMAP(phys); + + return (&l1[pmap_l1_index(va)]); +} + static __inline pd_entry_t * pmap_l1(pmap_t pmap, vm_offset_t va) { + pd_entry_t *l0; KASSERT(VIRT_IS_VALID(va), ("%s: malformed virtual address %#lx", __func__, va)); - return (&pmap->pm_top[pmap_l1_index(va)]); + if (pmap_mode == PMAP_MODE_SV39) { + return (&pmap->pm_top[pmap_l1_index(va)]); + } else { + l0 = pmap_l0(pmap, va); + if ((pmap_load(l0) & PTE_V) == 0) + return (NULL); + if ((pmap_load(l0) & PTE_RX) != 0) + return (NULL); + return (pmap_l0_to_l1(l0, va)); + } } static __inline pd_entry_t * @@ -390,6 +422,8 @@ pmap_l2(pmap_t pmap, vm_offset_t va) pd_entry_t *l1; l1 = pmap_l1(pmap, va); + if (l1 == NULL) + return (NULL); if ((pmap_load(l1) & PTE_V) == 0) return (NULL); if ((pmap_load(l1) & PTE_RX) != 0)