From patchwork Wed Aug 9 01:51:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13347309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF25EC04FE0 for ; Wed, 9 Aug 2023 01:53:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CD616B0074; Tue, 8 Aug 2023 21:53:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32EDD6B0075; Tue, 8 Aug 2023 21:53:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A96A8D0001; Tue, 8 Aug 2023 21:53:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 095BB6B0074 for ; Tue, 8 Aug 2023 21:53:11 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D41FA40267 for ; Wed, 9 Aug 2023 01:53:10 +0000 (UTC) X-FDA: 81102893340.19.F6D542A Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf07.hostedemail.com (Postfix) with ESMTP id 162CE40005 for ; Wed, 9 Aug 2023 01:53:08 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Z+OB3UIx; spf=pass (imf07.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691545989; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lS9t1IQslP2lZOcFIMMBEvL86hG9xRW12aLXbO27oNk=; b=mpbsE/zXH46VHqOqZvNgmTfVGUsmFs1KpEczCO0DqO4tJltU3YCycnFICTmntojtlny1pL IFfPG2yzsdunwfrhRAvR1uoka1PmvaQvVcQ0I7IbnE3DbfyOH8eyQxYh6hsbqVd8MsQ5/i 3QD0VSRFd7v0ZWLgebdluwIqP/xtudg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691545989; a=rsa-sha256; cv=none; b=KZ8F7vrX7Ri8QEw5mke5a/q1KgJdSRTJE04TZ0RYoKb3sLncOzog2n9wiU1zEZgeh9JhUj c2WB/4UyeSY0yr2E1j6ErRD/aF68UeZnj3uzVSQXqyajPApqtIo1sAZdqGKfhQUhQp32r6 lZELnBASgsGTZi/s7fPuAjaPhLI3cFQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Z+OB3UIx; spf=pass (imf07.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1bc7e65ea44so3257065ad.1 for ; Tue, 08 Aug 2023 18:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1691545988; x=1692150788; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lS9t1IQslP2lZOcFIMMBEvL86hG9xRW12aLXbO27oNk=; b=Z+OB3UIxb6UJl4LqG4lOl8uoEklqlYBf9fFwC0SMsGtkHV738p4LE/eBRuGJp3a7UL wiCEXG/nMIuiiOQ7dHYWcDcYDiZ0ZcWXZQ1pgmZ/9o7/7EIhMFgNACuq5EWyHaQJ3Z7E G6kwf7AbrVK8ofW7juhqT77yDPEbZow9W3sjyhQnYVmRcEDxZmUSGarbtD1I7I3ufInS hpDnZmswCg7wHzP7gZzoJ4bbO4uBGnuWGbFO0kEtksOZCBlotH47BAkIcT5zEnw+UIYM X6/5ndgr/c496H7frfwd+bRtqm0VeHE4I0TmM4v7PHuRHDwdflAx5jyymiQ36NBcmSnr I07w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691545988; x=1692150788; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lS9t1IQslP2lZOcFIMMBEvL86hG9xRW12aLXbO27oNk=; b=B3lobuK6QaQRHs/n6QOjCRUBmJmLEBR7IZcZWKmdq2A+Ndzu4wSfB5TScwP53469Gm l5rXM1CqbYHGRRgGY4L2FcjZ3xnP8RJfP5rPjlC9vVmj+zYtt+M+G4//DJShtm6peWnG kfu/9ah+ZQbwvklWnEYowl36naT6bW7UUx4ZVIn52qv8TmQkpe5sz2Y0YnG+P7/T+zLK C4qIDU2Y0jBXgleKoMCQIh4KlQ1z0Ygvo6BpOPGr5ee25Vvj0UBmcAE41pKM+vR0j4Hd FPQnpPilUCa2bA1fhuWqDXebnJVZcoqDO3ObcOclIqxqeCJQnU9YCDS8/9C9VmyL9j7j EB1Q== X-Gm-Message-State: AOJu0YxwJBOKIwSXYM0AGkkMUcy1Oj7mvSeo+wlOBpJmH3DghMx0qdmp AHxofdgQHe9Fem5q30IXgQJ+Yg== X-Google-Smtp-Source: AGHT+IFhoPRNUuepUsmxYmygopTPVe56v5cNvHLyHa5Ol8fKT1Rsk8P+vvViBz+AASwbOoRW+3rwYA== X-Received: by 2002:a17:902:d491:b0:1b0:3ab6:5140 with SMTP id c17-20020a170902d49100b001b03ab65140mr1838365plg.4.1691545987885; Tue, 08 Aug 2023 18:53:07 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id bj7-20020a170902850700b001b87bedcc6fsm9657591plb.93.2023.08.08.18.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 18:53:07 -0700 (PDT) From: Charlie Jenkins To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: charlie@rivosinc.com, conor@kernel.org, paul.walmsley@sifive.com, palmer@rivosinc.com, aou@eecs.berkeley.edu, anup@brainfault.org, konstantin@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mick@ics.forth.gr, jrtc27@jrtc27.com, rdunlap@infradead.org, alexghiti@rivosinc.com Subject: [PATCH v9 1/4] RISC-V: mm: Restrict address space for sv39,sv48,sv57 Date: Tue, 8 Aug 2023 18:51:07 -0700 Message-Id: <20230809015110.3290774-2-charlie@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230809015110.3290774-1-charlie@rivosinc.com> References: <20230809015110.3290774-1-charlie@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 162CE40005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 69aihb96eicahrwkowypwsttxhbyomqy X-HE-Tag: 1691545988-775508 X-HE-Meta: U2FsdGVkX199KTQ6SYU3FB+ns1f2C43YSA510I9z4kndiIIiIGyzs8RHTT1BnHPhiF9qWf7OxVNCqeScAr8slUjUPQamNDSgvP1MSX93A/rdrgdjqHWSNWDETWtyhP2isPApzsnNc7kCC9gtRucAFa52B0OUz418Xp1Xlt8vnKwv1jwu0nb+l3c4p6i2ddr0JaiuR0EjZmY6eJp6OM5+UEB09LOawivgyIvUTrbLu4BsZMYUAT1FSiDz5SDspshgtyuuZHKiD7i+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BNGdDYxvRhttYr3fuaIki/LuFovfzQ3sm75BBNCcIuiyaHNVzMubC5jMs3C0AihtQuulIfkAini00C2yjLSji3L2S7jx+qyfyOub X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Make sv48 the default address space for mmap as some applications currently depend on this assumption. A hint address passed to mmap will cause the largest address space that fits entirely into the hint to be used. If the hint is less than or equal to 1<<38, an sv39 address will be used. An exception is that if the hint address is 0, then a sv48 address will be used. After an address space is completely full, the next smallest address space will be used. Signed-off-by: Charlie Jenkins --- arch/riscv/include/asm/elf.h | 2 +- arch/riscv/include/asm/pgtable.h | 21 +++++++++++- arch/riscv/include/asm/processor.h | 52 ++++++++++++++++++++++++++---- 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index c24280774caf..5d3368d5585c 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -49,7 +49,7 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr); * the loader. We need to make sure that it is out of the way of the program * that it will "exec", and that there is sufficient room for the brk. */ -#define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2) +#define ELF_ET_DYN_BASE ((DEFAULT_MAP_WINDOW / 3) * 2) #ifdef CONFIG_64BIT #ifdef CONFIG_COMPAT diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 75970ee2bda2..2611c1324a7c 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -63,8 +63,27 @@ * position vmemmap directly below the VMALLOC region. */ #ifdef CONFIG_64BIT +#define VA_BITS_SV32 32 +#define VA_BITS_SV39 39 +#define VA_BITS_SV48 48 +#define VA_BITS_SV57 57 + +#define VA_USER_SV39 (UL(1) << (VA_BITS_SV39 - 1)) +#define VA_USER_SV48 (UL(1) << (VA_BITS_SV48 - 1)) +#define VA_USER_SV57 (UL(1) << (VA_BITS_SV57 - 1)) + #define VA_BITS (pgtable_l5_enabled ? \ - 57 : (pgtable_l4_enabled ? 48 : 39)) + VA_BITS_SV57 : (pgtable_l4_enabled ? VA_BITS_SV48 : VA_BITS_SV39)) + +#ifdef CONFIG_COMPAT +#define MMAP_VA_BITS_64 ((VA_BITS >= VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS) +#define MMAP_MIN_VA_BITS_64 (VA_BITS_SV39) +#define MMAP_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_VA_BITS_64) +#define MMAP_MIN_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_MIN_VA_BITS_64) +#else +#define MMAP_VA_BITS ((VA_BITS >= VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS) +#define MMAP_MIN_VA_BITS (VA_BITS_SV39) +#endif #else #define VA_BITS 32 #endif diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index c950a8d9edef..3e23e1786d05 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -13,19 +13,59 @@ #include +#ifdef CONFIG_64BIT +#define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1)) +#define STACK_TOP_MAX TASK_SIZE_64 + +#define arch_get_mmap_end(addr, len, flags) \ +({ \ + unsigned long mmap_end; \ + typeof(addr) _addr = (addr); \ + if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \ + mmap_end = STACK_TOP_MAX; \ + else if ((_addr) >= VA_USER_SV57) \ + mmap_end = STACK_TOP_MAX; \ + else if ((((_addr) >= VA_USER_SV48)) && (VA_BITS >= VA_BITS_SV48)) \ + mmap_end = VA_USER_SV48; \ + else \ + mmap_end = VA_USER_SV39; \ + mmap_end; \ +}) + +#define arch_get_mmap_base(addr, base) \ +({ \ + unsigned long mmap_base; \ + typeof(addr) _addr = (addr); \ + typeof(base) _base = (base); \ + unsigned long rnd_gap = DEFAULT_MAP_WINDOW - (_base); \ + if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \ + mmap_base = (_base); \ + else if (((_addr) >= VA_USER_SV57) && (VA_BITS >= VA_BITS_SV57)) \ + mmap_base = VA_USER_SV57 - rnd_gap; \ + else if ((((_addr) >= VA_USER_SV48)) && (VA_BITS >= VA_BITS_SV48)) \ + mmap_base = VA_USER_SV48 - rnd_gap; \ + else \ + mmap_base = VA_USER_SV39 - rnd_gap; \ + mmap_base; \ +}) + +#else +#define DEFAULT_MAP_WINDOW TASK_SIZE +#define STACK_TOP_MAX TASK_SIZE +#endif +#define STACK_ALIGN 16 + +#define STACK_TOP DEFAULT_MAP_WINDOW + /* * This decides where the kernel will search for a free chunk of vm * space during mmap's. */ -#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) - -#define STACK_TOP TASK_SIZE #ifdef CONFIG_64BIT -#define STACK_TOP_MAX TASK_SIZE_64 +#define TASK_UNMAPPED_BASE PAGE_ALIGN((UL(1) << MMAP_MIN_VA_BITS) / 3) #else -#define STACK_TOP_MAX TASK_SIZE +#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) #endif -#define STACK_ALIGN 16 #ifndef __ASSEMBLY__ From patchwork Wed Aug 9 01:51:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13347310 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B815C001DE for ; Wed, 9 Aug 2023 01:53:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1DA66B0075; Tue, 8 Aug 2023 21:53:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CCE8B6B0078; Tue, 8 Aug 2023 21:53:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAA538D0001; Tue, 8 Aug 2023 21:53:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9CAC36B0075 for ; Tue, 8 Aug 2023 21:53:12 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6D930C0488 for ; Wed, 9 Aug 2023 01:53:12 +0000 (UTC) X-FDA: 81102893424.10.DC45E50 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf24.hostedemail.com (Postfix) with ESMTP id 8E923180005 for ; Wed, 9 Aug 2023 01:53:10 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=jfbSHkA7; dmarc=none; spf=pass (imf24.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691545990; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IqoPeA6wKcuCb1RtSAVao8nNOFMZCDDFQoFYxZEN+6o=; b=1VXUCL+I2pH0mvqLJK+xHDpoDT6qKM3Nstq9Ykhw6Hz6/eSLEAy5A1UGHgpAUtVIvckDMf CtHBybHZzp8x6369FuMneqChvUOWW2lFNId2SDzMASZgFxJYBFNBbSAogr8W/SxUGFAB1F 8/Au3sJDoHwK3nkQ1+8lLR1+X3GmNRc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=jfbSHkA7; dmarc=none; spf=pass (imf24.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691545990; a=rsa-sha256; cv=none; b=TwwoQD8xaMvNQ20X2d3R3rE/aleto4GlNNxFoPBK4hw3aJaOTdoXj52mM7zZczd/RtV/IR vLPJddAoVWyNI6GZ3TRQOmWF8NJBSkBMo0MOnCvwZAqIZhbMqXl4wRE9cvHIbhaD1Tvz99 ttcy7bGQcjR6JIp1g0LvfllOirAEEAM= Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1bc83a96067so8323425ad.0 for ; Tue, 08 Aug 2023 18:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1691545989; x=1692150789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IqoPeA6wKcuCb1RtSAVao8nNOFMZCDDFQoFYxZEN+6o=; b=jfbSHkA7Pa9V10urCv21V3jIQY0QYOUZGE1Ipo41h89RqVS7Dlo1ZQf/9rDavN4Lol /9kpDm9g8K7UrGHoO0oBeNtrqiogHaSkuyH2qTnD2kAuNTN9/Wq9ZqnMrYKfFcotBYnA bgGT1QaHtdTyUqRU50oFnAWOmS2swDrenCSlf2rghBXKg1HjhoiTsQ3lFtu3U6CSvBfL HH355Zp66vKcPv+H4ev3D1zj5+VOQTUhnccIF8ox38aKRiflUWNizWFAg6sqVrV/g6Jy Nxe3PjFb30KRffIufTnykwJsYVZg6qefwS+oa+S+2RWoz4C7TVc4M2O5uPwxKqUOmIdU g43A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691545989; x=1692150789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IqoPeA6wKcuCb1RtSAVao8nNOFMZCDDFQoFYxZEN+6o=; b=UsA404mhH4YAvlHBdXeGhOz2L3LP3teENeR3wxK2Auq9Qkh+vD1sqwi9bmna4vhuAr RMPy6E2UrOuPHY098InGiw2TpRab7EejEuMN2EYcZrffeftqOcbuBncdgqVer8N6j5X5 AIHNOn+qlPEBciaeZJQuTHVCc0eD4VBODTiEr+o39qK24SILdM/mPgwVi5yOI/M3Io2z pUGYs/r9Ox9xeDLv+VE8v4JWmXM6allwsJM6GvBH6guyT2960m/SgdmjcgCSU+LP03Jj ABS1kA73Pr7JBO2j3RoGvua90H6RREE/rBH3EZOjF9ogD0XoELvTsFdCJ0S7axhPMJX7 Ke4Q== X-Gm-Message-State: AOJu0Yy/ApW8dq4vNiF0Qi0hOpyO/zFM8PdQynWLnX6m9ttpsjG+SBho +n70NnngAgpm22iZWRePPCqP0w== X-Google-Smtp-Source: AGHT+IHFQGEUvoYO9sxgVWzTl8vUEdV44C3X/h5cs/VEo+Kv4prar8zZst792RMZqIZyj/nYul07Xg== X-Received: by 2002:a17:902:ec81:b0:1b6:af1a:7dd3 with SMTP id x1-20020a170902ec8100b001b6af1a7dd3mr1496825plg.23.1691545989416; Tue, 08 Aug 2023 18:53:09 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id bj7-20020a170902850700b001b87bedcc6fsm9657591plb.93.2023.08.08.18.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 18:53:08 -0700 (PDT) From: Charlie Jenkins To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: charlie@rivosinc.com, conor@kernel.org, paul.walmsley@sifive.com, palmer@rivosinc.com, aou@eecs.berkeley.edu, anup@brainfault.org, konstantin@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mick@ics.forth.gr, jrtc27@jrtc27.com, rdunlap@infradead.org, alexghiti@rivosinc.com Subject: [PATCH v9 2/4] RISC-V: mm: Add tests for RISC-V mm Date: Tue, 8 Aug 2023 18:51:08 -0700 Message-Id: <20230809015110.3290774-3-charlie@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230809015110.3290774-1-charlie@rivosinc.com> References: <20230809015110.3290774-1-charlie@rivosinc.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: xej6f6ob1haarz9s84iy98qzysw6xagy X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8E923180005 X-HE-Tag: 1691545990-838172 X-HE-Meta: U2FsdGVkX19odSgm8krTkPoAG2lBucArjwWh31DMc2hkpxd3EAkwpztZ0kb+mvkCS5vmxMKyPMUsBvkjbLURZV4olW9NbiTkR5J97HRDOBoi/dRDxZTndv2mqeS3DBHj20S7mbC4d0y+Vbb7nBSdAQCgGRoxdpCP1m0wVQeEjyGJDwcOs+5qYSQbrfz5XFsP7cPlODSCPYGjSFzOMYFCZCg4Vu/j5Pnshgh6Ap4tJg3P6rA+gOSrqbgX6LGB3iNy3eDK3TSzQ5DWcyt1A2cCYibyQC5G3KPe5D15uq+msxFTFpXnp6NGhhnQ9uSBqbB/QwFTXnz+GMmqWqlnpkOVg3yIzoci2CvvZwYsO0j8cXxTtyS7g3NHFkzhdbcMKaLLvaQwPWpAMcivvMEcMQOACDUjCoPLI20/fLgnFSHZGBtXzfLiLQs83W4X/vU2kYKSmeLoaEFEn0D6wnyLpqBhHuPPaOOsbTmsKHi6i88GfNpd0zV2w4m5G492FDPpcDSk6+Ldae1LYIg5HEu8+K0vOZd10JWqVPDDGtH+y6nXvDWOVHOS3GE4s+9eXYrn+r8dlN6wN6bDSIlWmI0flMPPI4Sg7+kog/3+tdatfauK0X6ZacDHqgVjn9NXZucOyipfWJlDoDDzENGCCZ7qEa7VpDhWUV+NliYR4Jk3D2Fisng49iMpuPunbdZJnpjsMmhAs+fG0fTp7mNBvTqoC0O32xDR625Ap6rNMZJrt+/vUvNrKpH8uN9yBsImuITyTbZ9V56DU4a8zG/45pbQTw7fx7xEqAchKqCsXpxcFlk4An/TQCMRke2sqorQJtikeOkomiEn2T+xXA9EMe2wCvU7W7LTlLSDkRdHI1uOwjaPgoc4HE6dr2cdnjW+mByAlMlW7PPqtOcnGh4/8anN3RkcEBa+2xNHwnqWky9FoDpYaGeSGsDyRwGoJtQ6HFHC35BpEA9qGmXlp72l7owFPsb TR05xxS1 +/qfOxoS4Bivl7RmvT2rRBrJcfHzgVwu+PmlFdov/Xa48oOsj4gOrEWNg+KDDLk8ZpAO3yIV48D/yuGiKBF8FYrxMq61kWyl2os9m4muD7iJuAANuZsPa0/RWehG4J1DfGBYBMTAL+MEibqbGm/32i/mEhuozthgTp5+FDKvZfk4aC+SzmycStA+hWlwZE4kg4AQVhMYOVFvaow0sFW1yEdOGCLJdPO9BSJEQEROOypq3MGkOGezSM0+u1h/CHPEYtz2H/6QnATsLRijZyXQf6vrn7mZ8GbLXkSzQg1VEOt1ZJDRPpvM3pNQMJFwZsQd0oHBJBPgYJ8bajF+ldOR8GPd2Vz5BeqTKsvuSZkXVmhzd4K1Rxz0EPQZ8Tw85nIqlavY8a0hY4XfITBbmXJMrXmbLkVx5VosvHqLakdIa1Z5KvOcpVvJsC3ykxf5BIM4ltKAZ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000037, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add tests that enforce mmap hint address behavior. mmap should default to sv48. mmap will provide an address at the highest address space that can fit into the hint address, unless the hint address is less than sv39 and not 0, then it will return a sv39 address. These tests are split into two files: mmap_default.c and mmap_bottomup.c because a new process must be exec'd in order to change the mmap layout. The run_mmap.sh script sets the stack to be unlimited for the mmap_bottomup.c test which triggers a bottomup layout. Signed-off-by: Charlie Jenkins --- tools/testing/selftests/riscv/Makefile | 2 +- tools/testing/selftests/riscv/mm/.gitignore | 2 + tools/testing/selftests/riscv/mm/Makefile | 15 +++++ .../riscv/mm/testcases/mmap_bottomup.c | 35 ++++++++++ .../riscv/mm/testcases/mmap_default.c | 35 ++++++++++ .../selftests/riscv/mm/testcases/mmap_test.h | 64 +++++++++++++++++++ .../selftests/riscv/mm/testcases/run_mmap.sh | 12 ++++ 7 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/riscv/mm/.gitignore create mode 100644 tools/testing/selftests/riscv/mm/Makefile create mode 100644 tools/testing/selftests/riscv/mm/testcases/mmap_bottomup.c create mode 100644 tools/testing/selftests/riscv/mm/testcases/mmap_default.c create mode 100644 tools/testing/selftests/riscv/mm/testcases/mmap_test.h create mode 100755 tools/testing/selftests/riscv/mm/testcases/run_mmap.sh diff --git a/tools/testing/selftests/riscv/Makefile b/tools/testing/selftests/riscv/Makefile index f4b3d5c9af5b..4a9ff515a3a0 100644 --- a/tools/testing/selftests/riscv/Makefile +++ b/tools/testing/selftests/riscv/Makefile @@ -5,7 +5,7 @@ ARCH ?= $(shell uname -m 2>/dev/null || echo not) ifneq (,$(filter $(ARCH),riscv)) -RISCV_SUBTARGETS ?= hwprobe vector +RISCV_SUBTARGETS ?= hwprobe vector mm else RISCV_SUBTARGETS := endif diff --git a/tools/testing/selftests/riscv/mm/.gitignore b/tools/testing/selftests/riscv/mm/.gitignore new file mode 100644 index 000000000000..5c2c57cb950c --- /dev/null +++ b/tools/testing/selftests/riscv/mm/.gitignore @@ -0,0 +1,2 @@ +mmap_bottomup +mmap_default diff --git a/tools/testing/selftests/riscv/mm/Makefile b/tools/testing/selftests/riscv/mm/Makefile new file mode 100644 index 000000000000..11e0f0568923 --- /dev/null +++ b/tools/testing/selftests/riscv/mm/Makefile @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021 ARM Limited +# Originally tools/testing/arm64/abi/Makefile + +# Additional include paths needed by kselftest.h and local headers +CFLAGS += -D_GNU_SOURCE -std=gnu99 -I. + +TEST_GEN_FILES := testcases/mmap_default testcases/mmap_bottomup + +TEST_PROGS := testcases/run_mmap.sh + +include ../../lib.mk + +$(OUTPUT)/mm: testcases/mmap_default.c testcases/mmap_bottomup.c testcases/mmap_tests.h + $(CC) -o$@ $(CFLAGS) $(LDFLAGS) $^ diff --git a/tools/testing/selftests/riscv/mm/testcases/mmap_bottomup.c b/tools/testing/selftests/riscv/mm/testcases/mmap_bottomup.c new file mode 100644 index 000000000000..b29379f7e478 --- /dev/null +++ b/tools/testing/selftests/riscv/mm/testcases/mmap_bottomup.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include + +#include "../../kselftest_harness.h" + +TEST(infinite_rlimit) +{ +// Only works on 64 bit +#if __riscv_xlen == 64 + struct addresses mmap_addresses; + + EXPECT_EQ(BOTTOM_UP, memory_layout()); + + do_mmaps(&mmap_addresses); + + EXPECT_NE(MAP_FAILED, mmap_addresses.no_hint); + EXPECT_NE(MAP_FAILED, mmap_addresses.on_37_addr); + EXPECT_NE(MAP_FAILED, mmap_addresses.on_38_addr); + EXPECT_NE(MAP_FAILED, mmap_addresses.on_46_addr); + EXPECT_NE(MAP_FAILED, mmap_addresses.on_47_addr); + EXPECT_NE(MAP_FAILED, mmap_addresses.on_55_addr); + EXPECT_NE(MAP_FAILED, mmap_addresses.on_56_addr); + + EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.no_hint); + EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_37_addr); + EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_38_addr); + EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_46_addr); + EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_47_addr); + EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_55_addr); + EXPECT_GT(1UL << 56, (unsigned long)mmap_addresses.on_56_addr); +#endif +} + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/riscv/mm/testcases/mmap_default.c b/tools/testing/selftests/riscv/mm/testcases/mmap_default.c new file mode 100644 index 000000000000..d1accb91b726 --- /dev/null +++ b/tools/testing/selftests/riscv/mm/testcases/mmap_default.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include + +#include "../../kselftest_harness.h" + +TEST(default_rlimit) +{ +// Only works on 64 bit +#if __riscv_xlen == 64 + struct addresses mmap_addresses; + + EXPECT_EQ(TOP_DOWN, memory_layout()); + + do_mmaps(&mmap_addresses); + + EXPECT_NE(MAP_FAILED, mmap_addresses.no_hint); + EXPECT_NE(MAP_FAILED, mmap_addresses.on_37_addr); + EXPECT_NE(MAP_FAILED, mmap_addresses.on_38_addr); + EXPECT_NE(MAP_FAILED, mmap_addresses.on_46_addr); + EXPECT_NE(MAP_FAILED, mmap_addresses.on_47_addr); + EXPECT_NE(MAP_FAILED, mmap_addresses.on_55_addr); + EXPECT_NE(MAP_FAILED, mmap_addresses.on_56_addr); + + EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.no_hint); + EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_37_addr); + EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_38_addr); + EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_46_addr); + EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_47_addr); + EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_55_addr); + EXPECT_GT(1UL << 56, (unsigned long)mmap_addresses.on_56_addr); +#endif +} + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/riscv/mm/testcases/mmap_test.h b/tools/testing/selftests/riscv/mm/testcases/mmap_test.h new file mode 100644 index 000000000000..9b8434f62f57 --- /dev/null +++ b/tools/testing/selftests/riscv/mm/testcases/mmap_test.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _TESTCASES_MMAP_TEST_H +#define _TESTCASES_MMAP_TEST_H +#include +#include +#include + +#define TOP_DOWN 0 +#define BOTTOM_UP 1 + +struct addresses { + int *no_hint; + int *on_37_addr; + int *on_38_addr; + int *on_46_addr; + int *on_47_addr; + int *on_55_addr; + int *on_56_addr; +}; + +static inline void do_mmaps(struct addresses *mmap_addresses) +{ + /* + * Place all of the hint addresses on the boundaries of mmap + * sv39, sv48, sv57 + * User addresses end at 1<<38, 1<<47, 1<<56 respectively + */ + void *on_37_bits = (void *)(1UL << 37); + void *on_38_bits = (void *)(1UL << 38); + void *on_46_bits = (void *)(1UL << 46); + void *on_47_bits = (void *)(1UL << 47); + void *on_55_bits = (void *)(1UL << 55); + void *on_56_bits = (void *)(1UL << 56); + + int prot = PROT_READ | PROT_WRITE; + int flags = MAP_PRIVATE | MAP_ANONYMOUS; + + mmap_addresses->no_hint = + mmap(NULL, 5 * sizeof(int), prot, flags, 0, 0); + mmap_addresses->on_37_addr = + mmap(on_37_bits, 5 * sizeof(int), prot, flags, 0, 0); + mmap_addresses->on_38_addr = + mmap(on_38_bits, 5 * sizeof(int), prot, flags, 0, 0); + mmap_addresses->on_46_addr = + mmap(on_46_bits, 5 * sizeof(int), prot, flags, 0, 0); + mmap_addresses->on_47_addr = + mmap(on_47_bits, 5 * sizeof(int), prot, flags, 0, 0); + mmap_addresses->on_55_addr = + mmap(on_55_bits, 5 * sizeof(int), prot, flags, 0, 0); + mmap_addresses->on_56_addr = + mmap(on_56_bits, 5 * sizeof(int), prot, flags, 0, 0); +} + +static inline int memory_layout(void) +{ + int prot = PROT_READ | PROT_WRITE; + int flags = MAP_PRIVATE | MAP_ANONYMOUS; + + void *value1 = mmap(NULL, sizeof(int), prot, flags, 0, 0); + void *value2 = mmap(NULL, sizeof(int), prot, flags, 0, 0); + + return value2 > value1; +} +#endif /* _TESTCASES_MMAP_TEST_H */ diff --git a/tools/testing/selftests/riscv/mm/testcases/run_mmap.sh b/tools/testing/selftests/riscv/mm/testcases/run_mmap.sh new file mode 100755 index 000000000000..ca5ad7c48bad --- /dev/null +++ b/tools/testing/selftests/riscv/mm/testcases/run_mmap.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +original_stack_limit=$(ulimit -s) + +./mmap_default + +# Force mmap_bottomup to be ran with bottomup memory due to +# the unlimited stack +ulimit -s unlimited +./mmap_bottomup +ulimit -s $original_stack_limit From patchwork Wed Aug 9 01:51:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13347311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44246C04A94 for ; Wed, 9 Aug 2023 01:53:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 52E656B0078; Tue, 8 Aug 2023 21:53:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DEB56B007B; Tue, 8 Aug 2023 21:53:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 330D18D0001; Tue, 8 Aug 2023 21:53:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 250546B0078 for ; Tue, 8 Aug 2023 21:53:14 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 002E112087E for ; Wed, 9 Aug 2023 01:53:13 +0000 (UTC) X-FDA: 81102893466.30.6F04273 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf19.hostedemail.com (Postfix) with ESMTP id 15A7F1A000C for ; Wed, 9 Aug 2023 01:53:11 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=KQfNpvZb; spf=pass (imf19.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691545992; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5q2lf0ErqSwJrn3JbgeuhvaoxCnqdWFIkpf1V4h3asg=; b=8ky7CoxWeak0D6J2oiwH49uynKYlK+KBbWtt49T16LIi67spD0ZH9K9ThzaW5CwdlhC5ny gBCHRjWj4joG/tiQqmNssQ3w8mIhCe5miPv45Dk/+JqB0DGkDVanmnvvo5fk9aTdncLlqk nA/s21nTLca4z+hwZ1UH65FJUY+Tu3o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691545992; a=rsa-sha256; cv=none; b=dBzhgrDWa6PhMZSqMlpRoBL215BZa8eyurJGaULVMkKoG8If4N1JbgasYvBlVIaSWRLy0I L3qEprwfo7y7ilOvtzkOhtHQPM5Q4+OvX0OaXKSVFBsEznXMoQZPnJ68nxU4jjHRSODV3b qb9aLE85r+WOQ1LsSbgB34Er5RuLv7M= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=KQfNpvZb; spf=pass (imf19.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=charlie@rivosinc.com; dmarc=none Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1bc83a96067so8323495ad.0 for ; Tue, 08 Aug 2023 18:53:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1691545991; x=1692150791; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5q2lf0ErqSwJrn3JbgeuhvaoxCnqdWFIkpf1V4h3asg=; b=KQfNpvZbwPfJw4InJH3Gop3jL8C3JwJPDbX7mWsYj121ubZsb8RGRA2aI9F/PwCRVF VythodBAkVElVzcYFFbi1lDli1YK6i88YBAyJ4izWsKPC7TciTmEvVoHSJFMyct3/A1C QCjr27vWn57/CGMNexhGRhDrj7RKrU+Fm1uLuqZAWixGoxJgCb59LKtThbuUpPvCKADL SV/MKjcJ/vt528cSHhB3ZDKQVmxe2Pl4qLNnNm+Usxd5J+XvPi8hxQoSr+RdZwvLVwxq XkZe4sqD/xdLk4MoYZctFEDxxFdlv5Rih9i/apAmP5jgpZqpVJTVwvCWYM3sPWvQD09+ Qnvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691545991; x=1692150791; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5q2lf0ErqSwJrn3JbgeuhvaoxCnqdWFIkpf1V4h3asg=; b=B+FvD5sMJLROZsdsMhkc0/9ygtqVFiH+ODKtLG5DpvttnfkGyYRJgscdHHzxFC5Li9 RwIlH4FyV5E1BoHyza1eFV63pu/vnfutnnvB5rYQqxXSn+6YfCKDyXk03Gb/0EwyRl5L FYg9rTW8R2FDF+EEMxzngqCdUj7EZ/HHtP+8v4EWPgX6yV3UcGlKGIHZD9CyGM6p5B21 BGETX0dsPh9cNqdERcqSv7ZOvU/ic72fQmxfirVZk7A+QoBLK/K1pbuaSaur77FTvNuZ Fqv2d7fPaO9sNBqFD4/qSDKyK0zpgMEN6RIjiqCFjOliv9vIqSndB/gAmgH7Nt+KLr+A fyyQ== X-Gm-Message-State: AOJu0Ywg5gc6OdEImREYnpuU0cncIcz4ingA7ccQ6H8jMcOgS6obax0J uimSABDDGdfZgyEww1mTaoBzVg== X-Google-Smtp-Source: AGHT+IGg+v5KFzlU+jQrk/Y4IPjZqAfK6IzCZuHeB5tm9d5fjhnx1QdE7SY5R0FlUS9hkHWQ+fZbQA== X-Received: by 2002:a17:902:d2cf:b0:1bc:3f9b:d96 with SMTP id n15-20020a170902d2cf00b001bc3f9b0d96mr1444563plc.49.1691545990966; Tue, 08 Aug 2023 18:53:10 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id bj7-20020a170902850700b001b87bedcc6fsm9657591plb.93.2023.08.08.18.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 18:53:10 -0700 (PDT) From: Charlie Jenkins To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: charlie@rivosinc.com, conor@kernel.org, paul.walmsley@sifive.com, palmer@rivosinc.com, aou@eecs.berkeley.edu, anup@brainfault.org, konstantin@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mick@ics.forth.gr, jrtc27@jrtc27.com, rdunlap@infradead.org, alexghiti@rivosinc.com Subject: [PATCH v9 3/4] RISC-V: mm: Update pgtable comment documentation Date: Tue, 8 Aug 2023 18:51:09 -0700 Message-Id: <20230809015110.3290774-4-charlie@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230809015110.3290774-1-charlie@rivosinc.com> References: <20230809015110.3290774-1-charlie@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 15A7F1A000C X-Rspam-User: X-Stat-Signature: d1njajkc8fbdtxdtxssb7bysj8bjxogx X-Rspamd-Server: rspam03 X-HE-Tag: 1691545991-330420 X-HE-Meta: U2FsdGVkX19Fzs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ZRxQsy58hN4QqM7zuZu88EwIVswe/D26JdRqqznFzkjbkqEvFCq9AcIgDA3M63WJBNHP+xS7ZM6NOmMGfBEsLQ08udPEnhbe4EiNlJqsF3jDQ1dESNZ46KueK1EciM67jfJitlOwgBrhW7KXeCE+6siu7jWhqev6PsTtUi4zil+olNgFC5DE9lib6cDpSIcYXELr6HaSW5PcvnzwIRb57LtVdTVCnBZazSbnys17nbccAskuzyViFWFCKMGlwsLlWPnw73v1WgUjWaztMp6seAwrgGVYZOsJmtXhVo1X88057RepjxZLlhsaumfx5gQY81rEYZ8IKGYnN/P77CU2jT4sYBnWH2T6wL1t8fs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.004632, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: sv57 is supported in the kernel so pgtable.h should reflect that. Signed-off-by: Charlie Jenkins Reviewed-by: Alexandre Ghiti --- arch/riscv/include/asm/pgtable.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 2611c1324a7c..76907b95109a 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -849,14 +849,16 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) * Task size is 0x4000000000 for RV64 or 0x9fc00000 for RV32. * Note that PGDIR_SIZE must evenly divide TASK_SIZE. * Task size is: - * - 0x9fc00000 (~2.5GB) for RV32. - * - 0x4000000000 ( 256GB) for RV64 using SV39 mmu - * - 0x800000000000 ( 128TB) for RV64 using SV48 mmu + * - 0x9fc00000 (~2.5GB) for RV32. + * - 0x4000000000 ( 256GB) for RV64 using SV39 mmu + * - 0x800000000000 ( 128TB) for RV64 using SV48 mmu + * - 0x100000000000000 ( 64PB) for RV64 using SV57 mmu * * Note that PGDIR_SIZE must evenly divide TASK_SIZE since "RISC-V * Instruction Set Manual Volume II: Privileged Architecture" states that * "load and store effective addresses, which are 64bits, must have bits * 63–48 all equal to bit 47, or else a page-fault exception will occur." + * Similarly for SV57, bits 63–57 must be equal to bit 56. */ #ifdef CONFIG_64BIT #define TASK_SIZE_64 (PGDIR_SIZE * PTRS_PER_PGD / 2) From patchwork Wed Aug 9 01:51:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13347312 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD853C001B0 for ; Wed, 9 Aug 2023 01:53:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF2946B007B; Tue, 8 Aug 2023 21:53:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E54B96B007D; Tue, 8 Aug 2023 21:53:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C57C18D0001; Tue, 8 Aug 2023 21:53:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B442D6B007B for ; Tue, 8 Aug 2023 21:53:15 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8219780E0D for ; Wed, 9 Aug 2023 01:53:15 +0000 (UTC) X-FDA: 81102893550.28.A2EC4C6 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf02.hostedemail.com (Postfix) with ESMTP id 962C78001E for ; Wed, 9 Aug 2023 01:53:13 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=FPpY5cIU; dmarc=none; spf=pass (imf02.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691545993; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2tar+fwRF9EwexnZBlGXBQ+bino7OPSUOa9FVKEDgW8=; b=TkYHsbJ2J1lrNniWBK54yHY9AoQ/gtUpumU5dnVwCTJErlKrQIexJwTtyr60GkDToa2dFR NA/9OI63F1X8lqQz1/dONIoiNuiixs35WkPjWJOBsFTVh3KrVcoDIPPrHNON0Xs82WBCEn lcn8QE4HijldSzCUO7Wb7Pueh4lmoPM= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=FPpY5cIU; dmarc=none; spf=pass (imf02.hostedemail.com: domain of charlie@rivosinc.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=charlie@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691545993; a=rsa-sha256; cv=none; b=rIcUS+30aBt31zsrZhW38ZdrgsXEmPAb7ojdvpztDg3g0oY552RlXj974PU3HTmqlhWjpA tL06SitANKyktdOS2Y2zAv1Te2Fxk2k4A9JobeqoEYBPxEM8tpTsFQOXklsRCSTMOyldND Oac5cLZ/akfHHhlSxD6k4b+wv8xA3TY= Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1bc1c1c68e2so40592685ad.3 for ; Tue, 08 Aug 2023 18:53:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1691545992; x=1692150792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2tar+fwRF9EwexnZBlGXBQ+bino7OPSUOa9FVKEDgW8=; b=FPpY5cIUXnip2ZGbpSphNOYtcmoz+9UqNCzoKTIuGrXSltzFcKRrlt8IZVpkHLRqCx OnkTugPfEWDKKQRJ75G2J1aJXt6PH8fts5QVkJJs8njOPLx6pNBBDKHzo/kPhqxS0sx3 1HU8/tEpAVmLFR+F4zwPNJwDwa/GS5jdzeVtMhkd3NlduxYlQA9dfzjF/ys4sjj6OEtk sjDMhjLy6jjBKzFs07exQfX4lKo012NsKC4Zu68gj0Uv/D7Nb/c/EwcN8oQMkTg6va+w mYmQCyjU8OGyh+PyGz8lSNWVUIf8yU596h/YkYk7J+SNhMSNxobFIMZoGtxQE5T5cv3X /BDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691545992; x=1692150792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2tar+fwRF9EwexnZBlGXBQ+bino7OPSUOa9FVKEDgW8=; b=IsyrXPb4e7keoCnPIeBBu6J7ZlwGPnNwv+8WTRslTlLTNn++B78S9XJhVE3D9ZKT9l l1LmSkx30bmnCO2Tpe9+Caqj3Cy+7sSf8iRJSwj7Go3Nb4tCliC0LudsJk72Qr4+eR+h 6hmyV8KiXjeTqZUvMP5YmAbaZsrsvR21gq8u31Ya/FqV009t1+IJRb1xHBMFLSn3CQu1 dLLXA2tDzWOdhInoZAu8rdkST+TzbwmspVXvnKGdV3ZSHeN3lM8uACkha9jXVfjV6ECw 9vXps5fpxRty/n8F2QhieAJ2wVu+TwS6DS8AcU+b8L8JQhEX7RqAsLhk2s+v89Z3+M00 7RPQ== X-Gm-Message-State: AOJu0YzaLZm5dzp4eZQB40BULo31rLVW9r1IFd7MeRMrxxbua51aDY87 hlpkdYjzGxwSvyOURqzYo6pxKQ== X-Google-Smtp-Source: AGHT+IGZcbmVCa5ZDQZDqMBC5RXy8ZlAEnBSQVfL2GCWuQwF+OUfXTklfpU8ydkeXzNNensTQj2vcA== X-Received: by 2002:a17:903:1207:b0:1b8:6850:c3c4 with SMTP id l7-20020a170903120700b001b86850c3c4mr1594061plh.22.1691545992539; Tue, 08 Aug 2023 18:53:12 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id bj7-20020a170902850700b001b87bedcc6fsm9657591plb.93.2023.08.08.18.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 18:53:12 -0700 (PDT) From: Charlie Jenkins To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: charlie@rivosinc.com, conor@kernel.org, paul.walmsley@sifive.com, palmer@rivosinc.com, aou@eecs.berkeley.edu, anup@brainfault.org, konstantin@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mick@ics.forth.gr, jrtc27@jrtc27.com, rdunlap@infradead.org, alexghiti@rivosinc.com Subject: [PATCH v9 4/4] RISC-V: mm: Document mmap changes Date: Tue, 8 Aug 2023 18:51:10 -0700 Message-Id: <20230809015110.3290774-5-charlie@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230809015110.3290774-1-charlie@rivosinc.com> References: <20230809015110.3290774-1-charlie@rivosinc.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: frjrf4sqrbh1xahhsh3qx5bx7ukb7cn7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 962C78001E X-HE-Tag: 1691545993-811122 X-HE-Meta: U2FsdGVkX18LYnDG4l1GiIYb1TeRfqZy7XWPacVEUyzDiKJFkalKBgTwL43GG6F16pqag3jvQjDbnaJ/EM9gBwEi2MybeJFEzMQMItemY9twzLfq7tr3MKCxaRFRrrAp+WBDIHreDLliWNCPC7Qa9tbK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tG7dWeARAgcUt7s+Yr+zI+rLkUzJvwI64RP+TQWVVoOR6HaVJ5Dm/yLexKLd3gL1GfbjgqO2dRzv9JyCVnjpONojdtlLhstu695ZCKRLm9xsrjE++NIGvST31eeDf5sTsc5MXvvKoK/hkCB49oQxtH7CCJrDVflqOWJMVSxZzdJD3uVqHHWXMuSctOngKU4biNefuNjLFX881hQvYJxBlNct1uxfPUGyEWB X-Bogosity: Ham, tests=bogofilter, spamicity=0.000377, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The behavior of mmap is modified with this patch series, so explain the changes to the mmap hint address behavior. Signed-off-by: Charlie Jenkins Reviewed-by: Alexandre Ghiti --- Documentation/riscv/vm-layout.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Documentation/riscv/vm-layout.rst b/Documentation/riscv/vm-layout.rst index 5462c84f4723..69ff6da1dbf8 100644 --- a/Documentation/riscv/vm-layout.rst +++ b/Documentation/riscv/vm-layout.rst @@ -133,3 +133,25 @@ RISC-V Linux Kernel SV57 ffffffff00000000 | -4 GB | ffffffff7fffffff | 2 GB | modules, BPF ffffffff80000000 | -2 GB | ffffffffffffffff | 2 GB | kernel __________________|____________|__________________|_________|____________________________________________________________ + + +Userspace VAs +-------------------- +To maintain compatibility with software that relies on the VA space with a +maximum of 48 bits the kernel will, by default, return virtual addresses to +userspace from a 48-bit range (sv48). This default behavior is achieved by +passing 0 into the hint address parameter of mmap. On CPUs with an address space +smaller than sv48, the CPU maximum supported address space will be the default. + +Software can "opt-in" to receiving VAs from another VA space by providing +a hint address to mmap. A hint address passed to mmap will cause the largest +address space that fits entirely into the hint to be used, unless there is no +space left in the address space. If there is no space available in the requested +address space, an address in the next smallest available address space will be +returned. + +For example, in order to obtain 48-bit VA space, a hint address greater than +:code:`1 << 47` must be provided. Note that this is 47 due to sv48 userspace +ending at :code:`1 << 47` and the addresses beyond this are reserved for the +kernel. Similarly, to obtain 57-bit VA space addresses, a hint address greater +than or equal to :code:`1 << 56` must be provided.