From patchwork Sat Jan 20 21:48:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 13524460 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 A7DAEC47DAF for ; Sat, 20 Jan 2024 21:48:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F8006B0074; Sat, 20 Jan 2024 16:48:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A7F46B0075; Sat, 20 Jan 2024 16:48:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB27D6B0078; Sat, 20 Jan 2024 16:48:44 -0500 (EST) 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 D957A6B0074 for ; Sat, 20 Jan 2024 16:48:44 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7A078C03EF for ; Sat, 20 Jan 2024 21:48:44 +0000 (UTC) X-FDA: 81701029368.08.E27696D Received: from out203-205-251-72.mail.qq.com (out203-205-251-72.mail.qq.com [203.205.251.72]) by imf29.hostedemail.com (Postfix) with ESMTP id 73758120011 for ; Sat, 20 Jan 2024 21:48:41 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=Zf7leXdT; dmarc=none; spf=none (imf29.hostedemail.com: domain of cyy@cyyself.name has no SPF policy when checking 203.205.251.72) smtp.mailfrom=cyy@cyyself.name ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705787322; 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:references:dkim-signature; bh=6U2V9PznT/aHdEhNbmRHZ0xAzvTGSoyQ3tiDTQLv01Y=; b=yNFvWPGvXFNf/Dwg839t2bvgEWbrc/YYDPoZrI9poY+1FVKF4PPDndNx60CP/QMfgbEpUF 32a8F1RKibmFKAB7arI172jzLNGuoWkgiJCgP2INrbXHNSkSl9t/s6r2hF3UtS1z7vpWso zZ3L7QgC9pwburHn1j3zaSSHxv7GI9w= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=qq.com header.s=s201512 header.b=Zf7leXdT; dmarc=none; spf=none (imf29.hostedemail.com: domain of cyy@cyyself.name has no SPF policy when checking 203.205.251.72) smtp.mailfrom=cyy@cyyself.name ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705787322; a=rsa-sha256; cv=none; b=wgx9xDp2ELajqoUdEihAYnhmVB6k7c4nvd7usDIDEyPYdVsEronKFjbP1yzQk8ZoCsTlqk Eh+I1JwlRQqTVD9ScioWzaBaf8ZDYwSTDpYuLISCDkXxb9TUF8thM0C7+Dagz2KAeiT9Hn T5UcbT8Ft6Peso6ERlMZz2rYs9AyG4c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1705787311; bh=6U2V9PznT/aHdEhNbmRHZ0xAzvTGSoyQ3tiDTQLv01Y=; h=From:To:Cc:Subject:Date; b=Zf7leXdTRyLHolgwRVNO0JJ8ybL0fo9iCJs/yNoslTvyIEBp+ApMzeOrrcXP6b0rw 0TgoXaq3tj1XNufDdvewTdoAmg2X7MA3OyZrnPYp0b1djY/kXam3si91Jc+wYFQfrk +qRngseMtYaGWQOYADym1gg+0dspVpY/M2SYr4ro= Received: from cyy-pc.lan ([240e:379:2240:ed00:c92f:86c3:e615:ca18]) by newxmesmtplogicsvrszc5-1.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UrVCO+ kjq2pQVcAI9D3NRADA9Z97NIxn/QbpTx6YDghJW48nB18HxzjF9g1NXIcSpgck 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 0/3] RISC-V: mm: do not treat hint addr on mmap as the upper bound to search Date: Sun, 21 Jan 2024 05:48:09 +0800 X-OQ-MSGID: <20240120214809.291094-1-cyy@cyyself.name> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 73758120011 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 8wiz4ytfbrs7qgc58q3iiotj8oneqboo X-HE-Tag: 1705787321-619302 X-HE-Meta: U2FsdGVkX18Qlh73P8Gagu5PrBE7kgx1l4VIrSJBuEnFz/ijZqW1AHHOvZckGAHjXdPiFsKs+Y5lDrTrZXWZfS/4IqECz7VAFNHmKaS0Aj4wgvQA/IsJgMyACLxk6Q33DZ6K0CCQbRhlhuuzacvnuort/yTqihKTE2ASkIH6L5e0wfWhMG/mRfTHoIgJHV+lHB0J7fs6VxD9bwuyxRKzErT1ANG/nMkZ/2dG/ppZ/NznZWb9P+PBN5ZzZxi78bbuD/pksVZRLrECy5smgQItenoL2nwrgHQHlJJ+oVTh1vjoyc33cArVhTlLO3Tdv1Ju+SMun13bDkE0rT2Chb5dnRGFcGQICYb27s99FySM3gtZsZtG5GHzmXSGEEV/jyDEgfWL99tBBMfssVgrXqGYJJqS/CMi667d77ObyVwm5yC92zV9jlkXRWqYQAbnvN1Cs4GZ1/+RzYK4k4X+Z+msfNLusdPVaOfcNaAvxFvHv0qwOxBxdeWxFOSEJoMlRwXPlwVnIQ4ekThXVj0PVh4qrNria6Pn6USnGYaB7yhvzoHfRbdPT+EJ8tAM6krh3HXWnLr3gvRxilmuD4gjcQc9fAZ1pB0stKLGku8itVyo8/rrZmMKAWJf6uwbcn4EMxmB2m3VrG1FVax9HQLns+WOc8B1a/G0sWBrjvpS+rjpvn/iXbiGT1bI1y1OaYr2TWlxXySRDEYogBvtoRxlYmOE/OewP4e1hcEg29PRuGKCLAcGm5fAjfDtX9zxnk6oMj5N7wVDn5r7ZoZffIHNdNV188YMMfKqC7a/GjhC09rry33+3caPbbmsf5qI22eLNpIjqCfqn0IzXQPtpg8mB25iN4CrfH9cL+b/N7JZz146q/iLXkCtfHp6Rttpcn4jwaLDPN1ZqAcf5XGG7rFVnilIP+CoNvviB3T0vhDgVpXgGsV33pxd9s2DIZb+0dqjCOPbyIEW8aKn5dNVbcT386T olQgXGGD qLWzheapIpKOJLwcrzjKib/ruJdar+87sEf4TRwpo1+8CBBhcZniLLVL3wPIT+YDaEXGIdSfdkxXQMIxiypVyMO8aqE+kT7umcdlQOcXmXTZQyDZCNu44wr4BFrKk7AqDdJNvwBS+rJYhbq61Q6bkZ5x+BcyqYm0T0Gp4EYagVbUISLpXBPZkZGD6K9CuJKtyhLublpIysGbBY4PjaBs4LA09w+wxnfv7ysDfbaBNpRFTQbrN2PzWsWrcQcSqTeUcf57g X-Bogosity: Ham, tests=bogofilter, spamicity=0.001490, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Previous patch series[1] changes a mmap behavior that treats the hint address as the upper bound of the mmap address range. The motivation of the previous patch series is that some user space software may assume 48-bit address space and use higher bits to encode some information, which may collide with large virtual address space mmap may return. However, to make sv48 by default, we don't need to change the meaning of the hint address on mmap as the upper bound of the mmap address range, especially when this behavior only shows up on the RISC-V. This behavior also breaks some user space software which assumes mmap should try to create mapping on the hint address if possible. As the mmap manpage said: > If addr is not NULL, then the kernel takes it as a hint about where to > place the mapping; on Linux, the kernel will pick a nearby page boundary > (but always above or equal to the value specified by > /proc/sys/vm/mmap_min_addr) and attempt to create the mapping there. Unfortunately, what mmap said is not true on RISC-V since kernel v6.6. Other ISAs with larger than 48-bit virtual address space like x86, arm64, and powerpc do not have this special mmap behavior on hint address. They all just make 48-bit / 47-bit virtual address space by default, and if a user space software wants to large virtual address space, it only need to specify a hint address larger than 48-bit / 47-bit. Thus, this patch series keeps the change of mmap to use sv48 by default but does not treat the hint address as the upper bound of the mmap address range. After this patch, the behavior of mmap will align with existing behavior on other ISAs with larger than 48-bit virtual address space like x86, arm64, and powerpc. The user space software will no longer need to rewrite their code to fit with this special mmap behavior only on RISC-V. My concern is that the change of mmap behavior on the hint address is already in the upstream kernel since v6.6, and it might be hard to revert it although it already brings some regression on some user space software. And it will be harder than adding it since v6.6 because mmap not creating mapping on the hint address is very common, especially when running on a machine without sv57 / sv48. However, if some user space software already adopted this special mmap behavior on RISC-V, we should not return a mmap address larger than the hint if the address is larger than BIT(38). My opinion is that revert this change on the next kernel release might be a good choice as only a few of hardware support sv57 / sv48 now, these changes will have no impact on sv39 systems. Moreover, previous patch series said it make sv48 by default, which is in the cover letter, kernel documentation and MMAP_VA_BITS defination. However, the code on arch_get_mmap_end and arch_get_mmap_base marco still use sv39 by default, which makes me confused, and I still use sv48 by default in this patch series including arch_get_mmap_end and arch_get_mmap_base. Changes in v2: - correct arch_get_mmap_end and arch_get_mmap_base - Add description in documentation about mmap behavior on kernel v6.6-6.7. - Improve commit message and cover letter - Rebase to newest riscv/for-next branch - Link to v1: https://lore.kernel.org/linux-riscv/tencent_F3B3B5AB1C9D704763CA423E1A41F8BE0509@qq.com/ [1]. https://lore.kernel.org/linux-riscv/20230809232218.849726-1-charlie@rivosinc.com/ Yangyu Chen (3): RISC-V: mm: do not treat hint addr on mmap as the upper bound to search RISC-V: mm: only test mmap without hint Documentation: riscv: correct sv57 kernel behavior Documentation/arch/riscv/vm-layout.rst | 54 ++++++++++++------- arch/riscv/include/asm/processor.h | 38 +++---------- .../selftests/riscv/mm/mmap_bottomup.c | 12 ----- .../testing/selftests/riscv/mm/mmap_default.c | 12 ----- tools/testing/selftests/riscv/mm/mmap_test.h | 30 ----------- 5 files changed, 41 insertions(+), 105 deletions(-)