From patchwork Sat Jan 20 21:49:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 13524462 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 3C82BC47258 for ; Sat, 20 Jan 2024 21:50:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE6186B007B; Sat, 20 Jan 2024 16:50:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A95F96B007D; Sat, 20 Jan 2024 16:50:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E7DD6B007E; Sat, 20 Jan 2024 16:50:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7BCD86B007B for ; Sat, 20 Jan 2024 16:50:24 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4DBBEA0483 for ; Sat, 20 Jan 2024 21:50:24 +0000 (UTC) X-FDA: 81701033568.02.968A234 Received: from out203-205-251-36.mail.qq.com (out203-205-251-36.mail.qq.com [203.205.251.36]) by imf09.hostedemail.com (Postfix) with ESMTP id 6A38614000F for ; Sat, 20 Jan 2024 21:50:20 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=BCTJUEnR; dmarc=none; spf=none (imf09.hostedemail.com: domain of cyy@cyyself.name has no SPF policy when checking 203.205.251.36) smtp.mailfrom=cyy@cyyself.name ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705787421; 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=4nmX4hKeh/0WuigJrd8ANC0wflYIcPXPQU4r0VNEKp8=; b=UtgIMQxWyA6psuD6aly+uS6lxWXHty1/GRCsdNvsp9Hu8f8I6OluMFqm1z8WkSUAKwmgAh PBjk0v3JXQ3CTzyYMXbANlSZXZYiL9u9opHcohKuf4+O/LGmExz/7G0IvGZ25gDniOk28u KEhgMO3+pOzXEIrIbYoWoBbj0d9A2Yc= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=BCTJUEnR; dmarc=none; spf=none (imf09.hostedemail.com: domain of cyy@cyyself.name has no SPF policy when checking 203.205.251.36) smtp.mailfrom=cyy@cyyself.name ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705787421; a=rsa-sha256; cv=none; b=xFucspqt+ziXnqbAsRP7HL1H2CjjUetyxPh/eeuX7+PpkXEBRmm3R5BTKlLvPVqPTPlyZf RGUuUrebDWsq+jX4iavJR2MTbkRcEMMr36LHTyPMYqJkaunH3tBT8rnFHzV6hLjP/Rh9FY fbXuJT+Glwrep+ionHVjRjl7tZsb4o4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1705787407; bh=4nmX4hKeh/0WuigJrd8ANC0wflYIcPXPQU4r0VNEKp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BCTJUEnRp+uC0d0dRxHQsm/zVTkvWgVkAiSDO/Np0gxMBiylPltmYRRlaUxuRE5dT JNImCpHL9Z4E39CTM/nzV/g84s+7awuJxhKqNJLPRWtD/xn8+67ZyD+5zra9Iqkfk5 J9hS+sWGY04ORFsXjGfpC4+g8/l88pMguMUorMpg= Received: from cyy-pc.lan ([240e:379:2240:ed00:c92f:86c3:e615:ca18]) by new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qUYtUCIj2vddR9JwJhuka6alp ygJd0xxijjWzsLCCayIR99Dfr/ijIim+Z3cuceuUmlob4bU1jZwoh5pvhl8Q2/c10Bj37a/jyDxR eCDOn+v55wx5G1hZ7R7Lo7MkdxHpg= X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= From: Yangyu Chen To: linux-riscv@lists.infradead.org Cc: Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Guo Ren , Andy Chiu , Conor Dooley , Jisheng Zhang , Alexandre Ghiti , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Yangyu Chen Subject: [PATCH v2 1/3] RISC-V: mm: do not treat hint addr on mmap as the upper bound to search Date: Sun, 21 Jan 2024 05:49:58 +0800 X-OQ-MSGID: <20240120215000.291877-1-cyy@cyyself.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6A38614000F X-Stat-Signature: q41uj4qpdqicn3kd4pimn57gwagh64nq X-HE-Tag: 1705787420-206974 X-HE-Meta: U2FsdGVkX1/+/uxDQOqjOjBxfceZpBY25P1wR69qj/R11nhed/sLWArqMurclqwJn9SqdCqvq6OUYiM5ooX4IAg5AldQ9+Sf6X8QyFRuKBRlSE8UX+dgP5mGp7DzV/VOnLYe4hPhBmDA3FFzUAooVicMIcS+kmbkRXuRFQ1+VpoG+nPFKhaYoAkZN1RfF2A/ugNfAb5G9164fgGsAt+Ib+FBqcwOPlPbjIUC7RV3WvJ0LboDN+VCEDSq96ACvIT3Yjp/uP/7qeCBign0WPHdi18AeMLUUM3ZjfDUZK2EfvFn4PlSErg0B4pqmJ+6nJO4JJWF+WpSKH53GQfO2l3zhKf/R1M/mtRMxIAxJhgtc9IKn6UmQTXi1JhMQT/UR5EFMNvjHdaD4AXk2GB7ZpxI+jriZIKppsimAKguR3FhtQy10ATYjklwo+ZEO0AqAdQ1D+vYc8F1CDKVelAdDm147Z6P1QNu/IjIg4rqC2h6J81/dmWLLd/S7wAKSZbJsa482jIfBaqCLD7Z/MQeoSDSWB9T2k+Q3h9a0JELo1cKCw1QLmFRa88uqSx3o0KgEPXDriYbXQ59JAJ0MLHMpNgsQQPyhH0ad19W8JkBv+Dfi5gnJ4K1dx5lKfNAygaaUiddy9jtYVBBLV9ROoDq0Z5kLHblQ3qmkrhGyNjJdlPjrywcDu0/NQnNdQ0D8RAJ1YmTz4Vq8EjMx2iqQhPgJZJdsnJ6PgvFDhbqlJC5nqsn7hEhwkrztUnMHapyh8n9GUSCTg/2PccM0iw8qgVjaElgBCJdsixbDQWgcgEdLa4g5I9gwCTCze5yOw== 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: List-Subscribe: List-Unsubscribe: This patch reverted the meaning of the addr parameter in the mmap syscall change from the previous commit add2cc6b6515 ("RISC-V: mm: Restrict address space for sv39,sv48,sv57") from patch[1] which treats hint addr as the upper bound of the mmap return address. However, some userspace software assumes mmap will attempt to create mapping on the hint address if possible without MAP_FIXED set, thus these software will always use the fallback path as the return address is not the same as the hint, which may lead to some performance overhead. Other ISAs like x86, arm64, and powerpc also meet this issue which has userspace virtual address bits larger than 48-bit and userspace software may use the MSB beyond 48-bit to store some information. Still, these ISAs didn't change the meaning of the hint address and only limited the address space to 48-bit when the hint address did not go beyond the default map window. Thus, this patch makes the behavior of mmap syscall on RISC-V sv57 capable system align with x86, arm64, powerpc by only limiting the address space to DEFAULT_MAP_WINDOW which is defined as not larger than 47-bit. If a user program wants to use sv57 address space, it can use mmap with a hint address larger than BIT(47) as it is already documented in x86 and arm64. And this code is copied from kernel source code on powerpc. [1]. https://lore.kernel.org/r/20230809232218.849726-2-charlie@rivosinc.com Signed-off-by: Yangyu Chen --- arch/riscv/include/asm/processor.h | 38 ++++++------------------------ 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index a8509cc31ab2..bc604669f18e 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -18,37 +18,13 @@ #define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1)) #define STACK_TOP_MAX TASK_SIZE -#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; \ -}) +#define arch_get_mmap_end(addr, len, flags) \ + (((addr) > DEFAULT_MAP_WINDOW) || \ + (((flags) & MAP_FIXED) && ((addr) + (len) > DEFAULT_MAP_WINDOW)) ? TASK_SIZE : \ + DEFAULT_MAP_WINDOW) + +#define arch_get_mmap_base(addr, base) \ + (((addr) > DEFAULT_MAP_WINDOW) ? (base) + TASK_SIZE - DEFAULT_MAP_WINDOW : (base)) #else #define DEFAULT_MAP_WINDOW TASK_SIZE From patchwork Sat Jan 20 21:49:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 13524461 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 2922CC47258 for ; Sat, 20 Jan 2024 21:50:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D84E6B0078; Sat, 20 Jan 2024 16:50:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 788776B007B; Sat, 20 Jan 2024 16:50:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64FBC6B007D; Sat, 20 Jan 2024 16:50:21 -0500 (EST) 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 51E9D6B0078 for ; Sat, 20 Jan 2024 16:50:21 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1C860807FD for ; Sat, 20 Jan 2024 21:50:21 +0000 (UTC) X-FDA: 81701033442.20.0224C2F Received: from out203-205-251-73.mail.qq.com (out203-205-251-73.mail.qq.com [203.205.251.73]) by imf15.hostedemail.com (Postfix) with ESMTP id 79F0FA0006 for ; Sat, 20 Jan 2024 21:50:18 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=NuCknl05; dmarc=none; spf=none (imf15.hostedemail.com: domain of cyy@cyyself.name has no SPF policy when checking 203.205.251.73) smtp.mailfrom=cyy@cyyself.name ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705787419; 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=SbEh5VB4GzFFImDZ98RQo/aVP6rIyZlESD+33dGh2Zg=; b=JGZWExpUfyRe46kj0/mqMPVcIoz/CPCasOZ6JKyf/khiOvggtUMnlCspqsClB44hApjsWn K/r451WipQCXZ8BWmxGeNoNSNrSVg6GSjOh4aQFBhHt2ckaSOV3fSg6b+EaXYHtRqWoh2O H5CJ8PudL0mhX626wjoJAAVi7z7G6XU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=NuCknl05; dmarc=none; spf=none (imf15.hostedemail.com: domain of cyy@cyyself.name has no SPF policy when checking 203.205.251.73) smtp.mailfrom=cyy@cyyself.name ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705787419; a=rsa-sha256; cv=none; b=Brqh19k5eyZLPWHFX3s+n0e8CtA0fHKv9JLCAe7SHmQ6CzJ4+aZ3ssgcvpl3EcE4KPtr3n xU/Wpqk7ljShXZFRecoJiERECTtt+9+QwvC8OJwwa5AUJr6DKvPD4P+/FvZYv8snwBKXuS WbTzBRjbzGGlMuYdanT0N/Sch8iHtog= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1705787409; bh=SbEh5VB4GzFFImDZ98RQo/aVP6rIyZlESD+33dGh2Zg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NuCknl05Y9BtPtHq3TniUiL8depkg9vZKlYCkx+8ht7fkZvZLox6tld6yr4tMCcfK p2RNjRj9IEN4CFZmKeJ5S14KG4DLVdXaAaYvwDrEax6SUk1nxG4igG2PiqON5T2GOi TarUkkMa/8+8hJ/D2CuYy/uex17L5WBZDQk5IlS8= Received: from cyy-pc.lan ([240e:379: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ONG2i88yEh3h/cFq6HSCVY6UHhNSBz1uGQ4cPcsDlDbtUeV/GM1GjVXGG8O CzFRgV6aJwKNeVr+EctVVgKBxZ5za8xhjzLPo/ljYPJSGoQwrJQEd+nl/ShJyabAc9uCYCHE+dkD US+Bylb9/aetiTdVGmNmb0p6jQhaQ= X-QQ-XMRINFO: OWPUhxQsoeAVDbp3OJHYyFg= From: Yangyu Chen To: linux-riscv@lists.infradead.org Cc: Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Guo Ren , Andy Chiu , Conor Dooley , Jisheng Zhang , Alexandre Ghiti , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Yangyu Chen Subject: [PATCH v2 2/3] RISC-V: mm: only test mmap without hint Date: Sun, 21 Jan 2024 05:49:59 +0800 X-OQ-MSGID: <20240120215000.291877-2-cyy@cyyself.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 9y8b6j9qdp43sxtto4h7dtgxd4dye1u9 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 79F0FA0006 X-HE-Tag: 1705787418-292714 X-HE-Meta: U2FsdGVkX182NqW6oNxL997NxFl9OS06QmAfh0GglA+5ANBt+b6SN2SU5N6mLyb1O3gRKvVabQKXuwEsXGfix3pNpTzOACxLUJZr0MEvbri56Ry7baDl8oQsdcV+Ly8J8HM7wNWOnsF1KklC7YacqbmDJUqwt6Y0+P21lkINuoxuDTXVs29rP364HJhla8T7NdTxhuGVEObvZd3/Or4c4NcsSLW1BL8h8uYuT6UOOD9a57O/QBM7GfZbWCaZLCfaQoKFSQJSD/AWBu4s99Ug+ZLa4+bIiVKPgEGE64vWniOQcMZUhOieQjZC1vEkg+JzmBVWFwf5A6HH9JTInlgQ91XAL1GQEAyNPJZDJhKx1d6WnZhH1iFHqcMzQm/ojS6QTQ/NjWx7jW55qerPR5ha+r58coH66BvCt3sDon29qUwwRIw0A4e6PqzC38ZtMCF5fTTfTyQmEldGU47ebg2jnyPWQmBLv9rlcr3F6LurOIwW2Sx52olmTx9OTa6r3jzUcPJbwUim54qUvZ25H8j82ttDI7knP7ZFDJOXrwbVUw6ABFxoY5EZ+dwjPjoCREGGpIKqYtUd9k5L2bWeN8VeRYzKWspGKfi0d4fV0/PGy53/NyZ6KBgYaCK18unp+Z+vMrh5dOTsiaiB4dsKgQnrFvnBBRw3GDP44gF2FHHsZLsxjEHNYDx9ZQ8Xg/nMtnWnRv0TCJYBrb3Rk/rsyZSFUbWG3aobaM0dabhtWsOhIbLp0LBI0hSCvUaX78Nkw1G7afbTPfeu2mVm+wloj84vkVjen/qXfBumA1trUZBgOX/Cjj0GuwYadpOH4+SuVOHFcyyBeRd89Cv1lg4UNr5ytrApGdp93nm5NgfUt1ma4GCgmCsarwExtyX7CyUh4BWug6lN42PLT7q+t/vZQk/WmjmMNy1dICla4ueDk2SbAHAldQoo2hrpPmXHXPdSTlhsyitUfoq7xkgXzXxAkl/ nzRCan0z /GdPTrw5XhifQ3A/X97dfQSdbL3dusEwDdJ/Ci73emSMfR5djxbHz+EbXTPLw6t2JXvzuWnq7XyzX2XyshCKJ3qM0jZEKitco8XBkZ1hXa3qE000UXEs0RsgEgJiww2/ntRqwaNftm753mW14Tli0zBqKPCFwiEBoKWa5ZfAFn75WYOLr+w6HuvT8kD40rRrrlM6N7b3KrnYykAs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000079, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The original test from the previous patchset[1] assumes the hint address on mmap is treated as the upper bound of the return address. As we reverted this special behavior, this test should be updated to reflect the change. [1]. https://lore.kernel.org/linux-riscv/20230809232218.849726-1-charlie@rivosinc.com/ Signed-off-by: Yangyu Chen --- .../selftests/riscv/mm/mmap_bottomup.c | 12 -------- .../testing/selftests/riscv/mm/mmap_default.c | 12 -------- tools/testing/selftests/riscv/mm/mmap_test.h | 30 ------------------- 3 files changed, 54 deletions(-) diff --git a/tools/testing/selftests/riscv/mm/mmap_bottomup.c b/tools/testing/selftests/riscv/mm/mmap_bottomup.c index 1757d19ca89b..1ba703d3f552 100644 --- a/tools/testing/selftests/riscv/mm/mmap_bottomup.c +++ b/tools/testing/selftests/riscv/mm/mmap_bottomup.c @@ -15,20 +15,8 @@ TEST(infinite_rlimit) 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 } diff --git a/tools/testing/selftests/riscv/mm/mmap_default.c b/tools/testing/selftests/riscv/mm/mmap_default.c index c63c60b9397e..f1ac860dcf04 100644 --- a/tools/testing/selftests/riscv/mm/mmap_default.c +++ b/tools/testing/selftests/riscv/mm/mmap_default.c @@ -15,20 +15,8 @@ TEST(default_rlimit) 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 } diff --git a/tools/testing/selftests/riscv/mm/mmap_test.h b/tools/testing/selftests/riscv/mm/mmap_test.h index 2e0db9c5be6c..d2271426288f 100644 --- a/tools/testing/selftests/riscv/mm/mmap_test.h +++ b/tools/testing/selftests/riscv/mm/mmap_test.h @@ -10,47 +10,17 @@ 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; }; // Only works on 64 bit #if __riscv_xlen == 64 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); } #endif /* __riscv_xlen == 64 */ From patchwork Sat Jan 20 21:50:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 13524463 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 D0170C47DAF for ; Sat, 20 Jan 2024 21:50:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47DC36B0080; Sat, 20 Jan 2024 16:50:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42B936B0081; Sat, 20 Jan 2024 16:50:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CE246B0082; Sat, 20 Jan 2024 16:50:31 -0500 (EST) 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 19E0C6B0080 for ; Sat, 20 Jan 2024 16:50:31 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E98B1A1799 for ; Sat, 20 Jan 2024 21:50:30 +0000 (UTC) X-FDA: 81701033820.05.257F081 Received: from out203-205-251-36.mail.qq.com (out203-205-251-36.mail.qq.com [203.205.251.36]) by imf26.hostedemail.com (Postfix) with ESMTP id 8C5DA140013 for ; Sat, 20 Jan 2024 21:50:28 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=tkkUO3X1; spf=none (imf26.hostedemail.com: domain of cyy@cyyself.name has no SPF policy when checking 203.205.251.36) smtp.mailfrom=cyy@cyyself.name; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705787429; 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=wiHZS6ft7NfH/87XosWxG0akHz17+zK84hbyOL+xbfQ=; b=U+RYB9UOle6VGJLPdgVLN0gJ9pC0u17B6LV771mCmToCZei5hJ8hxZODAQbHXegbPr9udb OaY82Jduzh9WF6Yzx5MpZyNR861uleduFIVjyTJmAHE2c3iS9mTJNo3d1LagBzqHyyNOlX 3xtzMp293LvmPJ07IMn1Vw0sidWzRW8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705787429; a=rsa-sha256; cv=none; b=kYVCNuhy75ajQM1gTHDFMwifX79TFXQ2fmeqo9CluzpDeYJMNwodzlW36OMAbd/HnYLLus kV6/MwQUvQIlW52we4CgjzqKEV0JzwjYGXeG/b4JZKCgBUm7EQx75StH/Ke5o9cNJAjJVA cKvlkYEUijJxqJqxuiDTyU5GZLbjjAE= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=tkkUO3X1; spf=none (imf26.hostedemail.com: domain of cyy@cyyself.name has no SPF policy when checking 203.205.251.36) smtp.mailfrom=cyy@cyyself.name; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1705787410; bh=wiHZS6ft7NfH/87XosWxG0akHz17+zK84hbyOL+xbfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tkkUO3X12YqAA6at4NtFba+0ASKEt/e1buGrCZ49fvDwevmnFg4aozaujW4uZqrQf 9p/LzQft4WyK9gnsuENQG5R58YR9AYOVASo4oYcexxZQl3A3PjYwBoesdUhKvQy6Gc /raIZ/wH/vB6k4dyk9xiEJhPFTqXx+F8HFTHGVM4= Received: from cyy-pc.lan ([240e:379:2240:ed00:c92f:86c3:e615:ca18]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id C832D4DD; Sun, 21 Jan 2024 05:50:03 +0800 X-QQ-mid: xmsmtpt1705787408t5oxeyvxb Message-ID: X-QQ-XMAILINFO: MUa7vzS8moCUhEfLw/vyx4sgUoBQIP3idQluppaaYziV3yUX8uYoR2EirwDl7R y6qE4vaWFEn5uxFjflYiQ8TUINCgioSfsy9gQhrXXNQmC51UBKKhIbDHdDwsLwviIV5p4sdmbcun saTHYKScF7sDkCM7DSqASJUBmsDe8GN6X+m01eSCsNuqoI0KlrVfHfbv6xpGwDPeDu2BITu9udcJ G04ri04Dfw/gfWaSeyrUsvCzlGo+EiOPx9L1plLGRyJ7NZu7VJabM1TWGLGNEQpcXrRNY5vNd2oj u92FFLOA5riEAFvFJQixJcxj8zCxfkpvCe45k8F2piIjOcHens8A3WAWpSadsTHzHaSjYQy3NUE3 uXqvSkqZfm6LTytactOFHwCPZzhf4RmNMx3GR9CienhFl7Wb8J6wD6j+i2PWMYUNaiuikzMZc9qE ex8dNUHc5bz0rAVVWdmYqQBcT2K57tJSv+NgZ6aaqSw803GwiGdJ4uA78iRiF9ggoaicwrGpwbP0 k37nREd1kVJJC1GqDarjb1GfLk+KKNDZsjTkYbIJAyGyh9bmneNEY0gkd0EFrtWtNRXuzWM7cyGh BmW8DiDkzQPGBUBizBlGesZBIAR3+jOc8oklmcdhIpskiz6NBejwmqhcflUByoyYU+7YKQWr4yC0 U7g8Lvy2egmT/Fi7nuu/Qup6n6vtbzjgos9xrOMCKNzs9dOGomlWy1vFF/RwNAn0UGSDQpA8UdKj IDVxpPms0JmykcH2uDSY0HmvESHh7qi6TwnvRsqWx38TFUal2wXLebe52f1mf5wRwQ2pKGuBzDc3 2mLKPyn6uVYw2ftdxx5yJXazQN4k3d9jyta3qR6BI3zh3lkXZZpG2DEJAa0cIxm7iIDeUVGVZQyL OPNpl/t8shZLdc/5FnUQz3uE6y0eivYs0yipJFkxpBw2KEnAUY4MeSeafi0SjWDRBxVF+yFa5SPH RW+/qeYJngV9W13p7qDKgCAygh6UCBys9beE2YE7qh5f6ApmdN4At3Eeh6vPQjG6Yb6tky4RoICb UQ8JGUr/2fB8vGt4WQaU+gLpzfbqjT8NWr6dEy1tayhO7FCmXt X-QQ-XMRINFO: NI4Ajvh11aEj8Xl/2s1/T8w= From: Yangyu Chen To: linux-riscv@lists.infradead.org Cc: Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Guo Ren , Andy Chiu , Conor Dooley , Jisheng Zhang , Alexandre Ghiti , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Yangyu Chen Subject: [PATCH v2 3/3] Documentation: riscv: correct sv57 kernel behavior Date: Sun, 21 Jan 2024 05:50:00 +0800 X-OQ-MSGID: <20240120215000.291877-3-cyy@cyyself.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: fn7a79tu9nost6o63issfm8ii8pozq3m X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 8C5DA140013 X-Rspam-User: X-HE-Tag: 1705787428-188816 X-HE-Meta: U2FsdGVkX18h0oHfPuPs9VGbA38tkVWu+FdadEJj71h53qz23EDj4EeuE7flwIzsJEGUeBkiwfJe4/4VyWCLO+eOeF4dAzyJ1r+iL/NoczzHXPw5OdXaosPMYaBBIemeL0pLsm73JIjRLuO491zP7M5CvabXfV1cAzbA668Xh43yM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=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The original documentation from the previous patchset[1] treated the hint address on mmap as the upper bound, since we have already removed this behavior, this document should be updated. Most of the content is copied from the corresponding feature in x86_64 with some modifications to align with the current kernel's behavior on RISC-V. [1]. https://lore.kernel.org/linux-riscv/20230809232218.849726-1-charlie@rivosinc.com/ Signed-off-by: Yangyu Chen --- Documentation/arch/riscv/vm-layout.rst | 54 ++++++++++++++++---------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/Documentation/arch/riscv/vm-layout.rst b/Documentation/arch/riscv/vm-layout.rst index 69ff6da1dbf8..9d84362b9f91 100644 --- a/Documentation/arch/riscv/vm-layout.rst +++ b/Documentation/arch/riscv/vm-layout.rst @@ -135,23 +135,37 @@ RISC-V Linux Kernel SV57 __________________|____________|__________________|_________|____________________________________________________________ -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. +User-space and large virtual address space +========================================== +On RISC-V, Sv57 paging enables 56-bit userspace virtual address space. +Not all user space is ready to handle wide addresses. It's known that +at least some JIT compilers use higher bits in pointers to encode their +information. It collides with valid pointers with Sv57 paging and leads +to crashes. + +To mitigate this, we are not going to allocate virtual address space +above 47-bit by default. And on kernel v6.6-v6.7, that is 38-bit by +default. + +But userspace can ask for allocation from full address space by +specifying hint address (with or without MAP_FIXED) above 47-bits, or +hint address + size above 47-bits with MAP_FIXED. + +If hint address set above 47-bit, but MAP_FIXED is not specified, we try +to look for unmapped area by specified address. If it's already +occupied, we look for unmapped area in *full* address space, rather than +from 47-bit window. + +A high hint address would only affect the allocation in question, but not +any future mmap()s. + +Specifying high hint address without MAP_FIXED on older kernel or on +machine without Sv57 paging support is safe. On kernel v6.6-v6.7, the +hint will be treated as the upper bound of the address space to search, +but this was removed in the future version of kernels. On kernel older +than v6.6 or on machine without Sv57 paging support, the kernel will +fall back to allocation from the supported address space. + +This approach helps to easily make application's memory allocator aware +about large address space without manually tracking allocated virtual +address space.