From nobody Mon Mar 14 14:46:08 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 14C181A26D3D; Mon, 14 Mar 2022 14:46:09 +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 4KHK9D3Yvtz3hPb; Mon, 14 Mar 2022 14:46:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647269168; 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=FSKKa87ETPL+DWv0FypkBoFP0OwAzglxSL3m4+7mWbo=; b=sfVlgp064QtW5kpwcmA1rmwEPZVlKEHgwX9mNozPvhoz7oj/UZ31p4XkMy5PZkbOgKE6ql CFYzm745BI1R9avjRjgXFnoHqAxkEwxuhTsR7oC8F5gLq0PC0DrkDRZ49HTBvHMEwAW6lX baGYzuzXUUiVqzRTBlcedqyCFyL1b8BCb5Hl5yAY7Y8Pl5ibartCeSmHBKmSPLZavrrcuz B18cgUkQIXNnT0BEgBZeup0pf+F68Ta8DpY80rE+iwWOtdUPzpVdmvMiVqkpNTAARYwhqq reDgmsGqvYCMW8WG7jwPMzLcjmovKyr8opYBuo5rhBwkYynyq/9uBC/vQPCsmQ== 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 4B1D470F0; Mon, 14 Mar 2022 14:46:08 +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 22EEk8L1051921; Mon, 14 Mar 2022 14:46:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22EEk80X051920; Mon, 14 Mar 2022 14:46:08 GMT (envelope-from git) Date: Mon, 14 Mar 2022 14:46:08 GMT Message-Id: <202203141446.22EEk80X051920@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: 709db7b67f1d - stable/13 - riscv: Add various pmap definitions needed to support SV48 mode 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: 709db7b67f1d2f96b15bf33d57ce37633792d6f3 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647269168; 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=FSKKa87ETPL+DWv0FypkBoFP0OwAzglxSL3m4+7mWbo=; b=RQaY2d80aFaFwj7MuYqPyZ2aHTOg865WXfH26gQ6r/UtdYi6eY09reSWoRWTNWG1tNJIWz 7vTYq+jazSF/cgQI8mRyLV/taLpj4lPBja+Wi2ZNlEU9DmC061VKI331368QRGb5YfubNL mfk5xOGhSY1ftaRtV/srxE8eX1yg7mgbrNJJKvmz0VWxIbd1yvOjS4HMzEm3Zdjf19lqBJ jHkDxg1r9Ezd5w0LXgaixPcbfZ/I1y+WyYvbtEuoie5xB8hXG5qwcxDOT0ibqdUspUn9hc FILOyztGawQPX+n0RHjnsZZPpql1QZhgGocO/snYrVtOn4tkBdtDSvUeE06ZFA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647269168; a=rsa-sha256; cv=none; b=bv2xyOKD2n+guHtaCSlE69njF7SAMZVbykyzyyLl7kSi5j9DlRIOpUUr+xb68xEaD7gl4a WmpQSJVmq5dToWz8o4m6ZmRari9S92bmvOgqWjG2sEb0MoHkbDLW6syjc9PFzEJ7VzFwOA oPFuuN5yi/a08ZLrUWa9SM6S74O4pqBtNK5f2h38qILEcEN/ru7do90z0/WKcurpgD1Vin 9YSFpPHHAcjN7VI5Nq2WBdBu2nA43ptUe1oEejK3Cuzxuk2NIuXphYCPGsau4F6ANVi/sT /20J+31a7ldFEU1Q8ufDoQL1brlzc00Yi+rRn4e+4EqYcDul16cg/NFROe4pTA== 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=709db7b67f1d2f96b15bf33d57ce37633792d6f3 commit 709db7b67f1d2f96b15bf33d57ce37633792d6f3 Author: Mark Johnston AuthorDate: 2022-03-01 14:04:01 +0000 Commit: Mark Johnston CommitDate: 2022-03-14 14:45:32 +0000 riscv: Add various pmap definitions needed to support SV48 mode No functional change intended. Reviewed by: jhb Sponsored by: The FreeBSD Foundation (cherry picked from commit 59f192c507c49990b603f774bbb824fab71ee4c3) --- sys/riscv/include/pmap.h | 7 +++++++ sys/riscv/include/pte.h | 10 ++++++---- sys/riscv/include/vmparam.h | 12 ++++++++---- sys/riscv/riscv/pmap.c | 18 +++++++++++++++++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/sys/riscv/include/pmap.h b/sys/riscv/include/pmap.h index 40f99befade1..8ba46f0d61ae 100644 --- a/sys/riscv/include/pmap.h +++ b/sys/riscv/include/pmap.h @@ -137,6 +137,13 @@ extern vm_offset_t virtual_end; #define L1_MAPPABLE_P(va, pa, size) \ ((((va) | (pa)) & L1_OFFSET) == 0 && (size) >= L1_SIZE) +enum pmap_mode { + PMAP_MODE_SV39, + PMAP_MODE_SV48, +}; + +extern enum pmap_mode pmap_mode; + struct thread; #define pmap_vm_page_alloc_check(m) diff --git a/sys/riscv/include/pte.h b/sys/riscv/include/pte.h index 965faa7eea9e..f066f821cf2a 100644 --- a/sys/riscv/include/pte.h +++ b/sys/riscv/include/pte.h @@ -44,22 +44,24 @@ typedef uint64_t pt_entry_t; /* page table entry */ typedef uint64_t pn_t; /* page number */ #endif -/* Level 0 table, 512GiB per entry */ +/* Level 0 table, 512GiB per entry, SV48 only */ #define L0_SHIFT 39 +#define L0_SIZE (1UL << L0_SHIFT) +#define L0_OFFSET (L0_SIZE - 1) /* Level 1 table, 1GiB per entry */ #define L1_SHIFT 30 -#define L1_SIZE (1 << L1_SHIFT) +#define L1_SIZE (1UL << L1_SHIFT) #define L1_OFFSET (L1_SIZE - 1) /* Level 2 table, 2MiB per entry */ #define L2_SHIFT 21 -#define L2_SIZE (1 << L2_SHIFT) +#define L2_SIZE (1UL << L2_SHIFT) #define L2_OFFSET (L2_SIZE - 1) /* Level 3 table, 4KiB per entry */ #define L3_SHIFT 12 -#define L3_SIZE (1 << L3_SHIFT) +#define L3_SIZE (1UL << L3_SHIFT) #define L3_OFFSET (L3_SIZE - 1) #define Ln_ENTRIES_SHIFT 9 diff --git a/sys/riscv/include/vmparam.h b/sys/riscv/include/vmparam.h index 4ed95def2caa..d65664eff94e 100644 --- a/sys/riscv/include/vmparam.h +++ b/sys/riscv/include/vmparam.h @@ -180,8 +180,10 @@ ((va) - DMAP_MIN_ADDRESS) + dmap_phys_base; \ }) -#define VM_MIN_USER_ADDRESS (0x0000000000000000UL) -#define VM_MAX_USER_ADDRESS (0x0000004000000000UL) +#define VM_MIN_USER_ADDRESS_SV39 (0x0000000000000000UL) +#define VM_MAX_USER_ADDRESS_SV39 (0x0000004000000000UL) +#define VM_MIN_USER_ADDRESS VM_MIN_USER_ADDRESS_SV39 +#define VM_MAX_USER_ADDRESS VM_MAX_USER_ADDRESS_SV39 #define VM_MINUSER_ADDRESS (VM_MIN_USER_ADDRESS) #define VM_MAXUSER_ADDRESS (VM_MAX_USER_ADDRESS) @@ -191,8 +193,10 @@ (((va) < VM_MAX_USER_ADDRESS) || ((va) >= VM_MIN_KERNEL_ADDRESS)) #define KERNBASE (VM_MIN_KERNEL_ADDRESS) -#define SHAREDPAGE (VM_MAXUSER_ADDRESS - PAGE_SIZE) -#define USRSTACK SHAREDPAGE +#define SHAREDPAGE_SV39 (VM_MAX_USER_ADDRESS_SV39 - PAGE_SIZE) +#define SHAREDPAGE SHAREDPAGE_SV39 +#define USRSTACK SHAREDPAGE_SV39 +#define PS_STRINGS_SV39 (USRSTACK_SV39 - sizeof(struct ps_strings)) #define VM_EARLY_DTB_ADDRESS (VM_MAX_KERNEL_ADDRESS - (2 * L2_SIZE)) diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c index 55f0c7f4a86e..ac6b854ac3c3 100644 --- a/sys/riscv/riscv/pmap.c +++ b/sys/riscv/riscv/pmap.c @@ -160,7 +160,19 @@ __FBSDID("$FreeBSD$"); #include #include -#define NUL1E (Ln_ENTRIES * Ln_ENTRIES) +/* + * Boundary values for the page table page index space: + * + * L3 pages: [0, NUL2E) + * L2 pages: [NUL2E, NUL2E + NUL1E) + * L1 pages: [NUL2E + NUL1E, NUL2E + NUL1E + NUL0E) + * + * Note that these ranges are used in both SV39 and SV48 mode. In SV39 mode the + * ranges are not fully populated since there are at most Ln_ENTRIES^2 L3 pages + * in a set of page tables. + */ +#define NUL0E Ln_ENTRIES +#define NUL1E (Ln_ENTRIES * NUL0E) #define NUL2E (Ln_ENTRIES * NUL1E) #if !defined(DIAGNOSTIC) @@ -179,6 +191,7 @@ __FBSDID("$FreeBSD$"); #define PV_STAT(x) do { } while (0) #endif +#define pmap_l1_pindex(v) (NUL2E + ((v) >> L1_SHIFT)) #define pmap_l2_pindex(v) ((v) >> L2_SHIFT) #define pa_to_pvh(pa) (&pv_table[pa_index(pa)]) @@ -219,6 +232,8 @@ __FBSDID("$FreeBSD$"); LIST_HEAD(pmaplist, pmap); static struct pmaplist allpmaps = LIST_HEAD_INITIALIZER(); +enum pmap_mode __read_frequently pmap_mode = PMAP_MODE_SV39; + struct pmap kernel_pmap_store; vm_offset_t virtual_avail; /* VA of first avail page (after kernel bss) */ @@ -338,6 +353,7 @@ pagezero(void *p) bzero(p, PAGE_SIZE); } +#define pmap_l0_index(va) (((va) >> L0_SHIFT) & Ln_ADDR_MASK) #define pmap_l1_index(va) (((va) >> L1_SHIFT) & Ln_ADDR_MASK) #define pmap_l2_index(va) (((va) >> L2_SHIFT) & Ln_ADDR_MASK) #define pmap_l3_index(va) (((va) >> L3_SHIFT) & Ln_ADDR_MASK)