On Fri, Sep 6, 2024 at 5:16 AM Charlie Jenkins <char...@rivosinc.com> wrote:
>
> Some applications rely on placing data in free bits addresses allocated
> by mmap. Various architectures (eg. x86, arm64, powerpc) restrict the
> address returned by mmap to be less than the 48-bit address space,
> unless the hint address uses more than 47 bits (the 48th bit is reserved
> for the kernel address space).
>
> The riscv architecture needs a way to similarly restrict the virtual
> address space. On the riscv port of OpenJDK an error is thrown if
> attempted to run on the 57-bit address space, called sv57 [1].  golang
> has a comment that sv57 support is not complete, but there are some
> workarounds to get it to mostly work [2].
>
> These applications work on x86 because x86 does an implicit 47-bit
> restriction of mmap() address that contain a hint address that is less
> than 48 bits.
>
> Instead of implicitly restricting the address space on riscv (or any
> current/future architecture), provide a flag to the personality syscall
> that can be used to ensure an application works in any arbitrary VA
> space. A similar feature has already been implemented by the personality
> syscall in ADDR_LIMIT_32BIT.
>
> This flag will also allow seemless compatibility between all
> architectures, so applications like Go and OpenJDK that use bits in a
> virtual address can request the exact number of bits they need in a
> generic way. The flag can be checked inside of vm_unmapped_area() so
> that this flag does not have to be handled individually by each
> architecture.
Acked-by: Guo Ren <guo...@kernel.org>

Sv57's pain finds its cure in this antidote.

>
> Link:
> https://github.com/openjdk/jdk/blob/f080b4bb8a75284db1b6037f8c00ef3b1ef1add1/src/hotspot/cpu/riscv/vm_version_riscv.cpp#L79
> [1]
> Link:
> https://github.com/golang/go/blob/9e8ea567c838574a0f14538c0bbbd83c3215aa55/src/runtime/tagptr_64bit.go#L47
> [2]
>
> To: Arnd Bergmann <a...@arndb.de>
> To: Richard Henderson <richard.hender...@linaro.org>
> To: Ivan Kokshaysky <i...@jurassic.park.msu.ru>
> To: Matt Turner <matts...@gmail.com>
> To: Vineet Gupta <vgu...@kernel.org>
> To: Russell King <li...@armlinux.org.uk>
> To: Guo Ren <guo...@kernel.org>
> To: Huacai Chen <chenhua...@kernel.org>
> To: WANG Xuerui <ker...@xen0n.name>
> To: Thomas Bogendoerfer <tsbog...@alpha.franken.de>
> To: James E.J. Bottomley <james.bottom...@hansenpartnership.com>
> To: Helge Deller <del...@gmx.de>
> To: Michael Ellerman <m...@ellerman.id.au>
> To: Nicholas Piggin <npig...@gmail.com>
> To: Christophe Leroy <christophe.le...@csgroup.eu>
> To: Naveen N Rao <nav...@kernel.org>
> To: Alexander Gordeev <agord...@linux.ibm.com>
> To: Gerald Schaefer <gerald.schae...@linux.ibm.com>
> To: Heiko Carstens <h...@linux.ibm.com>
> To: Vasily Gorbik <g...@linux.ibm.com>
> To: Christian Borntraeger <borntrae...@linux.ibm.com>
> To: Sven Schnelle <sv...@linux.ibm.com>
> To: Yoshinori Sato <ys...@users.sourceforge.jp>
> To: Rich Felker <dal...@libc.org>
> To: John Paul Adrian Glaubitz <glaub...@physik.fu-berlin.de>
> To: David S. Miller <da...@davemloft.net>
> To: Andreas Larsson <andr...@gaisler.com>
> To: Thomas Gleixner <t...@linutronix.de>
> To: Ingo Molnar <mi...@redhat.com>
> To: Borislav Petkov <b...@alien8.de>
> To: Dave Hansen <dave.han...@linux.intel.com>
> To: x...@kernel.org
> To: H. Peter Anvin <h...@zytor.com>
> To: Andy Lutomirski <l...@kernel.org>
> To: Peter Zijlstra <pet...@infradead.org>
> To: Muchun Song <muchun.s...@linux.dev>
> To: Andrew Morton <a...@linux-foundation.org>
> To: Liam R. Howlett <liam.howl...@oracle.com>
> To: Vlastimil Babka <vba...@suse.cz>
> To: Lorenzo Stoakes <lorenzo.stoa...@oracle.com>
> To: Shuah Khan <sh...@kernel.org>
> To: Christoph Hellwig <h...@infradead.org>
> To: Michal Hocko <mho...@suse.com>
> To: "Kirill A. Shutemov" <kir...@shutemov.name>
> To: Chris Torek <chris.to...@gmail.com>
> Cc: linux-a...@vger.kernel.org
> Cc: linux-ker...@vger.kernel.org
> Cc: linux-al...@vger.kernel.org
> Cc: linux-snps-...@lists.infradead.org
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: linux-c...@vger.kernel.org
> Cc: loonga...@lists.linux.dev
> Cc: linux-m...@vger.kernel.org
> Cc: linux-par...@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-s...@vger.kernel.org
> Cc: linux...@vger.kernel.org
> Cc: sparcli...@vger.kernel.org
> Cc: linux...@kvack.org
> Cc: linux-kselft...@vger.kernel.org
> Cc: linux-abi-de...@lists.sourceforge.net
> Signed-off-by: Charlie Jenkins <char...@rivosinc.com>
>
> Changes in v2:
> - Added much greater detail to cover letter
> - Removed all code that touched architecture specific code and was able
>   to factor this out into all generic functions, except for flags that
>   needed to be added to vm_unmapped_area_info
> - Made this an RFC since I have only tested it on riscv and x86
> - Link to v1: 
> https://lore.kernel.org/r/20240827-patches-below_hint_mmap-v1-0-46ff2eb90...@rivosinc.com
>
> Changes in v3:
> - Use a personality flag instead of an mmap flag
> - Link to v2: 
> https://lore.kernel.org/r/20240829-patches-below_hint_mmap-v2-0-638a28d9e...@rivosinc.com
>
> ---
> Charlie Jenkins (2):
>       mm: Add personality flag to limit address to 47 bits
>       selftests/mm: Create ADDR_LIMIT_47BIT test
>
>  include/uapi/linux/personality.h                   |  1 +
>  mm/mmap.c                                          |  3 ++
>  tools/testing/selftests/mm/.gitignore              |  1 +
>  tools/testing/selftests/mm/Makefile                |  1 +
>  tools/testing/selftests/mm/map_47bit_personality.c | 34 
> ++++++++++++++++++++++
>  5 files changed, 40 insertions(+)
> ---
> base-commit: 5be63fc19fcaa4c236b307420483578a56986a37
> change-id: 20240827-patches-below_hint_mmap-b13d79ae1c55
> --
> - Charlie
>


-- 
Best Regards
 Guo Ren

Reply via email to